nirs4all.data.loaders.matlab_loader module
MATLAB file loader implementation.
This module provides the MatlabLoader class for loading MATLAB .mat files, supporting both older (v4, v6, v7) and newer (v7.3 HDF5) MATLAB file formats.
- class nirs4all.data.loaders.matlab_loader.MatlabLoader[source]
Bases:
FileLoaderLoader for MATLAB .mat files.
Supports: - MATLAB v4, v6, v7 files via scipy.io - MATLAB v7.3 (HDF5) files via h5py (if available)
- Parameters:
variable – Name of the variable to load. If None, auto-detects.
squeeze_me – Squeeze unit matrix dimensions (default: True).
struct_as_record – Load MATLAB structs as numpy record arrays (default: False).
header_unit – Unit for generated headers (‘index’, ‘cm-1’, ‘nm’, etc.)
Example
>>> loader = MatlabLoader() >>> result = loader.load( ... Path("data.mat"), ... variable="X", ... )
- load(path: Path, variable: str | None = None, squeeze_me: bool = True, struct_as_record: bool = False, header_unit: str = 'index', data_type: str = 'x', **params: Any) LoaderResult[source]
Load data from a MATLAB .mat file.
- Parameters:
path – Path to the MATLAB file.
variable – Name of the variable to load. If None, auto-detects.
squeeze_me – Squeeze unit matrix dimensions.
struct_as_record – Load structs as record arrays.
header_unit – Unit type for generated headers.
data_type – Type of data (‘x’, ‘y’, or ‘metadata’).
**params – Additional parameters.
- Returns:
LoaderResult with the loaded data.
- nirs4all.data.loaders.matlab_loader.load_matlab(path, variable: str | None = None, squeeze_me: bool = True, header_unit: str = 'index', **params)[source]
Load a MATLAB .mat file.
Convenience function for direct use.
- Parameters:
path – Path to the MATLAB file.
variable – Name of the variable to load.
squeeze_me – Squeeze unit dimensions.
header_unit – Unit type for headers.
**params – Additional parameters.
- Returns:
Tuple of (DataFrame, report, na_mask, headers, header_unit).