Loading a .mat reconstruction
RawMRISeries (and everything built on it — MRSSeries, MRSISeries, MRSWashinSeries) reads
its recon dict from load_mat_file under the hood. Scanner reconstructions come in two MATLAB
file formats depending on size and MATLAB version — plain (v5/v7, scipy-readable) and v7.3
(HDF5-based, needs mat73) — and load_mat_file hides that distinction behind one call.
| Function | What it does here |
|---|---|
load_mat_file() | loads either .mat format, returns a plain dict |
from mnutils.utils import data_loaders as dl
from mnutils.utils import file_helpers as fh
from mnutils.testing import build_fake_exam
mrsi_missing_series_exam = build_fake_exam("mrsi_missing_series_exam")The current format¶
mat_path = fh.get_mat_data_from_series(mrsi_missing_series_exam, 7)
data = dl.load_mat_file(mat_path)
print(type(data), sorted(data.keys())[:5])
print(data["spec"].shape)<class 'dict'> ['__globals__', '__header__', '__version__', 'bb', 'h']
(700, 16, 16, 16)
The older (v7.3) format¶
Older reconstructions saved as MATLAB v7.3 fail the plain scipy.io.loadmat path and fall back
to mat73 transparently — same call, same return type.
legacy_data = dl.load_mat_file(build_fake_exam("legacy_matlab73_example"))
print("pyr" in legacy_data)True
When the path isn’t a real .mat file¶
| Symptom | Cause | Fix |
|---|---|---|
FileNotFoundError | path doesn’t exist | double-check the series ID / get_mat_data_from_series result |
ValueError: ...does not have a .mat extension | wrong file passed | load_mat_file only accepts .mat |
RuntimeError: mat73 is required... | v7.3 file, but mat73 isn’t installed | mat73 is a core dependency (see pyproject.toml) — reinstall the env |