Axis class overview¶
An Axis is a one-dimensional array of values, representing some kind of
coordinate. For example, a Lat
axis represents a set of latitudes over the
globe. Axes are a subclass of Var
, and can be treated as such for many purposes
(such as arithmetic operations), though they have some specific behaviour, including
the fact that their values are always explicitly loaded into memory.
In practice the Axis
class is rarely instantiated directly; one of its subclasses
are typically used to represent a dimension of a particular type.
Types of axes¶
The following is a (non-exhaustive) list of more commonly used axes built into PyGeode:
Generic axis object identified by its name. |
|
Longitude axis. |
|
Latitude axis. |
|
Geometric height axis. |
|
Pressure height axis. |
|
Hybridized vertical coordinate axis. |
|
Time axis describing the standard Gregorian calendar. |
|
Time axis describing a model 365-day calendar. |
|
Time axis describing a model 360-day calendar. |
|
Time axis describing a calendar with no months or years. |
|
Non-coordinate axis (disables nearest-neighbour value matching, etc.) |
If PyGeode doesn’t have a built-in representation of an axis that your input
data uses, it will default to a generic NamedAxis
object, with no additional
context on what that axis represents. To get around this, you can always
define your own custom axis, and force your Var to use it
through Var.replace_axes()
or when importing from a data file.
In addition to the members listed below, Axis
objects inherit methods from
the Var
class; see Var class overview for this functionality.
- class pygeode.Axis[source]¶
Inherits from
Var
Generic attributes
Auxiliary arrays.
Auxiliary attributes.
The relative tolerance for identifying an element of this axis.
Generic Axis methods
Axis.__init__
(values[, name, atts, ...])Create a new Axis object with the given values.
Axis.argsort
([reverse])Generates a list of indices that would sort the Axis.
Axis.auxasvar
(name)Returns auxiliary array as a new
Var
object.Axis.rename
(name)Assigns a new name to this axis.
Axis.sorted
([reverse])Sorts the points of the Axis.
Axis.str_as_val
(key, s)str_as_val(self, key, s) - converts string s to a value corresponding to this axis.
Formatting and Plotting
Format specification for plotting values.
Returns a matplotlib formatter (pygeode.AxisFormatter) for use in plotting.
Returns a matplotlib locator object for use in plotting.
Dictionary of attributes for plotting; see plotting documentation.
Internal calls
Axis.__call__
(**kwargs)Keyword-based data subsetting.
Axis._getitem_asvar
(slices)Slice-based data subsetting.
Axis.class_has_alias
(name)Axis.isparentof
(other)Determines if an axis object is an instance of a base class (or the same class) of another axis.
Axis.map_to
(other)Returns indices of this axis which correspond to the axis
other
.
Defining a new type of axis¶
It’s impossible (or at least improbable) for the standard PyGeode package to include every possible type of axis that people may want. However, it’s fairly straight-forward to define your own custom axis. Simply define a new class, as a subclass of Axis
.
For example, suppose one of the dimensions of your data is solar zenith angle (SZA). You can make a simple Axis representation as follows:
>>> from pygeode import Axis
>>> class SZA_Axis (Axis): pass
...
You can now use it like any other axis:
>>> sza = SZA_Axis ([20.1, 20.2, 20.3, 20.4, 20.5])
>>> print(sza)
sza_axis <SZA_Axis>: 20.1 to 20.5 (5 values)
A more customized version:
>>> class SZA_Axis (Axis):
... name = "sza"
... units = "degrees"
...
>>> sza = SZA_Axis ([20.1, 20.2, 20.3, 20.4, 20.5])
>>> print(sza)
sza_axis <SZA_Axis>: 20.1 degrees to 20.5 degrees (5 values)
If you think your axis will be useful to others, please let us know, and we may include it in future versions.
Aspects of customizing an axis:
Defining its name
Customize how values are formatted as strings
Customize how strings are parsed into values
Customize matplotlib formatting and tick positioning
Customize CF-metadata encoding and decoding