Skip to content

Types#

Enums, result structures and aliases that appear in the signatures and attributes of the signal and spectrum types.

DeconvolutionResult dataclass #

DeconvolutionResult(
    peaks: list[FittedPeak],
    frequencies: ndarray,
    fitted_curve: ndarray,
    residuals: ndarray,
    bic: float,
    r_squared: float,
    snr: float,
    n_iterations: int,
    success: bool,
    message: str,
    raw_result: ModelResult | None = None,
)

Result of peak deconvolution.

Attributes:

Name Type Description
peaks list[FittedPeak]

List of fitted peaks

frequencies ndarray

Frequency array used for fitting

fitted_curve ndarray

Fitted model curve

residuals ndarray

Residuals (observed - fitted)

bic float

Final BIC value

r_squared float

Coefficient of determination

snr float

Estimated signal-to-noise ratio

n_iterations int

Number of BIC optimization iterations

success bool

Whether fitting converged

message str

Status message

peaks instance-attribute #

peaks: list[FittedPeak]

frequencies instance-attribute #

frequencies: ndarray

fitted_curve instance-attribute #

fitted_curve: ndarray

residuals instance-attribute #

residuals: ndarray

bic instance-attribute #

bic: float

r_squared instance-attribute #

r_squared: float

snr instance-attribute #

snr: float

n_iterations instance-attribute #

n_iterations: int

success instance-attribute #

success: bool

message instance-attribute #

message: str

raw_result class-attribute instance-attribute #

raw_result: ModelResult | None = field(
    default=None, repr=False
)

n_peaks property #

n_peaks: int

Number of peaks in result.

peak_centers property #

peak_centers: list[float]

List of peak center frequencies.

peak_heights property #

peak_heights: list[float]

List of peak heights.

LinewidthMeasurement dataclass #

LinewidthMeasurement(
    median_points: float,
    q90_points: float,
    median_hz: float,
    q90_hz: float,
    hz_per_point: float,
    n_lines: int,
)

Robust linewidth summary measured once from an unwindowed FID.

median_points instance-attribute #

median_points: float

q90_points instance-attribute #

q90_points: float

median_hz instance-attribute #

median_hz: float

q90_hz instance-attribute #

q90_hz: float

hz_per_point instance-attribute #

hz_per_point: float

n_lines instance-attribute #

n_lines: int

DistributionComponent dataclass #

DistributionComponent(
    center: float,
    amplitude: float,
    width: float,
    fraction: float,
)

A discrete component identified within a distribution.

center instance-attribute #

center: float

amplitude instance-attribute #

amplitude: float

width instance-attribute #

width: float

fraction instance-attribute #

fraction: float

RelaxationDistribution dataclass #

RelaxationDistribution(
    t_grid: ndarray, amplitudes: ndarray
)

Continuous relaxation time distribution from ILT.

Represents a distribution of T1, T2, or diffusion coefficient values with methods for computing moments, binning by cutoffs, and identifying discrete components.

All times are in seconds. Use the ms-suffixed properties for convenience.

t_grid instance-attribute #

t_grid: ndarray

amplitudes instance-attribute #

amplitudes: ndarray

total_amplitude class-attribute instance-attribute #

total_amplitude: float = field(init=False)

geometric_mean property #

geometric_mean: float

Log-weighted geometric mean relaxation time (seconds).

T2gm is the key input for the SDR permeability model.

geometric_mean_ms property #

geometric_mean_ms: float

arithmetic_mean property #

arithmetic_mean: float

arithmetic_mean_ms property #

arithmetic_mean_ms: float

log_std property #

log_std: float

Standard deviation in log space (distribution width).

cumulative #

cumulative() -> tuple[ndarray, ndarray]

Cumulative distribution function.

Returns:

Type Description
tuple[ndarray, ndarray]

(t_grid, cdf) where cdf goes from 0 to 1.

fraction_below #

fraction_below(cutoff: float) -> float

Fraction of distribution below a cutoff time (seconds).

fraction_above #

fraction_above(cutoff: float) -> float

Fraction of distribution above a cutoff time (seconds).

fraction_between #

fraction_between(low: float, high: float) -> float

Fraction of distribution between two cutoff times (seconds).

bin #

bin(cutoffs: list[float]) -> list[float]

Bin distribution by a sorted list of cutoff times (seconds).

Returns:

Type Description
list[float]

List of fractional volumes for each bin. Length = len(cutoffs) + 1.

list[float]

bins[0] = fraction below cutoffs[0]

list[float]

bins[-1] = fraction above cutoffs[-1]

peak_components #

peak_components(
    min_prominence: float = 0.05,
) -> list[DistributionComponent]

Identify discrete peaks within the distribution.

Parameters:

Name Type Description Default
min_prominence float

Minimum prominence as fraction of max amplitude.

0.05

Returns:

Type Description
list[DistributionComponent]

List of DistributionComponent with center, amplitude, width, fraction.

from_ilt classmethod #

from_ilt(ilt_result: ILTResult) -> RelaxationDistribution

Create from an ILTResult.

GroupAlternative dataclass #

GroupAlternative(
    kind: str,
    at_hz: float,
    probability: float,
    split_index: int = 0,
)

A correction a user could make to one group.

Attributes:

Name Type Description
kind str

"split" (cut the group in two), "merge_lower" or "merge_higher" (join it with the neighbouring group below/above in frequency).

at_hz float

The boundary concerned: midway between the two lines it separates.

probability float

Posterior probability that the correction is right.

split_index int

For "split", how many of the group's lines fall below the cut.

kind instance-attribute #

kind: str

at_hz instance-attribute #

at_hz: float

probability instance-attribute #

probability: float

split_index class-attribute instance-attribute #

split_index: int = 0

ILTResult dataclass #

ILTResult(
    t_grid: ndarray,
    amplitudes: ndarray,
    residual_norm: float,
    regularization_alpha: float,
    snr: float,
    kernel_type: Kernel,
    offset: float = 0.0,
    noise_std: float = 0.0,
)

Result of inverse Laplace transform.

Attributes:

Name Type Description
t_grid ndarray

Relaxation time grid (seconds).

amplitudes ndarray

Distribution amplitudes on t_grid (offset excluded).

