Spectrum1D
#
Spectrum1D(
frequencies: FloatArray | None = None,
amplitudes: ComplexArray | None = None,
frequency_unit: FrequencyUnit = HERTZ,
reference_frequency_hz: float | None = None,
metadata: dict[str, str] | None = None,
)
1D frequency-domain spectrum.
Attributes:
| Name | Type | Description |
|---|---|---|
frequencies |
FloatNdArray
|
Frequency coordinates |
amplitudes |
ComplexNdArray
|
Complex amplitudes |
frequency_unit |
Unit of frequency coordinates |
|
reference_frequency_hz |
Reference frequency for PPM calculations |
|
metadata |
dict[str, str]
|
Optional metadata dictionary |
processing_history
class-attribute
instance-attribute
#
processing_history: ProcessingHistory | None = (
betterproto2.field(
6, betterproto2.TYPE_MESSAGE, optional=True
)
)
Processing history - read-only audit log of all operations applied to this spectrum
metadata
class-attribute
instance-attribute
#
metadata: dict[str, str] = betterproto2.field(
4,
betterproto2.TYPE_MAP,
map_meta=betterproto2.map_meta(
betterproto2.TYPE_STRING, betterproto2.TYPE_STRING
),
)
Optional metadata
solvent_reference_ppm
class-attribute
instance-attribute
#
solvent_reference_ppm: float | None = betterproto2.field(
5, betterproto2.TYPE_FLOAT, optional=True
)
Solvent reference PPM for calibration (set from sample's solvent info)
raw_amplitudes
property
writable
#
Whether the amplitudes are unprocessed vendor data, stored without any rounding.
Set by importers; kept by copy(); cleared by any write to the amplitudes. Unset, it
follows the stored array (true when it was written losslessly). Integer values are
stored exactly either way; this decides whether other values beyond float32 stay exact.
raw_scale
property
writable
#
The factor the file's integers were multiplied by to give the raw amplitudes, if any.
Lets raw data a file declares as scaled integers (JCAMP-DX FACTOR) be stored as those
integers; only used while raw_amplitudes holds.
visualization_handler
property
writable
#
Plugin visualization handler ID (e.g., 'nanalysis:cosy_2d').
frequencies
instance-attribute
#
frequencies: FloatNdArray = np.asarray(
frequencies, dtype=np.float64
)
amplitudes
instance-attribute
#
amplitudes: ComplexNdArray = np.asarray(
amplitudes, dtype=np.complex128
)
reference_offset_ppm
property
#
How much higher this spectrum's axis reads than its acquisition frame, in ppm (0 when unreferenced).
frequency_range_hz
property
#
Frequency range of the spectrum in Hz.
absorb_creation
#
absorb_creation(
operation: str,
parameters: dict[str, str],
shape_before: tuple[int, ...],
shape_after: tuple[int, ...],
) -> bool
Record the operation that produced this object AS its creation.
A transform returning a NEW object otherwise writes two entries on it in the same millisecond: the bare construction, then the operation. They are one event -- the object was created BY that operation -- and two rows for it read as the transform having run twice. The operation replaces the construction record and keeps its parameters, so the entry still says how big the object came out while naming what made it.
Only an object whose history is still just its creation is rewritten; anything already operated on has a real past that must not move.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operation
|
str
|
Name of the operation that produced this object. |
required |
parameters
|
dict[str, str]
|
That operation's parameters; the creation's are kept too. |
required |
shape_before
|
tuple[int, ...]
|
Shape the operation started from. |
required |
shape_after
|
tuple[int, ...]
|
Shape of the produced object. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True when the creation record was rewritten, False when the caller |
bool
|
should append an entry of its own. |
suppress_region
#
suppress_region(
center: float,
width: float,
method: SuppressionMethod = SUPPRESS_INTERPOLATE,
) -> Self
Suppress a spectral region in-place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
center
|
float
|
Center of the region to suppress (in spectrum frequency units). |
required |
width
|
float
|
Full width of the region to suppress (in spectrum frequency units). |
required |
method
|
SuppressionMethod
|
Suppression method enum. |
SUPPRESS_INTERPOLATE
|
Returns:
| Type | Description |
|---|---|
Self
|
Self (mutated in-place) for method chaining. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the region is entirely outside the spectrum range. |
suppress_solvent_line
#
suppress_solvent_line(
expected_ppm: float,
search_window_ppm: float = DEFAULT_SOLVENT_SEARCH_WINDOW_PPM,
method: SolventSuppressionMethod | None = None,
multiplet_lines: int = 1,
j_coupling_hz: float = 0.0,
band_fwhm_multiple: float | None = None,
) -> SolventRemoval | None
Remove the solvent line near a known shift.
By default, a lineshape is fitted and only that solvent component is
subtracted, leaving other signal underneath it intact. Passing
method="band" instead filters the whole occupied band, including
anything else inside it. Passing method="hlsvd" models the line as a
sum of damped sinusoids and subtracts only those centred within a few
line widths of it.
Calling this a second time on the same spectrum removes nothing further, whichever method ran the first time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expected_ppm
|
float
|
The shift the sample's solvent predicts for the observed nucleus, in ppm. |
required |
search_window_ppm
|
float
|
PPM searched either side of |
DEFAULT_SOLVENT_SEARCH_WINDOW_PPM
|
method
|
SolventSuppressionMethod | None
|
|
None
|
multiplet_lines
|
int
|
Lines the solvent's own coupling produces, from the
solvent table; 1 for a singlet. |
1
|
j_coupling_hz
|
float
|
That coupling, in Hz. |
0.0
|
band_fwhm_multiple
|
float | None
|
For band removal, its half-width in measured FWHM units. None uses the library default. |
None
|
Returns:
| Type | Description |
|---|---|
SolventRemoval | None
|
What was removed, or None when no solvent line was found or the |
SolventRemoval | None
|
spectrum was already suppressed. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the spectrum has no reference frequency, so no ppm position can be located on its axis. |
reference_to_solvent
#
reference_to_solvent(
solvent: PredefinedSolvent,
nucleus: Nucleus | None = None,
search_window_ppm: float = 0.5,
) -> Self
Reference spectrum to a known solvent peak.
Finds the tallest peak within search_window_ppm of the expected solvent position and shifts the spectrum so that peak is at the correct PPM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solvent
|
PredefinedSolvent
|
Predefined solvent enum value |
required |
nucleus
|
Nucleus | None
|
Target nucleus (defaults to 1H) |
None
|
search_window_ppm
|
float
|
PPM range to search for solvent peak |
0.5
|
Returns:
| Type | Description |
|---|---|
Self
|
Self with shifted frequencies |
Raises:
| Type | Description |
|---|---|
ValueError
|
If solvent/nucleus combination not found or no peak in window |
reference_to_ppm
#
reference_to_ppm(
target_ppm: float,
search_window_ppm: float = 0.5,
use_centroid: bool = False,
) -> Self
Shift spectrum so the tallest peak near target is at target_ppm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_ppm
|
float
|
The PPM value where the peak should be placed |
required |
search_window_ppm
|
float
|
PPM range around target to search for peak |
0.5
|
use_centroid
|
bool
|
If True, use weighted centroid instead of maximum |
False
|
Returns:
| Type | Description |
|---|---|
Self
|
Self with shifted frequencies |
Raises:
| Type | Description |
|---|---|
ValueError
|
If reference_frequency_hz is not set or no peak found |
reference_manual
#
Manually reference spectrum by specifying current and target PPM.
This is for UI-driven referencing where user clicks on a peak and specifies what PPM it should be shifted to.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
click_ppm
|
float
|
The current PPM value of the clicked position |
required |
target_ppm
|
float
|
The PPM value it should be shifted to |
required |
Returns:
| Type | Description |
|---|---|
Self
|
Self with shifted frequencies |
Raises:
| Type | Description |
|---|---|
ValueError
|
If reference_frequency_hz is not set |
align_by_correlation
#
align_by_correlation(reference: Spectrum1D) -> Self
Align this spectrum to a reference using cross-correlation.
Computes the lag that maximizes the cross-correlation between the magnitude spectra, then shifts the frequency axis by that amount.
Both spectra must use the same frequency spacing (same number of points over the same spectral width). The reference spectrum is not modified.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference
|
Spectrum1D
|
Reference spectrum to align to. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
Self with shifted frequencies. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the spectra have different lengths. |
apply_harmonics_mask
#
Masks out harmonics by a cosine wave.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frequency_hz
|
float
|
Frequency of the harmonics to mask. |
50
|
k
|
float
|
Cutoff threshold of the cosine wave (higher = thinner mask). Defaults to 0.99. |
0.99
|
remove_peak
#
Zero-out a small window around peak_frequency_hz.
halves_symmetry_score
#
Compute a simple symmetry score of |z| around central_frequency_hz.
1.0 is perfectly symmetric; 0.0 very asymmetric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
central_frequency_hz
|
float
|
Central frequency to split the spectrum with. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Symmetry score between 0.0 and 1.0. |
find_peaks
#
find_peaks(
min_distance_hz: float | None = None,
min_height_ratio: float = 0.05,
prominence: float | None = None,
use_magnitude: bool = False,
adaptive: bool = False,
snr_threshold: float = 5.0,
mode: Literal["ml", "deconv"] = "ml",
ml_threshold: float | None = None,
inverted_lines: bool = False,
) -> list[PeakInfo]
Find peaks in spectrum with advanced filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_distance_hz
|
float | None
|
Minimum peak distance (in Hz). If None, taken from the trace's measured line width. |
None
|
min_height_ratio
|
float
|
Minimum peak height as a ratio of the maximum height (0-1). Ignored when adaptive=True. |
0.05
|
prominence
|
float | None
|
Minimum prominence as a ratio of the maximum height (0-1). None applies no prominence filter. Ignored when adaptive=True. |
None
|
use_magnitude
|
bool
|
If True, work on |z| else on Re(z). |
False
|
adaptive
|
bool
|
If True, run automatic peak detection, which takes its settings
from the trace itself. |
False
|
snr_threshold
|
float
|
Ignored; retained for API compatibility. |
5.0
|
mode
|
Literal['ml', 'deconv']
|
Automatic detection mode, used only with |
'ml'
|
ml_threshold
|
float | None
|
Detection sensitivity when |
None
|
inverted_lines
|
bool
|
Auto mode only: the experiment inverts lines on purpose (DEPT, APT), so negative absorptive lines are reported. Otherwise negative-going features are never peaks. |
False
|
analyze_multiplet
#
analyze_multiplet(
center_frequency: float | None = None,
search_width: float = 50.0,
min_height_ratio: float = 0.1,
method: Literal[
"structure", "fast", "pascal", "deconvolution"
] = "structure",
bootstrap_iterations: int | Literal["auto"] = "auto",
bic_threshold: float = 15.0,
peaks: list[PeakInfo] | None = None,
) -> MultipletAnalysis
Analyze peaks in a region to identify multiplet pattern and J-coupling.
Patterns reported: s, d, t, q, quint, sext,
sept, the compound patterns (dd, dt, dq, ...), and
m for a complex or unresolved multiplet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
center_frequency
|
float | None
|
Center of the search region (in spectrum units). If None and peaks provided, calculated from peaks. |
None
|
search_width
|
float
|
Width of search region on each side of center. |
50.0
|
min_height_ratio
|
float
|
Minimum peak height as ratio of tallest peak in region. |
0.1
|
method
|
Literal['structure', 'fast', 'pascal', 'deconvolution']
|
Analysis method: "structure" (default), "deconvolution", or "fast" (alias "pascal"). |
'structure'
|
bootstrap_iterations
|
int | Literal['auto']
|
Number of resampling iterations used to estimate uncertainty. Use "auto" to scale the count with the region's SNR. |
'auto'
|
bic_threshold
|
float
|
Model-selection threshold (BIC difference) for the number of lines fitted. |
15.0
|
peaks
|
list[PeakInfo] | None
|
Pre-detected peaks to use instead of re-detecting. When provided, the "fast" method uses these directly. For "structure"/"deconvolution", center_frequency and search_width are derived from peaks if not specified. |
None
|
Returns:
| Type | Description |
|---|---|
MultipletAnalysis
|
MultipletAnalysis with pattern, coupling constants, and confidence. |
MultipletAnalysis
|
For deconvolution/structure methods, includes uncertainties and fit metrics. |
plan_multiplet_groups
#
plan_multiplet_groups(
peaks: list[PeakInfo], conservative: bool = True
) -> GroupingPlan
Assign peaks to multiplet groups without analysing them.
Sets every line's group_id in place. The grouping matches the one
:meth:analyze_multiplet_groups uses on the same spectrum and lines.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
peaks
|
list[PeakInfo]
|
The lines to group. |
required |
conservative
|
bool
|
Keep ambiguous crowded envelopes as generic multiplets. |
True
|
Returns:
| Type | Description |
|---|---|
GroupingPlan
|
The grouping of the lines. |
analyze_multiplet_groups
#
analyze_multiplet_groups(
method: Literal[
"structure", "fast", "pascal", "deconvolution"
] = "structure",
peaks: list[PeakInfo] | None = None,
infer_missing_lines: bool = False,
conservative: bool = True,
) -> MultipletGroupsAnalysis
Detect and analyze all multiplet groups in the spectrum.
Peaks come from automatic detection (:meth:find_peaks with adaptive=True)
unless peaks is given.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
Literal['structure', 'fast', 'pascal', 'deconvolution']
|
Analysis method used to classify each group: - "structure" (default): fits the group's region and reports J uncertainties. - "fast" (alias: "pascal"): classifies from line positions only, without a fit. - "deconvolution": fits the region with an automatically chosen number of lines. |
'structure'
|
peaks
|
list[PeakInfo] | None
|
The lines to group and classify. Pass an already-detected (and possibly user-edited) peak list to have grouping use exactly that list. Default (None) runs automatic detection. |
None
|
conservative
|
bool
|
Keep ambiguous crowded envelopes as generic multiplets. On by default. |
True
|
infer_missing_lines
|
bool
|
Allow a group to include a line that was not detected.
Off by default. Inferred lines are marked |
False
|
Returns:
| Type | Description |
|---|---|
MultipletGroupsAnalysis
|
MultipletGroupsAnalysis with all detected groups. |
integrate_peaks
#
integrate_peaks(
peaks: list[PeakInfo],
integration_width: float | None = None,
normalize_to: int
| Literal["largest", "smallest"]
| None = None,
use_magnitude: bool = False,
width_multiplier: float = DEFAULT_INTEGRATION_HWHM_MULTIPLIER,
) -> list[IntegrationResult]
Calculate integrated areas for detected peaks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
peaks
|
list[PeakInfo]
|
List of peaks to integrate (from find_peaks()) |
required |
integration_width
|
float | None
|
Width of integration region on each side of peak (in spectrum units).
If None, auto-calculates from the peak's half-width at half-height
times |
None
|
normalize_to
|
int | Literal['largest', 'smallest'] | None
|
Index of peak to normalize to 1.00. If None, no normalization. |
None
|
use_magnitude
|
bool
|
If True, integrate |z|, else integrate Re(z). |
False
|
width_multiplier
|
float
|
Integration half-window in multiples of the peak's HWHM. A Lorentzian carries a heavy tail, so a narrow window introduces a systematic, linewidth-dependent quantitation bias: +/-1 HWHM captures 50% of the area, +/-20 (the default) ~97%. Reduce only for crowded spectra where neighbouring peaks would overlap the window. |
DEFAULT_INTEGRATION_HWHM_MULTIPLIER
|
Returns:
| Type | Description |
|---|---|
list[IntegrationResult]
|
List of IntegrationResult with area and bounds for each peak. |
integrate_shifts
#
integrate_shifts(
peaks: list[PeakInfo],
normalize_to: int
| Literal["largest", "smallest"]
| None = "largest",
use_magnitude: bool = False,
group_tolerance_hz: float = 20.0,
) -> list[ShiftIntegrationResult]
Integrate chemical shifts (multiplet groups) rather than individual peaks.
Peaks are grouped by their group_id (from multiplet analysis) or, when it is missing, by proximity. The result reports the total area of each group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
peaks
|
list[PeakInfo]
|
List of peaks (from find_peaks(), ideally with group_id set) |
required |
normalize_to
|
int | Literal['largest', 'smallest'] | None
|
Which group to normalize to 1.00. |
'largest'
|
use_magnitude
|
bool
|
If True, integrate |z|, else integrate Re(z). |
False
|
group_tolerance_hz
|
float
|
If peaks lack group_id, group by proximity (Hz). |
20.0
|
Returns:
| Type | Description |
|---|---|
list[ShiftIntegrationResult]
|
List of ShiftIntegrationResult, one per chemical shift group. |
deconvolve_region
#
deconvolve_region(
f_min: float,
f_max: float,
n_peaks: int | None = None,
bootstrap_iterations: int = 200,
) -> DeconvolutionResult
Full peak deconvolution for a spectral region.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f_min
|
float
|
Minimum frequency (Hz) |
required |
f_max
|
float
|
Maximum frequency (Hz) |
required |
n_peaks
|
int | None
|
Number of peaks to fit (auto-detect if None) |
None
|
bootstrap_iterations
|
int
|
Bootstrap iterations for uncertainty |
200
|
Returns:
| Type | Description |
|---|---|
DeconvolutionResult
|
DeconvolutionResult with fitted peaks and uncertainties |
estimate_snr
#
Estimate signal-to-noise ratio of the spectrum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signal_region
|
tuple[float, float] | None
|
Optional (f_min, f_max) to restrict signal calculation. If None, uses entire spectrum. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
Signal-to-noise ratio (linear scale) |
correct_baseline
#
correct_baseline(
method: BaselineMethod1D = "arpls",
edge_fraction: float = 0.1,
poly_order: int = 1,
smoothness_decades: float = 10.0,
asymmetry: float = 0.001,
iterations: int = 50,
tol: float = 0.001,
mask_sigma: float = 3.0,
als_lambda: float = 100000.0,
als_p: float = 0.01,
als_iterations: int = 10,
valley_prominence: float = 0.02,
valley_preserve_integral: bool = False,
valley_clip_negative: bool = False,
imaginary_method: ImaginaryBaselineMethod = "auto",
allow_unsafe_poly_order: bool = False,
exclude_regions: ExcludedRegions | None = None,
edge_mode: BaselineEdgeMode = "open",
**kwargs,
) -> Self
Apply baseline correction to the absorption channel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
BaselineMethod1D
|
Baseline correction method:
- "arpls" (default): a smooth baseline fitted to a signal-free mask
of the spectrum.
- "airpls": a smooth baseline fitted automatically to the whole
spectrum. Tends to inflate peak amplitudes; prefer "arpls".
- "asls": a smooth baseline controlled by |
'arpls'
|
edge_fraction
|
float
|
Fraction of each spectrum edge used by the edge-anchored methods ("edge", "median", "polynomial"). |
0.1
|
poly_order
|
int
|
Polynomial order for "polynomial" and "masked_poly". |
1
|
smoothness_decades
|
float
|
Smoothness of the fitted baseline on a log10 scale (larger is smoother). The effect does not depend on spectrum length. Useful range 7-12. |
10.0
|
asymmetry
|
float
|
Asymmetry parameter |
0.001
|
iterations
|
int
|
Maximum reweighting iterations for the smooth-baseline methods. |
50
|
tol
|
float
|
Relative convergence tolerance for the smooth-baseline methods. |
0.001
|
mask_sigma
|
float
|
Signal-mask threshold in robust noise sigma; points with
|
3.0
|
als_lambda
|
float
|
Smoothness parameter for "als"; the effect does not depend on spectrum length. |
100000.0
|
als_p
|
float
|
Asymmetry parameter for "als". |
0.01
|
als_iterations
|
int
|
Iteration count for "als"; must be >= 1. |
10
|
valley_prominence
|
float
|
Minimum valley prominence as a fraction of max|y|. |
0.02
|
valley_preserve_integral
|
bool
|
Rescale the corrected spectrum so its integral matches the input integral. The scale factor is unbounded when the corrected integral is small, so quantitative work must leave this off. |
False
|
valley_clip_negative
|
bool
|
Clamp negative values to zero before rescaling. Clipping makes the residual noise one-sided instead of zero-mean, which invalidates downstream noise/SNR estimates and biases integrals upward. |
False
|
imaginary_method
|
ImaginaryBaselineMethod
|
How to baseline-correct the dispersion (imaginary) channel: - "auto" (default): apply the same constant offset for the "edge" and "median" methods, and leave the dispersion channel untouched for every other method. Only a constant offset is well defined on a bipolar lineshape; anything else rotates the spectrum's phase. - "same": apply the absorption-channel method to the imaginary part. - "polynomial": use the edge-anchored polynomial fit. - "none": leave the imaginary part untouched. |
'auto'
|
allow_unsafe_poly_order
|
bool
|
Permit |
False
|
exclude_regions
|
ExcludedRegions | None
|
Spans of |
None
|
edge_mode
|
BaselineEdgeMode
|
|
'open'
|
**kwargs
|
Additional parameters (ignored for compatibility) |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
Self |
Raises:
| Type | Description |
|---|---|
ProcessingParameterError
|
If |
correct_phase_auto
#
correct_phase_auto(
method: Literal["acme", "peak_minima"] = "acme",
peak_width: int = 100,
return_phases: Literal[False] = False,
verbose: bool = False,
multi_start: bool | None = None,
p0_starts: Sequence[float] | None = None,
p1_starts: Sequence[float] | None = None,
strategy: Literal[
"seeded", "multistart", "per_line_seeded"
] = "seeded",
order: Literal["auto", 1, 2] | None = None,
mixed_polarity: bool = False,
orientation: OrientationCues | None = None,
) -> Self
correct_phase_auto(
method: Literal["acme", "peak_minima"] = "acme",
peak_width: int = 100,
return_phases: Literal[True] = True,
verbose: bool = False,
multi_start: bool | None = None,
p0_starts: Sequence[float] | None = None,
p1_starts: Sequence[float] | None = None,
strategy: Literal[
"seeded", "multistart", "per_line_seeded"
] = "seeded",
order: Literal["auto", 1, 2] | None = None,
mixed_polarity: bool = False,
orientation: OrientationCues | None = None,
) -> tuple[Self, tuple[float, ...]]
correct_phase_auto(
method: Literal["acme", "peak_minima"] = "acme",
peak_width: int = 100,
return_phases: bool = False,
verbose: bool = False,
multi_start: bool | None = None,
p0_starts: Sequence[float] | None = None,
p1_starts: Sequence[float] | None = None,
strategy: Literal[
"seeded", "multistart", "per_line_seeded"
] = "seeded",
order: Literal["auto", 1, 2] | None = None,
mixed_polarity: bool = False,
orientation: OrientationCues | None = None,
) -> Self | tuple[Self, tuple[float, ...]]
Apply automatic phase correction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
Literal['acme', 'peak_minima']
|
Phase objective, |
'acme'
|
peak_width
|
int
|
Width of the region used by the |
100
|
return_phases
|
bool
|
Whether to also return the applied phases: |
False
|
verbose
|
bool
|
Whether to log progress. |
False
|
multi_start
|
bool | None
|
Whether to try several starting phases. Accepted by
|
None
|
p0_starts
|
Sequence[float] | None
|
Zero-order starting phases in degrees. Accepted by
|
None
|
p1_starts
|
Sequence[float] | None
|
First-order starting phases in degrees. Accepted by
|
None
|
strategy
|
Literal['seeded', 'multistart', 'per_line_seeded']
|
Phasing approach: |
'seeded'
|
order
|
Literal['auto', 1, 2] | None
|
Phase model order: |
None
|
mixed_polarity
|
bool
|
The experiment inverts some lines by design (DEPT, APT, inversion recovery): they are phased absorptive and left pointing the way they do. |
False
|
orientation
|
OrientationCues | None
|
With |
None
|
Returns:
| Type | Description |
|---|---|
Self | tuple[Self, tuple[float, ...]]
|
Self if return_phases=False (default), otherwise (Self, phases). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If a multi-start-only argument is supplied to the seeded strategy. |
ProcessingParameterError
|
If the model order is not recognised. |
correct_phase_manual
#
correct_phase_manual(
p0: float,
p1: float = 0.0,
method: Literal["linear", "exponential"] = "linear",
p2: float = 0.0,
) -> Self
Apply manual phase correction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p0
|
float
|
Zero-order phase correction (degrees) |
required |
p1
|
float
|
First-order phase correction (degrees) |
0.0
|
method
|
Literal['linear', 'exponential']
|
Manual phase correction method |
'linear'
|
p2
|
float
|
Second-order phase correction (degrees). Supported by |
0.0
|
Returns:
| Type | Description |
|---|---|
Self
|
Self |
to_ppm
#
Convert spectrum to PPM scale.
Returns:
| Type | Description |
|---|---|
Self
|
New spectrum in PPM units (or copy if already in PPM) |
Raises:
| Type | Description |
|---|---|
ValueError
|
If reference frequency is not set |
to_signal
#
to_signal(
time_unit: TimeUnit = MICROSECOND,
carrier_offset_hz: float | None = None,
half: bool = False,
one_sided: bool | None = None,
first_point_scale: bool | None = None,
) -> Signal1D
Convert spectrum to a time-domain signal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time_unit
|
TimeUnit
|
Time unit for the output signal (default: MICROSECOND) |
MICROSECOND
|
carrier_offset_hz
|
float | None
|
Carrier offset in Hz (stored in output signal). |
None
|
half
|
bool
|
If True, return only the first half of the signal. Useful when the spectrum produces a mirrored/symmetric signal. |
False
|
one_sided
|
bool | None
|
Whether the frequency axis holds only non-negative frequencies
(as produced by |
None
|
first_point_scale
|
bool | None
|
Whether to undo a first-point scaling applied by the
forward transform, so the roundtrip is lossless. If None, read from the
|
None
|
Returns:
| Type | Description |
|---|---|
Signal1D
|
Signal1D object containing the time-domain signal |
Raises:
| Type | Description |
|---|---|
InvalidSignalError
|
If the spectrum has fewer than two points. |
ProcessingParameterError
|
If the axis is in PPM and no reference frequency is set. |
smooth
#
smooth(
sigma: float = 4.0,
preserve_integral: bool = True,
*,
method: Literal[
"gaussian", "savitzky_golay"
] = "gaussian",
window_points: int = 11,
poly_order: int = 3,
) -> Self
Apply smoothing to the spectrum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sigma
|
float
|
Gaussian width, in samples. Ignored by |
4.0
|
preserve_integral
|
bool
|
Whether to preserve total integral |
True
|
method
|
Literal['gaussian', 'savitzky_golay']
|
|
'gaussian'
|
window_points
|
int
|
Savitzky-Golay window in samples; odd and above |
11
|
poly_order
|
int
|
Savitzky-Golay polynomial order. |
3
|
Returns:
| Type | Description |
|---|---|
Self
|
Self |
Raises:
| Type | Description |
|---|---|
ProcessingParameterError
|
When a Savitzky-Golay window is even, not above the order, or longer than the spectrum. |
trim_frequency_range
#
Trim spectrum to specified frequency range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f_min
|
float
|
Minimum frequency (in spectrum's current units) |
-inf
|
f_max
|
float
|
Maximum frequency (in spectrum's current units) |
inf
|
Returns:
| Type | Description |
|---|---|
Self
|
A new, trimmed spectrum (the original is left unchanged). |
center_spectrum
#
Center the spectrum by shifting the main peak to 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
Centering method ("max" or "centroid") |
'max'
|
Returns:
| Type | Description |
|---|---|
Self
|
Self |
convert_frequency_unit
#
convert_frequency_unit(
target_unit: FrequencyUnit,
reference_freq_hz: float | None = None,
) -> Self
Convert spectrum to different frequency unit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_unit
|
FrequencyUnit
|
Target frequency unit. |
required |
reference_freq_hz
|
float | None
|
Reference frequency in Hz, required when converting to or
from PPM. If omitted, the spectrum's own |
None
|
Raises:
| Type | Description |
|---|---|
ProcessingParameterError
|
If a PPM conversion is requested and no reference frequency is available from either source. |
shift
#
shift(
shift: float, shift_unit: FrequencyUnit | None = None
) -> Self
Shift the frequency axis by a constant amount.
If shift_unit is PPM, requires reference_frequency_hz.
interpolate_at
#
interpolate_at(
sample_frequencies: FloatArray,
) -> ComplexNdArray
Interpolate spectrum at given frequencies.
normalize
#
Normalize spectrum amplitudes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
Literal['max', 'rms', 'unit']
|
Normalization method: - "max": Divide by maximum absolute value - "rms": Divide by RMS value - "unit": Divide by L2 norm |
'max'
|
Returns:
| Type | Description |
|---|---|
Self
|
Self for method chaining |
resample_as
#
Interpolate onto other's points inside the common axis range.
referenced
#
This spectrum's acquisition frame with its axis reading offset_ppm higher.
unreferenced gives the frame back while the amplitudes stay as they are.
unreferenced
#
The acquisition-frame spectrum: exact while the amplitudes are those referenced was given.
Once the amplitudes changed, the frame is rebuilt by shifting the axis back, which is exact only to rounding.
frequency_shift
#
Shift the frequency axis by a constant amount.
apply_window_notch
#
Zero (or mask) a window of the spectrum around center_hz.
The centre and the width are both expressed in Hz, relative to the carrier, regardless of what unit the spectrum's frequency axis is currently stored in.