pyinterp.TemporalAxis#
- class pyinterp.TemporalAxis(self, points: object, epsilon: object | None = None, period: object | None = None)#
Bases:
objectTemporal axis for datetime64 or timedelta64 values.
Create a coordinate axis for datetime64 or timedelta64 values.
This class accepts numpy.datetime64 or numpy.timedelta64 arrays and supports periodicity and tolerance (epsilon) using timedelta64 values.
- Parameters:
points – Axis coordinate values as a numpy datetime64 or timedelta64 array.
epsilon – Maximum allowed difference between two values to consider them equal. Must have the same or a coarser resolution than points. Defaults to None.
period – Period for cyclic/periodic axes (for example, 24 hours or 365 days). Must have the same or a coarser resolution than points. Defaults to None.
- Raises:
ValueError – If epsilon or period have a finer resolution than points.
TypeError – If points is not a datetime64 or timedelta64 array.
Examples
>>> import numpy as np >>> import pyinterp
Create a regular hourly axis over one day
>>> times = np.arange('2024-01-01', '2024-01-02', dtype='datetime64[h]') >>> axis = pyinterp.TemporalAxis(times)
Create a daily periodic axis (24-hour cycle)
>>> axis_periodic = pyinterp.TemporalAxis( ... times, ... epsilon=np.timedelta64(1, 'm'), # 1 minute tolerance ... period=np.timedelta64(24, 'h') # 24-hour period ... )
Create an irregular axis with tolerance
>>> irregular_times = np.array([ ... '2024-01-01T00:00', ... '2024-01-01T06:15', ... '2024-01-01T12:30', ... '2024-01-01T18:45' ... ], dtype='datetime64[m]') >>> axis_irregular = pyinterp.TemporalAxis( ... irregular_times, ... epsilon=np.timedelta64(5, 'm') # 5 minute tolerance ... )
Create a timedelta64 axis for durations
>>> durations = np.array([0, 3600, 7200, 10800], dtype='timedelta64[s]') >>> axis_duration = pyinterp.TemporalAxis(durations)
Attributes
Get the numpy dtype of this axis.
True if this axis represents a periodic variable.
Get the period of this axis.
Public Methods
back(self)Get the last value of this axis.
cast_to_temporal_axis(self, array)Safely cast an array to the axis resolution.
find_index(self, coordinates, bounded)Find the index of the axis element that contains a coordinate.
find_indexes(self, coordinates)Find indexes of axis elements surrounding each coordinate.
flip(self[, inplace])Reverse the order of elements in the axis.
front(self)Get the 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)Get the maximum value of this axis.
min_value(self)Get the 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__(-> object)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.