Changeset 2424 in lmdz_wrf
- Timestamp:
- Mar 26, 2019, 4:11:55 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic_tools.py
r2421 r2424 60 60 61 61 ####### Content 62 # advance_cfDate: Fucntion to advance a time object using a delta time in cf units 62 63 # advance_date: Function to advance a date object a certain given units of time 63 64 # advance_matDate: Function to advance matrix-date with a matrix-increment … … 539 540 return newdatetime 540 541 542 def advance_cfDate(dateval, dT, Tu): 543 """ Function to advance a time object using a delta time in cf units 544 dateval: time object 545 dT: interval of time to advance 546 Tu: temporal units 547 >>> advance_cfDate(dt.deltatime(1976,2,17,8,39,27), 3600, 'minutes') 548 1976-02-19 20:39:27 549 """ 550 import datetime as dt 551 fname = ' advance_cfDate' 552 553 availcfTu = ['weeks', 'days', 'hours', 'minutes', 'seconds', 'milliseconds'] 554 555 if Tu == 'weeks': 556 newdate = dateval + dt.timedelta(weeks=float(dT)) 557 elif Tu == 'days': 558 newdate = dateval + dt.timedelta(days=float(dT)) 559 elif Tu == 'hours': 560 newdate = dateval + dt.timedelta(hours=float(dT)) 561 elif Tu == 'minutes': 562 newdate = dateval + dt.timedelta(minutes=float(dT)) 563 elif Tu == 'seconds': 564 newdate = dateval + dt.timedelta(seconds=float(dT)) 565 elif Tu == 'milliseconds': 566 newdate = dateval + dt.timedelta(milliseconds=float(dT)) 567 else: 568 print errormsg 569 print ' ' + fname + ': time units"' + Tu + '" not ready!!!!' 570 print ' available ones:', availcfTu 571 quit(-1) 572 573 return newdate 574 541 575 def datetimeStr_conversion(StringDT,typeSi,typeSo): 542 576 """ Function to transform a string date to an another date object … … 595 629 quit() 596 630 597 if typeSi[0:6] == 'cfTime' :631 if typeSi[0:6] == 'cfTime' and typeSi[0:9] != 'cfTimeCal': 598 632 timeval = np.float(StringDT) 599 633 tunits = typeSi.split(',')[1].split(' ')[0] … … 647 681 mi = newdate.minute 648 682 se = newdate.second 649 elif typeSi[0: 6] == 'cfTimeCal':683 elif typeSi[0:9] == 'cfTimeCal': 650 684 timeval = np.float(StringDT) 651 685 tunits = typeSi.split(',')[1].split(' ')[0] … … 653 687 calendar = typeSi.split(',')[2] 654 688 655 if not gen.searchInlist(availcalendar , calendar):689 if not searchInlist(availcalendar , calendar): 656 690 print errormsg 657 691 print ' ' + fname + ": calendar '" + + "' not ready !!" … … 684 718 if calendar == 'noleap' or calendar == '365d': 685 719 removeleap = False 686 newdate = refdate + dt.timedelta(weeks=float(timeval)) 720 newdate = advance_cfDate(refdate, timeval, tunits) 721 print newdate, 'leap Feb;', days_month(newdate.year,2) 687 722 if days_month(newdate.year,2) == 29: 688 723 if newdate.mon == 2 and newdate.day == 28: … … 700 735 newdate = refdate + dt.timedelta(hours=float(timeval)) 701 736 elif tunits == 'minutes': 737 print 'Lluis here ', removeleap, calendar 702 738 if removeleap: timeval = timeval - 1.*24.*60. 703 739 newdate = refdate + dt.timedelta(minutes=float(timeval)) … … 1005 1041 1006 1042 return dateYmdHMS 1043 1044 print datetimeStr_conversion(str(137880),'cfTimeCal,minutes since 1979-12-01_00:00:00,noleap','Y/m/d H-M-S') 1045 quit() 1046 1007 1047 1008 1048 def period_information(idate, edate, totunits):
Note: See TracChangeset
for help on using the changeset viewer.