Types
gwexpy.types - Data type definitions and utilities.
- class gwexpy.types.MetaData(**kwargs)[source]
Bases:
dict- as_meta(obj)[source]
- property channel
- classmethod from_series(series)[source]
- property name
- property unit
- class gwexpy.types.MetaDataDict(entries: dict | list | DataFrame | MetaDataDict | None = None, expected_size: int | None = None, key_prefix: str = 'key')[source]
Bases:
OrderedDict[str,MetaData]Ordered dictionary mapping keys to MetaData instances.
This container enforces that all values are MetaData objects, providing a type-safe collection for row/column metadata in SeriesMatrix and related classes.
- property channels: list[Channel]
List of channels from all MetaData entries.
- classmethod from_series(collection)[source]
- property names: list[str]
List of names from all MetaData entries.
- classmethod read(path, **kwargs)[source]
- to_dataframe()[source]
- property units: list[UnitBase]
List of units from all MetaData entries.
- write(path, **kwargs)[source]
- class gwexpy.types.MetaDataMatrix(input_array=None, shape=None, default=None)[source]
Bases:
ndarray- property channels
- fill(value)[source]
Fill the matrix with a single MetaData value.
- Parameters:
value (MetaData | dict) – MetaData instance used as-is, or mapping passed once to
MetaData(**value).
Notes
Each cell receives an independent MetaData copy to avoid shared references.
- classmethod from_array(array2d)[source]
- classmethod from_dataframe(df, shape=None)[source]
- property names
- classmethod read(filepath, **kwargs)[source]
- to_dataframe()[source]
- property units
- write(filepath, **kwargs)[source]
- class gwexpy.types.AxisDescriptor(name: 'str', index: 'Quantity')[source]
Bases:
object- property delta: Quantity | None
- iloc_nearest(value)[source]
Return the integer index nearest to value.
- iloc_slice(s: slice)[source]
Convert a coordinate slice (start, stop, step) to an integer slice.
- property regular: bool
- property size
- to_value(q)[source]
Convert Quantity to axis unit value, or return float if dimensionless/compatible.
- property unit
- name: str
- index: Quantity
- class gwexpy.types.AxisApiMixin[source]
Bases:
ABC- property T
- abstract property axes: tuple[AxisDescriptor, ...]
Tuple of AxisDescriptor objects for each dimension.
- Returns:
Each descriptor contains the axis name and index values.
- Return type:
tuple of AxisDescriptor
- axis(key: int | str) AxisDescriptor[source]
Get an axis descriptor by index or name.
- Parameters:
key (int or str) – Axis index (0-based) or name.
- Returns:
The requested axis descriptor.
- Return type:
AxisDescriptor
- Raises:
KeyError – If axis name not found.
TypeError – If key is not int or str.
- property axis_names: tuple[str, ...]
Names of all axes as a tuple of strings.
- Returns:
The name of each axis in order.
- Return type:
tuple of str
- isel(indexers=None, **kwargs)[source]
Select by integer indices along specified axes.
- Parameters:
indexers (dict, optional) – Mapping of axis name/index to integer index or slice.
**kwargs – Additional indexers as keyword arguments.
- Returns:
Sliced array.
- Return type:
subset
- rename_axes(mapping: dict[str, str], *, inplace: bool = False) Any[source]
Rename axes using a mapping of old names to new names.
- Parameters:
mapping (dict) – Mapping from old axis names to new names.
inplace (bool, optional) – If True, modify in place. Otherwise return a copy.
- Return type:
self or copy
- sel(indexers=None, *, method='nearest', **kwargs)[source]
Select by coordinate values along specified axes.
- Parameters:
indexers (dict, optional) – Mapping of axis name to coordinate value or slice.
method (str, optional) – Selection method: ‘nearest’ (default).
**kwargs – Additional indexers as keyword arguments.
- Returns:
Sliced array at nearest coordinate values.
- Return type:
subset
- swapaxes(axis1: int | str, axis2: int | str) Any[source]
- transpose(*axes)[source]
Permute the dimensions of an array.
- class gwexpy.types.Array(data, axis_names=None, **kwargs)[source]
Bases:
AxisApiMixin,StatisticalMethodsMixin,ArrayN-dimensional array with axis unified API.
- property axes
- rms(axis=None, keepdims=False, ignore_nan=True)[source]
- class gwexpy.types.Array2D(data, axis_names=None, **kwargs)[source]
Bases:
AxisApiMixin,StatisticalMethodsMixin,Array2D2D Array with unified axis API.
- property axes
- imshow(**kwargs)[source]
Plot this array using matplotlib.axes.Axes.imshow. Inherited from gwpy.
- pcolormesh(**kwargs)[source]
Plot this array using matplotlib.axes.Axes.pcolormesh. Inherited from gwpy.
- class gwexpy.types.Plane2D(data, axis1_name='axis1', axis2_name='axis2', **kwargs)[source]
Bases:
FittingMixin,Array2D2D Array wrapper where the two axes are semantically significant as Axis 1 and Axis 2.
- property axis1
First axis descriptor (dimension 0).
- property axis2
Second axis descriptor (dimension 1).
- class gwexpy.types.Array3D(data, unit=None, axis0=None, axis1=None, axis2=None, axis_names=None, **kwargs)[source]
Bases:
Array3D Array with explicit axis management.
- property axes
- plane(drop_axis, drop_index, *, axis1=None, axis2=None)[source]
- class gwexpy.types.Array4D(data, unit=None, axis0=None, axis1=None, axis2=None, axis3=None, axis_names=None, **kwargs)[source]
Bases:
Array4D Array with explicit axis management.
This class extends
Arrayto provide explicit management of 4 axes, each with a name and index (Quantity array).- Parameters:
data (array-like) – 4-dimensional input data.
unit (~astropy.units.Unit, optional) – Physical unit of the data.
axis0 (~astropy.units.Quantity or array-like, optional) – Index values for axis 0 (1D).
axis1 (~astropy.units.Quantity or array-like, optional) – Index values for axis 1 (1D).
axis2 (~astropy.units.Quantity or array-like, optional) – Index values for axis 2 (1D).
axis3 (~astropy.units.Quantity or array-like, optional) – Index values for axis 3 (1D).
axis_names (iterable of str, optional) – Names for each axis (length 4). Defaults to
["axis0", "axis1", "axis2", "axis3"].**kwargs – Additional keyword arguments passed to
Array.
- Raises:
ValueError – If the input data is not 4-dimensional.
- property axes
Tuple of AxisDescriptor objects for each dimension.
- class gwexpy.types.MetaDataLike(*args, **kwargs)[source]
Bases:
ProtocolProtocol for single-object metadata containers.
This represents objects that carry name, channel, and unit information for a single data series or field component.
- name: str
- channel: Any
- unit: UnitBase
- class gwexpy.types.MetaDataDictLike(*args, **kwargs)[source]
Bases:
ProtocolProtocol for ordered collections of metadata.
This represents dict-like containers mapping keys to MetaData objects, used for row/column metadata in SeriesMatrix.
- items() Any[source]
Return (key, MetaData) pairs.
- keys() Any[source]
Return keys of the metadata collection.
- values() Any[source]
Return MetaData instances.