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.

utils.data_loaders

utils.data_loaders

Attributes

NameDescription
HEADER_FIELDS

Functions

NameDescription
list_mat_variablesList a .mat file’s top-level variable names without loading any of them.
load_mat_fileLoad a .mat file and return its contents as a dictionary.
load_raw_fidsLoad raw FIDs for a series, reading from a cached HDF5 file when available.
read_mat_headerRead 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

NameTypeDescriptionDefault
file_pathPath or strPath to the .mat file (v5/v7 or v7.3).required

Returns

NameTypeDescription
list of strThe 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

NameTypeDescriptionDefault
file_pathPath or strPath to the .mat file.required
variable_namessequence of strTop-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

NameTypeDescription
dictContents of the .mat file.

Raises

NameTypeDescription
FileNotFoundErrorIf file_path does not exist or is not a file.
ValueErrorIf file_path does not have a .mat extension.
RuntimeErrorIf 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

NameTypeDescriptionDefault
DATA_FOLDERPath or strPath to the exam’s data folder.required
series_idintSeries number to load raw FIDs for.required
load_most_recentboolIf True, return the most recently created cached *_raw_fids.h5 file instead of re-reading the scan archive.True
force_overrideboolIf True, delete and regenerate an existing output HDF5 file rather than returning its cached contents.False

Returns

NameTypeDescription
tuple[np.ndarray, Path]The complex raw FIDs array and the path to the HDF5 file it was loaded from (or written to).

read_mat_header

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

NameTypeDescriptionDefault
file_pathPath or strPath to the .mat file.required
fieldssequence of str"struct/field" paths below h. Defaults to HEADER_FIELDS.HEADER_FIELDS

Returns

NameTypeDescription
dictNested dict ({"series": {"se_desc": ...}}); empty if the file has no h.

Raises

NameTypeDescription
FileNotFoundErrorIf file_path does not exist or is not a file.
ValueErrorIf file_path does not have a .mat extension.