- Timestamp:
- Oct 11, 2018, 1:58:56 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic_tools.py
r2177 r2178 113 113 # get_specdictionary_HMT: Function to get specific values from a dictionary by selcting that keys with H*M*T 114 114 # 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 115 116 # grib_CFequiv: Function to provide the CF name of a GRIB variable code number 116 117 # inf_operSlist: Function to provide information from a string as a list separated by … … 14539 14540 datei: initial date of the period ([YYYY][MM][DD][HH][MI][SS] format) 14540 14541 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') 14543 14543 Tfreq: frequency of time-steps in number of [units] time 14544 14544 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' 14545 14547 """ 14546 14548 import datetime as dt 14547 14549 fname = 'generate_CFtimes' 14548 14550 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) 14550 14562 14551 14563 idate = dt.datetime.strptime(datei, '%Y%m%d%H%M%S') … … 14561 14573 diffT = delta.days*24*3600. + delta.seconds 14562 14574 14563 cftimes = [ diffT]14575 cftimes = [np.float64(diffT/ddt)] 14564 14576 14565 14577 date = idate 14566 while date < edate:14578 while date <= edate: 14567 14579 date = advance_date(date, units, freq) 14568 14580 … … 14573 14585 else: 14574 14586 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)) 14577 14588 14578 delta = edate - refdate14579 # Python version depending14580 if searchInlist(dir(delta), 'total_seconds'):14581 diffT = delta.total_seconds()14582 else:14583 diffT = delta.days*24*3600. + delta.seconds14584 14585 cftimes.append(diffT)14586 14589 timeu = units + ' since ' + refdateS 14587 14590 14588 14591 return cftimes, timeu 14589 14592 14590 print generate_CFtimes('20021201000000', '20030228000000', 'days', 1)14591 14592 14593 #quit() 14593 14594
Note: See TracChangeset
for help on using the changeset viewer.