Changeset 847 in lmdz_wrf


Ignore:
Timestamp:
Jun 16, 2016, 6:59:39 PM (9 years ago)
Author:
lfita
Message:

Adding:

  • `model_characteristics': Function to provide major characterisitcs of a given model output
  • `ModelChar?': Class object to determine major characterisitcs of a given model output
Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/nc_var.py

    r845 r847  
    1313## e.g. # nc_var.py -o subbasin -f routing.nc -S Caceres,-57.75,-16.25,left
    1414## e.g. # nc_var.py -o computevar_model -f ~/PY/wrfout_d01_2001-11-11_00:00:00 -S hurs
     15## e.g. # nc_var.py -o model_characteristics -f ~/PY/wrfout_d01_2001-11-11_00:00:00 -S WRF
    1516
    1617from optparse import OptionParser
     
    3738  'getvalues_lonlat', 'grattr',                                                      \
    3839  'grmattr', 'igattrs', 'increaseDimvar', 'isgattrs', 'isvattrs', 'ivars', 'ivattrs',\
    39   'maskvar',                                                                         \
     40  'maskvar', 'model_characteristics',                                                 \
    4041  'ncreplace', 'ncstepdiff', 'netcdf_concatenation', 'netcdf_fold_concatenation',    \
    4142  'Partialmap_Entiremap', 'Partialmap_EntiremapFor', 'Partialmap_EntiremapForExact', \
     
    203204elif oper == 'maskvar':
    204205    ncvar.maskvar(opts.values, opts.ncfile, opts.varname)
     206elif oper == 'model_characteristics':
     207    ncvar.model_characteristics(opts.values, opts.ncfile)
    205208elif oper == 'ncreplace':
    206209    ncvar.ncreplace(opts.values, opts.ncfile, opts.varname)
  • trunk/tools/nc_var_tools.py

    r845 r847  
    6666# lonlatProj: Function to compute longitudes and latitudes for a given projection following subroutine calc_resolution_in from ORCHIDEE/src_global/module_InterpWeight
    6767# maskvar: Function to mask a variable using a mask. It is assumed that mask[...,dimM,dimJ,dimK] and var[...,dimM,dimJ,dimK] share the last dimensions
     68# ModelCharacteristics: Class object to determine major characterisitcs of a given model output
    6869# ncreplace: Function to replace something from a netCDF file
    6970# ncstepdiff: Function to compute differencies between time-steps (deacumulate) a netCDF file
     
    1264712648
    1264812649    if varn == 'global':
    12649         if not searchInlist(onc.ncattrs(), attrn):
     12650        if not gen.searchInlist(onc.ncattrs(), attrn):
    1265012651            print errormsg
    1265112652            print '  ' + fname + ": file '" + filen + "' does not have atribute '" + \
     
    1265512656            attrv = onc.getncattr(attrn)
    1265612657    else:
    12657         if not searchInlist(onc.variables, varn):
     12658        if not gen.searchInlist(onc.variables, varn):
    1265812659            print errormsg
    1265912660            print '  ' + fname + ": file '" + filen + "' does not have variable '" + \
     
    1266212663        else:
    1266312664            ovar = onc.variables[varn]
    12664             if not searchInlist(ovar.ncattrs(), attrn):
     12665            if not gen.searchInlist(ovar.ncattrs(), attrn):
    1266512666                print errormsg
    1266612667                print '  ' + fname + ": variable '" + varn + "' does not have " +    \
     
    1267312674    onc.close()
    1267412675
    12675     print attrv
    12676 
    12677     return
     12676    return attrv
    1267812677
    1267912678def DimsLoop(ovar,seldims):
     
    1518815187    return
    1518915188
     15189class ModelChar(object):
     15190    """ Class object to determine major characterisitcs of a given model output
     15191      model= name of the model
     15192      ncfile= name of the file to use to check
     15193    """
     15194    def __init__(self,model,ncfile):
     15195        fname = 'ModelChar'
     15196        models = ['WRF', 'LMDZ', 'WRF_LMDZ']
     15197
     15198        if model == 'WRF' or model == 'WRF_LMDZ':
     15199            if model == 'WRF':
     15200                self.model = 'Weather Research and Forecasting'
     15201            else:
     15202                self.model= 'LMDZ physics coupled to Weather Research and Forecasting'
     15203
     15204            self.dimxn = 'west_east'
     15205            self.dimyn = 'south_north'
     15206            self.dimzn = 'bottom_top'
     15207            self.dimtn = 'Time'
     15208            self.vardxn = 'XLONG'
     15209            self.vardyn = 'XLAT'
     15210            self.vardzn = 'DN'
     15211            self.vardtn = 'Times'
     15212            if ncfile is not None and ncfile[0:2] == 'geo':
     15213                self.vardxn = 'XLONG_M'
     15214                self.vardyn = 'XLAT_M'
     15215
     15216            if ncfile is not None:
     15217                attrv = get_attribute('TITLE', ncfile, 'global')
     15218                self.version = attrv.split(' ')[4]
     15219
     15220        elif model == 'LMD':
     15221            self.model = 'LMDZ'
     15222            self.dimxn = 'lon'
     15223            self.dimyn = 'lat'
     15224            self.dimzn = 'presnivs'
     15225            self.dimtn = 'time_counter'
     15226            self.vardxn = 'lon'
     15227            self.vardyn = 'lat'
     15228            self.vardzn = 'pres'
     15229            self.vardtn = 'time_counter'
     15230
     15231            if ncfile is not None:
     15232                self.version = None
     15233
     15234def model_characteristics(values, ncfile):
     15235    """ Class object to determine major characterisitcs of a given model output
     15236      values= [model]
     15237        model: name of the model
     15238      ncfile= name of the file to use to check
     15239    """
     15240    fname = 'model_characteristics'
     15241
     15242    if values == 'h':
     15243        print fname + '_____________________________________________________________'
     15244        print model_characteristics.__doc__
     15245        quit()
     15246
     15247    model = values
     15248
     15249    if ncfile == 'None': ncfile = None
     15250
     15251    modchar = ModelChar(model,ncfile)
     15252    gen.printing_class(modchar)
     15253
     15254    return
     15255
    1519015256#quit()
    1519115257
Note: See TracChangeset for help on using the changeset viewer.