utils.data_loaders
utils.data_loaders
Attributes ¶ Name Description HEADER_FIELDS
Functions ¶ Name Description list_mat_variables List a .mat file’s top-level variable names without loading any of them. load_mat_file Load a .mat file and return its contents as a dictionary. load_raw_fids Load raw FIDs for a series, reading from a cached HDF5 file when available. read_mat_header Read selected fields of a ScanArchive*.mat’s h header, without loading the rest.
list_mat_variables ¶ utils.data_loaders.list_mat_variables(file_path)List a .mat file’s top-level variable names without loading any of them.
Parameters ¶ Name Type Description Default file_path Path or str Path to the .mat file (v5/v7 or v7.3). required
Returns ¶ Name Type Description list of str The variable names (MATLAB’s internal #refs#/#subsystem# groups excluded).
load_mat_file ¶ utils.data_loaders.load_mat_file(file_path, variable_names=None)Load a .mat file and return its contents as a dictionary.
Transparently falls back from scipy.io.loadmat (plain v5/v7 files) to
mat73 (v7.3, HDF5-based files) when the former can’t read the file.
Parameters ¶ Name Type Description Default file_path Path or str Path to the .mat file. required variable_names sequence of str Top-level variables to load; everything else is skipped. Defaults to all of them. On a v7.3 file this matters: the scanner header h alone is ~1600 HDF5 datasets. None
Returns ¶ Name Type Description dict Contents of the .mat file.
Raises ¶ Name Type Description FileNotFoundError If file_path does not exist or is not a file. ValueError If file_path does not have a .mat extension. RuntimeError If the file can’t be loaded by either scipy or mat73.
load_raw_fids ¶ utils.data_loaders.load_raw_fids(
DATA_FOLDER,
series_id,
load_most_recent=True,
force_override=False,
)Load raw FIDs for a series, reading from a cached HDF5 file when available.
Parameters ¶ Name Type Description Default DATA_FOLDER Path or str Path to the exam’s data folder. required series_id int Series number to load raw FIDs for. required load_most_recent bool If True, return the most recently created cached *_raw_fids.h5 file instead of re-reading the scan archive. Trueforce_override bool If True, delete and regenerate an existing output HDF5 file rather than returning its cached contents. False
Returns ¶ Name Type Description tuple[np.ndarray, Path] The complex raw FIDs array and the path to the HDF5 file it was loaded from (or written to).
utils.data_loaders.read_mat_header(file_path, fields=HEADER_FIELDS)Read selected fields of a ScanArchive*.mat’s h header, without loading the rest.
Returns the same nested dict as load_mat_file(file_path)["h"], pruned to fields.
On a v7.3 file only those datasets are opened (~6 ms instead of ~450 ms); on a plain v5/v7
file h is loaded alone and pruned. Fields missing from the file are left out.
Parameters ¶ Name Type Description Default file_path Path or str Path to the .mat file. required fields sequence of str "struct/field" paths below h. Defaults to HEADER_FIELDS.HEADER_FIELDS
Returns ¶ Name Type Description dict Nested dict ({"series": {"se_desc": ...}}); empty if the file has no h.
Raises ¶ Name Type Description FileNotFoundError If file_path does not exist or is not a file. ValueError If file_path does not have a .mat extension.