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.

Fitting spectra

I have a series loaded and want peak amplitudes out of it — one averaged spectrum, or a map across an MRSI grid.

MNUtils does not implement AMARES. xmris does (on top of pyAMARES), and a series hands its FIDs straight to it: the series knows its own reference_frequency and carrier_ppm, so all you supply is the prior knowledge — which peaks to look for. Every fit returns the xr.Dataset that xmris produces, unchanged.

MethodFits
MRSSeries.fit_average_fid()the averaged FID of a single-voxel series
MRSISeries.fit_single_voxel()one voxel of an MRSI grid
MRSISeries.fit_all_voxels()every voxel above an SNR threshold

1. Say which peaks to look for

A peak is a name plus a starting guess; chem_shift is in absolute ppm. The same mapping is used for every fit below.

2. Fit one averaged spectrum

Amplitudes are only comparable between series if they are scaled the same way, so pass a shared normalisation_factor; without one the series scales by its own maximum and warns.

Loading...

fit_status is 0 for a fitted spectrum, 1 for no signal and 2 for a failed fit, so a failure is never mistaken for a zero amplitude.

3. Fit a whole MRSI grid

fit_all_voxels fits only voxels whose SNR clears snr_threshold; the rest stay NaN on the full (i, j, k) grid. testing_mode=True limits it to the first 100 such voxels, which is plenty for trying a prior-knowledge file out.

/home/runner/work/mnutils/mnutils/.venv/lib/python3.12/site-packages/pyAMARES/kernel/fid.py:357: RuntimeWarning: invalid value encountered in scalar divide
  return signal_p / noise_p
('i', 'j', 'k')

The result is also summarised as plain arrays, ready for visualize_fitted_metabolite_map:

(['PCr', 'gATP'], ['residual_rms', 'fit_status'])