Changeset 1843 in lmdz_wrf


Ignore:
Timestamp:
Mar 22, 2018, 8:28:48 PM (7 years ago)
Author:
lfita
Message:

Adding:

  • `CFtime_freq': Function to provide the frequency of CF times (in seconds)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/generic_tools.py

    r1842 r1843  
    5757# CFcorValues: Function to provide CF information about a given coordinate
    5858# CFmonthU_daysU: Function to transform from a CF date series with units as 'months since [DATE]' to 'days since [DATE]'
     59# CFtime_freq: Function to provide the frequency of CF times (in seconds)
    5960# CFvar_DIAGvar: Function to provide which model diagnostic values can provide a CF-variable from ASCII file
    6061# CFvar_MODvar: Function to provide which model values can provide a CF-variable from ASCII file
     
    664665          str(da).zfill(2) + ' ' + str(ho).zfill(2) + '-' + str(mi).zfill(2) + '-' + \
    665666          str(se).zfill(2)
    666     elif typeSo = 'Y-m-dTH:M:SZ':
     667    elif typeSo == 'Y-m-dTH:M:SZ':
    667668        dateYmdHMS = str(yr).zfill(4) + '-' + str(mo).zfill(2) + '-' +               \
    668669          str(da).zfill(2) + 'T' + str(ho).zfill(2) + ':' + str(mi).zfill(2) + ':' + \
     
    1270012701    # Dictionary for each dimension
    1270112702    CFlon= {'dimn': 'lon', 'stdn': 'longitude', 'longname': 'Longitude', 'units':    \
    12702       'degrees_east', 'axis': 'X', '_CoordinateAxisType': 'Lon', 'maxrank:', 2,      \
     12703      'degrees_east', 'axis': 'X', '_CoordinateAxisType': 'Lon', 'maxrank': 2,       \
    1270312704      'length': 0}
    1270412705    CFlat= {'dimn': 'lat', 'stdn': 'latitude', 'longname': 'Latitude', 'units':      \
    12705       'degrees_north', 'axis': 'Y', '_CoordinateAxisType': 'Lat', 'maxrank:', 2,     \
     12706      'degrees_north', 'axis': 'Y', '_CoordinateAxisType': 'Lat', 'maxrank': 2,     \
    1270612707      'length': 0}
    1270712708    CFpress= {'dimn': 'pressure', 'stdn': 'pressure', 'longname': 'Pressure',        \
    1270812709      'units': 'Pa', 'axis': 'Z', '_CoordinateAxisType': 'Pres', 'positive': 'down', \
    12709       'maxrank:', 1, 'length': 0}
     12710      'maxrank': 1, 'length': 0}
    1271012711    CFheight= {'dimn': 'height', 'stdn': 'height', 'longname': 'Height',             \
    1271112712      'units': 'm', 'axis': 'Z', '_CoordinateAxisType': 'Height', 'positive': 'up',  \
    12712       'maxrank:', 1, 'length': 0}
     12713      'maxrank': 1, 'length': 0}
    1271312714    CFtime= {'dimn': 'time', 'stdn': 'time', 'longname': 'Time',                     \
    1271412715      'units': '[t] since [date]', 'axis': 'T', '_CoordinateAxisType': 'Time',       \
    12715       'calendar': '[calendar]', 'maxrank:', 1, 'length': -1}
     12716      'calendar': '[calendar]', 'maxrank': 1, 'length': -1}
    1271612717
    1271712718    # names to search for
     
    1274412745    return cdfim
    1274512746
     12747def CFtime_freq(time1, time2, tunits):
     12748    """ Function to provide the frequency of CF times (in seconds)
     12749      time1: time-step value
     12750      time2: following time-step value
     12751      tunits: time untis following CF conventions
     12752    >>> CFtime_freq(521438., 521439., 'hours since 1950-01-01_00:00:00')
     12753    3600.0
     12754    """
     12755    fname = 'CFtime_freq'
     12756
     12757    timediff = time2 - time1
     12758
     12759    tunitsval = tunits.split(' ')[0]
     12760
     12761    # Units for the variable 'time' to seconds
     12762    availtunitvals = ['centuries', 'years', 'days', 'hours', 'minutes', 'seconds']
     12763    if tunitsval == 'centuries':
     12764        tsecsuv = 100 * 365 * 24 * 3600.
     12765    elif tunitsval == 'years':
     12766        tsecsuv = 365 * 24 * 3600.
     12767    elif tunitsval == 'weeks':
     12768        tsecsuv = 7 * 24 * 3600.
     12769    elif tunitsval == 'days':
     12770        tsecsuv = 24 * 3600.
     12771    elif tunitsval == 'hours':
     12772        tsecsuv = 3600.
     12773    elif tunitsval == 'minutes':
     12774        tsecsuv = 60.
     12775    elif tunitsval == 'seconds':
     12776        tsecsuv = 1.
     12777    else:
     12778        print errormsg
     12779        print '  ' + fname + ":' tunitsvals= '" + tunitsval + "' not ready!!"
     12780        print '    available ones: ', availtunitvals
     12781        quit(-1)
     12782
     12783    freq = timediff*tsecsuv
     12784
     12785    return freq
     12786#print CFtime_freq(521438., 521439., 'hours since 1950-01-01_00:00:00')
     12787
    1274612788#quit()
    1274712789
Note: See TracChangeset for help on using the changeset viewer.