Skip to content

Fix Gaussian, Lorentzian and Voigt amplitudes being treated as integrated areas #38

Description

@PierreRaybaut

Summary

For Gaussian, Lorentzian and Voigt peaks, the public parameter named amp/amplitude currently represents an integrated area even though users and downstream interfaces naturally read it as peak height. This makes the numerical value depend on sigma, gives it compound units, and creates inconsistent behavior across fitting, signal creation and pulse measurements.

Define amplitude as the signed peak height above y0 for all three equal-width models, version every durable parameter representation affected by that semantic change, and reject historical unversioned values until the caller explicitly converts them.

Current behavior

The historical Gaussian and Lorentzian formulas normalize amp by a width-dependent area factor. A value displayed as amplitude therefore changes meaning when sigma changes and is not expressed in the signal's Y unit. The historical Voigt conversion follows the same area-oriented contract.

Creation parameters and persisted fit_params do not carry a structural version or an explicit parameterization marker. Renaming amp to amplitude without validating the raw payload would be unsafe because guidata deserialization supplies defaults for missing renamed fields and ignores unknown fields.

Proposed contract

  • amplitude is signed peak height above y0.
  • Gaussian: y0 + amplitude * exp(-0.5 * ((x - x0) / sigma) ** 2).
  • Lorentzian: y0 + amplitude / (1 + ((x - x0) / sigma) ** 2).
  • Voigt: normalize the profile by its value at the center so f(x0) == y0 + amplitude exactly.
  • Keep explicit area_from_amplitude(amplitude, sigma) and amplitude_from_area(area, sigma) helpers for scientific conversions.
  • Peak widths and relative-level offsets must be derived from each model rather than reusing Gaussian identities for Lorentzian or Voigt peaks.

Persistence and compatibility

  • Introduce FIT_PARAMS_VERSION = 2, CREATION_PARAMS_VERSION = 2 and PEAK_PARAMETERIZATION = "height".
  • Versioned peak fit dictionaries use amplitude/amplitude_N, include fit_params_version: 2 and include peak_parameterization: "height".
  • Versioned peak creation payloads include creation_params_version: 2 and peak_parameterization: "height".
  • Historical unversioned amp/amp_N and creation field a values are treated as integrated areas.
  • Historical payloads raise a dedicated LegacyPeakParameterizationError during validation or evaluation. No alias may reinterpret an old area as a new height.
  • Provide non-mutating conversion helpers that preserve unrelated metadata and convert each area using the corresponding model and sigma.
  • Reject future versions, contradictory markers, legacy keys in v2, missing required parameters and non-contiguous multi-peak indices.
  • Preserve signal X/Y samples during metadata conversion; conversion authorizes future reuse of parameters but never regenerates historical data implicitly.

Related issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions