Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

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.

FunctionWhat it does here
load_mat_file()loads either .mat format, returns a plain dict
read_mat_header()reads only the header fields MNUtils uses, fast on either format

The current format

<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.

True

Reading just the header

Series identification and the RawMRISeries properties (bandwidth, centre_frequency, …) need a few dozen numbers from the scanner header h, not the whole file. That matters on v7.3: h alone is ~1600 tiny HDF5 datasets, and a full load_mat_file spends ~0.45 s per file opening them — about 9 s for an exam with 20 raw series, again for every object built from the same file. read_mat_header opens only the allowlisted fields (HEADER_FIELDS), ~20x faster, and returns the same nested dict you would get from load_mat_file(path)["h"], pruned.

MRSI 3D Rolf fidall2 | ['exam', 'image', 'mrconfig', 'rdb_hdr', 'series']
16 of 27 allowlisted fields are under rdb_hdr

RawMRISeries.header is exactly this. Its recon dict (everything else in the file, h pruned to the same fields) loads on first access. To read a field that isn’t allowlisted, pass fields=[...] here or use load_mat_file for the full header; a new RawMRISeries header property needs its field added to HEADER_FIELDS.

When the path isn’t a real .mat file

SymptomCauseFix
FileNotFoundErrorpath doesn’t existdouble-check the series ID / get_mat_data_from_series result
ValueError: ...does not have a .mat extensionwrong file passedload_mat_file only accepts .mat
RuntimeError: mat73 is required...v7.3 file, but mat73 isn’t installedmat73 is a core dependency (see pyproject.toml) — reinstall the env