Changeset 1454 in lmdz_wrf for trunk/tools/generic_tools.py
- Timestamp:
- Feb 20, 2017, 4:44:18 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic_tools.py
r1444 r1454 62 62 # i,j-quads within which the curve lays (-1, no value for the given quad [2x2 points around]) and provide 63 63 # the weights of the quad to perform a distance-weighted mean at the given curve point 64 # DateTimeStr_date: Function to transform a string date-time ([YYYY][MM][DD][HH][MI][SS] format) to a date object 65 # datetimeStr_datetime: Function to transform a string date-time ([YYYY]-[MM]-[DD]_[HH]:[MI]:[SS] format) to a date object 64 66 # dictionary_key: Function to provide the first key in a dictionay with a given value 65 67 # dictionary_key_list: Function to provide the first key in a dictionary of lists with a given value … … 123 125 # timestep_conform: Function to provide the time-step in seconds which conforms 1 temporal unit and the resultant number 124 126 # of time-steps for a whole period is multiple of a given number 127 # timefmt_timelab: Function to transform from C-like time format to general one 125 128 # unitsdsDate: Function to know how many units of time are from a given pair of dates 126 129 # vals_around: Function to provide the 3x3 values around a given j,i point … … 2557 2560 def timeStr_time(StringDate): 2558 2561 """ Function to transform a string date ([HH]:[MI]:[SS] format) to a time object 2559 >>> datetimeStr_datetime('04:32:54')2562 >>> timeStr_datetime('04:32:54') 2560 2563 04:32:54 2561 2564 """ … … 2569 2572 2570 2573 return newtime 2574 2575 def DateTimeStr_date(StringDate): 2576 """ Function to transform a string date-time ([YYYY][MM][DD][HH][MI][SS] format) to a date object 2577 >>> DateTimeStr_date('19760217083205') 2578 1976-02-17 08:32:05 2579 """ 2580 import datetime as dt 2581 2582 yr = int(StringDate[0:4]) 2583 mo = int(StringDate[4:6]) 2584 da = int(StringDate[6:8]) 2585 ho = int(StringDate[8:10]) 2586 mi = int(StringDate[10:12]) 2587 se = int(StringDate[12:14]) 2588 2589 if yr == 0: 2590 print warnmsg 2591 print ' ' + fname + ': 0 reference year!! changing to 1' 2592 yr = 1 2593 newdate = dt.datetime(yr, mo, da, ho, mi, se) 2594 2595 return newdate 2571 2596 2572 2597 def timeref_datetime(refd, timeval, tu): … … 11314 11339 return uwindtestv, vwindtestv, twindtestv 11315 11340 11341 def timefmt_timelab(timefmt): 11342 """ Function to transform from C-like time format to general one 11343 timefmt= C-like instruction for time 11344 %y as [YY], %Y as [YYYY], %m as [MM], %d as [DD], %h as [HH], %M as [MI], %S as [SS] 11345 >>> timefmt_timelab('$%d^{%H}$') 11346 $[DD]^{[HH]}$ 11347 """ 11348 fname = 'timefmt_timelab' 11349 11350 # Dictionary wtth the equivalencies 11351 dictchanges = {'%y': '[YY]', '%Y': '[YYYY]', '%m': '[MM]', '%d': '[DD]', \ 11352 '%H': '[HH]', '%M': '[MI]', '%S': '[SS]'} 11353 timelab = timefmt 11354 for chg in dictchanges.keys(): 11355 newv = dictchanges[chg] 11356 timelab = timelab.replace(chg, newv) 11357 11358 if timelab.find('%') != -1: 11359 print warnsmg 11360 print ' '+fname+": unsuccesfull substitution of all C-like values from '" + \ 11361 timefmt + "' !!" 11362 11363 return timelab 11364 11316 11365 #quit()
Note: See TracChangeset
for help on using the changeset viewer.