2.3.4.2. Content¶
| Inheritance diagram: | |
|---|---|

Time utilities
- 
class 
DateSorter(pattern=None, basename=True)[source]¶ Bases:
objectSort a list of date string, optionally using a date pattern
Example:
>>> from vacumm.misc.atime import DateSorter >>> dates = ['annee 2006', 'annee 2002'] >>> ds = DateSorter('annee %Y') >>> dates.sort(ds) >>> print dates ['2002', '2006']
- 
class 
Gaps(var, tolerance=0.1, verbose=True, dt=None, **kwargs)[source]¶ Bases:
cdms2.tvariable.TransientVariableFind time gaps in a variable
A gap is defined as a missing time step or data. With this class, you can:
- get the gaps as a variable (the object itself)
 - where 1 refers to the start of gap and -1 to the end
 - print them (
show()) - plot them (
plot()) - save them in a netcdf or an ascii file (
save()) 
Parameters: - var: A cdms variable with a cdms time axis
 - dt: Time step [default: minimal time step]
 - tolerance: There is a gap when dt varies of more than tolerance*min(dt) [default: 0.1]
 - keyparam: verbose Verbose mode
 
Example: >>> import vacumm.misc as M >>> import MV2 >>> time = M.axes.create_time([1,2,4,5],units='days since 2000') >>> var = MV2.arange
- 
plot(show=True, savefig=None, figsize=(8, 2.0), title=None, color='red', subplots_adjust={'bottom': 0.55, 'left': 0.05, 'top': 0.8}, show_time_range=True, **kwargs)[source]¶ Plot the gaps
Params: - color: Color of gaps [default: ‘red’]
 - figure: Show results on a figure if there are gaps [default: True]
 - show: Show the figure plotted if gaps are found [default: True]
 - title: Use this title for the figure
 
- 
class 
Intervals(time_range, dt, reverse=False, roundto=None, bounds=True, lmargin=0, rmargin=None, innerbounds='co', roundmode='all')[source]¶ Bases:
objectIterator on intervals
Params: - time_range: Time range (optionally with bounds).
 - dt: Size of intervals.
 - reverse, optional: Reverse the iterator.
 - roundto, optional: Round times to this time units (like ‘hours’, etc).
 - bounds, optional: Add bounds specs to the intervals (like “co”).
 - l/rmargin, optional: Add a margin to the left and/or right of each interval.
See 
add_margin(). - innerbounds, optional: Add bounds specs to inner intervals (like “cc”).
 - roundmode, optional:
 - “all”: Round all dates.
 - “inner”: Round only inner dates, not first and last.
 
