pyinterp.Axis

Contents

pyinterp.Axis#

class pyinterp.Axis(self, values: numpy.ndarray[dtype=float64, shape=(*), writable=False], epsilon: float = 1e-06, period: float | None = None)#

Bases: object

Create a coordinate axis for variable values.

A coordinate axis defines the coordinates of a variable’s values. It accepts an array of floating-point values and optional parameters for comparison tolerance and periodicity.

Parameters:
  • values – Axis values as a numpy-compatible array of float64.

  • epsilon – Maximum allowed difference between two real numbers to consider them equal. Defaults to 1e-6.

  • period – Period of the axis for cyclic variables (e.g. 360 for degrees). Defaults to None.

Examples

>>> import numpy as np
>>> import pyinterp

Create a regular axis from 0 to 10 with step of 1

>>> values = np.arange(0, 11, dtype='float64')
>>> axis = pyinterp.Axis(values)

Create a regular periodic axis from 0° to 350° with a 10° increment. Since 360 is equivalent to 0, it is intentionally omitted from the array.

>>> values = np.arange(0, 351, 10, dtype='float64')
>>> axis_periodic = pyinterp.Axis(
...     values,
...     epsilon=1e-5,  # Tolerance for floating-point comparisons
...     period=360.0   # Period of the axis
... )

Create an irregular axis with tolerance

>>> values = np.array([0.0, 1.1, 2.5, 4.0, 7.3], dtype='float64')
>>> axis_irregular = pyinterp.Axis(
...     values,
...     epsilon=1e-5  # Tolerance for floating-point comparisons
... )

Initialize the axis with the given values, tolerance, and period.

Attributes

is_periodic

True if this axis represents a periodic variable.

period

Period value of this axis.

Public Methods

back(self)

Last value of this axis.

find_index(self, coordinates[, shape, writable])

Find the index of the axis element that contains a coordinate.

find_indexes(self, coordinates[, shape, ...])

Find indexes of axis elements surrounding each coordinate.

flip(self[, inplace])

Reverse the order of elements in the axis.

front(self)

First value of this axis.

increment(self)

Get the increment (step) between values in this axis.

is_ascending(self)

Check if the axis values are in ascending order.

is_regular(self)

Check if the axis is regular.

max_value(self)

Maximum value of this axis.

min_value(self)

Minimum value of this axis.

Special Methods

__copy__(self)

Implement the shallow copy operation.

__eq__(self, other)

Override the default behavior of the == operator.

__getitem__(-> float)

Overloaded function.

__getstate__(self)

Get the state for pickling.

__len__(self)

Return the length of the axis.

__ne__(self, other)

Override the default behavior of the != operator.

__new__(*args, **kwargs)

__repr__(self)

Return the string representation of this Axis.

__setstate__(self, state)

Set the state for unpickling.