Changeset 2197 in lmdz_wrf


Ignore:
Timestamp:
Oct 18, 2018, 10:20:14 PM (6 years ago)
Author:
lfita
Message:

Adding:

  • `same_deltasign': Function to determine if a given series of 1D values share the same sign of increase/decrease between consecutive values
Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/nc_var.py

    r2195 r2197  
    6363## 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
    6464## 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
    6566
    6667from optparse import OptionParser
     
    162163# remapnn: Function to remap to the nearest neightbor a variable using projection from another file
    163164# 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
    164167# seasmean: Function to compute the seasonal mean of a variable
    165168# sellonlatbox: Function to select a lotlan box from a data-set
     
    225228  'Partialmap_EntiremapFor', 'Partialmap_EntiremapForExact',                         \
    226229  'pinterp', 'reconstruct_matrix_from_vector', 'remapnn', 'retrieve_stations',       \
    227   'rm_FillValue',                                                                    \
     230  'rm_FillValue', 'same_deltasign',                                                  \
    228231  'seasmean', 'sellonlatbox', 'sellonlatlevbox', 'selvar', 'setvar_asciivalues',     \
    229232  'setvar_nc', 'sorttimesmat', 'spacemean', 'SpatialWeightedMean',                   \
     
    482485elif oper == 'rm_FillValue':
    483486    ncvar.rm_FillValue(opts.values, opts.ncfile, opts.varname)
     487elif oper == 'same_deltasign':
     488    ncvar.same_deltasign(opts.values, opts.ncfile, opts.varname)
    484489elif oper == 'seasmean':
    485490    ncvar.seasmean(timename, opts.ncfile, opts.varname)
  • trunk/tools/nc_var_tools.py

    r2196 r2197  
    138138# retrieve_stations: Function to retrieve temporal values at given stations provided by a secondary netcdf
    139139# 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
    140142# seasmean: Function to compute the seasonal mean of a variable
    141143# sellonlatbox: Function to select a lotlan box from a data-set
     
    2640126403#compute_slice2Dstats(values, '/home/lluis/PY/wrfout_d01_1995-01-01_00:00:00', 'T2,Q2')
    2640226404
    26403 def same_delat_sign(values, ncfile, variable):
     26405def same_deltasign(values, ncfile, variable):
    2640426406    """ Function to determine if a given series of 1D values share the same sign of
    2640526407         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
    2641426417      ncfile= netCDF file to use
    2641526418      variable: ',' list of variables ('all' for all variables)
    2641626419    """
    26417     fname = 'same_delat_sign'
     26420    fname = 'same_deltasign'
    2641826421
    2641926422    if values == 'h':
    2642026423        print fname + '_____________________________________________________________'
    26421         print same_delat_sign.__doc__
     26424        print same_deltasign.__doc__
    2642226425        quit()
    2642326426
    26424     expectargs = 'varn1,minvar1,maxvar1,slcevar1,varn2,minvar2,maxvar2,slcevar2,' +  \
    26425       'dimvars'
     26427    expectargs = '[slicedims]'
    2642626428    gen.check_arguments(fname, values, expectargs, ',')
    2642726429
    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()
    2643026475
    2643126476    return
    2643226477
     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
    2643326481#quit()
    2643426482
Note: See TracChangeset for help on using the changeset viewer.