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

fitting.prior_knowledge

Build validated pyAMARES prior-knowledge tables from a friendly spec.

pyAMARES reads prior knowledge from a positional CSV/XLSX whose row order and bound syntax are easy to get subtly — and silently — wrong:

build_prior_knowledge lets you name peaks and give plain numbers; it emits a correct file and refuses each trap at the door. Its output is the raw pyAMARES CSV text — save it with Path("pk.csv").write_text(...), or skip the file entirely and hand the spec straight to fit_amares(prior_knowledge=...).

The builder is dependency-light (no pyAMARES), so it is available even without the optional fitting extra installed.

Functions

NameDescription
build_prior_knowledgeBuild a validated pyAMARES prior-knowledge CSV from a friendly spec.

build_prior_knowledge

fitting.prior_knowledge.build_prior_knowledge(
    peaks,
    *,
    tie_phase_to=None,
    shift_window=0.5,
)

Build a validated pyAMARES prior-knowledge CSV from a friendly spec.

Each peak is named and described with plain numbers; the trap-prone positional layout, bound syntax, and column ordering are handled for you.

Parameters

NameTypeDescriptionDefault
peaksMapping[str, Mapping[str, Any]]Peaks keyed by name (letters only). Each value maps parameters to values: the required "amplitude" (a.u.), "chem_shift" (ppm — absolute literature ppm when fit_amares is given a carrier, else relative to it) and "linewidth" (Hz); the optional "phase" (degrees, default 0) and "g" (lineshape 0=Lorentzian..1=Gaussian, default 0); and optional "<name>_bounds" companions holding a (lower, upper) tuple (None opens a side). Phase is always bounded (-180, 180) unless overridden.required
tie_phase_tostrName of an anchor peak. When given, every other peak’s phase is tied to the anchor’s (an lmfit expression), and the anchor is written first so it is defined before the peaks referencing it. Defaults to None (free phases).None
shift_windowfloatHalf-width (ppm) of the default chemical-shift bound window placed symmetrically around each peak’s initial shift when no explicit "chem_shift_bounds" is given. Defaults to 0.5.0.5

Returns

NameTypeDescription
strThe pyAMARES prior-knowledge CSV as text. Pass the spec straight to fit_amares(prior_knowledge=...) to skip the file, or write this text to disk to keep a reusable, inspectable prior-knowledge file.

Raises

NameTypeDescription
ValueErrorIf peaks is empty, a peak name is not letters-only, a required parameter is missing, an unknown key is present, tie_phase_to names a peak that is not present, or any bound has lower > upper.

Examples

>>> csv_text = build_prior_knowledge(
...     {
...         "PCr": {"amplitude": 10, "chem_shift": 0.0, "linewidth": 15},
...         "ATP": {"amplitude": 5, "chem_shift": -7.5, "linewidth": 20,
...                 "chem_shift_bounds": (-8.0, -7.0)},
...     }
... )