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:

NamedAxis

Generic axis object identified by its name.

Lon

Longitude axis.

Lat

Latitude axis.

Height

Geometric height axis.

Pres

Pressure height axis.

Hybrid

Hybridized vertical coordinate axis.

StandardTime

Time axis describing the standard Gregorian calendar.

ModelTime365

Time axis describing a model 365-day calendar.

ModelTime360

Time axis describing a model 360-day calendar.

Yearless

Time axis describing a calendar with no months or years.

NonCoordinateAxis

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

Axis.auxarrays

Auxiliary arrays.

Axis.auxatts

Auxiliary attributes.

Axis.rtol

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

Axis.formatstr

Format specification for plotting values.

Axis.formatter()

Returns a matplotlib formatter (pygeode.AxisFormatter) for use in plotting.

Axis.locator()

Returns a matplotlib locator object for use in plotting.

Axis.plotatts

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