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.

GESeries.MRSISeries

GESeries.MRSISeries(DATA_FOLDER, SERIES_ID, load_processed_data=False)

A raw MRSI series: spectroscopic imaging spectra, fitting, and voxel maps.

Attributes

NameDescription
RAW_exp
SNR_mapThe per-voxel SNR, computed from the FIDs via pyAMARES.fidSNR.
avg_fidAverage fid across voxels with SNR above threshold.
default_SNR_maskThe default SNR mask, computed with get_SNR_mask’s default threshold.
dims
fidsThe FIDs, derived from the spectra via FFT.
fids_flatThe FIDs with the voxel dimensions stacked into a single voxel dim.
fit_results
fitted_metabolite_maps
goodness_of_fit_maps
npts
ppm
spec
spec_flatThe spectra with the voxel dimensions stacked into a single voxel dim.
voxel_sizeThe in-plane voxel size (mm), derived from the field of view and matrix.

Methods

NameDescription
create_MRSI_affineReturn an affine matrix rescaled to the MRSI voxel size and offset.
create_MRSI_niiReturn the RAW magnitude image as a NiiBase, with the MRSI affine.
create_map_niiWrap a per-voxel map array as a NiiBase, with the MRSI affine.
fit_all_voxelsFit all voxels above the SNR threshold with AMARES and store the maps.
fit_single_voxelFit the FID at voxel (x, y, slice) with AMARES (via xmris).
get_SNR_maskReturn a boolean mask of voxels with SNR at or above threshold.
get_voxel_spectrumReturn the spectrum at voxel (x, y, slice).
load_processed_dataLoad the most recent processed-data HDF5 file for this series.
save_processed_dataSave fitted maps, FIDs, and identifying attributes to an HDF5 file.
visualize_fitted_metabolite_mapDisplay the fitted metabolite map for metabolite_name.
visualize_fitted_valuesNot yet implemented.
visualize_goodness_of_fit_mapDisplay the goodness-of-fit map for metric_name.

create_MRSI_affine

GESeries.MRSISeries.create_MRSI_affine()

Return an affine matrix rescaled to the MRSI voxel size and offset.

create_MRSI_nii

GESeries.MRSISeries.create_MRSI_nii()

Return the RAW magnitude image as a NiiBase, with the MRSI affine.

create_map_nii

GESeries.MRSISeries.create_map_nii(map_data)

Wrap a per-voxel map array as a NiiBase, with the MRSI affine.

fit_all_voxels

GESeries.MRSISeries.fit_all_voxels(
    prior_knowledge,
    snr_threshold=1.5,
    testing_mode=False,
    **fit_kwargs,
)

Fit all voxels above the SNR threshold with AMARES and store the maps.

Parameters

NameTypeDescriptionDefault
prior_knowledgeMapping | pandas.DataFrame | str | PathPrior knowledge, forwarded to xmris fit_amares.required
snr_thresholdfloatVoxels with SNR_map below this are not fitted. Defaults to 1.5.1.5
testing_modeboolIf True, limit fitting to the first 100 voxels above the SNR threshold.False
**fit_kwargsFurther keyword arguments for fit_amares (method, g_global, ...). num_workers defaults to -1 (every core) here, unlike xmris’s in-process default of 1, because a voxel grid is exactly where a pool pays off.{}

Returns

NameTypeDescription
xarray.DatasetThe fit_amares result on the full (i, j, k) grid; voxels that were not fitted are NaN. Also stored as fit_results and summarised in fitted_metabolite_maps and goodness_of_fit_maps.

fit_single_voxel

GESeries.MRSISeries.fit_single_voxel(x, y, slice, prior_knowledge, **fit_kwargs)

Fit the FID at voxel (x, y, slice) with AMARES (via xmris).

Parameters

NameTypeDescriptionDefault
xintVoxel indices.required
yintVoxel indices.required
sliceintVoxel indices.required
prior_knowledgeMapping | pandas.DataFrame | str | PathPrior knowledge, forwarded to xmris fit_amares.required
**fit_kwargsFurther keyword arguments for fit_amares (method, g_global, ...).{}

Returns

NameTypeDescription
xarray.DatasetThe fit_amares result for this voxel.

get_SNR_mask

GESeries.MRSISeries.get_SNR_mask(threshold=1.5)

Return a boolean mask of voxels with SNR at or above threshold.

get_voxel_spectrum

GESeries.MRSISeries.get_voxel_spectrum(x, y, slice)

Return the spectrum at voxel (x, y, slice).

load_processed_data

GESeries.MRSISeries.load_processed_data(output_folder=None, force_load=False)

Load the most recent processed-data HDF5 file for this series.

Parameters

NameTypeDescriptionDefault
output_folderPathDirectory to search in. Defaults to OUTPUT_FOLDER / "processing_data".None
force_loadboolIf True, load the data even if SERIES_ID, exam_number, or acquisition time do not match this series.False

Returns

NameTypeDescription
boolTrue if data was loaded successfully, False otherwise.

save_processed_data

GESeries.MRSISeries.save_processed_data(output_folder=None)

Save fitted maps, FIDs, and identifying attributes to an HDF5 file.

Parameters

NameTypeDescriptionDefault
output_folderPathDirectory to save into. Defaults to OUTPUT_FOLDER / "processing_data".None

Returns

NameTypeDescription
PathPath to the saved (or, if a file already exists, the existing) HDF5 file.

Raises

NameTypeDescription
OSErrorIf the saved file fails the post-save integrity check.

visualize_fitted_metabolite_map

GESeries.MRSISeries.visualize_fitted_metabolite_map(metabolite_name, **kwargs)

Display the fitted metabolite map for metabolite_name.

visualize_fitted_values

GESeries.MRSISeries.visualize_fitted_values()

Not yet implemented.

visualize_goodness_of_fit_map

GESeries.MRSISeries.visualize_goodness_of_fit_map(metric_name, **kwargs)

Display the goodness-of-fit map for metric_name.