From: <js...@us...> - 2007-12-04 18:48:07
|
Revision: 4582 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4582&view=rev Author: jswhit Date: 2007-12-04 10:48:02 -0800 (Tue, 04 Dec 2007) Log Message: ----------- use num2date Modified Paths: -------------- trunk/toolkits/basemap/examples/fcstmaps.py Modified: trunk/toolkits/basemap/examples/fcstmaps.py =================================================================== --- trunk/toolkits/basemap/examples/fcstmaps.py 2007-12-04 18:37:40 UTC (rev 4581) +++ trunk/toolkits/basemap/examples/fcstmaps.py 2007-12-04 18:48:02 UTC (rev 4582) @@ -6,35 +6,9 @@ import sys from numpy import ma import datetime -from matplotlib.toolkits.basemap import Basemap, NetCDFFile, addcyclic +from matplotlib.toolkits.basemap import Basemap, NetCDFFile, addcyclic, num2date -hrsgregstart = 13865688 # hrs from 00010101 to 15821015 in Julian calendar. -# times in many datasets use mixed Gregorian/Julian calendar, datetime -# module uses a proleptic Gregorian calendar. So, I use datetime to compute -# hours since start of Greg. calendar (15821015) and add this constant to -# get hours since 1-Jan-0001 in the mixed Gregorian/Julian calendar. -gregstart = datetime.datetime(1582,10,15) # datetime.datetime instance - -def dateto_hrs_since_day1CE(curdate): - """given datetime.datetime instance, compute hours since 1-Jan-0001""" - if curdate < gregstart: - msg = 'date must be after start of gregorian calendar (15821015)!' - raise ValueError, msg - difftime = curdate-gregstart - hrsdiff = 24*difftime.days + difftime.seconds/3600 - return hrsdiff+hrsgregstart - -def hrs_since_day1CE_todate(hrs): - """return datetime.datetime instance given hours since 1-Jan-0001""" - if hrs < 0.0: - msg = "hrs must be positive!" - raise ValueError, msg - delta = datetime.timedelta(hours=1) - hrs_sincegreg = hrs - hrsgregstart - curdate = gregstart + hrs_sincegreg*delta - return curdate - # today's date is default. if len(sys.argv) > 1: YYYYMMDD = sys.argv[1] @@ -62,14 +36,17 @@ longitudes = data.variables['lon'] fcsttimes = data.variables['time'] times = fcsttimes[0:6] # first 6 forecast times. +# change 0.0 to 00 at end of time units string +# (so strptime will understand it). +timeunits = fcsttimes.units[:-2]+'0' ntimes = len(times) # put forecast times in YYYYMMDDHH format. verifdates = [] fcsthrs=[] -print times for time in times: + print time, times[0] fcsthrs.append(int((time-times[0])*24)) - fdate = hrs_since_day1CE_todate(int(time*24.0)) + fdate = num2date(time,'days since 0001-01-01 00:00:00') verifdates.append(fdate.strftime('%Y%m%d%H')) print fcsthrs print verifdates This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |