Horizonal axis objects reference

class pygeode.XAxis[source]

Inherits from Axis

Generic parent class for axes representing horizontal coordinates, plotted by default on the horizontal axis in contour plots and line plots. No new or overridden methods.

class pygeode.YAxis[source]

Inherits from Axis

Generic parent class for axes representing horizontal coordinates, plotted by default on the horizontal axis in line plots, but on the vertical in contour plots. No new or overridden methods.

class pygeode.Lon[source]

Inherits from YAxis

Represents longitude (in degrees East by default). Regular longitude grids can be created with the helper method regularlon().

New and overridden methods

Lon.__init__(values[, name, atts, plotatts, ...])

Create a new Axis object with the given values.

Lon.formatvalue(value[, fmt, units, unitstr])

Returns formatted string representation of longitude value.

Lon.locator()

Returns a matplotlib locator object for use in plotting.

class pygeode.Lat[source]

Inherits from YAxis

Represents latitude (in degrees North by default). Evenly spaced and gaussian latitude grids can be created with the helper functions regularlat() and gausslat().

New and overridden methods

Lat.__init__(values[, weights])

Create a new Axis object with the given values.

Lat.formatvalue(value[, fmt, units, unitstr])

Returns formatted string representation of latitude value.

Lat.locator()

Returns a matplotlib locator object for use in plotting.

Utility functions

regularlon(n[, origin, order, repeat_origin])

Constructs a regularly spaced Lon axis with n longitudes.

rotatelon(v, origin[, duplicate])

Rotates longitude axis to start at a new origin.

regularlat(n[, order, inc_poles])

Constructs a regularly spaced Lat axis with n latitudes.

gausslat(n[, order, axis_dict])

Constructs a Gaussian Lat axis with n latitudes.

Lon.__init__(values, name=None, atts=None, plotatts=None, rtol=None, **kwargs)

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 Axis need to call this __init__ method within their own __init__, to properly initialize all attributes.

Lon.formatvalue(value, fmt=None, units=False, unitstr=None)[source]

Returns formatted string representation of longitude value.

Parameters
valuefloat or int

Value to format.

fmtstring (optional)

Format specification; see Notes. If the default None is specified, self.formatstr is used.

unitsboolean (optional)

If True, will include the units in the string returned. Default is False.

unitstrstring (optional)

String to use for the units; default is self.units.

Returns
Formatted representation of the latitude. See notes.

Notes

If fmt is includes the character ‘E’, the hemisphere (‘E’ or ‘W’) is appended to the string. The value is wrapped to lie between 0 and 360., and the eastern hemisphere is defined as values less than 180. Optionally, the boundary between the hemispheres can be specified by adding, for example, ‘<360’ after the ‘E’; in this case all values less than 360 would have ‘E’ appended. Otherwise the behaviour is like Var.formatvalue().

Examples

>>> from pygeode.tutorial import t1
>>> print(t1.lon.formatvalue(270))
270 E
>>> print(t1.lon.formatvalue(-20.346, '%.4gE'))
20.35W
>>> print(t1.lon.formatvalue(-192.4, '%.3g'))
-192
Lon.locator()[source]

Returns a matplotlib locator object for use in plotting.

pygeode.regularlon(n, origin=0.0, order=1, repeat_origin=False)[source]

Constructs a regularly spaced Lon axis with n longitudes. The values range from origin to origin + 360. If repeat_origin is set to True, the final point is equal to origin + 360.

pygeode.rotatelon(v, origin, duplicate=False)[source]

Rotates longitude axis to start at a new origin.

Parameters
vVar

Variable with Lon axis to modify

origin: float

New origin for longitude axis

duplicate: boolean; optional

If true, duplicates the origin value at the end of the axis (can be useful for plotting). Default is False.

Returns
vnVar

Variable with modified longitude axis

Examples

>>> import pygeode as pyg; from pygeode.tutorial import t1
>>> print(t1.Temp.lon)
lon <Lon>      :  0 E to 354 E (60 values)
>>> print(pyg.rotatelon(t1.Temp, -180))
<Var 'Temp'>:
  Units: K  Shape:  (lat,lon)  (31,60)
  Axes:
    lat <Lat>      :  90 S to 90 N (31 values)
    lon <Lon>      :  180 E to 174 E (60 values)
  Attributes:
    {}
  Type:  SortedVar (dtype="float64")
>>> print(pyg.rotatelon(t1.Temp, 0, duplicate=True).lon[:])
[  0.   6.  12.  18.  24.  30.  36.  42.  48.  54.  60.  66.  72.  78.
  84.  90.  96. 102. 108. 114. 120. 126. 132. 138. 144. 150. 156. 162.
 168. 174. 180. 186. 192. 198. 204. 210. 216. 222. 228. 234. 240. 246.
 252. 258. 264. 270. 276. 282. 288. 294. 300. 306. 312. 318. 324. 330.
 336. 342. 348. 354. 360.]
Lat.__init__(values, weights=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 Axis need to call this __init__ method within their own __init__, to properly initialize all attributes.

Lat.formatvalue(value, fmt=None, units=False, unitstr=None)[source]

Returns formatted string representation of latitude value.

Parameters
valuefloat or int

Value to format.

fmtstring (optional)

Format specification; see Notes. If the default None is specified, self.formatstr is used.

unitsboolean (optional)

If True, will include the units in the string returned. Default is False.

unitstrstring (optional)

String to use for the units; default is self.units.

Returns
Formatted representation of the latitude. See notes.

Notes

If the last character of fmt is ‘N’, then the absolute value of value is formatted using the fmt[:-1] as the format specification, and the hemisphere is added, using ‘N’ for values greater than 0 and ‘S’ for values less than 0. The value 0 is formatted as ‘EQ’. Otherwise the behaviour is like Var.formatvalue().

Examples

>>> from pygeode.tutorial import t1
>>> print(t1.lat.formatvalue(0))
EQ
>>> print(t1.lat.formatvalue(-43.61, '%.3gN'))
43.6S
>>> print(t1.lat.formatvalue(-43.61, '%.3g'))
-43.6
Lat.locator()[source]

Returns a matplotlib locator object for use in plotting.

pygeode.regularlat(n, order=1, inc_poles=True)[source]

Constructs a regularly spaced Lat axis with n latitudes. If inc_poles is set to True, the grid includes the poles.

pygeode.gausslat(n, order=1, axis_dict={})[source]

Constructs a Gaussian Lat axis with n latitudes.