Example: >>> for itv in Intervals(('2000','2001','co'),(2,'month')): print itv >>> Intervals(('2000','2001','co'),12).tolist() >>> Intervals((cdtime.comptime(2000), '2001', 'month', ... reverse=True, lmargin=(3,'hours'))
- 
class 
IterDates(time_range, dt, reverse=False, roundto=None, closed=True)[source]¶ Bases:
objectIterator on dates
Example:
>>> from vacumm.misc.atime import IterDates >>> for date in IterDates(('2000','2001'),(1,'month')): print date >>> for date in IterDates(('2000','2001'),12,closed=False): print date
- 
class 
SpecialDateFormatter(level, fmt=None, special_fmt=None, join=None, phase=None, **kwargs)[source]¶ Bases:
matplotlib.dates.DateFormatterSpecial formatter for dates Example: [‘00h 01/10/2000’ ‘02h’ …. ‘23h’ ‘00h 01/10/2000’] to mark days and keep hours Here the ‘phase’ is 0 (00h) and the level is 3 (=’day’)
- 
add(mytime, amount, units=None, copy=True)¶ Add value to time
Params: - mytime: Target time, list of times or time axis.
 - amount: Value to add.
 - units, optional: Units, needed if 
mytimeis not a time axis. - copy, optional: Copy list or time axis?
 
Example:
>>> add_time('2008-02', 3, 'days') '2008-2-4 0:0:0.0'
- 
add_margin(interval, lmargin, rmargin=None)[source]¶ Add a margin to an interval
Params: interval: A time interval or selector such as
('2000', '20001', 'co')Specified times may be of any valid type.lmargin: Left margin. Examples:
(3,'months'): explicit.'hours': Same as``(1,'hours').4: Relative margin of size(interval[1]-interval[0)/4.False: no margin.
A negative margin decrease the size of the interval.
rmargin, optional: Right margin (defaults to the left).
Example: >>> print add_margin(('2000', '2001', 'co'), (5, 'days')) ('1999-12-27 0:0:0.0', '2001-1-6 0:0:0.0', 'co')
- 
add_time(mytime, amount, units=None, copy=True)[source]¶ Add value to time
Params: - mytime: Target time, list of times or time axis.
 - amount: Value to add.
 - units, optional: Units, needed if 
mytimeis not a time axis. - copy, optional: Copy list or time axis?
 
Example:
>>> add_time('2008-02', 3, 'days') '2008-2-4 0:0:0.0'
- 
are_same_units(units1, units2)[source]¶ Compare time units
>>> are_same_units('days since 1900-1', 'days since 1900-01-01 00:00:0.0') True
- 
are_valid_units(units)[source]¶ Check that units are well formatted
Example: >>> from vacumm.misc.atime import are_good_units >>> are_good_units('months since 2000') True >>> are_good_units('months since 2000-01-01 10h20') False
- 
ascii_to_num(ss)[source]¶ Convert from ‘yyyy-mm-dd hh:mn:ss’ to [yyyy,mm,dd,hh,mn,ss]
Example: >>> ascii_to_num('2000-01') 2000, 1, 1, 0, 0, 0
- 
axis_add(mytime, amount, units=None, copy=True)¶ Add value to time
Params: - mytime: Target time, list of times or time axis.
 - amount: Value to add.
 - units, optional: Units, needed if 
mytimeis not a time axis. - copy, optional: Copy list or time axis?
 
Example:
>>> add_time('2008-02', 3, 'days') '2008-2-4 0:0:0.0'
- 
ch_units(mytimes, newunits, copy=True)[source]¶ Change units of a CDAT time axis or a list (or single element) or cdtime times
Params: mytimes: CDAT axis time object, a CDAT variable with a time axis, a valid time ot list of times.
newunits: New time units.
copy, optional: Create a new axis instead of updating the current one.
Note
If
mytimes is True, thencopyis set toFalse.
Return: New time axis, or relatives times.
Example: >>> mytimes = ch_units(time_axis,relative=False,value=False,copy=True)
Warning
In the case of a single time object or a list of them, all object that is not
cdtime.reltime()object will not be converted.
- 
check_range(this_time, time_range)[source]¶ Check wether a time is before, within or after a range
Params: - this_time: time to check (string or cdat time)
 - time_range: 2(or 3)-element range (strings or cdat times) like (‘1975’,1980-10-01’,’co)
 
Example: >>> from vacumm.misc.atime import comptime, reltime, check_range >>> check_range('2000-12', ('2000-11', '2001')) 0 >>> check_range(comptime(2000), (comptime(2000), ('2000','20001','oc')))
-1
Returns: -1 is before, 0 if within, 1 if after 
- 
comptime(mytime, nummode='mpl')[source]¶ Convert to
cdtime.comptime()formatParams: mytime: Time as string,
datetime,cdtime.comptime(),cdtime.reltime()or a: mod:cdms2 time axis.nummod, optional: Numeric case mode.
"mpl": Converted usingmatplotlib.dates.num2date()andcdtime.comptime."julday","cnes","nasa": Considered as juldian days.- Valid time units string: Converted using 
cdtime.reldate. 
Note
If not an
cdms2time axis, first argument may be a list. In this case, a list is also returned.Example: >>> from datetime import datetime ; import cdtime >>> from vacumm.misc.atime import comptime >>> comptime(datetime(2000,1,1)) 2000-1-1 0:0:0.0 >>> comptime(cdtime.reltime(10,'days since 2008')).day 10 >>> comptime('1900-01-01').year 1900
Sea also: reltime()datetime()
- 
daily(data, hstart=0, **kwargs)[source]¶ Convert to daily means
Params: - data: A cdms variable with a time axis.
 - hstart: First hour of daily intervals.
 
Example: >>> dsst = daily(sst, hstart=12)
See also: Return: A cdms variable on a daily time axis
- 
daily_bounds(taxis, hstart=0)[source]¶ Create a daily time bounds array from a time axis
Params: - taxis: A time axis or a variable with a time axis.
 - hstart, optional: First hour of each daily bounds.
 
- 
datetime(mytimes, nummode='mpl')[source]¶ Convert to
datetime.datetimeformatParams: - mytimes: Time as string, 
datetime,cdtime.comptime(),cdtime.reltime(), a number, or a: mod:cdms2 time axis. 
Note
If not an
cdms2time axis, first argument may be a list. In this case, a list is also returned.Sea also: comptime()reltime()strtime()numtime()- mytimes: Time as string, 
 
- 
filter_time_selector(*args, **kwargs)[source]¶ Create a pure time selector from all arguments
All components that are not recognized as a time selection are not kept.
Params: - ids, optional: Special keyword to specify allowed time ids in addition
to generic ones defined by 
cdms2.convention.time_aliases. - out, optional: Inverse the process by removing all time selections
(see 
filter_selector())? - keeppos, optional: Remove positional components
(see 
filter_selector())? - noslice, optional: Remove slices
(see 
filter_selector())? - Positional argument can be coordinates intervals, slices, dictionaries or cdms2 selectors.
 - Optional arguments must have a key identified as time, and a value as coordinates or slice.
 
- ids, optional: Special keyword to specify allowed time ids in addition
to generic ones defined by 
 
- 
fixcomptime(mytime, decimals=3, copy=False)[source]¶ Fix the 60s bug of
cdtime.comptimeobjectsParams: - mytime: Comptime or list of comptimes
 
- 
get_dt(axis, units=None)[source]¶ Returns the time steps of an axis. Value is computed according to the median time step, and returned in original or specified units.
Params: - axis: A time axis.
 - units, optional: Another valid unit type (cdtime or string)
 
Return: Time step
Example: >>> get_dt(var.getTime() >>> get_dt(var.getTime(), cdtime.Months) >>> get_dt(var.getTime(), 'months')
See also: 
- 
hourly(data, frequency=24, **kwargs)[source]¶ Convert to hourly means
Params: - data: A cdms variable.
 - frequency Used when different from hourly is requested [default: 24]
 
Return: A cdms variable on a hourly time axis
- 
hourly_bounds(taxis, mstart=0)[source]¶ Create a hourly time bounds array from a time axis
Params: - taxis: A time axis or a variable with a time axis.
 - mstart, optional: First minute of each daily bounds.
 
- 
hourly_exact(data, time_units=None, maxgap=None, ctlims=None)[source]¶ Linearly interpolate data at exact beginning of hours
Params: - data: Cdms variable.
 - time_units: Change time units.
 - maxgap: Maximal gap in hours to enable interpolation [default: None].
 
- 
interp(vari, outtimes, squeeze=1, **kwargs)[source]¶ Linear interpolation in time
Params: - vari**: A cdms variable with a time axis
 - outtimes: A time axis, or a list (or single element) of date strings, comptime, reltime, datetime times.
 - squeeze: Remove uneeded output dimensions [default: 1]
 - all other keywords are passed to 
interp1d(). 
- 
interp_clim(clim, times, method='linear', day=15)[source]¶ Interpolate a climatology at specified dates
- 
is_axistime(mytime)[source]¶ Check if a time is a
cdms2time axisSimple shortcut to
istime().Params: - mytime: object to check
 
Sea also: 
- 
is_cdtime(mytime)[source]¶ Check if a mytime is a cdat time (from cdtime)
Equivalent to:
is_reltime(mytime) or is_comptime()
Params: - mytime: object to check
 
Example: >>> import cdtime >>> from datetime import datetime >>> from vacumm.misc.atime import is_cdtime >>> is_cdtime(cdtime.reltime(2,'days since 2000')) True >>> is_cdtime(cdtime.comptime(2000,2)) True >>> is_cdtime(datetime(2000,2,1) False
See also: 
- 
is_comptime(mytime)[source]¶ Check if a time is a cdat comptime (from
cdtime)Params: - mytime: object to check
 
Sea also: 
- 
is_datetime(mytime)[source]¶ Check if a time is a
datetime.datetimetimeParams: - mytime: object to check
 
Sea also: 
- 
is_in_time_interval(this_time, time_range)[source]¶ Check if a time is in specified closed/open range
Params: - this_time: time to check (string or cdat time)
 - time_range: 2(or 3)-element range (strings or cdat times) like (‘1975’,1980-10-01’,’co)
 
Example: >>> is_in_range('2000-12', ('2000-11', '2001')) True
Sea also: 
- 
is_interval(interval)[source]¶ Check if interval is a valid time interval
Params: - interval: It should be in the following generic form
 
(<time0>,<time1>[,<bounds>]), where<time?>is a valid time (seetime_type()andis_valid()) and<bounds>are interval bounds such as"co".
- 
is_numtime(mytime)[source]¶ Simply check if a mytime is a number !
Params: - mytime: object to check
 
Sea also: is_datetime()is_comptime()is_reltime()is_cdtime()is_time()
- 
is_reltime(mytime)[source]¶ Check if a time is a cdat reltime (from
cdtime)Params: - mytime: object to check
 
Sea also: 
- 
is_strtime(mytime)[source]¶ Check if a time is a valid string date
Params: - mytime: object to check
 
Sea also: is_datetime()is_comptime()is_reltime()is_cdtime()is_time()
- 
is_time(mytime, alsonum=False)[source]¶ Check if mytime is a CDAT time, a
datetime.datetimeor date valid string.Equivalent to:
timetype(mytime) is not None
Sea also: is_datetime()is_reltime()is_cdtime()is_numtime()is_time()
- 
itv_intersect(itv1, itv2, bb=None, aslogical=False)[source]¶ Return the intersection of 2 time intervals
Return: The interval or Falseif not intersection is found
- 
julday(mytime, mode='cnes')[source]¶ Convert to a CNES julian days, i.e. days from 1950 (CNES) or 1958 (NASA)
Params: mytime: Time as string,
datetime,cdtime.comptime(),cdtime.reltime(), a number or a: mod:cdms2 time axis.ref, optional: computation mode
"cnes": days from 1958-01-01"nasa": days from 1958-01-01
Note
If not an
cdms2time axis, first argument may be a list. In this case, a list is also returned.Sea also: comptime()reltime()datetime()strtime()
- 
lindates(first, last, incr, units=None)[source]¶ Create a list of linearly incrementing dates
Params: - first: first date
 - last: first date
 - incr: increment step OR number of steps if units is None
 - units: units like “days” (see 
unit_type()) or None 
Example: >>> dates = lindates('2000', '2002-05', 3, 'months') >>> dates = lindates('2000', '2002-05', 8)
Return: - list of 
cdtime.comptime()dates 
- 
midnight_date(mydate)[source]¶ Round a date to the closest midnight
Example: >>> print midnight_date('2010-11-29 23:10') 2010-11-30 0:0:0.0
Return: cdtime.comptimedate at midnight
- 
midnight_interval(date)[source]¶ Round dates of a closed interval to the closest midnight
Example: >>> print midnight_interval('2010-11-29 23:10') (2010-11-30 0:0:0.0, 2010-11-30 0:0:0.0, 'ccb') >>> print midnight_interval(('2010-11-29 23:10','2010-11-30 04')) (2010-11-30 0:0:0.0, 2010-11-30 0:0:0.0, 'ccb')
Return: cdtime.comptimeinterval
- 
monthly(data, **kwargs)[source]¶ Convert to monthly means
Params: - data: A cdms variable.
 
Return: A cdms variable on a hourly time axis
- 
mpl(mytimes, copy=True)[source]¶ Convert to Matplotlib units.
Time objects (or list of them) are converted to pure numerical values.
Params: - mytimes: Time object (or list), or time axis.
 - copy, optional: Copy time axis or not?
 
Note
This function does not use
ch_units(). It uses Matplotlib internal functionmatplotlib.dates.date2num()instead.Example: >>> taxis = create_time((0, 10.), 'hours since 2000-01-01') >>> maxis = mpl(taxis) >>> print maxis[0] 730120.0 >>> print maxis.units days since 0001
- 
notz(mytime)[source]¶ Suppres time zone
Params: Return: - A 
datetime.datetimeinstance with not TZ 
- A 
 
- 
now(utc=False)[source]¶ Return current time as
cdtime.comptime()Params: - utc, optional: Return UTC time [default: False]
 
- 
num_to_ascii(yyyy=1, mm=1, dd=1, hh=0, mn=0, ss=0)[source]¶ Convert from [yyyy,mm,dd,hh,mn,ss] or component time or relative time to ‘yyyy-mm-dd hh:mn:ss’
Params: - yyyy: int year OR component OR relative time (cdms) [default: 1]
 - mm: month [default: 1]
 - dd: day [default: 1]
 - hh: hour [default: 0]
 - mn: minute [default: 0]
 - ss: second [default: 0]
 
Example: >>> num_to_ascii(month=2) 0001-02-01 00:00:00 >>> num_to_ascii(comptime(2000,10)) 2000-10-01 00:00:00
- 
numtime(mytime)[source]¶ Convert to a numeric time using
date2num()Params: - mytime: Time as string, 
datetime,cdtime.comptime(),cdtime.reltime(), a number or a: mod:cdms2 time axis. 
Note
If not an
cdms2time axis, first argument may be a list. In this case, a list is also returned.Sea also: comptime()reltime()datetime()strtime()- mytime: Time as string, 
 
- 
pat2freq(pattern)[source]¶ Get the maximal frequency (“days”, “hours”, etc) associated with a date pattern
Params: - pattern: A string containg date patterns (like ‘%d’ or ‘%%d’)
 
Return: One of
None,"seconds","minutes","hours","days","months","yaers".Example: >>> print pat2freq('%d/%m/%Y') days
- 
pat2glob(pattern, esc=False)[source]¶ Convert a date pattern to a rough global matching pattern
Note
A global matching pattern is a UNIX file pattern. See
glob.glob()for more information.Warning
The output global pattern is NOT strict, and thus may embed more than requested by the date pattern.
Params: - pattern: A string containg date patterns (like ‘%d’ or ‘%%d’)
 - esc, optional: If 
True, date patterns are escaped (like ‘%%d’) 
- 
reduce(vari, geterr=False, **kwargs)[source]¶ Average time steps that have the same bounds or time
Params: - vari: Aray with a valid time axis.
 
Example: >>> taxis = sst.getTime() >>> tbounds = daily_bounds(taxis, hstart=12) >>> taxis.setBounds(tbounds) >>> nightly_sst = reduce(sst)
- 
reduce_old(data, comp=True, fast=True)[source]¶ Reduce a variable in time by performing time average on time step that have the same time or time bounds.
- data: A cdms variable with first axis supposed to be time.
 - comp: Call to 
compress()before reducing [default: True] - fast: Convert to pure numpy before processing, then convert back to cdms variable [default: True]
 
Return: The new variable on its new time axis.
- 
reltime(mytime, units)[source]¶ Convert to func:cdtime.reltime format
Params: - mytime: Time as string, 
datetime,cdtime.comptime(),cdtime.reltime(), a number or a: mod:cdms2 time axis. 
Note
If not an
cdms2time axis, first argument may be a list. In this case, a list is also returned.Sea also: comptime()datetime()strtime()numtime()- mytime: Time as string, 
 
- 
round_date(mydate, round_type, mode='round')[source]¶ Round a date to a step in year, month, day, hour, minute or second
Params: mydate: A date compatible with
comptime().round_type: A string like “year” or a tuple like (3, “year”).
mode, optional: Rounding mode
"ceil": Choose the upper time."floor": Choose the lower time.- Else choose the nearest.
 
- 
round_interval(time, round_type, mode='inner')[source]¶ Round an time interval using
round_date()Params: time: A time interval like
(time0, time1, 'cce')round_type: A string like “year” or a tuple like (3, “year”).
mode, optional: Rounding mode
"inner": Upper for the lower bound and lower for the upper bound."outer": Opposite to “inner”- tuple: first is applied to lower bound, second to upper bound.
 - Else, passed to 
round_date()and applied to both bounds. 
- 
selector(*args, **kwargs)¶ Create a pure time selector from all arguments
All components that are not recognized as a time selection are not kept.
Params: - ids, optional: Special keyword to specify allowed time ids in addition
to generic ones defined by 
cdms2.convention.time_aliases. - out, optional: Inverse the process by removing all time selections
(see 
filter_selector())? - keeppos, optional: Remove positional components
(see 
filter_selector())? - noslice, optional: Remove slices
(see 
filter_selector())? - Positional argument can be coordinates intervals, slices, dictionaries or cdms2 selectors.
 - Optional arguments must have a key identified as time, and a value as coordinates or slice.
 
- ids, optional: Special keyword to specify allowed time ids in addition
to generic ones defined by 
 
- 
strftime(fmt, mytime=None)[source]¶ Convert current time, datetime, cdtime or string time to strftime
Params: - fmt: Time format with date patterns, like 
"%Y-%m-%d". - mytime, optional: If None, takes current time using
 
(
now())Examples: >>> print strftime('%Y-%m-%d') 2014-02-25 >>> ctime = strftime('%Hh%M', '2020') 00h00
Sea also: - fmt: Time format with date patterns, like 
 
- 
strptime(mytime, fmt)[source]¶ Parse a string according to a format to retreive a component time
Params: - fmt: Time format with date patterns, like 
"%Y-%m-%d". - mytime: Date string.
 
Example: >>> print strptime('25 Jan 2000, '%d %b %Y').month 1
Sea also: - fmt: Time format with date patterns, like 
 
- 
strtime(mytime)[source]¶ Convert to valid string date
Params: - mytime: Time as string, 
datetime,cdtime.comptime(),cdtime.reltime(), a number, or a: mod:cdms2 time axis. 
Note
If not an
cdms2time axis, first argument may be a list. In this case, a list is also returned.Sea also: comptime()reltime()datetime()numtime()- mytime: Time as string, 
 
- 
tic()[source]¶ Launch a time counter at the begining of your program.
Return: - A time to be used with the toc() function.
 
Examples: >>> stime = tic()
- 
time_selector(arg0, arg1=None, bounds=None, round=False, utc=True)[source]¶ Time selector formatter that returns start date and end date as component times
Example: >>> selector('2006','2007') # between two dates >>> selector(comptime(1950)) # from a date to now >>> selector(1,'month','co') # from now into the past
- 
time_split(what, how, roundit=None, bb='co')[source]¶ Generic function to split an interval into subintervals
Params: what: Time interval, dates or time axis that can be converted using
comptime().how: Splitting specifications.
roundit, optional: Round interval. Valid only if
howis an time step specification such as(1,'year')or"year"(seeIntervals).
- 
time_split_nmax(what, nmax, roundit=True)[source]¶ Smartly split an interval with a length into subintervals of max length
- 
time_type(mytime, out='string', check=False)[source]¶ Get the type of time
Params: mytime: A time of one of the following types:
cdtime.comptime(),cdtime.reltime(),datetime.datetime()or a date string.out, optional: Output format, one of:
"string": Return one of"comptime","reltime""datetime","strtime","numtime"."type": Simply return result oftype(mytime)"func": Return the function used to convert to this type :comptime(),reltime(),datetime(),numtime().
Return: Noneif not a time, or see out.Example: >>> time_type('2000-10') 'str' >>> time_type(cdtime.comptime(2000,10), out='func') <function comptime at 0x31c4aa0>
- 
toc(stime=0.0)[source]¶ Compute the cost of the computation and display in an adapted format.
Params: - stime, optional: The initial time given by the tic() function.
 
Return: - Display the time spent in the program.
 
Examples: >>> stime = tic() >>> >>> toc(stime=stime)
- 
tsel2slice(taxis, *args, **kwargs)[source]¶ Convert time selections on a time axis to a valid slice or None
Params: - asind, optional: Return indices instead of a slice.
 - nonone, optional: Return the full slice instead of 
Noneif everything is selected. - Positional argument can be coordinates intervals, slices, dictionaries or cdms2 selectors.
 - Optional arguments must have a key identified as time or be the axis id, and a value as coordinates or slice.
 
Return: - A 
sliceor(i,j,k)when possible. Noneor the full slice if no slice needed (everything is selected).Falseif no intersection is found.
Examples: >>> myslice = tsel2slice(taxis, ('2000', '2002', 'co'), time=slice(4,6)) >>> myslice = tsel2slice(taxis, cdms2.selectors.Selector(lon=(5,6), time=('2000','2002')) >>> myslice = tsel2slice(taxis, slice(10,12), dict(time=slice(4,5), time=('2000','2002'))
- 
unit_type(units, string_type=False, s=True, raiseerr=True)[source]¶ Returns a type of units in a suitable form with checkings.
Params: - units: A valid string or cdtime type of units.
 - string_type: Returns a string type instead of a cdtime type [default: False]
 
Return: A valid string or cdtime type of units
Example: >>> unit_type('minutes') >>> unit_type(cdtime.Minutes,True)