envipat.envelope

Isotope pattern envelope (profile) calculation.

Port of R’s envelope. Convolutes an isotope pattern (from envipat.isopattern.isopattern()) with a peak shape function (Gaussian or Cauchy-Lorentz) into a discretized theoretical profile, by calling envipat._core.enviPat_py.ppm_trace and profile_with_trace (Python bindings of the original iso_core.c algorithms).

Mass trace construction

R builds the mass trace (“stick” positions) three different ways, depending on ppm/dmz:

  • ppm=True: via the C core directly (_core.ppm_trace) – no seq() involved, so this branch is exact (same core, same inputs) up to the rtol=1e-12 bound this module’s results are verified at overall (see module docstring below).

  • ppm=False, dmz numeric: seq(min(m) - 0.5, max(m) + 0.5, dmz).

  • ppm=False, dmz="get": derives the step from resolution – dmz2 = mean(m) / resolution; seq(min(m) - 1, max(m) + 0.5, dmz2 * frac).

The two seq()-based branches are reproduced via envipat._rseq.r_seq (see that module for why this is a semantic, not bit-exact, port of R’s seq.default – this is the known source of floating-point divergence from R, which is why envelope/vdetect are verified at rtol=1e-12 rather than exact match, unlike isopattern).

Result shape

Returns dict[str, pandas.DataFrame | str] keyed like the input pattern dict, each DataFrame with two columns, "m/z" and "abundance". As in R (and envipat.isopattern.isopattern()), an empty/erroring convolution result is reported as the literal string "error" for that entry, covering both a raised EnviPatCoreError and a legitimate zero-length result.

envipat.envelope.envelope(pattern, ppm=False, dmz='get', frac=0.25, env='Gaussian', resolution=500000.0, verbose=True)[source]

Convolute isotope pattern(s) into their theoretical envelope profile(s).

Port of R’s envelope.

Parameters:
pattern

Mapping of formula -> isotope-pattern DataFrame, as returned by envipat.isopattern.isopattern() (columns "m/z", "abundance", … in that order).

ppm

If True, discretize the mass trace in ppm (dmz is then a ppm value, must be numeric – not "get"). If False (default), discretize in absolute m/z, either fixed (dmz numeric) or derived from resolution (dmz="get").

dmz

"get" (default) to derive the step from resolution/frac, or a numeric step (ppm or absolute m/z, per ppm).

frac

Only used when dmz="get": fraction of the peak’s FWHM (mean(m)/resolution) used as the trace step.

env

Peak shape: "Gaussian" (default) or "CauchyLorentz".

resolution

A single resolution value, or a sequence with one value per formula in pattern (length must then equal len(pattern)).

verbose

If True, prints " done." on completion (matching R’s message(" done.")).

Returns:
dict[str, pandas.DataFrame | str]

Keyed like pattern; see module docstring for the "error" sentinel.

Notes

R’s plotit argument is intentionally not ported – no plotting side effect, matching envipat.isopattern.isopattern().