Time axes objects reference¶
- class pygeode.TAxis[source]¶
Inherits from
AxisGeneric parent class for axes representing time coordinates, plotted by default on the horizontal axis in line plots and in contour plots. No new or overridden methods.
- class pygeode.timeaxis.Time[source]¶
Inherits from
TAxisParent class for axes representing times.
New and overridden methods
Time.__init__([values, startdate, units])Create a new Axis object with the given values.
Returns a matplotlib axis Formatter object; by default a FuncFormatter which calls formatvalue().
locator() - Returns an AutoCalendarLocator object
Time.map_to(other)Define a mapping between this time axis and another one, if one exists.
- class pygeode.timeaxis.CalendarTime[source]¶
Inherits from
TimeParent class for time axes with an associated calendar.
Attributes
CalendarTime.parse_patternsNew and overridden methods
CalendarTime.__init__([values, datefmt, ...])Create a new Axis object with the given values.
CalendarTime.days_in_month(yr, mn)CalendarTime.formatvalue(value[, fmt, ...])Returns formatted string representation of
value, using a strftime-like specification.CalendarTime.str_as_val(key, s)Converts a string representation of a date to a value according to the calendar defined by this time axis.
CalendarTime.val_as_date([vals, startdate, ...])CalendarTime.date_as_val([dates, startdate, ...])
- class pygeode.StandardTime[source]¶
Inherits from
CalendarTimeTime axis representing the standard calendar.
- class pygeode.ModelTime365[source]¶
Inherits from
CalendarTimeTime axis representing a calendar with a 365 day year.
- class pygeode.ModelTime360[source]¶
Inherits from
CalendarTimeTime axis representing a calendar with a 360 day year.
- class pygeode.Yearless[source]¶
Inherits from
CalendarTimeTime axis representing a calendar that marks days independent of years and months.
New and overridden methods
Yearless.__init__(*args, **kwargs)Create a new Axis object with the given values.
Yearless.days_in_month(yr, mn)
Utility functions
|
Creates a |
|
Creates a |
|
Creates a |
|
Creates a |
|
Creates a |
|
Creates a |
|
Creates a |
- Time.__init__(values=None, startdate=None, units=None, **kwargs)[source]¶
Create a new Axis object with the given values.
- Parameters
- valuesnumpy.ndarray
A one-dimensional coordinate defining the axis grid.
- namestring (optional)
What to call the axis (i.e. for plot titles & when saving to file)
- attsdict (optional)
Any additional metadata to associate with the axis. The dictionary keys should be strings.
- plotattsdict (optional)
Parameters that control plotting behaviour; default values are available. The dictionary keys should be strings.
- rtolfloat
A relative tolerance used for identifying an element of this axis.
Notes
All subclasses of
Axisneed to call this __init__ method within their own __init__, to properly initialize all attributes.
- Time.formatter()[source]¶
Returns a matplotlib axis Formatter object; by default a FuncFormatter which calls formatvalue().
- Time.map_to(other)[source]¶
Define a mapping between this time axis and another one, if one exists.
- Parameters
- other
Axisinstance Axis instance to find map to.
- other
- Returns
- indicesAn array of integer indices or None
If a mapping exists, an array of integer indices which define mapping from this axis to other (i.e. self[indices] will return the elements in the appropriate ordering for the mapped axis). Otherwise None.
Notes
A mapping from this time axis to other can exist only if they are of the same class (e.g.
StandardTime), and if the list of auxarrays defined in this class is a subset of those defined in the other (e.g. a climatology which defines only ‘month’, and ‘day’ can be mapped to a time axis with ‘year’, ‘month’ ‘day’ and ‘hour’, but not one with only ‘year’ and ‘month’.Matches are sought between the auxiliary arrays shared by the two axes
- CalendarTime.parse_pattern¶
A Python regular expression used to parse a string as a date. Date fields are extracted using the groups ‘year’, ‘month’, ‘day’, ‘hour’, ‘minute’, and ‘second’. Default pattern recognized strings of the form ‘1 Jan 2000’ or ‘06:00 1 Jan 2000’ or ‘06:00:00 1 Jan 2000’.
- CalendarTime.__init__(values=None, datefmt=None, units=None, startdate=None, **kwargs)[source]¶
Create a new Axis object with the given values.
- Parameters
- valuesnumpy.ndarray
A one-dimensional coordinate defining the axis grid.
- namestring (optional)
What to call the axis (i.e. for plot titles & when saving to file)
- attsdict (optional)
Any additional metadata to associate with the axis. The dictionary keys should be strings.
- plotattsdict (optional)
Parameters that control plotting behaviour; default values are available. The dictionary keys should be strings.
- rtolfloat
A relative tolerance used for identifying an element of this axis.
Notes
All subclasses of
Axisneed to call this __init__ method within their own __init__, to properly initialize all attributes.
- CalendarTime.formatvalue(value, fmt=None, units=True, unitstr=None)[source]¶
Returns formatted string representation of
value, using a strftime-like specification.- Parameters
- valuefloat or int
Value to format, in calendar defined by this time axis.
- fmtstring (optional)
Format specification. If the default
Noneis specified,self.formatstris used.- unitsboolean (optional)
Not used;, included for consistency with
Var.formatvalue()- unitstrstring (optional)
Not used;, included for consistency with
Var.formatvalue()
Notes
The following codes ($$ will yield the character $):
$b - short month name
$B - full month name
$d - day of the month
$D - 2-digit day of the month, zero-padded
$H - hour (24 hr clock)
$I - hour (12 hr clock)
$j - day of the year
$m - month number (Jan=1, …, Dec=12)
$M - minute
$p - am/pm
$P - AM/PM
$S - second
$y - 2 digit year
$a - 4 digit year
$Y - full year; if less than 100, preceeded by ‘y’
$v - value formatted with %d
$V - value formatted with str()
Examples
>>> from pygeode.tutorial import t2 >>> print(t2.time.formatvalue(17.25)) Jan 18, 2011 06:00:00 >>> print(t2.time.formatvalue(0, '$B $d')) January 1 >>> print(t2.time.formatvalue(512, '$d/$m/$y')) 28/5/12
- CalendarTime.str_as_val(key, s)[source]¶
Converts a string representation of a date to a value according to the calendar defined by this time axis.
- Parameters
- keystring
key used in select()
- sstring
string to convert
- Returns
- valvalue
value corresponding to specified date.
Notes
The string is parsed using the regular expression pattern(s) defined in
parse_patterns. By default this assumes a string in an ISO 8601-like format, or in the form ‘12 Dec 2008’ or ‘06:00:00 1 Jan 1979’. A ValueError is thrown if the regular expression does not match the string.
- Yearless.__init__(*args, **kwargs)[source]¶
Create a new Axis object with the given values.
- Parameters
- valuesnumpy.ndarray
A one-dimensional coordinate defining the axis grid.
- namestring (optional)
What to call the axis (i.e. for plot titles & when saving to file)
- attsdict (optional)
Any additional metadata to associate with the axis. The dictionary keys should be strings.
- plotattsdict (optional)
Parameters that control plotting behaviour; default values are available. The dictionary keys should be strings.
- rtolfloat
A relative tolerance used for identifying an element of this axis.
Notes
All subclasses of
Axisneed to call this __init__ method within their own __init__, to properly initialize all attributes.
- pygeode.standardtimerange(start, end, step=1, units='days', ref=None, inc=False)[source]¶
Creates a
StandardTimeaxis for the period from start to end.- Parameters
- startstring
Date to start time axis from (see
str_as_val())- endstring
Date to end time axis at. Note this date will not be included.
- stepfloat, optional
Interval between grid points. Default is 1.
- unitsone of ‘seconds’, ‘minutes’, ‘hours’, ‘days’, optional
Unit in which to define time step values. Default is ‘days’.
- refstring, optional
Reference date for calendar. If the default None is specified, start is used.
- incboolean, optional (default False)
- pygeode.standardtimen(start, n, step=1, units='days', ref=None)[source]¶
Creates a
StandardTimeaxis of length n.- Parameters
- startstring
Date to start time axis from (see
str_as_val())- ninteger
Length of axis to create
- stepfloat, optional
Interval between grid points. Default is 1.
- unitsone of ‘seconds’, ‘minutes’, ‘hours’, ‘days’, optional
Unit in which to define time step values. Default is ‘days’.
- refstring, optional
Reference date for calendar. If the default None is specified, start is used.
- pygeode.modeltime365range(start, end, step=1, units='days', ref=None, inc=False)[source]¶
Creates a
ModelTime365axis for the period from start to end.- Parameters
- startstring
Date to start time axis from (see
str_as_val())- endstring
Date to end time axis at. Note this date will not be included.
- stepfloat, optional
Interval between grid points. Default is 1.
- unitsone of ‘seconds’, ‘minutes’, ‘hours’, ‘days’, optional
Unit in which to define time step values. Default is ‘days’.
- refstring, optional
Reference date for calendar. If the default None is specified, start is used.
- incboolean, optional (default False)
- pygeode.modeltime365n(start, n, step=1, units='days', ref=None)[source]¶
Creates a
ModelTime365axis of length n.- Parameters
- startstring
Date to start time axis from (see
str_as_val())- ninteger
Length of axis to create
- stepfloat, optional
Interval between grid points. Default is 1.
- unitsone of ‘seconds’, ‘minutes’, ‘hours’, ‘days’, optional
Unit in which to define time step values. Default is ‘days’.
- refstring, optional
Reference date for calendar. If the default None is specified, start is used.
- pygeode.modeltime360range(start, end, step=1, units='days', ref=None, inc=False)[source]¶
Creates a
ModelTime360axis for the period from start to end.- Parameters
- startstring
Date to start time axis from (see
str_as_val())- endstring
Date to end time axis at. Note this date will not be included.
- stepfloat, optional
Interval between grid points. Default is 1.
- unitsone of ‘seconds’, ‘minutes’, ‘hours’, ‘days’, optional
Unit in which to define time step values. Default is ‘days’.
- refstring, optional
Reference date for calendar. If the default None is specified, start is used.
- incboolean, optional (default False)
- pygeode.modeltime360n(start, n, step=1, units='days', ref=None)[source]¶
Creates a
ModelTime360axis of length n.- Parameters
- startstring
Date to start time axis from (see
str_as_val())- ninteger
Length of axis to create
- stepfloat, optional
Interval between grid points. Default is 1.
- unitsone of ‘seconds’, ‘minutes’, ‘hours’, ‘days’, optional
Unit in which to define time step values. Default is ‘days’.
- refstring, optional
Reference date for calendar. If the default None is specified, start is used.
- pygeode.yearlessn(n, start=1, step=1, units='days')[source]¶
Creates a
Yearlessaxis of length n.- Parameters
- startstring
Date to start time axis from (see
str_as_val())- ninteger
Length of axis to create
- stepfloat, optional
Interval between grid points. Default is 1.
- unitsone of ‘seconds’, ‘minutes’, ‘hours’, ‘days’, optional
Unit in which to define time step values. Default is ‘days’.