Changeset 2197 in lmdz_wrf
- Timestamp:
- Oct 18, 2018, 10:20:14 PM (6 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var.py
r2195 r2197 63 63 ## e.g. # nc_var.py -o retrieve_stations -f wrfout_d01_1995-01-01_00:00:00 -S 'tmin_percentiles.nc:stname:None:stlon:stlat:None:nearest:west_east:XLONG:south_north:XLAT:HGT:Time:WRFtime' -v T2,QVAPOR 64 64 ## e.g. # nc_var.py -o compute_slice2Dstats -S 'XLAT,-63.,19.,2.,HGT,250.,7000.,500.,Time|Times:west_east|XLONG:south_north|XLAT' -f wrfout_d01_1995-01-01_00:00:00 -v T2,Q2 65 ## e.g. # nc_var.py -o same_deltasign -f wrfout_d01_1995-01-01_00:00:00 -S 'Time:0|south_north:60|west_east:-1' -v T2,Q2,XLAT,XLONG 65 66 66 67 from optparse import OptionParser … … 162 163 # remapnn: Function to remap to the nearest neightbor a variable using projection from another file 163 164 # retrieve_stations: Function to retrieve temporal values at given stations provided by a secondary netcdf 165 # same_deltasign: Function to determine if a given series of 1D values share the same sign of 166 # increase/decrease between consecutive values 164 167 # seasmean: Function to compute the seasonal mean of a variable 165 168 # sellonlatbox: Function to select a lotlan box from a data-set … … 225 228 'Partialmap_EntiremapFor', 'Partialmap_EntiremapForExact', \ 226 229 'pinterp', 'reconstruct_matrix_from_vector', 'remapnn', 'retrieve_stations', \ 227 'rm_FillValue', 230 'rm_FillValue', 'same_deltasign', \ 228 231 'seasmean', 'sellonlatbox', 'sellonlatlevbox', 'selvar', 'setvar_asciivalues', \ 229 232 'setvar_nc', 'sorttimesmat', 'spacemean', 'SpatialWeightedMean', \ … … 482 485 elif oper == 'rm_FillValue': 483 486 ncvar.rm_FillValue(opts.values, opts.ncfile, opts.varname) 487 elif oper == 'same_deltasign': 488 ncvar.same_deltasign(opts.values, opts.ncfile, opts.varname) 484 489 elif oper == 'seasmean': 485 490 ncvar.seasmean(timename, opts.ncfile, opts.varname) -
trunk/tools/nc_var_tools.py
r2196 r2197 138 138 # retrieve_stations: Function to retrieve temporal values at given stations provided by a secondary netcdf 139 139 # rm_FillValue: Operation to remove the _FillValue from a variable inside a netCDF file 140 # same_deltasign: Function to determine if a given series of 1D values share the same sign of 141 # increase/decrease between consecutive values 140 142 # seasmean: Function to compute the seasonal mean of a variable 141 143 # sellonlatbox: Function to select a lotlan box from a data-set … … 26401 26403 #compute_slice2Dstats(values, '/home/lluis/PY/wrfout_d01_1995-01-01_00:00:00', 'T2,Q2') 26402 26404 26403 def same_del at_sign(values, ncfile, variable):26405 def same_deltasign(values, ncfile, variable): 26404 26406 """ Function to determine if a given series of 1D values share the same sign of 26405 26407 increase/decrease between consecutive values 26406 values= [slicedims], values to the dimensions to perform a slice of variables 26407 [slicedims]: '|' separated list of [dimname]:[valdim] 26408 [valdim]: 26409 * [integer]: which value of the dimension 26410 * -1: all along the dimension 26411 * -9: last value of the dimension 26412 * [beg]@[end]@[freq] slice from [beg] to [end] every [freq] 26413 * NOTE, no dim name all the dimension size 26408 values= [slicedims] 26409 [slicedims]: '|' separated list of [dimname]:[valdim] with he values to the 26410 dimensions with which perform a slice of the variables 26411 [valdim]: 26412 * [integer]: which value of the dimension 26413 * -1: all along the dimension 26414 * -9: last value of the dimension 26415 * [beg]@[end]@[freq] slice from [beg] to [end] every [freq] 26416 * NOTE, no dim name all the dimension size 26414 26417 ncfile= netCDF file to use 26415 26418 variable: ',' list of variables ('all' for all variables) 26416 26419 """ 26417 fname = 'same_del at_sign'26420 fname = 'same_deltasign' 26418 26421 26419 26422 if values == 'h': 26420 26423 print fname + '_____________________________________________________________' 26421 print same_del at_sign.__doc__26424 print same_deltasign.__doc__ 26422 26425 quit() 26423 26426 26424 expectargs = 'varn1,minvar1,maxvar1,slcevar1,varn2,minvar2,maxvar2,slcevar2,' + \ 26425 'dimvars' 26427 expectargs = '[slicedims]' 26426 26428 gen.check_arguments(fname, values, expectargs, ',') 26427 26429 26428 varn1 = values.split(',')[0] 26429 minvar1 = np.float(values.split(',')[1]) 26430 slicedims = values.split(',')[0] 26431 26432 if variable == 'all': 26433 varns = onc.variables.keys() 26434 else: 26435 varns = gen.str_list(variable, ',') 26436 26437 onc = NetCDFFile(ncfile, 'r') 26438 for varn in varns: 26439 if not onc.variables.has_key(varn): 26440 print errormsg 26441 print ' ' +fname+ ": file '" + ncfile + "' does noty have variable '" + \ 26442 varn + "' !!" 26443 ivarns = onc.variables.keys() 26444 ivarns.sort() 26445 print ' available ones:', ivarns 26446 quit(-1) 26447 26448 ovar = onc.variables[varn] 26449 slcvar, slcdims = slice_variable(ovar, slicedims) 26450 26451 if len(slcvar.shape) != 1: 26452 print errormsg 26453 print ' ' + fname + ": resultant slice of variable '" + varn + \ 26454 "' has not rank 1 !!" 26455 print ' dimensions of the variable:', ovar.dimensions 26456 print ' shape of the variable:', ovar.dimensions 26457 print ' resultant slice shape:', slcvar.shape 26458 print ' provided values for the slice _______' 26459 dicslice = gen.stringS_dictvar(slicedims, '|', ':') 26460 gen.printing_dictionary(dicslice) 26461 quit(-1) 26462 26463 dim1 = slcvar.shape[0] 26464 deltavar = slcvar[1:dim1] - slcvar[0:dim1-1] 26465 absdeltav = np.abs(deltavar) 26466 singdelta = deltavar/absdeltav 26467 26468 delta0 = singdelta[0] 26469 if np.all(singdelta == delta0): 26470 print ' *' + varn + ': -same-', delta0 26471 else: 26472 print ' *' + varn + ': -NOTsame- !!' 26473 26474 onc.close() 26430 26475 26431 26476 return 26432 26477 26478 #values='Time:0|south_north:60|west_east:-1' 26479 #same_deltasign(values, '/home/lluis/PY/wrfout_d01_1995-01-01_00:00:00', 'T2,Q2,XLAT,XLONG') 26480 26433 26481 #quit() 26434 26482
Note: See TracChangeset
for help on using the changeset viewer.