Changeset 2471 in lmdz_wrf for trunk/tools
- Timestamp:
- Apr 24, 2019, 8:43:23 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic_tools.py
r2469 r2471 122 122 # fill_Narray: Function to fill a n-dimensional array with an arrary of lesser rank 123 123 # fix_CFdates: Fixing CF-time values with wrong setting 124 # fromanydate_CFYmd: Function to transform from any string format of date to Y-m-d used in 125 # CF-conventions 124 126 # gen_impose_gregorian: Function to impose gregorian calendar to a series of times with a 125 127 # non-standard calendar independently from datetime (imposes yr > 1900) … … 16239 16241 # 'days since 1949-12-01 00:00:00') 16240 16242 16243 def fromanydate_CFYmd(date): 16244 """ Function to transform from any string format of date to Y-m-d used in 16245 CF-conventions 16246 date: date to transform 16247 >>> fromanydate_Ymd('0001-01-01') 16248 '0001-01-01' 16249 >>> fromanydate_Ymd('1850-1-1') 16250 '1850-01-01' 16251 >>> fromanydate_Ymd('1850/1/1') 16252 '1850-01-01' 16253 >>> fromanydate_Ymd('1976-02-17_08:32:27') 16254 '1976-02-17' 16255 """ 16256 fname = 'fromanydate_CFYmd' 16257 16258 if date.count('-') + date.count('/') == 0: 16259 print errormsg 16260 print ' ' + fname + ": date without either '-' or '/' not ready !!" 16261 print " passed date '" + date + "' not manegeable" 16262 quit(-1) 16263 16264 # Replacing '/' by '-' 16265 if date.count('/') != 0: date = date.replace('/','-') 16266 16267 # Removing possible [datre]_[time] 16268 if date.count('_') != 0: date = date.split('_')[0] 16269 16270 ldate = date.split('-') 16271 if len(ldate) != 3: 16272 print errormsg 16273 print ' ' + fname + ": date '" + date + "' not ready !!" 16274 print " it requires 3 '-' sections '[yr]-[mo]-[dd]'" 16275 quit(-1) 16276 16277 yr = str(int(ldate[0])).zfill(4) 16278 mo = str(int(ldate[1])).zfill(2) 16279 dd = str(int(ldate[2])).zfill(2) 16280 16281 newdate = yr + '-' + mo + '-' + dd 16282 16283 return newdate 16284 16241 16285 def change_CFRefdate(timevals, origcftimeu, newSrefdate='1949-12-01 00:00:00'): 16242 16286 """ Change CF-time values with a new reference date … … 16258 16302 origtv = origcftimeu.split(' ') 16259 16303 origtunits = origtv[0] 16260 origSrefdate = origtv[2] 16304 origSrefdate0 = origtv[2] 16305 16306 origSrefdate = fromanydate_Ymd(origSrefdate) 16261 16307 16262 16308 yrref = int(origSrefdate[0:4]) … … 16368 16414 origtunits = origtv[0] 16369 16415 if len(origtv) == 4: 16370 origSrefdate = origtv[2]+ ' ' + origtv[3]16416 origSrefdate = fromanydate_Ymd(origtv[2]) + ' ' + origtv[3] 16371 16417 else: 16372 16418 print warnmsg 16373 16419 print ' ' + fname + ": original time units wihout time !!" 16374 16420 print " adding it as '00:00:00'" 16375 origSrefdate = origtv[2]+ ' 00:00:00'16421 origSrefdate = fromanydate_Ymd(origtv[2]) + ' 00:00:00' 16376 16422 16377 16423 # From original to days … … 16437 16483 """ 16438 16484 fname = 'change_CFcalendar' 16439 availorigcal = ['noleap', '365d' ]16485 availorigcal = ['noleap', '365d', '365_day'] 16440 16486 availnewcal = ['gregorian', 'standard'] 16441 16487 16442 16488 # If the calendar is not gregorian, it needs to be fixed from origSrefdate! 16443 if origcal == 'noleap' or origcal == '365d' :16489 if origcal == 'noleap' or origcal == '365d' or origcal == '365_day' : 16444 16490 print ' ' + fname + ": found non-standard calendar '" + origcal + "' !!" 16445 16491 if newcal == 'gregorian' or newcal == 'standard':
Note: See TracChangeset
for help on using the changeset viewer.