GESeries.MRSISeries
GESeries.MRSISeries(DATA_FOLDER, SERIES_ID, load_processed_data=False)A raw MRSI series: spectroscopic imaging spectra, fitting, and voxel maps.
Attributes¶
| Name | Description |
|---|---|
RAW_exp | |
SNR_map | The per-voxel SNR, computed from the FIDs via pyAMARES.fidSNR. |
avg_fid | Average fid across voxels with SNR above threshold. |
default_SNR_mask | The default SNR mask, computed with get_SNR_mask’s default threshold. |
dims | |
fids | The FIDs, derived from the spectra via FFT. |
fids_flat | The FIDs with the voxel dimensions stacked into a single voxel dim. |
fit_results | |
fitted_metabolite_maps | |
goodness_of_fit_maps | |
npts | |
ppm | |
spec | |
spec_flat | The spectra with the voxel dimensions stacked into a single voxel dim. |
voxel_size | The in-plane voxel size (mm), derived from the field of view and matrix. |
Methods¶
| Name | Description |
|---|---|
| create_MRSI_affine | Return an affine matrix rescaled to the MRSI voxel size and offset. |
| create_MRSI_nii | Return the RAW magnitude image as a NiiBase, with the MRSI affine. |
| create_map_nii | Wrap a per-voxel map array as a NiiBase, with the MRSI affine. |
| fit_all_voxels | Fit all voxels above the SNR threshold with AMARES and store the maps. |
| fit_single_voxel | Fit the FID at voxel (x, y, slice) with AMARES (via xmris). |
| get_SNR_mask | Return a boolean mask of voxels with SNR at or above threshold. |
| get_voxel_spectrum | Return the spectrum at voxel (x, y, slice). |
| load_processed_data | Load the most recent processed-data HDF5 file for this series. |
| save_processed_data | Save fitted maps, FIDs, and identifying attributes to an HDF5 file. |
| visualize_fitted_metabolite_map | Display the fitted metabolite map for metabolite_name. |
| visualize_fitted_values | Not yet implemented. |
| visualize_goodness_of_fit_map | Display 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¶
| Name | Type | Description | Default |
|---|---|---|---|
| prior_knowledge | Mapping | pandas.DataFrame | str | Path | Prior knowledge, forwarded to xmris fit_amares. | required |
| snr_threshold | float | Voxels with SNR_map below this are not fitted. Defaults to 1.5. | 1.5 |
| testing_mode | bool | If True, limit fitting to the first 100 voxels above the SNR threshold. | False |
| **fit_kwargs | Further 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¶
| Name | Type | Description |
|---|---|---|
| xarray.Dataset | The 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¶
| Name | Type | Description | Default |
|---|---|---|---|
| x | int | Voxel indices. | required |
| y | int | Voxel indices. | required |
| slice | int | Voxel indices. | required |
| prior_knowledge | Mapping | pandas.DataFrame | str | Path | Prior knowledge, forwarded to xmris fit_amares. | required |
| **fit_kwargs | Further keyword arguments for fit_amares (method, g_global, ...). | {} |
Returns¶
| Name | Type | Description |
|---|---|---|
| xarray.Dataset | The 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¶
| Name | Type | Description | Default |
|---|---|---|---|
| output_folder | Path | Directory to search in. Defaults to OUTPUT_FOLDER / "processing_data". | None |
| force_load | bool | If True, load the data even if SERIES_ID, exam_number, or acquisition time do not match this series. | False |
Returns¶
| Name | Type | Description |
|---|---|---|
| bool | True 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¶
| Name | Type | Description | Default |
|---|---|---|---|
| output_folder | Path | Directory to save into. Defaults to OUTPUT_FOLDER / "processing_data". | None |
Returns¶
| Name | Type | Description |
|---|---|---|
| Path | Path to the saved (or, if a file already exists, the existing) HDF5 file. |
Raises¶
| Name | Type | Description |
|---|---|---|
| OSError | If 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.