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) – noseq()involved, so this branch is exact (same core, same inputs) up to thertol=1e-12bound this module’s results are verified at overall (see module docstring below).ppm=False, dmznumeric:seq(min(m) - 0.5, max(m) + 0.5, dmz).ppm=False, dmz="get": derives the step fromresolution–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 (
dmzis then a ppm value, must be numeric – not"get"). If False (default), discretize in absolute m/z, either fixed (dmznumeric) or derived fromresolution(dmz="get").- dmz
"get"(default) to derive the step fromresolution/frac, or a numeric step (ppm or absolute m/z, perppm).- 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 equallen(pattern)).- verbose
If True, prints
" done."on completion (matching R’smessage(" done.")).
- Returns:
- dict[str, pandas.DataFrame | str]
Keyed like
pattern; see module docstring for the"error"sentinel.
Notes
R’s
plotitargument is intentionally not ported – no plotting side effect, matchingenvipat.isopattern.isopattern().