Changeset 1176 in lmdz_wrf for trunk/tools/nc_var_tools.py


Ignore:
Timestamp:
Oct 11, 2016, 5:29:14 PM (8 years ago)
Author:
lfita
Message:

Fixing `reproject' and make it wrongly work

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/nc_var_tools.py

    r1173 r1176  
    1581715817    projlatn = values.split(',')[4]
    1581815818    kind = values.split(',')[5]
    15819     dimvars = gen.Str_list(values.split(',')[6],':')
    15820 
    15821     varns = gen.Str_list(variable,',')
     15819    dimvars = gen.str_list(values.split(',')[6],':')
     15820
     15821    varns = gen.str_list(variable,',')
    1582215822
    1582315823    inf = NetCDFFile(filen, 'r')
     
    1585515855    oprojlat = projf.variables[projlatn]
    1585615856
    15857     inlonvals0 = oinlon[:]
    15858     inlatvals0 = oinlat[:]
     15857    ilonvals0 = oinlon[:]
     15858    ilatvals0 = oinlat[:]
    1585915859    olonvals0 = oprojlon[:]
    1586015860    olatvals0 = oprojlat[:]
     
    1586215862    # Getting 2D longitudes and latitudes
    1586315863    ilonvals, ilatvals = gen.lonlat2D(ilonvals0, ilatvals0)
    15864     olonvals, olatvals = gen.lonlat2D(olonvals0, olatvals0)
     15864    rlonvals, rlatvals = gen.lonlat2D(olonvals0, olatvals0)
    1586515865
    1586615866    if len(ilonvals.shape) != 2:
     
    1587615876        quit(-1)
    1587715877
    15878     if len(olonvals.shape) != 2:
     15878    if len(rlonvals.shape) != 2:
    1587915879        print errormsg
    15880         print '  ' + fname + ': wrong output longitude rank:', olonvals.shape,       \
     15880        print '  ' + fname + ': wrong output longitude rank:', rlonvals.shape,       \
    1588115881          'it must be 2!!'
    1588215882        quit(-1)
    1588315883
    15884     if len(olatvals.shape) != 2:
     15884    if len(rlatvals.shape) != 2:
    1588515885        print errormsg
    15886         print '  ' + fname + ': wrong output latitude rank:', olatvals.shape,        \
     15886        print '  ' + fname + ': wrong output latitude rank:', rlatvals.shape,        \
    1588715887          'it must be 2!!'
    1588815888        quit(-1)
    1588915889
    1589015890    for i in range(2):
    15891         if ilonvals[i] != ilatvals[i]:
     15891        if ilonvals.shape[i] != ilatvals.shape[i]:
    1589215892            print errormsg
    1589315893            print '  ' + fname + ': dimension',i,'of input longitude:', ilonvals[i], \
    1589415894              'differs from latitude:', ilatvals[i], 'they must be the same!!'
    1589515895            quit(-1)
    15896         if rlonvals[i] != rlatvals[i]:
     15896        if rlonvals.shape[i] != rlatvals.shape[i]:
    1589715897            print errormsg
    1589815898            print '  ' + fname + ': dimension',i,'of output longitude:', ilonvals[i],\
     
    1595715957
    1595815958        if Nvarind == 2:
    15959             varout = fin.var2D_IntProj(var2Din=varint, inlonv=inlont, inlatv=inlatt, \
    15960               projlon=rlont, projlat=rlatt, intkind=kind, idimx=idx, idimy=idy,      \
    15961               pdimx=rdx, pdimy=rdy)
     15959            varout = fin.module_forinterpolate.var2d_intproj(var2din=varint,        \
     15960              inlonv=ilont, inlatv=ilatt, projlon=rlont, projlat=rlatt, intkind=kind,\
     15961              idimx=idx, idimy=idy, pdimx=rdx, pdimy=rdy)
    1596215962        elif Nvarind == 3:
    15963             varout = fin.var3D_IntProj(var3Din=varint, inlonv=inlont, inlatv=inlatt, \
    15964               projlon=rlont, projlat=rlatt, intkind=kind, idimx=idx, idimy=idy,      \
    15965               pdimx=rdx, pdimy=rdy, d3=varin.shape[0])
     15963            varout = fin.module_forinterpolate.var3d_intproj(var3din=varint,        \
     15964              inlonv=ilont, inlatv=ilatt, projlon=rlont, projlat=rlatt, intkind=kind,\
     15965              idimx=idx, idimy=idy, pdimx=rdx, pdimy=rdy, d3=varin.shape[0])
    1596615966        elif Nvarind == 4:
    15967             varout = fin.var4D_IntProj(var4Din=varint, inlonv=inlont, inlatv=inlatt, \
    15968               projlon=rlont, projlat=rlatt, intkind=kind, idimx=idx, idimy=idy,      \
    15969               pdimx=rdx, pdimy=rdy, d3=varin.shape[0], d4=varin.shape[1])
     15967            varout = fin.module_forinterpolate.var4d_intproj(var4din=varint,         \
     15968              inlonv=ilont, inlatv=ilatt, projlon=rlont, projlat=rlatt, intkind=kind,\
     15969              idimx=idx, idimy=idy, pdimx=rdx, pdimy=rdy, d3=varin.shape[0],         \
     15970              d4=varin.shape[1])
    1597015971        elif Nvarind == 5:
    15971             varout = fin.var4D_IntProj(var4Din=varint, inlonv=inlont, inlatv=inlatt, \
    15972               projlon=rlont, projlat=rlatt, intkind=kind, idimx=idx, idimy=idy,      \
    15973               pdimx=rdx, pdimy=rdy, d3=varin.shape[0], d4=varin.shape[1],            \
    15974               d5=varin.shape[2])
     15972            varout = fin.module_forinterpolate.var5d_intproj(var5din=varint,        \
     15973              inlonv=ilont, inlatv=ilatt, projlon=rlont, projlat=rlatt, intkind=kind,\
     15974              idimx=idx, idimy=idy, pdimx=rdx, pdimy=rdy, d3=varin.shape[0],         \
     15975              d4=varin.shape[1], d5=varin.shape[2])
    1597515976        else:
    1597615977            print errormsg
     
    1597915980   
    1598015981        # Variable's dimensions and their related variables
    15981         dimsfile = onewnc.dimensions()
    15982         for dimn in ovarin.dimensions():
     15982        vdims = list(ovarin.dimensions)
     15983        dimsfile = onewnc.dimensions.keys()
     15984        for dimn in vdims:
    1598315985            if not gen.searchInlist(dimsfile, dimn):
    1598415986                odimn = inf.dimensions[dimn]
     
    1598715989                else:
    1598815990                    newdim = onewnc.createDimension(dimn, len(odimn))
    15989                 if not vardimsn.has_key(dimn):
     15991                if not vardimns.has_key(dimn):
    1599015992                    print errormsg
    1599115993                    print '  ' + fname + ": dimension '" + dimn + "' does not have "+\
    1599215994                      'assigned any variable !!'
    1599315995                    print '    assigned pairs (via [dimvars]) _______'
    15994                     gen.print_dictionary(vardimsn)
     15996                    gen.print_dictionary(vardimns)
    1599515997                    quit(-1)
    1599615998                else:
    15997                     add_vars(inf,onewnc,vardimsn[dimn])
     15999                    add_vars(inf,onewnc,[vardimns[dimn]])
    1599816000
    1599916001        # Interpolated variable
    16000         vardims = ovarin.dimensions()
     16002        vardims = list(ovarin.dimensions)
    1600116003        newvardims = gen.replace_list(vardims,inlonn,'lon')
    1600216004        newvardims = gen.replace_list(newvardims,inlatn,'lat')
     
    1601816020
    1601916021    # Global attributes
    16020     add_globalattrs(inf,onewnc,'all')
     16022    add_globattrs(inf,onewnc,'all')
    1602116023    onewnc.sync()
    1602216024
     
    1715717159
    1715817160    ncvars = ncf.variables.keys()
    17159     # CFing variables 'lon, lat'
     17161    print fname + '; Lluis ncvars:', ncvars
    1716017162    olon2 = ncf.variables['lon2']
    1716117163    dimslon2 = olon2.dimensions
     
    1716717169        set_attribute(newvar,attrn,attrv)
    1716817170
     17171    ncf.sync()
     17172    ncf.sync()
     17173    ncf.sync()
     17174    ncf.sync()
     17175    ncvars = ncf.variables.keys()
    1716917176    olat2 = ncf.variables['lat2']
    1717017177    dimslat2 = olat2.dimensions
     17178    print fname + '; Lluis ncvars after 1st:', ncvars, 'dimslat2:', dimslat2
    1717117179    newvar = ncf.createVariable('lat','f8',dimslat2)
    1717217180    newvar[:] = olat2[:]
Note: See TracChangeset for help on using the changeset viewer.