Changeset 2329 in lmdz_wrf
- Timestamp:
- Feb 11, 2019, 6:23:19 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r2326 r2329 27699 27699 #area_weighted('yes:min,max,mean,stddev',fvals,'ct_values') 27700 27700 27701 def ovar_reducedims(ovar, dimns ):27701 def ovar_reducedims(ovar, dimns, dimvs=[0]): 27702 27702 """ Function to reduce a variable removing some of its dimensions 27703 27703 ovar: Object variable to reduce 27704 27704 dimns: list of dimensions to remove from the variable 27705 dimvs: list values of the dimensions to use 27705 27706 """ 27706 27707 fname = 'ovar_reducedims' 27707 27708 27708 27709 dimv = ovar.dimensions 27710 27711 Ndims = len(dimns) 27712 if len(dimvs) == 1 and Ndims > 1: 27713 oldimvs = dimvs + [] 27714 dimvs = [] 27715 for iid in range(Ndims): dimvs.append(oldimvs[0]) 27709 27716 27710 27717 slicevar = [] … … 27713 27720 iid = 0 27714 27721 for idn in dimv: 27715 if gen.searchInlist(dimns,idn): slicevar.append( 0)27722 if gen.searchInlist(dimns,idn): slicevar.append(dimvs[idn]) 27716 27723 else: 27717 27724 ldim = ovar.shape[iid] … … 29387 29394 #compute_slices_stats_areaweighted(values, '/home/lluis/PY/wrfout_d01_1995-01-01_00:00:00', 'T2') 29388 29395 29396 def except_fillValue(values, ncfile, variable): 29397 """ Function to fill a file with fill_Value except a given value of a variable 29398 values= [varname]:[value]:[rmdims] 29399 [varname]: name of the variable to use its values for the filling 29400 [value]: value of the variable from which grid points will not be filled by 29401 fill_value 29402 'exact',[value]: just a single value to use to avoid filling 29403 'range',[ivalue],[evalue]: avoid filling points with values within the 29404 range [ivaule],[evalue] 29405 [rmdims]: ',' separated list of [dimn]@[dimv] name of dimensions and value to 29406 remove from [varname] to find the value 29407 [dimn]: name of the dimension from [varname] 29408 [dimv]: value of [dimn] to use 29409 ncfile= netCDF file to fill 29410 variable= name of the variables to use 29411 """ 29412 fname = 'except_fillValue' 29413 29414 availvalue = ["'exact',[value]", "'range',[ivalue],[evalue]"] 29415 29416 if values == 'h': 29417 print fname + '_____________________________________________________________' 29418 print except_fillValue.__doc__ 29419 quit() 29420 29421 expectargs = '[varname]:[value]:[rmdims]' 29422 gen.check_arguments(fname, values, expectargs, ':') 29423 29424 varname = values.split(':')[0] 29425 value = values.split(':')[1] 29426 rmdims = values.split(':')[2] 29427 29428 if value[0:5] == 'exact': 29429 varvalue = value.split(',')[1] 29430 elif value[0:5] == 'range': 29431 ivarvalue = value.split(',')[1] 29432 evarvalue = value.split(',')[2] 29433 else: 29434 print errormsg 29435 print ' ' + fname + ": value for variable '" + value + "' not ready !!" 29436 print ' available ones:', availvalue 29437 quit(-1) 29438 29439 onc = NetCDFFile(ncfile, 'r') 29440 if not onc.variables.has_key(varname): 29441 print errormsg 29442 print ' ' + fname + ": file '" + + "' does not have variable '" + varname + \ 29443 "' !!" 29444 varns = list(onc.variables.keys()) 29445 varns.sort() 29446 print ' available ones:', varns 29447 quit(-1) 29448 29449 ovar = onc.variables[varname] 29450 29451 29389 29452 #quit() 29390 29453
Note: See TracChangeset
for help on using the changeset viewer.