Changeset 2178 in lmdz_wrf for trunk


Ignore:
Timestamp:
Oct 11, 2018, 1:58:56 PM (7 years ago)
Author:
lfita
Message:

Adding:

  • `generate_CFtimes': Function to generate CFtimes for a given period, frequency and units
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/generic_tools.py

    r2177 r2178  
    113113# get_specdictionary_HMT: Function to get specific values from a dictionary by selcting that keys with H*M*T
    114114# getting_fixedline: Function to get the values from a line of text with fixed lenght of different values
     115# generate_CFtimes: Function to generate CFtimes for a given period, frequency and units
    115116# grib_CFequiv: Function to provide the CF name of a GRIB variable code number
    116117# inf_operSlist: Function to provide information from a string as a list separated by
     
    1453914540      datei: initial date of the period ([YYYY][MM][DD][HH][MI][SS] format)
    1454014541      datef: final date of the period ([YYYY][MM][DD][HH][MI][SS] format)
    14541       units: units of time (one from 'years', 'months', 'days', 'minutes', 'hours',
    14542         'seconds')
     14542      units: units of time (one from 'days', 'hours', 'minutes', 'seconds')
    1454314543      Tfreq: frequency of time-steps in number of [units] time
    1454414544      dateref: reference date ([YYYY][MM][DD][HH][MI][SS] format)
     14545    >>> generate_CFtimes('20021230000000', '20030103000000', 'days', 1)
     14546    [19387.0, 19388.0, 19389.0, 19390.0, 19391.0, 19392.0], 'days since 1949-12-01 00:00:00'
    1454514547    """
    1454614548    import datetime as dt
    1454714549    fname = 'generate_CFtimes'
    1454814550
    14549     availtunits = ['years', 'months', 'days', 'minutes', 'hours', 'seconds']
     14551    availtunits = ['days', 'minutes', 'hours', 'seconds']
     14552
     14553    if units == 'days': ddt = 3600.*24.
     14554    elif units == 'hours': ddt = 3600.
     14555    elif units == 'minutes': ddt = 60.
     14556    elif units == 'seconds': ddt = 1.
     14557    else:
     14558        print errormsg
     14559        print '  ' + fname + ": time units '" + uints + "' not ready !!"
     14560        print '    available ones:', availtunits
     14561        quit(-1)
    1455014562
    1455114563    idate = dt.datetime.strptime(datei, '%Y%m%d%H%M%S')
     
    1456114573        diffT = delta.days*24*3600. + delta.seconds
    1456214574
    14563     cftimes = [diffT]
     14575    cftimes = [np.float64(diffT/ddt)]
    1456414576
    1456514577    date = idate
    14566     while date < edate:
     14578    while date <= edate:
    1456714579        date = advance_date(date, units, freq)
    1456814580
     
    1457314585        else:
    1457414586            diffT = delta.days*24*3600. + delta.seconds
    14575         cftimes.append(diffT)
    14576         print 'Lluis:', date, ':', diffT, 'frq:', freq
     14587        cftimes.append(np.float64(diffT/ddt))
    1457714588   
    14578     delta = edate - refdate
    14579     # Python version depending
    14580     if searchInlist(dir(delta), 'total_seconds'):
    14581         diffT = delta.total_seconds()
    14582     else:
    14583         diffT = delta.days*24*3600. + delta.seconds
    14584 
    14585     cftimes.append(diffT)
    1458614589    timeu = units + ' since ' + refdateS
    1458714590
    1458814591    return cftimes, timeu
    1458914592
    14590 print generate_CFtimes('20021201000000', '20030228000000', 'days', 1)
    14591 
    1459214593#quit()
    1459314594
Note: See TracChangeset for help on using the changeset viewer.