Changeset 2329 in lmdz_wrf


Ignore:
Timestamp:
Feb 11, 2019, 6:23:19 PM (6 years ago)
Author:
lfita
Message:

Adding value of the dimension to `ovar_reducedims'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/nc_var_tools.py

    r2326 r2329  
    2769927699#area_weighted('yes:min,max,mean,stddev',fvals,'ct_values')
    2770027700
    27701 def ovar_reducedims(ovar, dimns):
     27701def ovar_reducedims(ovar, dimns, dimvs=[0]):
    2770227702    """ Function to reduce a variable removing some of its dimensions
    2770327703      ovar: Object variable to reduce
    2770427704      dimns: list of dimensions to remove from the variable
     27705      dimvs: list values of the dimensions to use
    2770527706    """
    2770627707    fname = 'ovar_reducedims'
    2770727708 
    2770827709    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])
    2770927716   
    2771027717    slicevar = []
     
    2771327720    iid = 0
    2771427721    for idn in dimv:
    27715         if gen.searchInlist(dimns,idn): slicevar.append(0)
     27722        if gen.searchInlist(dimns,idn): slicevar.append(dimvs[idn])
    2771627723        else:
    2771727724            ldim = ovar.shape[iid]
     
    2938729394#compute_slices_stats_areaweighted(values, '/home/lluis/PY/wrfout_d01_1995-01-01_00:00:00', 'T2')
    2938829395
     29396def 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
    2938929452#quit()
    2939029453
Note: See TracChangeset for help on using the changeset viewer.