DataCube
Module Overview
This module provides the DataCube class, which is used to store hyperspectral imaging (HSI) data. The DataCube is a 3D array where the x and y axes represent pixels, and the v axis stores measured values like counts or wavelengths.
Class DataCube
- class datacube.DataCube(cube=None, wavelengths=None, name=None, notation=None, record=False)
The DataCube class stores hyperspectral imaging (HSI) data as a 3D array.
- Parameters:
cube (np.ndarray, optional) – 3D numpy array representing the data cube. Default is None.
wavelengths (list | np.ndarray, optional) – List of wavelengths corresponding to the v axis of the data cube.
name (str, optional) – Name of the data cube. Default is None.
notation (str, optional) – Specifies whether the wavelength data is in nm or cm⁻¹. Default is None.
record (bool, optional) – If True, execution of the methods will be recorded. Default is False.
Warning
Warning: DataCube does not perform automatic validation of the array’s shape or check that you’ve used the correct (v, x, y) ordering. It assumes you know your data structure and provides no spectral/spatial checks under the hood. Incorrectly ordered or shaped arrays may lead to unexpected results.
Methods
- datacube.__add__(other)
Add two DataCube instances along the v axis.
- datacube.__len__()
Return the number of layers (v dimension) in the data cube.
- Returns:
Number of layers in the data cube.
- Return type:
int
- datacube.__getitem__(idx)
Retrieve an item from the data cube.
- Parameters:
idx (int) – Index of the item to retrieve.
- Returns:
Selected item from the data cube.
- Return type:
np.ndarray
- datacube.__setitem__(idx, value)
Set an item in the data cube.
- Parameters:
idx (int) – Index where the value should be set.
value (np.ndarray) – Value to be set at the given index.
- datacube.__str__()
Return a string representation of the DataCube.
- Returns:
String containing information about the data cube.
- Return type:
str
- datacube.set_name(name)
Set a name for the DataCube.
- Parameters:
name (str) – Name as a string.
- Raises:
AttributeError – If the input is not a string.
- datacube.set_wavelengths(wavelengths)
Set wavelength data for the DataCube.
- Parameters:
wavelengths (list | np.ndarray) – 1D numpy array or list of wavelength data.
- Raises:
AttributeError – If the input is not a 1D array or list.
- datacube.set_cube(cube)
Set data for the DataCube.
- Parameters:
cube (np.ndarray) – 2D, 3D, or 4D numpy array of data.
- Raises:
AttributeError – If the input cube is not valid.
- datacube.set_notation(notation)
Update the notation for the DataCube.
- Parameters:
notation (str) – Notation describing wavelength units, such as ‘nm’ or ‘cm⁻¹’.
- datacube.start_recording()
Start recording method execution for the DataCube.
- datacube.stop_recording()
Stop recording method execution for the DataCube.
- datacube.save_template(filename)
Save a template of recorded methods to a YAML file.
- Parameters:
filename (str) – Name of the YAML file where the template will be saved.
- Raises:
AttributeError – If filename is invalid.
- datacube.execute_template(filename)
Load a template and execute the corresponding methods.
- Parameters:
filename (str) – Name of the YAML file containing the template.