residual_norm float

Magnitude of the data residual of the full model.

regularization_alpha float

Regularization strength actually used.

snr float

Signal-to-noise ratio, max|data| / noise_std.

kernel_type Kernel

Decay model used.

offset float

Fitted constant baseline (0.0 when offset fitting is disabled).

noise_std float

Noise standard deviation used for snr.

t_grid instance-attribute #

t_grid: ndarray

amplitudes instance-attribute #

amplitudes: ndarray

residual_norm instance-attribute #

residual_norm: float

regularization_alpha instance-attribute #

regularization_alpha: float

snr instance-attribute #

snr: float

kernel_type instance-attribute #

kernel_type: Kernel

offset class-attribute instance-attribute #

offset: float = 0.0

noise_std class-attribute instance-attribute #

noise_std: float = 0.0

Kernel #

Relaxation decay models supported by ILT.

T2 class-attribute instance-attribute #

T2 = 'T2'

T1_IR class-attribute instance-attribute #

T1_IR = 'T1_IR'

T1_SR class-attribute instance-attribute #

T1_SR = 'T1_SR'

FittedPeak dataclass #

FittedPeak(
    center: float,
    height: float,
    width: float,
    phase: float = 0.0,
    center_stderr: float | None = None,
    height_stderr: float | None = None,
    width_stderr: float | None = None,
    lineshape: Literal[
        "lorentzian",
        "phased_lorentzian",
        "voigt",
        "pseudo_voigt",
    ] = "phased_lorentzian",
    gaussian_fraction: float | None = None,
)

Result of fitting a single peak.

Attributes:

Name Type Description
center float

Peak center frequency (Hz)

height float

Peak height (amplitude)

width float

Peak width - HWHM for Lorentzian, FWHM for others (Hz)

phase float

Phase angle in radians (for phased models)

center_stderr float | None

Standard error of center estimate

height_stderr float | None

Standard error of height estimate

width_stderr float | None

Standard error of width estimate

lineshape Literal['lorentzian', 'phased_lorentzian', 'voigt', 'pseudo_voigt']

Type of lineshape fitted

gaussian_fraction float | None

Gaussian fraction for pseudo-Voigt (0-1)

center instance-attribute #

center: float

height instance-attribute #

height: float

width instance-attribute #

width: float

phase class-attribute instance-attribute #

phase: float = 0.0

center_stderr class-attribute instance-attribute #

center_stderr: float | None = None

height_stderr class-attribute instance-attribute #

height_stderr: float | None = None

width_stderr class-attribute instance-attribute #

width_stderr: float | None = None

lineshape class-attribute instance-attribute #

lineshape: Literal[
    "lorentzian",
    "phased_lorentzian",
    "voigt",
    "pseudo_voigt",
] = "phased_lorentzian"

gaussian_fraction class-attribute instance-attribute #

gaussian_fraction: float | None = None

fwhm property #

fwhm: float

Full-width at half-maximum (Hz).

hwhm property #

hwhm: float

Half-width at half-maximum (Hz).

to_dict #

to_dict() -> dict

Convert to dictionary for serialization.

evaluate #

evaluate(frequencies: ndarray) -> ndarray

Evaluate the peak at given frequencies.

from_lmfit_params classmethod #

from_lmfit_params(
    params: Parameters, prefix: str = ""
) -> FittedPeak

Create FittedPeak from lmfit Parameters result.

MultipletReading dataclass #

MultipletReading(
    best: PatternReading,
    alternatives: tuple[PatternReading, ...] = (),
    second_order: bool = False,
    unnamed: PatternReading | None = None,
)

Every reading of a multiplet worth reporting.

Attributes:

Name Type Description
best PatternReading

The reported reading; crowded groups can remain unnamed when no specific interpretation has majority support.

alternatives tuple[PatternReading, ...]

The next most probable readings, most probable first.

second_order bool

The best reading is m: a strongly coupled spin system, or lines that are mirror-symmetric but follow no first-order pattern.

best instance-attribute #

alternatives class-attribute instance-attribute #

alternatives: tuple[PatternReading, ...] = ()

second_order class-attribute instance-attribute #

second_order: bool = False

unnamed class-attribute instance-attribute #

unnamed: PatternReading | None = None

PatternReading dataclass #

PatternReading(
    label: str,
    j_hz: tuple[float, ...],
    j_sd_hz: tuple[float, ...],
    centre_hz: float,
    probability: float,
    roof: float = 0.0,
    system: str = "",
    system_couplings: tuple[str, ...] = (),
    shifts_hz: tuple[float, ...] = (),
)

One reading of a multiplet.

Attributes:

Name Type Description
label str

"s", a first-order label ("td", "quint"...), or "m".

j_hz tuple[float, ...]

Couplings. For a first-order label, largest first, one per coupling of the label (a td has two); for a spin system, in the order of system_couplings. Empty for an unnamed m.

j_sd_hz tuple[float, ...]

Standard error of each coupling.

centre_hz float

Centre of the pattern.

probability float

Posterior probability of the reading among all those tried.

roof float

Fitted lean, log height of the last line over the first.

system str

For a strongly coupled reading (label m), the spin system: "AB", "ABX", "AA'BB'" or "AA'XX'". Empty otherwise.

system_couplings tuple[str, ...]

Names of j_hz for a spin system ("J_AB"...).

shifts_hz tuple[float, ...]

For a spin system, the shift of each observed site (A, then B).

label instance-attribute #

label: str

j_hz instance-attribute #

j_hz: tuple[float, ...]

j_sd_hz instance-attribute #

j_sd_hz: tuple[float, ...]

centre_hz instance-attribute #

centre_hz: float

probability instance-attribute #

probability: float

roof class-attribute instance-attribute #

roof: float = 0.0

system class-attribute instance-attribute #

system: str = ''

system_couplings class-attribute instance-attribute #

system_couplings: tuple[str, ...] = ()

shifts_hz class-attribute instance-attribute #

shifts_hz: tuple[float, ...] = ()

Anchor dataclass #

Anchor(
    hz: float,
    f1_hz: float | None = None,
    ppm: float | None = None,
    f1_ppm: float | None = None,
    peak_id: str | None = None,
)

The position an edit points to, in Hz.

