Changeset 2473 in lmdz_wrf for trunk/tools
- Timestamp:
- Apr 25, 2019, 2:12:54 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic_tools.py
r2472 r2473 16245 16245 CF-conventions 16246 16246 date: date to transform 16247 >>> fromanydate_ Ymd('0001-01-01')16247 >>> fromanydate_CFYmd('0001-01-01') 16248 16248 '0001-01-01' 16249 >>> fromanydate_ Ymd('1850-1-1')16249 >>> fromanydate_CFYmd('1850-1-1') 16250 16250 '1850-01-01' 16251 >>> fromanydate_ Ymd('1850/1/1')16251 >>> fromanydate_CFYmd('1850/1/1') 16252 16252 '1850-01-01' 16253 >>> fromanydate_ Ymd('1976-02-17_08:32:27')16253 >>> fromanydate_CFYmd('1976-02-17_08:32:27') 16254 16254 '1976-02-17' 16255 16255 """ 16256 16256 fname = 'fromanydate_CFYmd' 16257 16257 16258 if date.count('-') + date.count('/') == 0 :16258 if date.count('-') + date.count('/') == 0 + date.count('.') == 0: 16259 16259 print errormsg 16260 print ' ' + fname + ": date without either '-' or '/' not ready !!"16260 print ' ' + fname + ": date without either '-' or '/' or '.' not ready !!" 16261 16261 print " passed date '" + date + "' not manegeable" 16262 16262 quit(-1) 16263 16263 16264 # Replacing '/' by '-'16264 # Replacing '/', '.' by '-' 16265 16265 if date.count('/') != 0: date = date.replace('/','-') 16266 if date.count('.') != 0: date = date.replace('.','-') 16266 16267 16267 16268 # Removing possible [datre]_[time] … … 16304 16305 origSrefdate0 = origtv[2] 16305 16306 16306 origSrefdate = fromanydate_ Ymd(origSrefdate)16307 origSrefdate = fromanydate_CFYmd(origSrefdate) 16307 16308 16308 16309 yrref = int(origSrefdate[0:4]) … … 16414 16415 origtunits = origtv[0] 16415 16416 if len(origtv) == 4: 16416 origSrefdate = fromanydate_ Ymd(origtv[2]) + ' ' + origtv[3]16417 origSrefdate = fromanydate_CFYmd(origtv[2]) + ' ' + origtv[3] 16417 16418 else: 16418 16419 print warnmsg 16419 16420 print ' ' + fname + ": original time units wihout time !!" 16420 16421 print " adding it as '00:00:00'" 16421 origSrefdate = fromanydate_ Ymd(origtv[2]) + ' 00:00:00'16422 origSrefdate = fromanydate_CFYmd(origtv[2]) + ' 00:00:00' 16422 16423 16423 16424 # From original to days … … 16468 16469 return newtimevals, newcftimeu 16469 16470 16471 print fromanydate_CFYmd('1979.12.07') 16472 16473 class CFtimeU_inf(object): 16474 """ Classs to provide information of CFtime units 16475 cftimeu: CF time units to provide information for [Timeu] since [RefDate] 16476 """ 16477 16478 def __init__(self, cftimeu): 16479 fname = 'CFtimeU_inf' 16480 origtv = cftimeu.split(' ') 16481 origtunits = origtv[0] 16482 origSrefdate0 = origtv[2] 16483 16484 origSrefdate = fromanydate_CFYmd(origSrefdate0) 16485 16486 yrref = int(origSrefdate[0:4]) 16487 monref = int(origSrefdate[5:7]) 16488 dayref = int(origSrefdate[8:10]) 16489 16490 # Does original reference date contain a time value [YYYY]-[MM]-[DD] [HH]:[MI]:[SS] 16491 ## 16492 trefT = origcftimeu.find(':') 16493 if not trefT == -1: 16494 if len(origtv) == 3: 16495 horref=int(origSrefdate[11:13]) 16496 minref=int(origSrefdate[14:16]) 16497 secref=int(origSrefdate[17:19]) 16498 else: 16499 origSreftime = origtv[3] 16500 horref=int(origSreftime[0:2]) 16501 minref=int(origSreftime[3:5]) 16502 secref=int(origSreftime[6:8]) 16503 else: 16504 horref = 0 16505 minref = 0 16506 secref = 0 16507 16508 self.refdate = origSrefdate + ' ' + horref + ':' + minref + ':' + secref 16509 self.refdateYMHdms = yrref + monref + dayref + horref + minref + secref 16510 self.Tunits = origtunits 16511 16512 cftimev = CFtimeU_inf('hours since 1979-12-1') 16513 printing_class(cftimev) 16514 16515 quit() 16516 16517 def from360d_reg(tvals, tunits): 16518 """ Function to transform from 360d = 12 * 30d calendar to a regular one 16519 tvals: temporal values 16520 tunits: units of the values in CF format [Tunits] since [RefDate] 16521 """ 16522 fname = 'from360d_reg' 16523 16524 16525 16526 return newtvals 16527 16470 16528 def change_CFcalendar(timevals, origcftimeu, origcal, newcal='gregorian'): 16471 16529 """ Changing CF-time values to a new calendar … … 16498 16556 quit(-1) 16499 16557 16558 elif origcal == '3650d': 16559 # We only can fix the 12x30 days calendar for monthly values... 16560 if type(timevals) == type(range(2)) or type(timevals) == type(np.arange(2)): 16561 dt = timevals[1] - timevals[0] 16562 else: 16563 dt = 30. 16564 # Transforming to regular months 16565 16500 16566 else: 16501 16567 print errormsg
Note: See TracChangeset
for help on using the changeset viewer.