Changeset 2194 in lmdz_wrf
- Timestamp:
- Oct 18, 2018, 3:52:29 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r2192 r2194 26234 26234 slcvar2[islc,] = ma.masked_inside(var2v, slices2[islc], slices2[islc+1]).mask 26235 26235 26236 # Looking for coincident dimensions 26237 for dn1 in ovar1.diensions: 26238 for dn2 in ovar1.diensions: 26239 print 'Hola' 26236 if variable == 'all': 26237 varns = onc.variables.keys() 26238 else: 26239 varns = gen.str_list(variable, ',') 26240 26241 for varn in varns: 26242 ovar = onc.variables[varn] 26243 varv = ovar[:] 26244 vdimns = list(ovar.dimensions) 26245 vshape = list(ovar.shape) 26246 26247 # mask1 in var slice 26248 NOTcoinc1 = list(set(ovar1.dimensions) - set(vdimns)) 26249 if len(NOTcoinc1) > 0: 26250 notcoincdim1 = {} 26251 for dn in NOTcoinc1: notcoincdim1[dn] = 0 26252 else: 26253 notcoincdim1 = None 26254 mask1varslice = [] 26255 for islc in range(Nslices1): 26256 varmask1 = gen.mat_dimreshape(list(ovar1.dimensions), slcvar1[islc,], \ 26257 vdimns, vshape, notcoincdim1) 26258 mask1varslice.append(varmask1) 26259 26260 # mask2 in var slice 26261 NOTcoinc2 = list(set(ovar2.dimensions) - set(vdimns)) 26262 if len(NOTcoinc2) > 0: 26263 notcoincdim2 = {} 26264 for dn in NOTcoinc2: notcoincdim2[dn] = 0 26265 else: 26266 notcoincdim2 = None 26267 mask2varslice = [] 26268 for islc in range(Nslices2): 26269 varmask2 = gen.mat_dimreshape(list(ovar2.dimensions), slcvar2[islc,], \ 26270 vdimns, vshape, notcoincdim2) 26271 mask2varslice.append(varmask2) 26272 26273 newvarshape = [Nslices2, Nslices1] + vshape 26274 newvar2masked = np.zeros(tuple(newvarshape), dtype=ovar.dtype) 26275 26276 for islc2 in range(Nslices2): 26277 newmask2 = mask2varslice[islc2] 26278 for islc1 in range(Nslices1): 26279 newmask1 = mask1varslice[islc1] 26280 newmask = newmask2+newmask1 26281 26282 print ' Lluis shapes: newvar2masked', newvar2masked[islc2,islc1,].shape, 'varv:', varv[newmask].shape 26283 newvar2masked[islc2,islc1,] = ma.masked_array(varv, mask=~newmask) 26284 26285 onewnc = NetCDFFile(fname + '.nc', 'w') 26286 # dimensions 26287 newdim = onewnc.createDimension('lon', varv.shape[2]) 26288 newdim = onewnc.createDimension('lat', varv.shape[1]) 26289 newdim = onewnc.createDimension('time', None) 26290 newdim = onewnc.createDimension('slice_'+varn1, Nslices1) 26291 newdim = onewnc.createDimension('slice_'+varn2, Nslices2) 26292 26293 # variables 26294 newvar = onewnc.createVariable(varn, 'f', ('slice_'+varn2, 'slice_'+varn1, 'time', 'lat', 'lon')) 26295 newvar[:] = newvar2masked[:] 26296 26297 onewnc.sync() 26298 onewnc.close() 26299 26300 quit() 26240 26301 26241 26302 return 26242 26303 26243 #values='south_north,XLAT,-63.,19.,2.,all,HGT,250.,7000.,500.'26244 26245 #compute_slice2Dstats(values, '/home/lluis/PY/wrfout_d01_1995-01-01_00:00:00', 'T2')26304 values='south_north,XLAT,-63.,19.,2.,all,HGT,250.,7000.,500.' 26305 26306 compute_slice2Dstats(values, '/home/lluis/PY/wrfout_d01_1995-01-01_00:00:00', 'T2') 26246 26307 26247 26308 #quit()
Note: See TracChangeset
for help on using the changeset viewer.