xdas.atoms.Sequential#
- class xdas.atoms.Sequential(atoms: Any, name: str | None = None)[source]#
A class to handle a sequence of operations.
Each operation is represented by an Atom class object, which contains the function and its arguments. Sequence inherits from list, and therefore behaves as it.
- Parameters:
Examples
>>> from xdas.atoms import Partial, Sequential >>> import xdas.signal as xs >>> import numpy as np
Basic usage:
>>> seq = Sequential( ... [ ... Partial(xs.taper, dim="time"), ... Partial(xs.lfilter, [1.0], [0.5], ..., dim="time", zi=...), ... Partial(np.square), ... ], ... name="Low frequency energy", ... ) >>> seq Low frequency energy: 0: taper(..., dim=time) 1: lfilter([1.0], [0.5], ..., dim=time) [stateful] 2: square(...)
Nested sequences:
>>> seq = Sequential( ... [ ... Partial(xs.decimate, 16, dim="distance"), ... seq, ... ] ... ) >>> seq Sequence: 0: decimate(..., 16, dim=distance) 1: Low frequency energy: 0: taper(..., dim=time) 1: lfilter([1.0], [0.5], ..., dim=time) [stateful] 2: square(...)
Applying the sequence to data:
>>> from xdas.synthetics import wavelet_wavefronts >>> da = wavelet_wavefronts() >>> seq(da) <xdas.DataArray (time: 300, distance: 26)> [[0.000000e+00 0.000000e+00 0.000000e+00 ... 0.000000e+00 0.000000e+00 0.000000e+00] [5.925923e-10 3.640952e-11 1.315744e-11 ... 4.024388e-14 3.245748e-12 7.679807e-12] [3.497487e-09 1.191342e-10 4.021543e-11 ... 7.463132e-12 9.458801e-11 2.833292e-10] ... [2.331440e-08 5.785383e-10 4.336722e-11 ... 1.827452e-11 5.099163e-10 1.320907e-09] [1.826236e-09 5.470673e-11 1.045146e-11 ... 1.561169e-13 3.063598e-14 7.832009e-16] [0.000000e+00 0.000000e+00 0.000000e+00 ... 0.000000e+00 0.000000e+00 0.000000e+00]] Coordinates: * time (time): 2023-01-01T00:00:00.000 to 2023-01-01T00:00:05.980 * distance (distance): 0.000 to 10000.000
Methods
__init__(atoms[, name])append(object, /)Append object to the end of the list.
call(x, **flags)Pass x through each atom in order and return the final result.
clear()Remove all items from list.
copy()Return a shallow copy of the list.
count(value, /)Return number of occurrences of value.
extend(iterable, /)Extend list by appending elements from the iterable.
index(value[, start, stop])Return first index of value.
initialize(x, **flags)Initialise the atom from a first chunks of data.
initialize_from_state()Initialise the atom from its current state.
insert(index, object, /)Insert object before index.
load_state(path)Load the atom state from the NetCDF4 file at path.
pop([index])Remove and return item at index (default last).
remove(value, /)Remove first occurrence of value.
reset()Reset the state of all stateful atoms in the sequence.
reverse()Reverse IN PLACE.
save_state(path)Serialise the current state to a NetCDF4 file at path.
set_state(state)Restore the atom state from a previously saved state dict.
sort(*[, key, reverse])Sort the list in ascending order and return None.
Attributes
initializedTrueif every state key has been initialised (no...sentinels remain).stateDict of the current state, including nested atom states.