Typesο
Stability: Stable
gwexpy.types - Data type definitions and utilities.
- class gwexpy.types.MetaData(**kwargs)[source]
Bases:
dictA dictionary-like container for metadata describing a single data object.
This class serves as the core metadata container for channels, parameters, or matrix rows/columns in GWexpy. It ensures type safety and consistency for crucial physical attributes, particularly the physical unit.
- Parameters:
name (str, optional) β A human-readable name or label (default: ββ).
channel (str or gwpy.detector.Channel, optional) β The data channel associated with this metadata (default: ββ).
unit (str, astropy.units.UnitBase, or pint.Unit, optional) β The physical unit of the data. Automatically converted to an astropy.units.UnitBase instance (default: dimensionless).
**kwargs β Additional arbitrary metadata key-value pairs.
- name
The human-readable name.
- Type:
- channel
The associated data channel.
- Type:
- unit
The physical unit of the data.
- Type:
Examples
>>> from gwexpy.types.metadata import MetaData >>> from astropy import units as u >>> meta = MetaData(name="strain", channel="H1:STRAIN", unit="m") >>> meta.unit Unit("m") >>> meta.name 'strain'
Notes
When performing arithmetic with MetaData instances (e.g., using NumPy ufuncs), the unit attribute is automatically propagated correctly. For example, multiplying two MetaData objects will result in a new MetaData object with the multiplied units.
- property name
Return the name of the metadata.
- property channel
Return the channel name of the metadata.
- property unit
Return the physical unit of the metadata.
- classmethod from_series(series)[source]
Create a MetaData instance from a GWpy Series object.
- as_meta(obj)[source]
Coerce an object into a MetaData instance.
If obj is already a
MetaDatainstance it is returned unchanged. Otherwise a newMetaDatais constructed whose name and channel are inherited fromselfand whose unit is inferred from obj viaget_unit().- Parameters:
obj (MetaData, astropy.Quantity, numeric, or any object with a .unit) β The object to coerce.
- Return type:
MetaData
- 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.
- to_dataframe()[source]
Convert the metadata collection to a pandas DataFrame.
The
unitcolumn is serialised as a string so that the DataFrame can be written to CSV and read back without loss of unit information.
- write(path, **kwargs)[source]
Write the metadata collection to a CSV file.
- classmethod read(path, **kwargs)[source]
Read a metadata collection from a CSV file.
- classmethod from_series(collection)[source]
Create a MetaDataCollection from a group of series.
- class gwexpy.types.MetaDataMatrix(input_array=None, shape=None, default=None)[source]
Bases:
ndarrayA matrix container for multiple MetaData instances.
This class extends numpy.ndarray to provide a grid-like view of metadata, supporting vectorized attribute access (names, units, 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.
- property names
Return a matrix of metadata names.
- property units
Return a matrix of physical units.
- property channels
Return a matrix of channel names.
- classmethod from_array(array2d)[source]
Create a MetaDataMatrix from a 2D array of MetaData objects.
- to_dataframe()[source]
Convert the matrix to a long-format pandas DataFrame (row, col, name, etc.).
- classmethod from_dataframe(df, shape=None)[source]
Create a MetaDataMatrix from a long-format pandas DataFrame.
- write(filepath, **kwargs)[source]
Write the matrix to a CSV file.
- classmethod read(filepath, **kwargs)[source]
Read a matrix from a CSV file.
- class gwexpy.types.AxisDescriptor(name: str, index: Quantity)[source]
Bases:
objectDescribe a named one-dimensional axis and its coordinate values.
- name: str
- index: Quantity
- property unit
Return the axis unit.
- property size
Return the number of axis samples.
- property regular: bool
Return whether the axis spacing is regular.
- to_value(q)[source]
Convert Quantity to axis unit value, or return float if dimensionless/compatible.
- iloc_nearest(value)[source]
Return the integer index nearest to value.
- class gwexpy.types.AxisApiMixin[source]
Bases:
ABCMixin that exposes axis-aware selection and permutation helpers.
- 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
- rename_axes(mapping: dict[str, str], *, inplace: bool = False) Any[source]
Rename axes using a mapping of old names to new names.
- 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
- sel(indexers=None, *, method='nearest', **kwargs)[source]
Select by coordinate values along specified axes.
- transpose(*axes)[source]
Permute the dimensions of an array.
- property T
Return the transposed view using reversed axis order.
- class gwexpy.types.Array(data, axis_names=None, **kwargs)[source]
Bases:
AxisApiMixin,StatisticalMethodsMixin,ArrayN-dimensional array with a unified axis API.
- property axes
Return axis descriptors for each dimension.
- rms(axis=None, keepdims=False, ignore_nan=True)[source]
Return the RMS value along the requested axis.
- class gwexpy.types.Array2D(data, axis_names=None, **kwargs)[source]
Bases:
AxisApiMixin,StatisticalMethodsMixin,Array2D2D array with a unified axis API.
- property axes
Return axis descriptors for both dimensions.
- imshow(**kwargs)[source]
Plot this array with matplotlib.axes.Axes.imshow.
Inherited from GWpy.
- pcolormesh(**kwargs)[source]
Plot this array with matplotlib.axes.Axes.pcolormesh.
Inherited from GWpy.
- class gwexpy.types.Plane2D(data, axis1_name: str = 'axis1', axis2_name: str = 'axis2', **kwargs)[source]
Bases:
FittingMixin,Array2DTwo-dimensional array with explicit semantic names for each axis.
Plane2D is used by field and transform APIs when a derived slice should keep human-readable axis meaning instead of anonymous array dimensions.
Examples
>>> import numpy as np >>> from gwexpy.types import Plane2D >>> plane = Plane2D(np.ones((2, 3)), axis1_name="time", axis2_name="frequency") >>> plane.axis1.name, plane.axis2.name ('time', 'frequency')
- 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
Return axis descriptors for all three dimensions.
- plane(drop_axis, drop_index, *, axis1=None, axis2=None)[source]
Extract a 2D plane by dropping one axis at a single index.
- 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