Changeset 2287 in lmdz_wrf for trunk/tools
- Timestamp:
- Jan 24, 2019, 5:10:19 PM (7 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var.py
r2272 r2287 69 69 ## e.g. # nc_var.py -o area_weighted -f 'reference_data.nc:lon;lon;lon_bnds;-1;lat;lat;lat_bnds;-1,get_data.nc:lon;lon;lon_bnds;-1;lat;lat;lat_bnds;-1' -S 'yes:min,max,mean,stddev,count' -v ct_values,xband_values,box_values,mosaic_values 70 70 ## e.g. # nc_var.py -o area_weighted -f '/media/lluis/ExtDiskC_ext4/bkup/llamp/estudios/dominios/SA150k/geo_em.d01.nc:west_east;XLONG_M;WRFxbnds;-1;south_north;XLAT_M;WRFybnds;-1,/media/lluis/ExtDiskC_ext4/bkup/llamp/estudios/dominios/SA50k/geo_em.d01.nc:west_east;XLONG_M;WRFxbnds;-1;south_north;XLAT_M;WRFybnds;-1' -S 'no:mean' -v HGT_M 71 ## e.g. # nc_var.py -o compute_slices_stats_areaweighted -S 'XLONG,-74.,-36.4,4.;XLAT,-63.,19.,4.;HGT,500.,7000.,500.@Time|WRFtime:west_east|XLONG:south_north|XLAT@Time@south_north|lat_bnds,west_east|lon_bnds@Time' -f /home/lluis/PY/wrfout_d01_1995-01-01_00:00:00 -V T2 71 72 72 73 from optparse import OptionParser … … 100 101 # compute_slices_stats: Function to compute stats of variables of a file splitting variables by 101 102 # slices along sets of ranges for a series of variables 103 # compute_slices_stats_areaweighted: Function to compute stats of variables of a file splitting variables by 104 # slices along sets of ranges for a series of variables weighting by the area 105 # covered by each grid (defined as polygon) within the slice 102 106 # compute_slice2Dstats: Function to compute stats of variables of a file following slices along 2 variables 103 107 # compute_tevolboxtraj: Function to compute tevolboxtraj: temporal evolution at a given point along a box following a trajectory … … 219 223 'compute_opersvarsfiles', \ 220 224 'compute_opervaralltime', 'compute_opervartimes', 'compute_slices_stats', \ 221 'compute_slice 2Dstats',\225 'compute_slices_stats_areaweighted', 'compute_slice2Dstats', \ 222 226 'compute_tevolboxtraj', \ 223 227 'computevar_model', 'curve_section', 'DatesFiles', \ … … 364 368 elif oper == 'compute_slices_stats': 365 369 ncvar.compute_slices_stats(opts.values, opts.ncfile, opts.varname) 370 elif oper == 'compute_slices_stats_areaweighted': 371 ncvar.compute_slices_stats_areaweighted(opts.values, opts.ncfile, opts.varname) 366 372 elif oper == 'compute_slice2Dstats': 367 373 ncvar.compute_slice2Dstats(opts.values, opts.ncfile, opts.varname) -
trunk/tools/nc_var_tools.py
r2284 r2287 52 52 # slices along sets of ranges for a series of variables 53 53 # compute_slice2Dstats: Function to compute stats of variables of a file following slices along 2 variables 54 # compute_slices_stats: Function to compute stats of variables of a file splitting variables by 55 # slices along sets of ranges for a series of variables 56 # compute_slices_stats_areaweighted: Function to compute stats of variables of a file splitting variables by 57 # slices along sets of ranges for a series of variables weighting by the area 58 # covered by each grid (defined as polygon) within the slice 54 59 # computevar_model: Function to provide the way to compute a CF-variable providing its name 55 60 # compute_tevolboxtraj: Function to compute tevolboxtraj: temporal evolution at a given point along a box following a trajectory … … 27898 27903 newvar[:] = slcvalsc[:] 27899 27904 basicvardef(newvar, 'slice_'+varn, 'slices for variable ' + varn, vu) 27905 onewnc.sync() 27900 27906 27901 27907 newvar = onewnc.createVariable('slice_'+varn+'_bnds', 'f', ('slice_'+varn, \ … … 27904 27910 basicvardef(newvar, 'slice_'+varn+'_bnds', 'boundaries of slices for ' + \ 27905 27911 'variable ' + varn, vu) 27912 onewnc.sync() 27906 27913 27907 27914 slcdims = ['slice_'+varn] + rmdims … … 27920 27927 vardimbndslice = {} 27921 27928 27929 print 'Lluis slcvarns:', slcvarns 27930 newslcvarns = [] 27922 27931 for varn in slcvarns: 27923 27932 ovar = onc.variables[varn] 27924 27933 vu = ovar.units 27925 27934 dimnv = list(ovar.dimensions) 27926 dv = ovar[:] 27927 27928 print 'varn:', varn, ' dims:', dimnv 27935 27936 # Removing undesired dimensions from slicing variable 27937 if sliceremovedim is not None: 27938 print infmsg 27939 print ' ' + fname + ": removing dimension '", sliceremovedim, \ 27940 "' from slice ..." 27941 dv, rmdims, rmshape = ovar_reducedims(ovar, sliceremovedim) 27942 else: 27943 dv = ovar[:] 27944 rmdims = dimnv 27945 rmshape = list(ovar.shape) 27929 27946 27930 27947 dimbnds = [] 27931 for dn in dimnv:27948 for dn in rmdims: 27932 27949 if slicebndsdim.has_key(dn): dimbnds.append(dn) 27933 27950 … … 27953 27970 ovarbnds = onc.variables[slicebndsdim[dn]] 27954 27971 27955 # Removing undesired dimensions from slicing variable27972 # Removing undesired dimensions from bounds slicing variable 27956 27973 if sliceremovedim is not None: 27957 27974 varv, rmdims, rmshape = ovar_reducedims(ovarbnds, sliceremovedim) … … 27962 27979 27963 27980 dimvbnds[dn] = varv 27964 dimvdnds[dn] = rmdims 27965 dimvsnds[dn] = rmshape 27966 27967 if gen.searchInlist(slcvarns, dn) and not vardimbndslice.has_key(dn): 27981 dimdbnds[dn] = rmdims 27982 dimsbnds[dn] = rmshape 27983 27984 dn = '_'.join(slicebndsdim) 27985 if not gen.searchInlist(slcvarns, dn) and not \ 27986 gen.searchInlist(newslcvarns, dn) and not vardimbndslice.has_key(dn): 27968 27987 if len(dv.shape) == 1: 27969 27988 print infmsg … … 28012 28031 dxget = dd 28013 28032 dyget = 1 28033 dvref = 4 28034 dvget = 4 28035 28036 # Values for file 28037 dref = [dn] 28038 sref = [dxref] 28039 dget = [dn] 28040 sget = [dxget] 28014 28041 28015 28042 elif len(dv.shape) == 2: 28016 xdim = rmdims[1] 28017 ydim = rmdims[0] 28018 getdims = dimvsnds[xdim] 28043 print " 2D slicing bounded variable: '" + varn + "': ", dv.shape 28044 xdim = rmdims[2] 28045 ydim = rmdims[1] 28046 getdims = dimdbnds[xdim] 28047 28019 28048 # ref values 28020 if slicesinf.has_key( getdims[1]):28021 varslcv = slicesinf[ getdims[1]]28049 if slicesinf.has_key(dimvars[getdims[2]]): 28050 varslcv = slicesinf[dimvars[getdims[2]]] 28022 28051 dxref = varslcv[0] 28023 reflon1D = varslcv[4] 28052 reflon1D = varslcv[3] 28053 refblon1D = varslcv[4] 28024 28054 else: 28025 28055 print infmsg 28026 28056 print ' ' + fname + ": 2D slicing varibale '" + varn + \ 28027 "' with x-dimension '" + getdims[1] + "' without related "+\ 28028 " slicing-variable !!" 28029 quit(-1) 28030 if slicesinf.has_key(getdims[0]): 28031 varslcv = slicesinf[getdims[0]] 28057 "' with x-dimension '" +dimvars[getdims[2]]+ "' without "+ \ 28058 "related slicing-variable !!" 28059 oxvar = onc.variables[dimvars[getdims[2]]] 28060 28061 # Removing undesired dimensions from bounds slicing variable 28062 if sliceremovedim is not None: 28063 xvar, rmd, rms = ovar_reducedims(oxvar, sliceremovedim) 28064 else: 28065 xvar = oxvar[:] 28066 rmd = oxvar.dimensions 28067 rms = list(oxvar.shape) 28068 28069 xn = np.min(xvar) 28070 xx = np.max(xvar) 28071 dxref = 1 28072 reflon1D = xvar 28073 refblon1D = np.array([xn, xx]) 28074 print ' using variable extremes instead: ',reflon1D 28075 28076 if slicesinf.has_key(dimvars[getdims[1]]): 28077 varslcv = slicesinf[dimvars[getdims[1]]] 28032 28078 dyref = varslcv[0] 28033 reflat1D = varslcv[4] 28079 reflat1D = varslcv[3] 28080 refblat1D = varslcv[4] 28034 28081 else: 28035 28082 print infmsg 28036 28083 print ' ' + fname + ": 2D slicing varibale '" + varn + \ 28037 "' with y-dimension '" + getdims[0] + "' without related "+\ 28038 " slicing-variable !!" 28039 quit(-1) 28084 "' with y-dimension '" +dimvars[getdims[1]]+ "' without " +\ 28085 "related slicing-variable !!" 28086 oyvar = onc.variables[dimvars[getdims[1]]] 28087 28088 # Removing undesired dimensions from bounds slicing variable 28089 if sliceremovedim is not None: 28090 yvar, rmd, rms = ovar_reducedims(oyvar, sliceremovedim) 28091 else: 28092 yvar = oyvar[:] 28093 rmd = oyvar.dimensions 28094 rms = list(oxvar.shape) 28095 28096 yn = np.min(yvar) 28097 yx = np.max(yvar) 28098 dyref = 1 28099 reflat1D = yvar 28100 refblat1D = np.array([yn, yx]) 28101 print ' using variable extremes instead: ',reflat1D 28040 28102 # Slicing following boundaries, dimensions are 1D thus expand to 28041 28103 # 2D filling as NW, NE, SE, SW … … 28043 28105 reflon = np.zeros((dyref,dxref), dtype=np.float) 28044 28106 reflat = np.zeros((dyref,dxref), dtype=np.float) 28045 xslice2D = np.zeros((4,dyref,dxref), dtype=np.float) 28046 yslice2D = np.zeros((4,dyref,dxref), dtype=np.float) 28107 dvref = 4 28108 xslice2D = np.zeros((dvref,dyref,dxref), dtype=np.float) 28109 yslice2D = np.zeros((dvref,dyref,dxref), dtype=np.float) 28047 28110 for j in range(dyref): 28048 28111 for i in range(dxref): 28049 reflon[j,i] = slcvalsc28050 reflat[j,i] = slcvalsc28051 xslice2D[0,j,i] = ref lon1D[i,0]28052 xslice2D[1,j,i] = ref lon1D[i,1]28053 xslice2D[2,j,i] = ref lon1D[i,1]28054 xslice2D[3,j,i] = ref lon1D[i,0]28055 yslice2D[0,j,i] = ref lat1D[j,1]28056 yslice2D[1,j,i] = ref lat1D[j,1]28057 yslice2D[2,j,i] = ref lat1D[j,0]28058 yslice2D[3,j,i] = ref lat1D[j,0]28112 reflon[j,i] = reflon1D[i] 28113 reflat[j,i] = reflat1D[j] 28114 xslice2D[0,j,i] = refblon1D[i,0] 28115 xslice2D[1,j,i] = refblon1D[i,1] 28116 xslice2D[2,j,i] = refblon1D[i,1] 28117 xslice2D[3,j,i] = refblon1D[i,0] 28118 yslice2D[0,j,i] = refblat1D[j,1] 28119 yslice2D[1,j,i] = refblat1D[j,1] 28120 yslice2D[2,j,i] = refblat1D[j,0] 28121 yslice2D[3,j,i] = refblat1D[j,0] 28059 28122 28060 28123 # get values 28061 if dimvars.has_key(getdims[1]): getlon = dimvars[getdims[1]] 28124 if dimvars.has_key(getdims[2]): 28125 ogetlon = onc.variables[dimvars[getdims[2]]] 28126 # Removing undesired dimensions from bounds slicing variable 28127 if sliceremovedim is not None: 28128 getlon, rmd, rms = ovar_reducedims(ogetlon, sliceremovedim) 28129 else: 28130 getlon = ogetlon[:] 28131 rmd = ogetlon.dimensions 28132 rms = list(ogetlon.shape) 28062 28133 else: 28063 28134 print infmsg 28064 print ' ' + fname + ": 2D slicingvaribale '" + varn + \28065 "' with x-dimension '" + getdims[ 1] + "' without related "+\28135 print ' ' + fname + ": 2D bounded varibale '" + varn + \ 28136 "' with x-dimension '" + getdims[2] + "' without related "+\ 28066 28137 " dimension-variable !!" 28067 28138 quit(-1) 28068 if dimvars.has_key(getdims[0]): getlat = dimvars[getdims[0]] 28139 if dimvars.has_key(getdims[1]): 28140 ogetlat = onc.variables[dimvars[getdims[1]]] 28141 # Removing undesired dimensions from bounds slicing variable 28142 if sliceremovedim is not None: 28143 getlat, rmd, rms = ovar_reducedims(ogetlat, sliceremovedim) 28144 else: 28145 getlat = ogetlat[:] 28146 rmd = ogetlat.dimensions 28147 rms = list(ogetlat.shape) 28069 28148 else: 28070 28149 print infmsg 28071 print ' ' + fname + ": 2D slicingvaribale '" + varn + \28072 "' with y-dimension '" + getdims[ 0] + "' without related "+\28150 print ' ' + fname + ": 2D bounded varibale '" + varn + \ 28151 "' with y-dimension '" + getdims[1] + "' without related "+\ 28073 28152 " dimension-variable !!" 28074 28153 quit(-1) 28075 28154 28076 getshape = dimvsnds[xdim] 28077 dxget = getshape[1] 28078 dyget = getshape[0] 28155 getshape = dimsbnds[xdim] 28156 dxget = getshape[2] 28157 dyget = getshape[1] 28158 dvget = getshape[0] 28079 28159 xdimvarbnds2D = dimvbnds[xdim] 28080 28160 ydimvarbnds2D = dimvbnds[ydim] 28081 28161 28082 reflon = np.zeros((1,Nslices), dtype=np.float) 28083 reflon[0,:] = slcvalsc 28084 reflat = np.zeros((1,Nslices), dtype=np.float) 28085 xslice2D = np.zeros((4,1,Nslices), dtype=np.float) 28086 xslice2D[0,0,:] = slcvals[:,1] 28087 xslice2D[1,0,:] = slcvals[:,1] 28088 xslice2D[2,0,:] = slcvals[:,0] 28089 xslice2D[3,0,:] = slcvals[:,0] 28090 yslice2D = np.zeros((4,1,Nslices), dtype=np.float) 28091 yslice2D[0,0,:] = -1. 28092 yslice2D[1,0,:] = 1. 28093 yslice2D[2,0,:] = 1. 28094 yslice2D[3,0,:] = -1. 28095 28096 dd = len(onc.dimensions[dn]) 28097 getlon = np.zeros((1,dd), dtype=np.float) 28098 getlon[0,:] = dv 28099 getlat = np.zeros((1,dd), dtype=np.float) 28100 xdimvarbnds2D = np.zeros((4,1,dd), dtype=np.float) 28101 xdimvarbnds2D[0,0,:] = ovarbnds[:,1] 28102 xdimvarbnds2D[1,0,:] = ovarbnds[:,1] 28103 xdimvarbnds2D[2,0,:] = ovarbnds[:,0] 28104 xdimvarbnds2D[3,0,:] = ovarbnds[:,0] 28105 ydimvarbnds2D = np.zeros((4,1,dd), dtype=np.float) 28106 ydimvarbnds2D[0,0,:] = -1. 28107 ydimvarbnds2D[1,0,:] = 1. 28108 ydimvarbnds2D[2,0,:] = 1. 28109 ydimvarbnds2D[3,0,:] = -1. 28110 28111 dxref = Nslices 28112 dyref = 1 28113 dxget = dd 28114 dyget = 1 28115 28116 dimvar2D.append(dn) 28117 continue 28162 # Values for file 28163 dref = [dimvars[getdims[1]], dimvars[getdims[2]]] 28164 sref = [dyref, dxref] 28165 dget = [getdims[1], getdims[2]] 28166 sget = [dyget, dxget] 28167 28118 28168 # Issue with WRF's XLONG(time, sout_north, west_east) .... 28119 28169 else: … … 28138 28188 xcbvals=getlont, ycbvals=getlatt, xbbvals=getvarxbndst, \ 28139 28189 ybbvals=getvarybndst, strict=False, dxa=dxref, dya=dyref, \ 28140 navertexmax= 4, dxb=dxget, dyb=dyget, dxyb=dxget*dyget,\28141 nbvertexmax= 4)28190 navertexmax=dvref, dxb=dxget, dyb=dyget, dxyb=dxget*dyget, \ 28191 nbvertexmax=dvget) 28142 28192 28143 28193 Ngridsin = Ngridsint.transpose() … … 28147 28197 Ngridsinmax = np.max(Ngridsin) 28148 28198 else: 28199 # Here is only done by 1D variables !!! 28149 28200 print infmsg 28150 28201 print ' ' + fname + ": slicing variable '" + dn + "' without bounds !!" … … 28167 28218 for islc in range(Nslices): 28168 28219 unmasked = slcvar[islc,] 28169 unma = np.where(unmasked, 0., 1 .)28220 unma = np.where(unmasked, 0., 1) 28170 28221 unmat = unma.transpose() 28171 28222 if (len(unma.shape) == 1): 28172 indices = gen.multi_index_mat(unmat,1 .)28223 indices = gen.multi_index_mat(unmat,1) 28173 28224 Nt = len(indices) 28174 28225 elif (len(unma.shape) == 2): 28175 28226 drng = unma.shape[0]*unma.shape[1] 28176 Nt,indices=fsci.module_scientific.multi_index_mat2d rk(d12=drng,\28177 mat=unmat, value=1 ., d1=unma.shape[1], d2=unma.shape[0])28227 Nt,indices=fsci.module_scientific.multi_index_mat2di(d12=drng, \ 28228 mat=unmat, value=1, d1=unma.shape[1], d2=unma.shape[0]) 28178 28229 elif (len(unma.shape) == 3): 28179 28230 drng = unma.shape[0]*unma.shape[1]*unma.shape[2] 28180 Nt,indices=fsci.module_scientific.multi_index_mat3d rk(d123=drng,\28181 mat=unmat, value=1 ., d1=unma.shape[2], d2=unma.shape[1],\28231 Nt,indices=fsci.module_scientific.multi_index_mat3di(d123=drng, \ 28232 mat=unmat, value=1, d1=unma.shape[2], d2=unma.shape[1], \ 28182 28233 d3=unma.shape[0]) 28183 28234 elif (len(unma.shape) == 4): 28184 28235 drng = unma.shape[0]*unma.shape[1]*unma.shape[2]*unma.shape[3] 28185 Nt,indices=fsci.module_scientific.multi_index_mat4d rk(d1234=drng,\28186 mat=unmat, value=1 ., d1=unma.shape[3], d2=unma.shape[2],\28236 Nt,indices=fsci.module_scientific.multi_index_mat4di(d1234=drng, \ 28237 mat=unmat, value=1, d1=unma.shape[3], d2=unma.shape[2], \ 28187 28238 d3=unma.shape[1], d4=unma.shape[0]) 28188 28239 else: 28189 28240 rS = str(len(unma.shape)) 28190 28241 print errormsg 28191 print ' ' + fname + ": 'multi_index_mat" + rS + "d rk' not ready !!"28242 print ' ' + fname + ": 'multi_index_mat" + rS + "di' not ready !!" 28192 28243 quit(-1) 28193 28244 … … 28199 28250 28200 28251 # Let's avoid memory issues... 28252 newslcvarns.append(dn) 28201 28253 lvalues = [Ngridsin, gridsin, percens] 28202 28254 vardimbndslice[dn] = lvalues 28203 28204 # Writting it to the file variables space-weight 28205 if not gen.searchInlist(onewnc.dimensions, dn+'slice'): 28206 newdim = onewnc.createDimension(dn+'slice',Nslices) 28207 newdim = onewnc.createDimension(dn+'bnds',4) 28208 newdim = onewnc.createDimension(dn+'gridin',Ngridsinmax) 28209 if not gen.searchInlist(onewnc.dimensions, 'coord'): 28210 newdim = onewnc.createDimension('coord',2) 28211 28212 newvar = onewnc.createVariable(dn+'Ngrid','i',(dn+'slice')) 28213 28214 newvar[:] = Ngridsin[:] 28215 basicvardef(newvar, dn+'Ngrid', "number of grids cells from " + \ 28216 ".get. laying within .ref.", '-') 28217 newvar.setncattr('coordinates',dn) 28218 28219 innewvar = onewnc.createVariable(dn+'gridin', 'i', ('coord', \ 28220 dn+'gridin',dn+'slice')) 28221 basicvardef(innewvar, dn+'gridin', "coordinates of the grids " + \ 28222 "cells from .get. laying within .ref.",'-') 28223 innewvar.setncattr('coordinates',dn+'slice') 28255 if not onewnc.variables.has_key(dn+'gridin'): 28256 28257 # Writting it to the file variables space-weight 28258 Srgrid = [] 28259 Scgrid = [] 28260 Sigrid = ['coord', dn+'gridin'] 28261 Spgrid = [dn+'gridin'] 28262 iid = 0 28263 for dnn in dref: 28264 if not gen.searchInlist(onewnc.dimensions, 'slice_' + dnn): 28265 newdim = onewnc.createDimension('slice_' + dnn,sref[iid]) 28266 28267 if not gen.searchInlist(onewnc.dimensions, dnn+'bnds'): 28268 newdim = onewnc.createDimension(dnn+'bnds',4) 28269 Srgrid.append('slice_' + dnn) 28270 Scgrid.append('slice_' + dnn) 28271 Sigrid.append('slice_' + dnn) 28272 Spgrid.append('slice_' + dnn) 28273 iid = iid + 1 28274 if not gen.searchInlist(onewnc.dimensions, dn+'gridn'): 28275 newdim = onewnc.createDimension(dn+'gridin',Ngridsinmax) 28276 if not gen.searchInlist(onewnc.dimensions, 'coord'): 28277 newdim = onewnc.createDimension('coord',2) 28278 28279 newvar = onewnc.createVariable(dn+'Ngrid','i', tuple(Srgrid)) 28280 newvar[:] = Ngridsin[:] 28281 basicvardef(newvar, dn+'Ngrid', "number of grids cells from " + \ 28282 ".get. laying within .ref.", '-') 28283 newvar.setncattr('coordinates',' '.join(Scgrid[::-1])) 28284 28285 innewvar = onewnc.createVariable(dn+'gridin', 'i', tuple(Sigrid)) 28286 basicvardef(innewvar, dn+'gridin', "coordinates of the grids " + \ 28287 "cells from .get. laying within .ref.",'-') 28288 innewvar.setncattr('coordinates',' '.join(Scgrid[::-1])) 28224 28289 28225 pnewvar = onewnc.createVariable(dn+'gridpercen','f',(dn+'gridin', \ 28226 dn+'slice')) 28227 basicvardef(pnewvar ,dn+'gridpercen', "percentages of the " + \ 28228 "grids cells from .get. laying within .ref.", '1') 28229 pnewvar.setncattr('coordinates',dn) 28230 for j in range(1): 28231 for i in range(Nslices): 28232 innewvar[:,0:Ngridsin[j,i],i] = gridsin[:,0:Ngridsin[j,i],j,i] 28233 pnewvar[0:Ngridsin[j,i],i]= percens[0:Ngridsin[j,i],j,i] 28234 onewnc.sync() 28235 28236 # # Slicing 2D dimension-variables 28237 # if len(dimvar2D) != 0: 28238 # ovar = onc.variables[varn] 28239 # vu = ovar.units 28240 # dimnv = list(ovar.dimensions) 28241 28242 # varbndns = [] 28243 # dimvals = {} 28244 # dimslcs = {} 28245 # for dn in dimnv: 28246 # # Looking for boundaries 28247 # varbnds = [] 28248 # dn = varn 28249 # vdarattrs = ovar.ncattrs() 28250 # dv = ovar[:] 28251 28252 # if gen.searchInlist(vdarattrs,'bounds'): 28253 # boundsv = ovar.getncattr('bounds') 28254 # print ' ' + infmsg 28255 # print ' ' +fname+ ": slicing variable '" +dn+ "' with bounds !!" 28256 # print ' bounds found:', boundsv 28257 # print ' getting them to retrieve the slices' 28258 # bndvarns = boundsv.replace(' ','').split(',') 28259 28260 # for vn in bndvarns: 28261 # if not gen.searchInlist(varbnds, vn): varbnds.append(vn) 28262 28263 # # Slicing following boundaries 28264 # if gen.searchInlist(slcvarns, dn) and not vardimbndslice.has_key(dn): 28265 # print infmsg 28266 # print ' ' + fname + ": slicing dimension '" + dn + "' ... " 28267 # varslcv = slicesinf[dn] 28268 # Nslices = varslcv[0] 28269 # ovardims = varslcv[1] 28270 # slcvar = varslcv[2] 28271 # slcvalsc = varslcv[3] 28272 # slcvals = varslcv[4] 28273 # dimslcs[dn] = slcvals 28274 28275 # if len(varbndns) != 0: 28276 # for boundsv in varbnds: 28277 # ovarbnds = onc.variables[boundsv] 28278 # varbnds = ovarbnds[:] 28279 # dimvals[ 28280 28281 28290 pnewvar = onewnc.createVariable(dn+'gridpercen','f',tuple(Spgrid)) 28291 basicvardef(pnewvar ,dn+'gridpercen', "percentages of the " + \ 28292 "grids cells from .get. laying within .ref.", '1') 28293 pnewvar.setncattr('coordinates',' '.join(Scgrid[::-1])) 28294 28295 if len(dv.shape) == 1: 28296 for j in range(1): 28297 for i in range(Nslices): 28298 innewvar[:,0:Ngridsin[j,i],i] = \ 28299 gridsin[:,0:Ngridsin[j,i],j,i] 28300 pnewvar[0:Ngridsin[j,i],i]= percens[0:Ngridsin[j,i],j,i] 28301 elif len(dv.shape) == 2: 28302 for j in range(dyref): 28303 for i in range(dxref): 28304 innewvar[:,0:Ngridsin[j,i],j,i] = \ 28305 gridsin[:,0:Ngridsin[j,i],j,i] 28306 pnewvar[0:Ngridsin[j,i],j,i]= percens[0:Ngridsin[j,i],j,i] 28307 28308 onewnc.sync() 28309 28310 slcvarns = slcvarns + newslcvarns 28282 28311 28283 28312 for varn in varns: … … 28584 28613 return 28585 28614 28586 #values='lon,286.,323.6,4.;lat,-63.,19.,4.;orog, 250.,7000.,500.@time|time:lon|lon:lat|lat@time'28615 #values='lon,286.,323.6,4.;lat,-63.,19.,4.;orog,500.,7000.,500.@time|time:lon|lon:lat|lat@time' 28587 28616 #compute_slices_stats_areaweighted(values, '/media/lluis/ExtDiskC_ext3/DATA/estudios/Andes/DATA/concatenated/historical/tasmin/tasmin_Amon_ACCESS1-0_historical_r1i1p1_185001-200512_Andes_19600101000000-19900101000000.nc', 'tasmin') 28588 values='XLONG,-74.,-36.4,4.;XLAT,-63.,19.,4.;HGT,250.,7000.,500.@Time|WRFtime:' + \28589 'west_east|XLONG:south_north|XLAT@Time@south_north|lat_bnds,west_east|lon_bnds@Time'28590 compute_slices_stats_areaweighted(values, '/home/lluis/PY/wrfout_d01_1995-01-01_00:00:00', 'T2')28617 #values='XLONG,-74.,-36.4,4.;XLAT,-63.,19.,4.;HGT,500.,7000.,500.@Time|WRFtime:' + \ 28618 # 'west_east|XLONG:south_north|XLAT@Time@south_north|lat_bnds,west_east|lon_bnds@Time' 28619 #compute_slices_stats_areaweighted(values, '/home/lluis/PY/wrfout_d01_1995-01-01_00:00:00', 'T2') 28591 28620 28592 28621 #quit()
Note: See TracChangeset
for help on using the changeset viewer.