LazyIrregularTimeSeries#
- class temporaldata.LazyIrregularTimeSeries(**kwargs)[source]#
Bases:
IrregularTimeSeriesLazy variant of
IrregularTimeSeries. The data is not loaded until it is accessed. This class is meant to be used when the data is too large to fit in memory, and is intended to be intantiated via.LazyIrregularTimeSeries.from_hdf5.Note
To access an attribute without triggering the in-memory loading use self.__dict__[key] otherwise using self.key or getattr(self, key) will trigger the lazy loading and will automatically convert the h5py dataset to a numpy array as well as apply any outstanding masks.
- select_by_mask(mask)[source]#
Index all arrays with a boolean mask and return a copy.
Lazy attributes will remain lazy, and masking will be applied to them upon access.
- Parameters:
mask (
ndarray) – Boolean array used for masking. The mask needs to be 1-dimensional, and of equal length as the object itself.
- slice(start, end, reset_origin=True)[source]#
Returns a new
IrregularTimeSeriesobject that contains the data between the start and end times. The end time is exclusive, the slice will only include data in \([\textrm{start}, \textrm{end})\).If
reset_originisTrue, all time attributes are updated to be relative to the new start time. The domain is also updated accordingly.Warning
If the time series is not sorted, it will be automatically sorted in place.
- property domain#
The time domain over which the time series is defined. Usually a single interval, but could also be a set of intervals.
- classmethod from_dataframe(df, domain='auto', unsigned_to_long=True)#
Create an
IrregularTimeseriesobject from a pandas DataFrame. The dataframe must have a timestamps column, with the name"timestamps"(use pd.Dataframe.rename if needed).The columns in the DataFrame are converted to arrays when possible, otherwise they will be skipped.
- Parameters:
df (
DataFrame) – DataFrame.unsigned_to_long (
bool) – Whether to automatically convert unsigned integers to int64 dtype. Defaults toTrue.domain (optional) – The domain over which the time series is defined. If set to
"auto", the domain will be automatically the interval defined by the minimum and maximum timestamps. Defaults to"auto".
- materialize()#
Materializes the data object, i.e., loads into memory all of the data that is still referenced in the HDF5 file.
- Return type:
- register_timekey(timekey)#
Register a new time-based attribute.
- select_by_interval(interval)#
Return a new
IrregularTimeSeriesobject where all timestamps are within the interval.- Parameters:
interval (
Interval) – Interval object.
- sort()#
Sorts the timestamps, and reorders the other attributes accordingly. This method is applied in place.
- timekeys()#
Returns a list of all time-based attributes.
- to_hdf5(file)[source]#
Saves the data object to an HDF5 file.
- Parameters:
file (h5py.File) – HDF5 file.
Warning
If the time series is not sorted, it will be automatically sorted in place.
import h5py from temporaldata import IrregularTimeseries data = IrregularTimeseries( unit_index=np.array([0, 0, 1, 0, 1, 2]), timestamps=np.array([0.1, 0.2, 0.3, 0.4, 0.5, 0.6]), waveforms=np.zeros((6, 48)), domain="auto", ) with h5py.File("data.h5", "w") as f: data.to_hdf5(f)