Attributes:

Name Type Description
hz float

Direct-axis (F2) position in Hz.

f1_hz float | None

Indirect-axis position in Hz. Non-None marks a 2D crosspeak.

ppm float | None

Direct-axis position in ppm, informational only (not resolved against; unaffected by re-referencing).

f1_ppm float | None

Indirect-axis position in ppm, informational only.

peak_id str | None

Id of the peak this anchor was made against, if known. Used as a resolution hint; not guaranteed to survive re-detection.

hz instance-attribute #

hz: float

f1_hz class-attribute instance-attribute #

f1_hz: float | None = None

ppm class-attribute instance-attribute #

ppm: float | None = None

f1_ppm class-attribute instance-attribute #

f1_ppm: float | None = None

peak_id class-attribute instance-attribute #

peak_id: str | None = None

is_2d property #

is_2d: bool

Whether this anchor identifies a 2D crosspeak (f1_hz is set).

EditKind #

The kind of change one log entry represents.

ADD class-attribute instance-attribute #

ADD = 'add'

DELETE class-attribute instance-attribute #

DELETE = 'delete'

MOVE class-attribute instance-attribute #

MOVE = 'move'

SET_FIELD class-attribute instance-attribute #

SET_FIELD = 'set_field'

GROUP class-attribute instance-attribute #

GROUP = 'group'

UNGROUP class-attribute instance-attribute #

UNGROUP = 'ungroup'

SET_TIER class-attribute instance-attribute #

SET_TIER = 'set_tier'

ANNOTATE class-attribute instance-attribute #

ANNOTATE = 'annotate'

SET_REFERENCE class-attribute instance-attribute #

SET_REFERENCE = 'set_reference'

ASSIGN class-attribute instance-attribute #

ASSIGN = 'assign'

SET_INTEGRAL_SCALE class-attribute instance-attribute #

SET_INTEGRAL_SCALE = 'set_integral_scale'

EditablePeak dataclass #

EditablePeak(
    peak_id: str,
    frequency_hz: float,
    f1_hz: float | None = None,
    index: int = -1,
    index_f1: int = -1,
    frequency_ppm: float | None = None,
    f1_ppm: float | None = None,
    height: float = 0.0,
    area: float = 0.0,
    linewidth_hz: float = 0.0,
    group_id: int | None = None,
    multiplet_pattern: str = "",
    j_couplings: tuple[float, ...] = (),
    label: str = "",
    annotation: str = "",
    inferred: bool = False,
    manual: bool = False,
    tier_override: int | None = None,
    edit_ids: list[str] = list(),
    linewidth_f1_hz: float = 0.0,
    linewidth_f1_ppm: float = 0.0,
    linewidth_f2_ppm: float = 0.0,
    peak_type: int = 0,
    diagonal: bool = False,
)

A plain, backend-independent representation of one peak line.

f1_hz being set marks this as a 2D crosspeak.

Attributes:

Name Type Description
manual bool

True when this peak was created by an ADD edit rather than detected automatically. The sole indicator of manual origin.

tier_override int | None

Chemical-shift tier set by a SET_TIER edit, if any.

edit_ids list[str]

Ids of every edit that touched this peak in the current replay.

linewidth_f1_hz float

Indirect-axis linewidth in Hz of a crosspeak; 0 when not stated.

linewidth_f1_ppm float

Indirect-axis linewidth in ppm of a crosspeak; 0 when not stated.

linewidth_f2_ppm float

Direct-axis linewidth in ppm of a crosspeak; 0 when not stated.

peak_type int

