Changeset 1838 in lmdz_wrf for trunk/tools/generic_tools.py


Ignore:
Timestamp:
Mar 22, 2018, 6:13:46 PM (7 years ago)
Author:
lfita
Message:

Adding:

  • `CFcorValues': Function to provide CF information about a given coordinate
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/generic_tools.py

    r1837 r1838  
    5555# Capturing: Class to capture the standard output from a function
    5656# CF_gribequiv: Function to provide the GRIB variable code number from a CF name
     57# CFcorValues: Function to provide CF information about a given coordinate
    5758# CFmonthU_daysU: Function to transform from a CF date series with units as 'months since [DATE]' to 'days since [DATE]'
    5859# CFvar_DIAGvar: Function to provide which model diagnostic values can provide a CF-variable from ASCII file
     
    1267012671    return xtrm
    1267112672
     12673def CFcorValues(name):
     12674    """ Function to provide CF information about a given coordinate
     12675      name: name of dimension, axis, ....
     12676    >>> CFcorValues('lon')
     12677   {'units': 'degrees_east', '_CoordinateAxisType': 'Lon', 'stdn': 'longitude',
     12678     'axis': 'X', 'longname': 'Longitude'}
     12679    >>> CFcorValues('T')
     12680   {'stdn': 'time', 'longname': 'Time', 'units': '[t] since [date]',
     12681     '_CoordinateAxisType': 'Time', 'calendar': '[calendar]', 'axis': 'T'}
     12682    """
     12683    fname = 'CFDIMvalues'
     12684
     12685    # Dictionary for each dimension
     12686    CFlon= {'stdn': 'longitude', 'longname': 'Longitude', 'units': 'degrees_east',   \
     12687      'axis': 'X', '_CoordinateAxisType': 'Lon'}
     12688    CFlat= {'stdn': 'latitude', 'longname': 'Latitude', 'units': 'degrees_north',    \
     12689      'axis': 'Y', '_CoordinateAxisType': 'Lat'}
     12690    CFpress= {'stdn': 'pressure', 'longname': 'Pressure', 'units': 'Pa', 'axis': 'Z',\
     12691      '_CoordinateAxisType': 'Pres', 'positive': 'down'}
     12692    CFheight= {'stdn': 'height', 'longname': 'Height', 'units': 'm', 'axis': 'Z',    \
     12693      '_CoordinateAxisType': 'Height', 'positive': 'up'}
     12694    CFtime= {'stdn': 'time', 'longname': 'Time', 'units': '[t] since [date]',        \
     12695      'axis': 'T', '_CoordinateAxisType': 'Time', 'calendar': '[calendar]'}
     12696
     12697    # names to search for
     12698    lonn = ['lon', 'X', 'Longitude', 'longitude', 'x']
     12699    latn = ['lat', 'Y', 'Latitude', 'latitude', 'y']
     12700    pressn = ['press', 'P', 'Press', 'Pressure', 'pressure', 'p']
     12701    heightn = ['height', 'Z', 'Height', 'z']
     12702    timen = ['time', 'T', 'Time', 'TIME', 't']
     12703
     12704    if searchInlist(lonn, name):
     12705        cdfim = CFlon
     12706    elif searchInlist(latn, name):
     12707        cdfim = CFlat
     12708    elif searchInlist(pressn, name):
     12709        cdfim = CFpress
     12710    elif searchInlist(heightn, name):
     12711        cdfim = CFheight
     12712    elif searchInlist(timen, name):
     12713        cdfim = CFtime
     12714    else:
     12715        print errormsg
     12716        print '  ' + fname + ": coordinate name '" + name + "' not ready !!"
     12717        print "    available ones for 'X':", lonn
     12718        print "    available ones for 'Y':", latn
     12719        print "    available ones for 'Z' [pressure]:", pressn
     12720        print "    available ones for 'Z' [height]:", heightn
     12721        print "    available ones for 'T':", timen
     12722        quit(-1)
     12723
     12724    return cdfim
     12725
    1267212726#quit()
    1267312727
Note: See TracChangeset for help on using the changeset viewer.