|
Encode/decode dates as floating point time values in netCDF files
|
Methods
|
|
__init__
buildcompliantdatestring
getdatefields
getoffsetfromdate
getscalefactorfromunits
gettimevalue
match
|
|
|
__init__
|
__init__ (
self,
tstring,
mydebug=0,
)
Constructor for the class JDTimeHandler
Each instance is created passing the units attribute
of the time variable in the COARDS--Compliant netCDF file
Arguments:
-
tstring
- COARDS--Compliant netCDF time units string
|
|
|
buildcompliantdatestring
|
buildcompliantdatestring ( self, tokens )
Building a compliant date string
The date string should be writen according to a strict
grammar, ideally (remeber, no time zone handled...):
YYYY-MM-DD H:M:S
Like in 1956-08-03 00:36:25.6
But users could be lazy and write things like
1985 - 5 - 1 2 : 3: 4.5
Or, even worse...
1985 - 5 -1 2
Thus, we should try to overcome these defects
in the set of tokens... and create a fixed-leng date structure
that will be easily used by the function that parses it.
BTW, I am writing this AFTER 20000101, so, nobody should
expect this function prepends 1900 to the year strings.
In fact, somebody could be trying to use this
functions to represent very ancient dates... (though
I have not checked if they work correctly for those years)
|
|
|
getdatefields
|
getdatefields (
self,
tvalue,
listlen=6,
)
Get a date from the offset since the origin
Get the fields of a date structure corresponding to
the current value of time as defined by the
units attribute of the time variable used in the constructor
Arguments:
-
tvalue
- time offset since te origin
Optional argument:
-
listlen
- Precision in the returned date. For
example, 1 returns the year, 3 the [year,month,day],
etc... Defaults to 6 ([yr,mth,day,hour,min,sec]).
|
|
|
getoffsetfromdate
|
getoffsetfromdate ( self, datestr )
|
|
|
getscalefactorfromunits
|
getscalefactorfromunits ( self, units )
Get the scale factor from units
The scfactor must be such that t*scfactor==(Julian) days
Some time units like month/year are not very
clearly defined in terms of days, so, they
are not handled, because they should not be used
In the case of month, this is clear (How many days are in a month?,
28, 29, 30, 31???)
For years, the same applies, 365, 366, tropical year?...
Better not to use those units
|
|
|
gettimevalue
|
gettimevalue (
self,
datefields,
listlen=6,
)
Returns the scaled offset since origin from the date
|
|
|
match
|
match (
self,
str,
strref,
)
Match strings using plurals and no case
|
|