Class a source tool gave a crosspeak (the wire enum's value); 0 when it gave none.

diagonal bool

Whether a source tool marked the crosspeak as lying on the diagonal.

peak_id instance-attribute #

peak_id: str

frequency_hz instance-attribute #

frequency_hz: float

f1_hz class-attribute instance-attribute #

f1_hz: float | None = None

index class-attribute instance-attribute #

index: int = -1

index_f1 class-attribute instance-attribute #

index_f1: int = -1

frequency_ppm class-attribute instance-attribute #

frequency_ppm: float | None = None

f1_ppm class-attribute instance-attribute #

f1_ppm: float | None = None

height class-attribute instance-attribute #

height: float = 0.0

area class-attribute instance-attribute #

area: float = 0.0

linewidth_hz class-attribute instance-attribute #

linewidth_hz: float = 0.0

group_id class-attribute instance-attribute #

group_id: int | None = None

multiplet_pattern class-attribute instance-attribute #

multiplet_pattern: str = ''

j_couplings class-attribute instance-attribute #

j_couplings: tuple[float, ...] = ()

label class-attribute instance-attribute #

label: str = ''

annotation class-attribute instance-attribute #

annotation: str = ''

inferred class-attribute instance-attribute #

inferred: bool = False

manual class-attribute instance-attribute #

manual: bool = False

tier_override class-attribute instance-attribute #

tier_override: int | None = None

edit_ids class-attribute instance-attribute #

edit_ids: list[str] = field(default_factory=list)

linewidth_f1_hz class-attribute instance-attribute #

linewidth_f1_hz: float = 0.0

linewidth_f1_ppm class-attribute instance-attribute #

linewidth_f1_ppm: float = 0.0

linewidth_f2_ppm class-attribute instance-attribute #

linewidth_f2_ppm: float = 0.0

peak_type class-attribute instance-attribute #

peak_type: int = 0

diagonal class-attribute instance-attribute #

diagonal: bool = False

is_2d property #

is_2d: bool

Whether this is a 2D crosspeak.

GroupScope dataclass #

GroupScope(
    start_hz: float,
    end_hz: float,
    member_peak_ids: tuple[str, ...] = (),
    f1_start_hz: float | None = None,
    f1_end_hz: float | None = None,
    shift_id: str | None = None,
)

The region and members a group-scoped edit applies to.

Attributes:

Name Type Description
shift_id str | None

The shift:<hz>hz identity from shift curation, carried for display and cross-referencing; derived from start_hz/ end_hz.

start_hz instance-attribute #

start_hz: float

end_hz instance-attribute #

end_hz: float

member_peak_ids class-attribute instance-attribute #

member_peak_ids: tuple[str, ...] = ()

f1_start_hz class-attribute instance-attribute #

f1_start_hz: float | None = None

f1_end_hz class-attribute instance-attribute #

f1_end_hz: float | None = None

shift_id class-attribute instance-attribute #

shift_id: str | None = None

contains #

contains(peak: EditablePeak) -> bool

Whether peak falls inside this scope's interval on every axis it has.

PeakEdit dataclass #

PeakEdit(
    edit_id: str,
    kind: EditKind,
    anchors: tuple[Anchor, ...] = (),
    scope: GroupScope | None = None,
    created_at: str = "",
    author: str = "",
    source: str = UI,
    reason: str | None = None,
    batch_id: str = "",
    disabled: bool = False,
    reverts_edit_id: str | None = None,
    payload: Mapping[str, Any] = dict(),
)

One immutable entry in a peak edit log.

Attributes:

Name Type Description
edit_id str

Client-generated uuid, unique per entry. Used to deduplicate retried submissions.

kind EditKind

What the edit does.

anchors tuple[Anchor, ...]

Position(s) the edit applies to. GROUP carries one per member; most kinds carry exactly one; SET_REFERENCE may carry none.

scope GroupScope | None

Interval + member ids, for the group-scoped kinds.

created_at str

RFC 3339 UTC timestamp.

author str

Profile name of whoever made the edit.

source str

"ui", "script", "rpc", "plugin:<id>" or "vendor".

reason str | None

Why the edit was made. Required for script, plugin and vendor sources.

batch_id str

Groups edits made in one user gesture; one batch is undone as a unit.

disabled bool

True once this entry has been reverted. Entries are never removed, only marked disabled.

reverts_edit_id str | None

Id of the entry this one undoes, if it is a revert.

payload Mapping[str, Any]

Kind-specific values. See :func:apply_peak_edits.

Raises:

Type Description
EditValidationError

If edit_id is empty, if source requires a reason and none is given, if kind is UNGROUP and payload has no boundary_hz, or if kind is ASSIGN and payload lacks f2_atom_index or f1_atom_index, or if kind is SET_INTEGRAL_SCALE and scope is missing or payload["value"] is not a positive finite number.

edit_id instance-attribute #

edit_id: str

kind instance-attribute #

kind: EditKind

anchors class-attribute instance-attribute #

anchors: tuple[Anchor, ...] = ()

scope class-attribute instance-attribute #

scope: GroupScope | None = None

created_at class-attribute instance-attribute #

created_at: str = ''

author class-attribute instance-attribute #

author: str = ''

source class-attribute instance-attribute #

source: str = EditSource.UI

reason class-attribute instance-attribute #

reason: str | None = None

batch_id class-attribute instance-attribute #

batch_id: str = ''

disabled class-attribute instance-attribute #

disabled: bool = False

reverts_edit_id class-attribute instance-attribute #

reverts_edit_id: str | None = None

payload class-attribute instance-attribute #

payload: Mapping[str, Any] = field(default_factory=dict)

GroupingEvidence dataclass #

GroupingEvidence(
    group_id: int,
    member_indices: tuple[int, ...],
    probability: float,
    reason: str,
    label: str,
    alternatives: tuple[GroupAlternative, ...],
    reading: MultipletReading,
    unresolved: bool = False,
)

How firmly the data support one group, and the corrections most likely to fix it.

Attributes:

Name Type Description
group_id int

The group's MultipletGroup.group_id.

member_indices tuple[int, ...]

PeakInfo.index of every line in MultipletGroup.peak_indices.

probability float

Posterior probability that these lines are exactly one multiplet, neither split nor joined with a neighbour.

reason str

Competing reading that holds the rest of the probability: "split", "merge_lower", "merge_higher", or "".

label str

Pattern label of the best model for the group.

alternatives tuple[GroupAlternative, ...]

Best split and both merges, most probable first.

reading MultipletReading

What the group's lines say its multiplet is, with the alternatives.

group_id instance-attribute #

group_id: int

member_indices instance-attribute #

member_indices: tuple[int, ...]

probability instance-attribute #

probability: float

reason instance-attribute #

reason: str

label instance-attribute #

label: str

alternatives instance-attribute #

alternatives: tuple[GroupAlternative, ...]

reading instance-attribute #

unresolved class-attribute instance-attribute #

unresolved: bool = False

GroupingPlan dataclass #

GroupingPlan(groups: list[MultipletGroup])

A segmentation whose multiplet reads have not run yet: the fast half of :func:group_peaks_with_evidence.

Attributes:

Name Type Description
groups list[MultipletGroup]

The groups, sorted by centre frequency, with bounds and integration; no pattern.

groups instance-attribute #

read #

read(index: int) -> MultipletReading

The multiplet reading of group index; memoised on its inputs, safe from any thread.

evidence #

evidence(
    readings: list[MultipletReading],
) -> list[GroupingEvidence]

One :class:GroupingEvidence per group, given every group's reading in group order.

SolventBand dataclass #

SolventBand(
    offset_hz: float,
    fwhm_hz: float,
    half_width_hz: float,
    perturbed_half_width_hz: float,
    apex: float,
    noise_sigma: float,
    multiplet_half_span_hz: float = 0.0,
)

The band of frequencies a solvent line occupies, measured on the FID.

Attributes:

Name Type Description
offset_hz float

Position of the line relative to the carrier, in Hz. This is what the FID is shifted by, so it is signed.

fwhm_hz float

Full width at half maximum of the line, measured by walking down from its apex in the magnitude spectrum of the raw FID.

half_width_hz float

Half-width of the band that will be removed, in Hz.

perturbed_half_width_hz float

How far from the line the filter changes the spectrum by more than the noise, in Hz. Never smaller than half_width_hz.

apex float

Magnitude of the line at its apex, in the units of the FID.

noise_sigma float

Noise sigma the detection threshold was built from.

offset_hz instance-attribute #

offset_hz: float

fwhm_hz instance-attribute #

fwhm_hz: float

half_width_hz instance-attribute #

half_width_hz: float

perturbed_half_width_hz instance-attribute #

perturbed_half_width_hz: float

apex instance-attribute #

apex: float

noise_sigma instance-attribute #

noise_sigma: float

multiplet_half_span_hz class-attribute instance-attribute #

multiplet_half_span_hz: float = 0.0

ImaginarySource module-attribute #

ImaginarySource = Literal['measured', 'hilbert']

SolventHlsvdFit dataclass #

SolventHlsvdFit(
    center_hz: float,
    fwhm_hz: float,
    window_half_width_hz: float,
    component_frequencies_hz: tuple[float, ...],
    component_fwhm_hz: tuple[float, ...],
    component_amplitudes: tuple[complex, ...],
    n_components: int,
    noise_sigma: float,
    imaginary_source: ImaginarySource,
)

The solvent signal measured at a known shift, as a sum of damped sinusoids.

Attributes:

Name Type Description
center_hz float

Measured centre of the line, in Hz on the spectrum's axis.

fwhm_hz float

Measured full width at half maximum of the line's real part, in Hz.

window_half_width_hz float

Half-width of the selection window around center_hz, in Hz.

component_frequencies_hz tuple[float, ...]

Centre of each removed component, in Hz on the axis.

component_fwhm_hz tuple[float, ...]

Full width at half maximum of each removed component, in Hz.

component_amplitudes tuple[complex, ...]

Complex height of each removed component on the spectrum.

n_components int

Components in the whole model of the estimation band.

noise_sigma float

Noise standard deviation the model order was chosen against.

imaginary_source ImaginarySource

"measured" when the spectrum's own imaginary part was used, "hilbert" when it was rebuilt from the real part.

center_hz instance-attribute #

center_hz: float

fwhm_hz instance-attribute #

fwhm_hz: float

window_half_width_hz instance-attribute #

window_half_width_hz: float

component_frequencies_hz instance-attribute #

component_frequencies_hz: tuple[float, ...]

component_fwhm_hz instance-attribute #

component_fwhm_hz: tuple[float, ...]

component_amplitudes instance-attribute #

component_amplitudes: tuple[complex, ...]

n_components instance-attribute #

n_components: int

noise_sigma instance-attribute #

noise_sigma: float

imaginary_source instance-attribute #

imaginary_source: ImaginarySource

evaluate #

evaluate(size: int) -> ndarray

Evaluate the removed solvent model on the full grid it was fitted on.

Parameters:

Name Type Description Default
size int

Number of points of that grid.

required

Returns:

Type Description
ndarray

The complex model, one value per grid point, in the grid's own order.

SolventLineFit dataclass #

SolventLineFit(
    peak: FittedPeak,
    components: tuple[FittedPeak, ...],
    search_center_hz: float,
    search_half_width_hz: float,
    noise_sigma: float,
    subtraction_low_hz: float,
    subtraction_high_hz: float,
)

The solvent signal measured at a known shift.

Attributes:

Name Type Description
peak FittedPeak

The tallest fitted component, with center and width in Hz.

components tuple[FittedPeak, ...]

Every component of the solvent's own signal, peak included; membership follows the solvent's own coupling grid, not distance.

search_center_hz float

The expected shift the search was centered on, in Hz.

search_half_width_hz float

Half-width of the window that was searched, in Hz.

noise_sigma float

Noise standard deviation the detection threshold was built from.

peak instance-attribute #

peak: FittedPeak

components instance-attribute #

components: tuple[FittedPeak, ...]

search_center_hz instance-attribute #

search_center_hz: float

search_half_width_hz instance-attribute #

search_half_width_hz: float

noise_sigma instance-attribute #

noise_sigma: float

subtraction_low_hz instance-attribute #

subtraction_low_hz: float

subtraction_high_hz instance-attribute #

subtraction_high_hz: float

center_hz property #

center_hz: float

Center of the fitted line, in Hz.

fwhm_hz property #

fwhm_hz: float

Full width at half maximum of the fitted line, in Hz.

half_width_hz property #

half_width_hz: float

Half-width of the span the fitted components occupy, in Hz.

evaluate #

evaluate(frequencies_hz: FloatArray) -> FloatArray

Evaluate the fitted solvent signal.

Parameters:

Name Type Description Default
frequencies_hz FloatArray

Frequencies to evaluate at, in Hz.

required

Returns:

Type Description
FloatArray

The signal's amplitude at each frequency, real valued.

SolventRemoval dataclass #

SolventRemoval(
    method: SolventSuppressionMethod,
    center_hz: float,
    fwhm_hz: float,
    half_width_hz: float,
    band: SolventBand | None = None,
    fit: SolventLineFit | None = None,
    hlsvd: SolventHlsvdFit | None = None,
)

What a solvent removal took out, whichever method took it out.

A removal that found no line to remove is represented by None, not by an instance of this type.

Attributes:

Name Type Description
method SolventSuppressionMethod

Which method was used.

center_hz float

Where the line was found, in Hz on the spectrum's axis.

fwhm_hz float

The line's full width at half maximum, in Hz.

half_width_hz float

Half-width of the span the removal treated, in Hz.

band SolventBand | None

The measured band, when method is "band".

fit SolventLineFit | None

The fitted component, when method is "fit".

hlsvd SolventHlsvdFit | None

The removed sinusoid model, when method is "hlsvd".

method instance-attribute #

center_hz instance-attribute #

center_hz: float

fwhm_hz instance-attribute #

fwhm_hz: float

half_width_hz instance-attribute #

half_width_hz: float

band class-attribute instance-attribute #

band: SolventBand | None = None

fit class-attribute instance-attribute #

fit: SolventLineFit | None = None

hlsvd class-attribute instance-attribute #

hlsvd: SolventHlsvdFit | None = None

from_band classmethod #

from_band(band: SolventBand) -> SolventRemoval

Describe a band removal.

Parameters:

Name Type Description Default
band SolventBand

The band that was removed.

required

Returns:

Type Description
SolventRemoval

The removal record.

from_fit classmethod #

from_fit(fit: SolventLineFit) -> SolventRemoval

Describe a fitted-line subtraction.

Parameters:

Name Type Description Default
fit SolventLineFit

The component that was subtracted.

required

Returns:

Type Description
SolventRemoval

The removal record.

from_hlsvd classmethod #

from_hlsvd(model: SolventHlsvdFit) -> SolventRemoval

Describe a subtraction of the solvent's sinusoid model.

Parameters:

Name Type Description Default
model SolventHlsvdFit

The model that was subtracted.

required

Returns:

Type Description
SolventRemoval

The removal record.

SolventSuppressionMethod module-attribute #

SolventSuppressionMethod = Literal['band', 'fit', 'hlsvd']

InvalidSignalError #

Raised when signal data is invalid.

ProcessingParameterError #

Raised when processing parameters are invalid.

NumericScalar #

NumericScalar = (
    int
    | float
    | complex
    | integer
    | floating
    | complexfloating
)

SupportsRead #

read #

read(length: int = ...) -> T_co

F1AcquisitionMode #

F1AcquisitionMode = Literal[
    "undefined",
    "qf",
    "qseq",
    "tppi",
    "states",
    "states_tppi",
    "echo_antiecho",
]

WindowShape dataclass #

WindowShape(
    sine_offset: float = 0.5,
    sine_power: float = 1.0,
    rise_fraction: float = 0.0,
    fall_fraction: float = 0.5,
)

Parameters of the windows that take more than a width.

Attributes:

Name Type Description
sine_offset float

sine_bell start as a fraction of pi, 0 to 0.5 (0.5 is a cosine).

sine_power float

sine_bell exponent, 1 for sine and 2 for squared sine.

rise_fraction float

trapezoid linear rise over this fraction of the FID, 0 to 1.

fall_fraction float

trapezoid linear fall over this fraction of the FID's end, 0 to 1.

sine_offset class-attribute instance-attribute #

sine_offset: float = 0.5

sine_power class-attribute instance-attribute #

sine_power: float = 1.0

rise_fraction class-attribute instance-attribute #

rise_fraction: float = 0.0

fall_fraction class-attribute instance-attribute #

fall_fraction: float = 0.5

WindowType #

WindowType = Literal[
    "none",
    "exponential",
    "gaussian",
    "hamming",
    "hann",
    "blackman",
    "blackmanharris",
    "kaiser",
    "bartlett",
    "cosine",
    "tukey",
    "sine_bell",
    "trapezoid",
    "traf",
    "lorentz_gauss",
]

MultiExponentialResult dataclass #

MultiExponentialResult(
    n_components: int,
    time_constants_ms: list[float],
    amplitudes: list[float],
    offset: float,
    residual: float,
)

Result of discrete multi-exponential fitting.

n_components instance-attribute #

n_components: int

time_constants_ms instance-attribute #

time_constants_ms: list[float]

amplitudes instance-attribute #

amplitudes: list[float]

offset instance-attribute #

offset: float

residual instance-attribute #

residual: float

Direction #

Direction = Literal['forward', 'backward']

Lineshape #

Lineshape = Literal['lorentzian', 'gaussian']

BaselineEdgeMode #

BaselineEdgeMode = Literal['open', 'signal_free_mask']

BaselineMethod1D #

BaselineMethod1D = Literal[
    "polynomial",
    "median",
    "als",
    "edge",
    "valley",
    "arpls",
    "airpls",
    "asls",
    "snip",
    "masked_poly",
]

BaselineMethod2D #

BaselineMethod2D = Literal[
    "plane",
    "polynomial",
    "median",
    "als",
    "edge",
    "valley",
    "arpls",
    "airpls",
    "asls",
    "snip",
    "masked_poly",
]

ExcludedRegions #

ExcludedRegions = Sequence[tuple[float, float]]

ImaginaryBaselineMethod #

ImaginaryBaselineMethod = Literal[
    "auto", "same", "polynomial", "none"
]

AlignmentGeometry dataclass #

AlignmentGeometry(
    shared_f1: float,
    shared_f2: float,
    spread_f1: float,
    spread_f2: float,
    quality: float,
    resolution_f1_hz: float,
    resolution_f2_hz: float,
    n_vectors: int,
    reason: str,
)

The direction along which a plane's peaks line up, measured from the peaks.

Attributes:

Name Type Description
shared_f1 float

F1 coefficient of the shared coordinate, in Hz per Hz.

shared_f2 float

F2 coefficient of the shared coordinate, in Hz per Hz.

spread_f1 float

F1 component of the unit spread direction, in Hz per Hz.

spread_f2 float

F2 component of the unit spread direction, in Hz per Hz.

quality float

Concentration of the displacement directions, 0 to 1.

resolution_f1_hz float

Measured line width along F1, in Hz.

resolution_f2_hz float

Measured line width along F2, in Hz.

n_vectors int

Number of short displacement vectors the direction was read from.

reason str

Human-readable summary, for logs and for callers explaining a route.

shared_f1 instance-attribute #

shared_f1: float

shared_f2 instance-attribute #

shared_f2: float

spread_f1 instance-attribute #

spread_f1: float

spread_f2 instance-attribute #

spread_f2: float

quality instance-attribute #

quality: float

resolution_f1_hz instance-attribute #

resolution_f1_hz: float

resolution_f2_hz instance-attribute #

resolution_f2_hz: float

n_vectors instance-attribute #

n_vectors: int

reason instance-attribute #

reason: str

is_aligned property #

is_aligned: bool

Whether the peaks line up well enough for the direction to mean anything.

shear_slope property #

shear_slope: float | None

Slope s of the shear F2 + s*F1 that collapses the alignment, if any.

None when the shared coordinate does not involve F2 at all.

shared_resolution_hz property #

shared_resolution_hz: float

Line width projected onto the shared coordinate, in Hz.

spread_resolution_hz property #

spread_resolution_hz: float

Line width projected onto the spread direction, in Hz.

max_spread_spacing_hz property #

max_spread_spacing_hz: float

Widest spacing along the spread direction that still chains two lines.

shared_coordinate #

shared_coordinate(
    f1_hz: ndarray, f2_hz: ndarray
) -> ndarray

Shared coordinate of each point, in Hz.

spread_coordinate #

spread_coordinate(
    f1_hz: ndarray, f2_hz: ndarray
) -> ndarray

Position of each point along the spread direction, in Hz.

shears_the_plane #

shears_the_plane(
    f1_span_hz: float, f2_span_hz: float
) -> bool

Whether a shear along F2 is what collapses this alignment.

Parameters:

Name Type Description Default
f1_span_hz float

Width of the indirect axis, in Hz.

required
f2_span_hz float

Width of the direct axis, in Hz.

required

Returns:

Type Description
bool

False when the shear would move nothing or the alignment runs along

bool

the F2 axis; otherwise whether to shear.

JresDetection dataclass #

JresDetection(
    is_jres: bool,
    reason: str,
    f1_span_hz: float,
    f2_span_hz: float,
    slope: float | None = None,
    quality: float = 0.0,
)

Outcome of J-resolved detection on a 2D plane.

Attributes:

Name Type Description
is_jres bool

Whether the plane's multiplets lie on a line that a shear can collapse.

reason str

Human-readable justification, logged when processing is skipped.

f1_span_hz float

Indirect spectral width in Hz.

f2_span_hz float

Direct spectral width in Hz.

slope float | None

Measured shear slope in Hz of F2 per Hz of F1, or None when no shear applies.

quality float

How concentrated the measured alignment is, 0 to 1.

is_jres instance-attribute #

is_jres: bool

reason instance-attribute #

reason: str

f1_span_hz instance-attribute #

f1_span_hz: float

f2_span_hz instance-attribute #

f2_span_hz: float

slope class-attribute instance-attribute #

slope: float | None = None

quality class-attribute instance-attribute #

quality: float = 0.0

MultipletGroupsAnalysis dataclass #

MultipletGroupsAnalysis(
    groups: list[MultipletGroup] = list(),
    total_groups: int = 0,
    method: str = "structure",
    noise_level: float = 0.0,
    noise_multiplier: float = 3.0,
    inferred_peaks: list[PeakInfo] = list(),
    grouping: list[GroupingEvidence] = list(),
)

Result of multi-group multiplet analysis.

Attributes:

Name Type Description
groups list[MultipletGroup]

List of MultipletGroup objects, one per detected group.

total_groups int

Number of detected multiplet groups.

method str

Analysis method used ('structure', 'deconvolution', 'pascal').

noise_level float

Estimated noise standard deviation.

noise_multiplier float

The threshold multiplier used for detection.

inferred_peaks list[PeakInfo]

Lines no detector picked, concluded from a group's own intensities and confirmed against the trace. Empty unless infer_missing_lines was asked for. Each carries PeakOrigin.INFERRED, the height its pattern predicts, and no area; absent from every group's measured arrays.

grouping list[GroupingEvidence]

How firmly the data support each group, in groups order.

groups class-attribute instance-attribute #

groups: list[MultipletGroup] = field(default_factory=list)

total_groups class-attribute instance-attribute #

total_groups: int = 0

method class-attribute instance-attribute #

method: str = 'structure'

noise_level class-attribute instance-attribute #

noise_level: float = 0.0

noise_multiplier class-attribute instance-attribute #

noise_multiplier: float = 3.0

inferred_peaks class-attribute instance-attribute #

inferred_peaks: list[PeakInfo] = field(default_factory=list)

grouping class-attribute instance-attribute #

grouping: list[GroupingEvidence] = field(
    default_factory=list
)

ShiftIntegrationResult dataclass #

ShiftIntegrationResult(
    group_id: int,
    peaks: list[PeakInfo],
    area: float,
    normalized_area: float,
    bounds: tuple[float, float],
    center_ppm: float | None,
    center_hz: float | None,
    pattern: str | None,
    n_peaks: int,
)

Result of chemical shift (multiplet group) integration.

group_id instance-attribute #

group_id: int

peaks instance-attribute #

peaks: list[PeakInfo]

area instance-attribute #

area: float

normalized_area instance-attribute #

normalized_area: float

bounds instance-attribute #

bounds: tuple[float, float]

center_ppm instance-attribute #

center_ppm: float | None

center_hz instance-attribute #

center_hz: float | None

pattern instance-attribute #

pattern: str | None

n_peaks instance-attribute #

n_peaks: int

PeakInfo2D dataclass #

PeakInfo2D(
    index_f1: int,
    index_f2: int,
    frequency_f1: float,
    frequency_f2: float,
    height: float,
    volume: float | None = None,
    group_id: int | None = None,
    width_f1: float | None = None,
    width_f2: float | None = None,
    ridge_id: str | None = None,
    signed_height: float | None = None,
)

Information about a detected 2D peak.

index_f1 instance-attribute #

index_f1: int

index_f2 instance-attribute #

index_f2: int

frequency_f1 instance-attribute #

frequency_f1: float

frequency_f2 instance-attribute #

frequency_f2: float

height instance-attribute #

height: float

volume class-attribute instance-attribute #

volume: float | None = None

group_id class-attribute instance-attribute #

group_id: int | None = None

width_f1 class-attribute instance-attribute #

width_f1: float | None = None

width_f2 class-attribute instance-attribute #

width_f2: float | None = None

ridge_id class-attribute instance-attribute #

ridge_id: str | None = None

signed_height class-attribute instance-attribute #

signed_height: float | None = None

PlaneNoiseEstimate dataclass #

PlaneNoiseEstimate(
    detection: tuple[float, float], grouping_sigma: float
)

A magnitude plane's noise, measured in one pass for detection and grouping.

detection is the (level, sigma) find_peaks(noise=...) takes on |z|; grouping_sigma is the sigma group_peaks and infer_multiplets take.

detection instance-attribute #

detection: tuple[float, float]

grouping_sigma instance-attribute #

grouping_sigma: float

OrientationCues dataclass #

OrientationCues(
    reference: tuple[SignedLine, ...] = (),
    solvent: tuple[SignedLine, ...] = (),
    structure: Callable[[], Sequence[SignedLine]]
    | None = None,
    structure_window_ppm: float = 0.0,
)

What a mixed-polarity spectrum's half turn may be read from, strongest first.

Attributes:

Name Type Description
reference tuple[SignedLine, ...]

The declared internal reference compound's line(s).

solvent tuple[SignedLine, ...]

The solvent table's line(s) for the sample's solvent.

structure Callable[[], Sequence[SignedLine]] | None

The lines the sample's structure predicts, asked for only when no anchor stands.

structure_window_ppm float

How far a predicted line may sit from an observed one and still be it.

reference class-attribute instance-attribute #

reference: tuple[SignedLine, ...] = ()

solvent class-attribute instance-attribute #

solvent: tuple[SignedLine, ...] = ()

structure class-attribute instance-attribute #

structure: Callable[[], Sequence[SignedLine]] | None = None

structure_window_ppm class-attribute instance-attribute #

structure_window_ppm: float = 0.0

PhaseRamp #

A phase along one axis of a spectrum, in degrees.

phi(u) = p0 + p1 * (u - pivot) + p2 * (u - pivot)**2 with u = index / n along the axis in array order, applied as a multiplication by exp(+i * phi) -- the 1D ps2 convention.

Attributes:

Name Type Description
p0 float

Phase at the pivot.

p1 float

First-order phase across the whole axis.

p2 float

Second-order phase across the whole axis.

pivot float

The pivot as a fraction of the axis (0 = first point), so p0 changes nothing but the pivot's own phase while p1 is dragged.

p0 class-attribute instance-attribute #

p0: float = 0.0

p1 class-attribute instance-attribute #

p1: float = 0.0

p2 class-attribute instance-attribute #

p2: float = 0.0

pivot class-attribute instance-attribute #

pivot: float = 0.0

at_first_point #

at_first_point() -> tuple[float, float, float]

The same phase as (p0, p1, p2) measured from the first point, which ps2 takes.

from_topspin_direct classmethod #

from_topspin_direct(phc0: float, phc1: float) -> PhaseRamp

The ramp TopSpin's PHC0/PHC1 of a direct dimension mean on this engine's axis.

TopSpin counts PHC1 from the left (high-frequency) edge and rotates the other way, so phi(u) = -(PHC0 + PHC1 * (1 - u)) on this engine's ascending axis.

SignedLine #

A line the experiment shows on a known side: sign +1 up, -1 down.

ppm instance-attribute #

ppm: float

sign instance-attribute #

sign: int

Axis #

Axis = Literal['f2', 'f1', 'both']

RegionMixin2D #

Mixin giving Spectrum2D the region operations Spectrum1D has, along each axis.

f1 instance-attribute #

f2 instance-attribute #

f1_unit instance-attribute #

f1_unit: FrequencyUnit

f2_unit instance-attribute #

f2_unit: FrequencyUnit

f1_reference_frequency_hz instance-attribute #

f1_reference_frequency_hz: float | None

f2_reference_frequency_hz instance-attribute #

f2_reference_frequency_hz: float | None

nucleus_f1 instance-attribute #

nucleus_f1: Nucleus

nucleus_f2 instance-attribute #

nucleus_f2: Nucleus

amplitudes instance-attribute #

amplitudes: ndarray

f2_imaginary instance-attribute #

f2_imaginary: ndarray | None

suppress_region #

suppress_region(
    center: float,
    width: float,
    method: SuppressionMethod = SUPPRESS_INTERPOLATE,
    axis: Axis = "f2",
    center_f1: float | None = None,
    width_f1: float | None = None,
) -> Self

Suppress a band of every row (F2), of every column (F1), or both, in place.

Each row or column is treated exactly as Spectrum1D.suppress_region treats a 1D spectrum.

Parameters:

Name Type Description Default
center float

Centre of the F2 band, in the F2 axis unit.

required
width float

Full width of the F2 band, in the F2 axis unit.

required
method SuppressionMethod

Zero, interpolate across the edges, or fill with a fitted polynomial.

SUPPRESS_INTERPOLATE
axis Axis

Which band to suppress.

'f2'
center_f1 float | None

Centre of the F1 band, in the F1 axis unit; required for f1 and both.

None
width_f1 float | None

Full width of the F1 band; required for f1 and both.

None

Returns:

Type Description
Self

Self for method chaining.

Raises:

Type Description
ProcessingParameterError

When an F1 band is asked for without its centre and width.

ValueError

When a band lies outside its axis.

suppress_diagonal #

suppress_diagonal(
    width: float,
    method: SuppressionMethod = SUPPRESS_INTERPOLATE,
) -> Self

Suppress the band along the F1 = F2 diagonal of a homonuclear plane, in place.

Parameters:

Name Type Description Default
width float

Full width of the band about the diagonal, in the axis unit.

required
method SuppressionMethod

How the band is filled, as for suppress_region.

SUPPRESS_INTERPOLATE

Returns:

Type Description
Self

Self for method chaining.

Raises:

Type Description
ProcessingParameterError

On a heteronuclear plane, one with unknown nuclei, or axes in different units.

reference_to_ppm #

reference_to_ppm(
    target_f2_ppm: float | None,
    target_f1_ppm: float | None = None,
    search_window_f2_ppm: float = 0.5,
    search_window_f1_ppm: float = 0.5,
) -> Self

Shift the axes so the tallest peak near a target lies on it.

The peak is the largest magnitude inside the box of the two search windows about the target. An axis with no target is left alone; at least one target is needed.

Parameters:

Name Type Description Default
target_f2_ppm float | None

Where the peak should lie on F2, or None to shift F1 only.

required
target_f1_ppm float | None

Where it should lie on F1, or None to shift F2 only.

None
search_window_f2_ppm float

Half-width of the box on F2.

0.5
search_window_f1_ppm float

Half-width of the box on F1.

0.5

Returns:

Type Description
Self

Self with shifted axes.

Raises:

Type Description
ValueError

When no target is given, the box holds no data, or an axis cannot be put in ppm.

align_by_correlation #

align_by_correlation(reference: RegionMixin2D) -> Self

Align to a reference plane by the lag that maximises the correlation of the magnitudes.

Parameters:

Name Type Description Default
reference RegionMixin2D

Plane on the same grid, which is not modified.

required

Returns:

Type Description
Self

Self with shifted axes.

Raises:

Type Description
ValueError

When the planes differ in shape.

ComplexArray #

ComplexArray = ComplexNdArray | list[complex]

ComplexNdArray #

ComplexNdArray = NDArray[complexfloating]

FloatArray #

FloatArray = FloatNdArray | list[float]

FloatNdArray #

FloatNdArray = NDArray[floating]

NumericArray #

NumericArray = (
    FloatArray | ComplexArray | NumericNdArray | ndarray
)

NumericNdArray #

NumericNdArray = FloatNdArray | ComplexNdArray