Changeset 1176 in lmdz_wrf for trunk/tools/nc_var_tools.py
- Timestamp:
- Oct 11, 2016, 5:29:14 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r1173 r1176 15817 15817 projlatn = values.split(',')[4] 15818 15818 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,',') 15822 15822 15823 15823 inf = NetCDFFile(filen, 'r') … … 15855 15855 oprojlat = projf.variables[projlatn] 15856 15856 15857 i nlonvals0 = oinlon[:]15858 i nlatvals0 = oinlat[:]15857 ilonvals0 = oinlon[:] 15858 ilatvals0 = oinlat[:] 15859 15859 olonvals0 = oprojlon[:] 15860 15860 olatvals0 = oprojlat[:] … … 15862 15862 # Getting 2D longitudes and latitudes 15863 15863 ilonvals, ilatvals = gen.lonlat2D(ilonvals0, ilatvals0) 15864 olonvals, olatvals = gen.lonlat2D(olonvals0, olatvals0)15864 rlonvals, rlatvals = gen.lonlat2D(olonvals0, olatvals0) 15865 15865 15866 15866 if len(ilonvals.shape) != 2: … … 15876 15876 quit(-1) 15877 15877 15878 if len( olonvals.shape) != 2:15878 if len(rlonvals.shape) != 2: 15879 15879 print errormsg 15880 print ' ' + fname + ': wrong output longitude rank:', olonvals.shape, \15880 print ' ' + fname + ': wrong output longitude rank:', rlonvals.shape, \ 15881 15881 'it must be 2!!' 15882 15882 quit(-1) 15883 15883 15884 if len( olatvals.shape) != 2:15884 if len(rlatvals.shape) != 2: 15885 15885 print errormsg 15886 print ' ' + fname + ': wrong output latitude rank:', olatvals.shape, \15886 print ' ' + fname + ': wrong output latitude rank:', rlatvals.shape, \ 15887 15887 'it must be 2!!' 15888 15888 quit(-1) 15889 15889 15890 15890 for i in range(2): 15891 if ilonvals [i] != ilatvals[i]:15891 if ilonvals.shape[i] != ilatvals.shape[i]: 15892 15892 print errormsg 15893 15893 print ' ' + fname + ': dimension',i,'of input longitude:', ilonvals[i], \ 15894 15894 'differs from latitude:', ilatvals[i], 'they must be the same!!' 15895 15895 quit(-1) 15896 if rlonvals [i] != rlatvals[i]:15896 if rlonvals.shape[i] != rlatvals.shape[i]: 15897 15897 print errormsg 15898 15898 print ' ' + fname + ': dimension',i,'of output longitude:', ilonvals[i],\ … … 15957 15957 15958 15958 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) 15962 15962 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]) 15966 15966 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]) 15970 15971 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 d 5=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]) 15975 15976 else: 15976 15977 print errormsg … … 15979 15980 15980 15981 # 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: 15983 15985 if not gen.searchInlist(dimsfile, dimn): 15984 15986 odimn = inf.dimensions[dimn] … … 15987 15989 else: 15988 15990 newdim = onewnc.createDimension(dimn, len(odimn)) 15989 if not vardim sn.has_key(dimn):15991 if not vardimns.has_key(dimn): 15990 15992 print errormsg 15991 15993 print ' ' + fname + ": dimension '" + dimn + "' does not have "+\ 15992 15994 'assigned any variable !!' 15993 15995 print ' assigned pairs (via [dimvars]) _______' 15994 gen.print_dictionary(vardim sn)15996 gen.print_dictionary(vardimns) 15995 15997 quit(-1) 15996 15998 else: 15997 add_vars(inf,onewnc, vardimsn[dimn])15999 add_vars(inf,onewnc,[vardimns[dimn]]) 15998 16000 15999 16001 # Interpolated variable 16000 vardims = ovarin.dimensions()16002 vardims = list(ovarin.dimensions) 16001 16003 newvardims = gen.replace_list(vardims,inlonn,'lon') 16002 16004 newvardims = gen.replace_list(newvardims,inlatn,'lat') … … 16018 16020 16019 16021 # Global attributes 16020 add_globa lattrs(inf,onewnc,'all')16022 add_globattrs(inf,onewnc,'all') 16021 16023 onewnc.sync() 16022 16024 … … 17157 17159 17158 17160 ncvars = ncf.variables.keys() 17159 # CFing variables 'lon, lat'17161 print fname + '; Lluis ncvars:', ncvars 17160 17162 olon2 = ncf.variables['lon2'] 17161 17163 dimslon2 = olon2.dimensions … … 17167 17169 set_attribute(newvar,attrn,attrv) 17168 17170 17171 ncf.sync() 17172 ncf.sync() 17173 ncf.sync() 17174 ncf.sync() 17175 ncvars = ncf.variables.keys() 17169 17176 olat2 = ncf.variables['lat2'] 17170 17177 dimslat2 = olat2.dimensions 17178 print fname + '; Lluis ncvars after 1st:', ncvars, 'dimslat2:', dimslat2 17171 17179 newvar = ncf.createVariable('lat','f8',dimslat2) 17172 17180 newvar[:] = olat2[:]
Note: See TracChangeset
for help on using the changeset viewer.