Structured arrays (arrays
)¶
Provide structured arrays for cosmological data.
Abstract data array with save and load methods. |
|
|
Structured array for spherically decomposed cosmological data. |
|
Structured array for Cartesian decomposition of cosmological data. |
- exception harmonia.algorithms.arrays.IndexingError[source]¶
Exception raised for unsupported slicing or indexing in __getitem__ methods.
- class harmonia.algorithms.arrays.DataArray[source]¶
Abstract data array with save and load methods.
- save(output_file, file_extension)[source]¶
Save the structured array.
- Parameters:
output_file (str or
pathlib.Path
) – Output file path.extension ({‘.pkl’, ‘.npz’}) – Output file extension.
- classmethod load(input_file)[source]¶
Load the structured array from a .npz or .pkl file.
- Parameters:
input_file (str or
pathlib.Path
) – Input file path.
- class harmonia.algorithms.arrays.SphericalArray(disc)[source]¶
Structured array for spherically decomposed cosmological data.
Array is initialised with a discrete spectrum of Fourier modes and consists of three fields: the ‘index’ field of \((\ell, m_\ell, n_\ell)\) triplets, the ‘wavenumber’ field of discrete \(k_{\ell n}\), and the ‘coefficient’ field of spherically decomposed data.
- Parameters:
disc (
DiscreteSpectrum
) – Discrete spectrum associated with the structured array.- Variables:
array (
numpy.ndarray
) – Structured NumPy array.size (int) – Total number of elements in the array. This should equal the sum of
disc.mode_counts
.attrs (dict) – Attributes of the structured array inherited from disc.
See also
- __getitem__(key)[source]¶
Get the ‘coefficient’ field value(s).
The access key can be an integer, a slice expression, a tuple of index triplet or a string, e.g.
[-1]
,[:]
,[(0, 0, 1)]
or'degree_0'
.- Parameters:
key (int, slice, tuple(int, int, int) or str) – ‘coefficient’ field access key.
- Returns:
‘coefficient’ field data entry.
- Return type:
- __setitem__(key, value)[source]¶
Set the ‘coefficient’ field value(s).
- Parameters:
key (int, tuple of int or slice) – ‘coefficient’ field access key.
value (complex) – ‘coefficient’ field data entry.
See also
- vectorise(pivot, collapse=None)[source]¶
Returrn a data vector from the ‘coefficient’ field.
Vectorisation is performed by pivoting in either of the following orders of precedence—
‘natural’: ordered by \((\ell, m, n)\);
‘spectral’: ordered by \((k_{\ell n}, m)\).
Subarrays of equivalent \((\ell, n)\) may be further collapsed over spherical order \(m\) by simple averaging or averaging in quadrature.
- Parameters:
pivot ({‘natural’, ‘spectral’}) – Pivot order for vectorisation.
collapse ({None, ‘mean’, ‘qaudrature’}, optional) – If not None (default), subarrays are collapsed over equivalent spherical order \(m\) by averaging (‘mean’) or averaging in quadrature (‘qaudrature’).
- Returns:
vectorised_data – Vectorised coefficient data.
- Return type:
- class harmonia.algorithms.arrays.CartesianArray(orders, wavenumbers, mode_counts=None, shot_noise=None)[source]¶
Structured array for Cartesian decomposition of cosmological data.
Array is initialised with three fields: the ‘order’ field of the Legendre multipoles, the ‘wavenumber’ field of \(k\)-bin centres and the ‘power’ field for power spectrum multipole measurements.
- Parameters:
orders (list of tuple of int) – Orders of the power spectrum multipole.
wavenumbers (float, array_like) – Wavenumbers of the multipole data.
mode_counts (list of int or None, optional) – Mode counts in wavenumber bins (default is None).
shot_noise (float or None, optional) – Shot noise level (default is None).
- Variables:
array (
numpy.ndarray
) – Structured NumPy array.size (int) – Total number of elements in the array. This should equal the product of the numbers of wavenumbers and multipoles.
attrs (dict) – Initialisation parameters as attributes.
- __getitem__(key)[source]¶
Access the ‘power’ field.
The access key can be an integer positional index, a slice, a tuple of (order, wavenumber) or a string, e.g.
[-1]
,[:]
,[(0, 0.04)]
or'power_0'
.- Parameters:
key (int, slice, tuple(int, float) or str) – ‘power’ field access key.
- Returns:
‘power’ field data entry.
- Return type:
- __setitem__(key, value)[source]¶
Set the ‘power’ field value(s).
- Parameters:
key (int, tuple(int, float) or slice) – ‘power’ field access key.
value (float) – ‘power’ field data entry.
See also
- vectorise(pivot)[source]¶
Return a data vector from the ‘power’ field.
Vectorisation is performed by pivoting in either of the following orders of precedence—
‘order’: ordered by multipole order \(\ell\);
‘wavenumber’: ordered by wavenumber \(k\).
- Parameters:
pivot ({‘order’, ‘wavenumber’}) – Pivot order for vectorisation.
- Returns:
vectorised_data – Vectorised power spectrum data.
- Return type: