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.amares

fitting.amares

Functions

NameDescription
fit_amaresApply AMARES time-domain fitting to an N-dimensional Free Induction Decay (FID).

fit_amares

fitting.amares.fit_amares(
    da,
    prior_knowledge_file,
    dim='time',
    mhz=None,
    sw=None,
    deadtime=None,
    method='leastsq',
    initialize_with_lm=True,
    num_workers=4,
    init_fid=None,
    verbose=False,
)

Apply AMARES time-domain fitting to an N-dimensional Free Induction Decay (FID).

This function isolates the stateful pyAMARES API to perform parallelized batch fitting across spatial or repetition dimensions. It automatically scans the dataset to initialize the fitting template using the voxel with the highest Signal-to-Noise Ratio (SNR), ensuring robust prior knowledge instantiation.

The numerical results and the reconstructed time-domain fits are packed into an aligned xarray Dataset, preserving all physical coordinates.

Parameters

NameTypeDescriptionDefault
daxr.DataArrayInput FID data. Must contain the specified time dimension.required
prior_knowledge_filestr | PathPath to the CSV or XLSX file containing the prior knowledge constraints.required
dimstrThe time dimension along which to fit, by default “time”.'time'
mhzfloatSpectrometer frequency in MHz. If None, attempts to read from da.attrs[‘MHz’].None
swfloatSpectral width in Hz. If None, attempts to calculate from dim coordinates.None
deadtimefloatTime delay before the first point in seconds. If None, defaults to 0.0.None
method(leastsq, least_squares)Fitting method. Defaults to ‘leastsq’ (Levenberg-Marquardt)."leastsq"
initialize_with_lmboolRun an internal Levenberg-Marquardt initializer before fitting. Defaults to True.True
num_workersintNumber of parallel processes to spawn. Defaults to 4.4
init_fidnp.ndarrayA 1D complex array to use as the template for pyAMARES initialization. If None, the function automatically selects the spectrum with the highest SNR.None
verboseboolIf True, sets logging level to INFO. Default is False -> log level ERROR.False

Returns

NameTypeDescription
xr.DatasetA dataset containing the original data, the fitted FIDs, the residuals, and quantified parameters (amplitude, chem_shift, linewidth, phase, CRLB, SNR) mapped across the original dimensions and the new ‘Metabolite’ dimension.