SPECTRA Module

All the classes in the Spectra module are automatically imported together with KLASSEZ itself. Refer to the examples reported in the USER GUIDE section to understand how to use them, or read the documentation of the single methods to get detailed info on how they exactly work.

class klassez.Spectra.DOSY(*args, **kws)[source]

Bases: Pseudo_2D

Class: DOSY spectrum

It has the same structure of a klassez.Spectra.Pseudo_2D, with added functionalities and dedicated fitting.

Attributes:
Dfit.DosyFit object

Fitting object created when integrals are read or instanced.

.. seealso::

klassez.fit.DosyFit

Methods

abs([n, lims, alpha, qfil, qfilp])

Correct the baseline automatically on the real part of the spectrum, then retrieve the imaginary part through Hilbert transform.

abs_v2([n, lims, alpha, winsize, qfil, qfilp])

Correct the baseline automatically on the real part of the spectrum, then retrieve the imaginary part through Hilbert transform.

add_noise([s_n])

Adds noise to the FID, using the function klassez.sim.noisegen().

adjph([expno, p0, p1, pv, update])

Adjusts the phases of the spectrum according to the given parameters, or interactively if they are left as default.

align([lims, u_off, ref_idx])

Aligns the spectrum to a reference signal in the reference spectrum (default: first one).

basl([from_procs, phase])

Apply baseline correction to the whole pseudo-2D by subtracting self.baseline from self.S.

cal([offset, isHz, update, from_procs, ref])

Calibration of the ppm and frequency scales according to a given value, or interactively.

calf1([value, isHz, update, from_procs, ref])

Calibrates the ppm and frequency scale of the indirect dimension according to a given value, or interactively.

calf2([value, isHz, update, from_procs, ref])

Calibrates the ppm and frequency scale of the direct dimension according to a given value, or interactively.

convdta([scaling])

Calls processing.convdta

diffplot([what, xlims, filename, ext, dpi, dim])

Makes a plot of the diffusion coefficients, with error bars, as a function of the integrated regions.

eae()

Calls klassez.processing.eae() to shuffle the data and make a States-like FID.

integrate(*args, **kws)

Performs the same integration procedure of the parent class, which sets the self.integrals attribute.

inv_process()

Performs the inverse processing of the spectrum according to the given parameters.

mc()

Computes the magnitude of the spectrum on self.S.

mount([fids, filename, newacqus])

Replaces the FID of the experiment with a custom one, made by stacking 1D experiments.

pknl()

Reverses the effect of the digital filter by applying a first order phase correction.

plot([fqscale, Neg, lvl0, Y_label, name])

Plots the real part of the spectrum (self.rr).

plot_md([which, lims])

Plot a number of experiments, superimposed.

plot_stacked([which, lims])

Plot a number of experiments, stacked.

process()

Process the data as in a normal klassez.Spectra.Pseudo_2D object.

projf1(a[, b])

Calculates the sum trace of the indirect dimension, from a ppm to b ppm in F2.

projf2(a[, b])

Calculates the sum trace of the direct dimension, from a ppm to b ppm in F1.

qfil([which, u, s, from_procs, fqscale])

Gaussian filter to suppress signals.

read_integrals(*args, **kws)

Reads a .igrl file as well as its father class, which sets the self.integrals attribute.

read_procs([other_dir])

Reads the procs dictionary from a file named "filename.procs" in the same directory of the input file.

rpbc([ref_exp])

Computes the phase angles and the baseline using klassez.processing.rpbc() on self.S.

scan([ns, s_n])

Simulates the acquisition of ns scans, by adding a different realization of noise at each iteration.

splitcomb([J])

Applies the IPAP virtual decoupling scheme by calling klassez.processing.splitcomb`() with appropriate parameters.

strip([xlim])

Perform the strip transform in F2 with xlim.

to_wav([filename, cutoff, rate])

Converts the FID in an audio file by using klasse.misc.data2wav().

write_acqus([other_dir])

Write the acqus dictionary in a file named "filename.acqus".

write_integrals([other_dir])

Write the integrals in a file named {self.filename}.igrl.

write_pdata([path, procno])

Writes a real/complex array in binary format in <path>/pdata/<procno>.

write_procs([other_dir])

Writes the actual procs dictionary in a file named "filename.procs" in the same directory of the input file.

write_ser(ser, acqus[, path, filename])

Writes a real/complex array in binary format.

xf1()

Process only the indirect dimension.

xf2()

Process only the direct dimension.

__init__(*args, **kws)[source]

Initialize the class as it is a normal klassez.Spectra.Pseudo_2D object. Then, reads the difflist file and stores it in the self.difflist attribute.

diffplot(what='result', xlims=None, filename=None, ext='svg', dpi=300, dim=None)[source]

Makes a plot of the diffusion coefficients, with error bars, as a function of the integrated regions.

Parameters:
whatstr

'iguess' or 'result'

xlimssequence of float or False or None

Limits for the chemical shift axis. If False, the whole spectrum is plotted. If None, a restricted portion of the spectrum which includes all the fitted regions is shown instead

filenamestr or None

Filename for the figure to save. If None, the plot is shown instead

extstr

Format for the figure to save

dpiint

Resolution of the figure in dots per inches

dimtuple of int

Dimension of the figure in inches

Returns:
None
integrate(*args, **kws)[source]

Performs the same integration procedure of the parent class, which sets the self.integrals attribute. Then, uses it to either create or update the self.D DosyFit object.

process()[source]

Process the data as in a normal klassez.Spectra.Pseudo_2D object. Then, replaces self.ppm_f1 with the self.difflist.

read_integrals(*args, **kws)[source]

Reads a .igrl file as well as its father class, which sets the self.integrals attribute. Then, uses it to either create or update the self.D klassez.fit.DosyFit object.

class klassez.Spectra.DOSY_T1(in_file)[source]

Bases: object

Class: 3D DOSY spectrum

It should be acquired with the sequence described in Novakovic M. et al. (2025), Nature Communications, 16(1), 4628, Supporting Information, Figure 12a. This sequence, adapted in the pulse program stebpgp1s193D.rav, evolves the big delta (d20) in dimension F2 and the gradient strength according to the difflist in dimension F1. This sequence is actually equivalent to acquiring separate DOSY with different d20.

Attributes:
datadirstr

Path to the input file/dataset directory

filenamestr

Base of the name of the file, without extensions

fid3darray

FID

acqusdict

Dictionary of acqusition parameters

ngdicdict

Created only if it is an experimental spectrum. Generated by nmrglue.<spectrometer>.read(), contains all the information on the spectrometer and on the spectrum.

procsdict

Dictionary of processing parameters

S3darray

Complex (or hypercomplex, depending on FnMODE) spectrum

x_f11darray

gradient list

x_f21darray

big delta list

freq_f21darray

Frequency scale of the direct dimension, in Hz

ppm_f21darray

ppm scale of the direct dimension

Methods

adjph([fromplane, expno, dim, p0, p1, pv, ...])

Adjusts the phases of the spectrum according to the given parameters, or interactively if they are left as default.

getplane(idx[, dim])

Extract from self.S the idx-th plane (python numbering) on the direction dim.

integrate([filename])

Create the attribute self.D as klassez.fit.DosyFit_pp3D, and integrate the planes along the 31 direction.

pknl()

Reverses the effect of the digital filter by applying a first order phase correction.

plot([dim, fqscale, Neg, lvl0, name])

Plots the real part of the spectrum as a 2D contour plot.

process()

Process only the direct dimension.

read_procs([other_dir])

Reads the procs dictionary from a file named filename.procs in the same directory of the input file.

write_procs([other_dir])

Writes the actual procs dictionary in a file named "filename.procs" in the same directory of the input file.

__init__(in_file)[source]

Initialize the class.

Parameters:
in_filestr

path to file to read, or to the folder of the spectrum

adjph(fromplane=0, expno=0, dim='31', p0=None, p1=None, pv=None, update=True)[source]

Adjusts the phases of the spectrum according to the given parameters, or interactively if they are left as default.

Parameters:
fromplaneint

Index of the plane to use in the dim direction

expno: int

Index of the experiment (python numbering) of the extracted plane to use in the interactive panel

dimstr

If '31', the directive fromplane is relative to the F3-F1 direction. If '32', the directive fromplane is relative to the F3-F2 direction.

p0: float or None

0-th order phase correction /°

p1: float or None

1-st order phase correction /°

pv: float or None

1-st order pivot /ppm

update: bool

Choose if to upload the procs dictionary or not

.. seealso::

klassez.processing.ps()

klassez.gui.interactive_phase_1D()

getplane(idx, dim='31')[source]

Extract from self.S the idx-th plane (python numbering) on the direction dim. Keeps a reference to it as the attribute self._active.

Parameters:
idxint

Index of the plane to extract

dimstr

'31' = plane F3-F1; '32' = plane F3-F2

Returns:
activepDOSY object

Extracted plane as klassez.Spectra.pDOSY object

integrate(filename=None)[source]

Create the attribute self.D as klassez.fit.DosyFit_pp3D, and integrate the planes along the 31 direction.

Parameters:
filenamestr or None

Custom filename for data and plots. If None, self.filename is used.

Returns:
None
pknl()[source]

Reverses the effect of the digital filter by applying a first order phase correction. To be called after having processed the data by self.process().

plot(dim='31', fqscale=False, Neg=True, lvl0=0.2, name=None)[source]

Plots the real part of the spectrum as a 2D contour plot. You can scroll between the various planes inside the interactive panel.

Parameters:
dimstr

'31' = plane F3-F1; '32' = plane F3-F2

fqscalebool

Display using frequency scale instead of ppm

Negbool

Plot (True) or not (False) the negative contours.

lvl0float

Starting contour value.

namestr

Custom name for the figure. If None, self.filename is used.

process()[source]

Process only the direct dimension. Calls klassez.processing.fp() on each transient. The parameters are read from the procs dictionary.

read_procs(other_dir=None)[source]

Reads the procs dictionary from a file named filename.procs in the same directory of the input file.

Parameters:
other_dirstr or None

Different location for the procs dictionary to look into. If None, self.datadir is used instead.

Warning

Do not put the trailing slash!

Returns:
procs: dict

Dictionary of processing parameters

write_procs(other_dir=None)[source]

Writes the actual procs dictionary in a file named "filename.procs" in the same directory of the input file.

Parameters:
other_dir: str or None

Different location for the procs dictionary to write into. If None, self.datadir is used instead.

Warning

Do not put the trailing slash!

class klassez.Spectra.Pseudo_2D(in_file, pv=False, isexp=True)[source]

Bases: Spectrum_2D

Subclass of klassez.Spectra.Spectrum_2D to simulate and handle pseudo-2D experiments. Basically, they share more or less the same attributes, but some methods were adapted in order to suit well with a not-Fourier-transformed indirect dimension.

Attributes:
datadir: str

Path to the input file/dataset directory

filename: str

Base of the name of the file, without extensions

fid: 2darray

FID. For simulated data, this must be explicitely set!

acqus: dict

Dictionary of acqusition parameters

ngdic: dict

Created only if it is an experimental spectrum. Generated by nmrglue.bruker.read(), contains all the information on the spectrometer and on the spectrum.

procs: dict

Dictionary of processing parameters

S: 2darray

Complex spectrum

rr: 2darray

Real part F2, real part F1

ii: 2darray

Imaginary part F2, imaginary part F1

freq_f1: 1darray

Indeces of the experiments, works as placeholder

freq_f2: 1darray

Frequency scale of the direct dimension, in Hz

ppm_f1: 1darray

Indeces of the experiments, works as placeholder

ppm_f2: 1darray

ppm scale of the direct dimension

trf1: dict

Projections of the indirect dimension, as 1darrays . Keys: 'ppm_f2' where they were taken

trf2: dict

Projections of the direct dimension, as 1darrays . Keys: 'ppm_f1' where they were taken

Trf1: dict

Projections of the indirect dimension, as pSpectrum_1D objects. Keys: ‘ppm_f2’ where they were taken

Trf2: dict

Projections of the direct dimension, as pSpectrum_1D objects. Keys: ‘ppm_f1’ where they were taken

integrals: dict

Dictionary where to save the regions and values of the integrals.

F: fit.Voigt_Fit_P2D object

Interface for lineshape deconvolution.

Methods

abs([n, lims, alpha, qfil, qfilp])

Correct the baseline automatically on the real part of the spectrum, then retrieve the imaginary part through Hilbert transform.

abs_v2([n, lims, alpha, winsize, qfil, qfilp])

Correct the baseline automatically on the real part of the spectrum, then retrieve the imaginary part through Hilbert transform.

add_noise([s_n])

Adds noise to the FID, using the function klassez.sim.noisegen().

adjph([expno, p0, p1, pv, update])

Adjusts the phases of the spectrum according to the given parameters, or interactively if they are left as default.

align([lims, u_off, ref_idx])

Aligns the spectrum to a reference signal in the reference spectrum (default: first one).

basl([from_procs, phase])

Apply baseline correction to the whole pseudo-2D by subtracting self.baseline from self.S.

cal([offset, isHz, update, from_procs, ref])

Calibration of the ppm and frequency scales according to a given value, or interactively.

calf1([value, isHz, update, from_procs, ref])

Calibrates the ppm and frequency scale of the indirect dimension according to a given value, or interactively.

calf2([value, isHz, update, from_procs, ref])

Calibrates the ppm and frequency scale of the direct dimension according to a given value, or interactively.

convdta([scaling])

Calls processing.convdta

eae()

Calls klassez.processing.eae() to shuffle the data and make a States-like FID.

integrate([ref, filename, lims, use_bas])

Integrate the spectrum with a dedicated GUI.

inv_process()

Performs the inverse processing of the spectrum according to the given parameters.

mc()

Computes the magnitude of the spectrum on self.S.

mount([fids, filename, newacqus])

Replaces the FID of the experiment with a custom one, made by stacking 1D experiments.

pknl()

Reverses the effect of the digital filter by applying a first order phase correction.

plot([fqscale, Neg, lvl0, Y_label, name])

Plots the real part of the spectrum (self.rr).

plot_md([which, lims])

Plot a number of experiments, superimposed.

plot_stacked([which, lims])

Plot a number of experiments, stacked.

process()

Process only the direct dimension.

projf1(a[, b])

Calculates the sum trace of the indirect dimension, from a ppm to b ppm in F2.

projf2(a[, b])

Calculates the sum trace of the direct dimension, from a ppm to b ppm in F1.

qfil([which, u, s, from_procs, fqscale])

Gaussian filter to suppress signals.

read_integrals(filename[, n])

Reads the integrals in the .igrl file named filename, and stores the result in self.integrals

read_procs([other_dir])

Reads the procs dictionary from a file named "filename.procs" in the same directory of the input file.

rpbc([ref_exp])

Computes the phase angles and the baseline using klassez.processing.rpbc() on self.S.

scan([ns, s_n])

Simulates the acquisition of ns scans, by adding a different realization of noise at each iteration.

splitcomb([J])

Applies the IPAP virtual decoupling scheme by calling klassez.processing.splitcomb`() with appropriate parameters.

strip([xlim])

Perform the strip transform in F2 with xlim.

to_wav([filename, cutoff, rate])

Converts the FID in an audio file by using klasse.misc.data2wav().

write_acqus([other_dir])

Write the acqus dictionary in a file named "filename.acqus".

write_integrals([other_dir])

Write the integrals in a file named {self.filename}.igrl.

write_pdata([path, procno])

Writes a real/complex array in binary format in <path>/pdata/<procno>.

write_procs([other_dir])

Writes the actual procs dictionary in a file named "filename.procs" in the same directory of the input file.

write_ser(ser, acqus[, path, filename])

Writes a real/complex array in binary format.

xf1()

Process only the indirect dimension.

xf2()

Process only the direct dimension.

property S: ndarray[source]

Normal getter for self.S attribute

__init__(in_file, pv=False, isexp=True)[source]

Initialize the class.

Parameters:
in_filestr

path to file to read, or to the folder of the spectrum

pvbool

True if you want to use pseudo-voigt lineshapes for simulation, False for Voigt

isexpbool

True if this is an experimental dataset, False if it is simulated

abs(n=5, lims=None, alpha=2.75, qfil=False, qfilp={'s': 10, 'u': 4.7})[source]

Correct the baseline automatically on the real part of the spectrum, then retrieve the imaginary part through Hilbert transform.

Parameters:
nint

Number of coefficients of the polynomial baseline

limstuple or None

Limits for the region on which to compute the baseline, in ppm

alphafloat

The threshold will be set as thr = alpha * np.std(np.gradient(data))

qfilbool

Choose whether to apply a filter on the solvent region (True) or not (False)

qfilpdict

Parameters to be used to compute the filter if qfil=True. Keys:

  • ‘u’ = center of the filter in ppm

  • ‘s’ = width of the filter in Hz

Returns:
baseline1darray

Employed baseline for correction

abs_v2(n=5, lims=None, alpha=5, winsize=2, qfil=False, qfilp={'s': 10, 'u': 4.7})[source]

Correct the baseline automatically on the real part of the spectrum, then retrieve the imaginary part through Hilbert transform.

Parameters:
nint

Number of coefficients of the polynomial baseline

limstuple or None

Limits for the region on which to compute the baseline, in ppm

alphafloat

The threshold will be set as thr = alpha * np.std(np.gradient(data))

qfilbool

Choose whether to apply a filter on the solvent region (True) or not (False)

qfilpdict

Parameters to be used to compute the filter if qfil=True. Keys: * ‘u’ = center of the filter in ppm * ‘s’ = width of the filter in Hz

Returns:
baseline1darray

Employed baseline for correction

add_noise(s_n=1)[source]

Adds noise to the FID, using the function klassez.sim.noisegen().

Parameters:
s_nfloat

Standard deviation of the noise

Returns:
None
adjph(expno=0, p0=None, p1=None, pv=None, update=True)[source]

Adjusts the phases of the spectrum according to the given parameters, or interactively if they are left as default.

Parameters:
expno: int

Index of the experiment (python numbering) to use in the interactive panel

p0: float or None

0-th order phase correction /°

p1: float or None

1-st order phase correction /°

pv: float or None

1-st order pivot /ppm

update: bool

Choose if to upload the procs dictionary or not

Returns:
None
align(lims=None, u_off=0.5, ref_idx=0)[source]

Aligns the spectrum to a reference signal in the reference spectrum (default: first one).

Parameters:
lims: tuple or None

Reference signal region, in ppm. If None, you can select it interactively.

u_off: float

Maximum displacement allowed, in ppm

ref_idx: int

Index of the spectrum to be used as a reference (python numbering)

Returns:
None
basl(from_procs=False, phase=True)[source]

Apply baseline correction to the whole pseudo-2D by subtracting self.baseline from self.S. Then, self.S is unpacked in self.rr and self.ii.

Parameters:
from_procsbool

If True, computes the baseline using the polynomion model reading self.procs['basl_c'] as coefficients

phasebool

Choose if to apply the same phase correction of the spectrum to the baseline. This should be done if the baseline was computed before the phase adjustment!

cal(offset=None, isHz=False, update=True, from_procs=True, *, ref=None)[source]

Calibration of the ppm and frequency scales according to a given value, or interactively. In this latter case, a reference peak must be chosen.

Parameters:
offsetfloat

scale shift F2

isHztuple of bool

True if offset is in frequency units, False if offset is in ppm

updatebool

Choose if to update the procs dictionary or not

from_procsbool

Read the parameters from the procs dictionary

reflist of 1darray

Reference ppm scale and spectrum to be used as reference for calibration [ppm, spectrum]

Returns:
None

See also

klassez.processing.calibrate()

convdta(scaling=1)[source]

Calls processing.convdta

integrate(ref=0, filename=None, lims=None, use_bas=False)[source]

Integrate the spectrum with a dedicated GUI. Calls klassez.anal.integrate_p2D() and writes in self.integrals with keys [ppm1:ppm2] The values are saved in <filename>.igrl.

Parameters:
refint

Index of the transient to be used as reference for the integration.

filenamestr

The integral values will be saved in <filename>.igrl. If None, <self.filename> will be used instead.

Returns:
None
mount(fids=[], filename=None, newacqus=None)[source]

Replaces the FID of the experiment with a custom one, made by stacking 1D experiments. If the default filename exists (i.e. ‘<self.filename>.npy’), the function loads it, otherwise calls klassez.processing.stack_fids() to create it. The fid attribute is overwritten. The key ‘TD1’ of the acqus dictionary is updated to match the first dimension of the new FID.

Parameters:
fidssequence of 1darray or Spectrum_1D objects

FIDs to be stacked. It can be empty if the .npy file already exists.

filenamestr or None

Path to the filename, without the .npy extension. If it is None, the default filename is used.

newacqusdict

New acqus dictionary that replaces the actual one. If it is not a dictionary, no actions are performed.

Returns:
None
pknl()[source]

Reverses the effect of the digital filter by applying a first order phase correction. To be called after having processed the data by self.process().

plot(fqscale=False, Neg=True, lvl0=0.2, Y_label='', name=None)[source]

Plots the real part of the spectrum (self.rr). Use the mouse scroll to adjust the contour starting level.

Parameters:
fqscalebool

Display using frequency scale instead of ppm

Negbool

Plot (True) or not (False) the negative contours.

lvl0float

Starting contour value with respect to the maximum of the spectrum

Y_labelstr

Custom label for the y axis

namestr

Name of the figure. If None, self.filename is used.

plot_md(which=None, lims=None)[source]

Plot a number of experiments, superimposed.

Parameters:
whichstr or None

List of experiment indexes, so that eval(which) is meaningful. None plots all of them

limstuple

Region of the spectrum to show (ppm1, ppm2)

plot_stacked(which=None, lims=None)[source]

Plot a number of experiments, stacked.

Parameters:
whichstr or None

List of experiment indexes, so that eval(which) is meaningful. None plots all of them.

limstuple

Region of the spectrum to show (ppm1, ppm2)

process()[source]

Process only the direct dimension. Calls klassez.processing.fp() on each transient. The parameters are read from the procs dictionary.

projf1(a, b=None)[source]

Calculates the sum trace of the indirect dimension, from a ppm to b ppm in F2. Store the trace in the dictionary self.trf1 and as pSpectrum_1D in self.Trf1. The key is 'a' or 'a:b' with two decimal figures.

Calls klassez.anal.get_trace() on self.rr with column=True

Parameters:
afloat

ppm F2 value where to extract the trace.

bfloat or None.

If it is None, extract the trace in a. Else, sum from a to b in F2.

Returns:
None
projf2(a, b=None)[source]

Calculates the sum trace of the direct dimension, from a ppm to b ppm in F1. Store the trace in the dictionary self.trf2 and as pSpectrum_1D in self.Trf2. The key is 'a' or 'a:b' with two decimal figures.

Calls klassez.anal.get_trace() on self.rr with column=False

Parameters:
afloat

ppm F1 value where to extract the trace.

bfloat or None.

If it is None, extract the trace in a. Else, sum from a to b in F1.

Returns:
None
qfil(which=None, u=None, s=None, from_procs=True, fqscale=False)[source]

Gaussian filter to suppress signals. Tries to read self.procs['qfil'], which is { 'u': u, 's': s } Otherwise, these are set interactively by klassez.gui.interactive_qfil() and then added to self.procs.

Parameters:
whichint or None

Index of the F2 trace to be used for klassez.gui.interactive_qfil(). If None, a suitable trace can be selected using klassez.anal.select_traces().

ufloat

Position /ppm

sfloat

Width (standard deviation) /Hz

from_procsbool

Tries to read the values from self.procs

fqscalebool

True to use the frequency scale, False for the ppm scale.

Returns:
None
read_integrals(filename, n=-1)[source]

Reads the integrals in the .igrl file named filename, and stores the result in self.integrals

Parameters:
filenamestr

Path to the filename to be read

nint

Number of performed integrating procedure to be read. Default: last one. The breakpoints are lines that start with “!”. For this reason, n=0 returns an empty dictionary, hence the first attempt is n=1.

Returns:
None
rpbc(ref_exp=0, **rpbc_kws)[source]

Computes the phase angles and the baseline using klassez.processing.rpbc() on self.S. Then applies the phase correction and subtracts the baseline, automatically, to all experiments of the pseudo-2D. The procs dictionary is then updated and saved. The polynomial baseline is computed according to the given coefficients and stored in self.baseline

Parameters:
ref_exp: int

Index of the reference experiment on which to apply the algorithm

rpbc_kwskeyworded arguments

See klassez.processing.rpbc() for details.

Returns:
None
scan(ns=1, s_n=1)[source]

Simulates the acquisition of ns scans, by adding a different realization of noise at each iteration. The function is supposed to start with the FID without noise at all. If not, the results will be biased. For reproducible results, fix the seed!

Parameters:
nsint

Number of scans to accumulate

s_nfloat

Standard deviation of the noise for each scan

Returns:
None
strip(xlim=None)[source]

Perform the strip transform in F2 with xlim. The frequency and ppm scales are updated as well. The pivot for phase correction is moved to the center of the new scale. The imaginary parts are reconstructed via Hilbert transform.

Parameters:
xlimtuple or None

Limits in F2 in ppm

Returns:
None
to_wav(filename=None, cutoff=None, rate=44100)[source]

Converts the FID in an audio file by using klasse.misc.data2wav().

Parameters:
filenamestr

Path where to save the file. If None, self.filename is used

cutofffloat

Clipping limits for the FID

rateint

Sampling rate in samples/sec

Returns:
None
write_integrals(other_dir=None)[source]

Write the integrals in a file named {self.filename}.igrl. The default path is self.datadir.

Parameters:
other_dirstr or None

Different location for the integrals file to write into. If None, self.datadir is used instead.

Returns:
None
class klassez.Spectra.Spectrum_1D(in_file, pv=False, isexp=True, spect='bruker')[source]

Bases: object

Class: 1D NMR spectrum

Attributes:
datadirstr

Path to the input file/dataset directory

filenamestr

Base of the name of the file, without extensions

fid1darray

FID

acqusdict

Dictionary of acqusition parameters

ngdicdict

Created only if it is an experimental spectrum. Generated by nmrglue, contains all the information on the spectrometer and on the spectrum.

procsdict

Dictionary of processing parameters

S1darray

Normal getter for self.S attribute

r1darray

Real part of the spectrum

i1darray

Imaginary part of the spectrum

freq1darray

Frequency scale of the spectrum, in Hz

ppm1darray

ppm scale of the spectrum

Ffit.Voigt_Fit object

Used for deconvolution. See klassez.fit.Voigt_fit

baseline1darray

Baseline of the spectrum.

integralsdict

Dictionary where to save the regions and values of the integrals.

Methods

abs([n, lims, alpha, qfil, qfilp])

Correct the baseline automatically on the real part of the spectrum, then retrieve the imaginary part through Hilbert transform.

abs_v2([n, lims, alpha, winsize, qfil, qfilp])

Correct the baseline automatically on the real part of the spectrum, then retrieve the imaginary part through Hilbert transform.

acme(**method_kws)

Automatic phase correction based on entropy minimization.

add_noise([s_n])

Adds noise to the FID, using the function klassez.sim.noisegen().

adjph([p0, p1, pv, update, reference])

Adjusts the phases of the spectrum according to the given parameters, or interactively if they are left as default.

apk([alpha, winsize, ap1, seethrough, update])

Automatic phase correction with klassez.processing.apk().

basl([from_procs, phase])

Apply the baseline correction by subtracting self.baseline from self.S.

blp([pred, order])

Call klassez.processing.blp() on self.fid for the application of backward linear prediction to the data.

cal([offset, isHz, update, from_procs, ref])

Calibrates the ppm and frequency scale according to a given value, or interactively.

convdta([scaling])

Call klassez.processing.convdta() using self.acqus['GRPDLY']

integrate([filename, lims, use_bas])

Integrate the spectrum with a dedicated GUI.

inv_process()

Performs the inverse processing of the spectrum according to the given parameters.

mc()

Calculates the magnitude of the spectrum and overwrites self.S, self.r, self.i

pknl()

Reverses the effect of the digital filter by applying a first order phase correction.

plot([fqscale, name])

Plots the real part of the spectrum in an interactive panel for inspection.

process([interactive])

Performs the processing of the FID.

qfil([u, s, from_procs, fqscale])

Gaussian filter to suppress signals.

read_integrals(filename[, n])

Reads the integrals in the .igrl file named filename, and stores the result in self.integrals

read_procs([other_dir])

Reads the procs dictionary from a file named filename.procs in the same directory of the input file.

rpbc(**rpbc_kws)

Computes the phase angles and the baseline using klassez.processing.rpbc() on self.S.

scan([ns, s_n])

Simulates the acquisition of ns scans, by adding a different realization of noise at each iteration.

to_vf([filename, Hs, fvf])

Transform a simulated spectrum in a .ivf or .fvf file to be used in a deconvolution procedure.

to_wav([filename, cutoff, rate])

Converts the FID in an audio file by using klasse.misc.data2wav().

write_acqus([other_dir])

Write the acqus dictionary in a file named <self.filename>.acqus.

write_integrals([other_dir])

Write the integrals in a file named {self.filename}.igrl.

write_procs([other_dir])

Writes the actual procs dictionary in a file named filename.procs in the same directory of the input file.

write_ser(ser, acqus[, path, filename])

Writes a real/complex array in binary format.

Returns:
None
property S: ndarray[source]

Normal getter for self.S attribute

__init__(in_file, pv=False, isexp=True, spect='bruker')[source]

Initialize the class. Simulation of the dataset (i.e. isexp=False) employs klasez.sim.sim_1D().

Parameters:
in_filestr or dict

path to file to read, or to the folder of the spectrum, or a dictionary of acquisition parameters

pvbool

True if you want to use pseudo-voigt lineshapes for simulation, False for Voigt

isexpbool

True if this is an experimental dataset, False if it is simulated

spectstr

Data file format. Allowed: 'bruker', 'varian', 'magritek', 'oxford', 'jeol'

Returns:
None
abs(n=5, lims=None, alpha=2.75, qfil=False, qfilp={'s': 10, 'u': 4.7})[source]

Correct the baseline automatically on the real part of the spectrum, then retrieve the imaginary part through Hilbert transform.

Parameters:
nint

Number of coefficients of the polynomial baseline

limstuple or None

Limits for the region on which to compute the baseline, in ppm

alphafloat

The threshold will be set as thr = alpha * np.std(np.gradient(data))

qfilbool

Choose whether to apply a filter on the solvent region (True) or not (False)

qfilpdict

Parameters to be used to compute the filter if qfil=True. Keys:

  • ‘u’ = center of the filter in ppm

  • ‘s’ = width of the filter in Hz

Returns:
baseline1darray

Employed baseline for correction

abs_v2(n=5, lims=None, alpha=5, winsize=2, qfil=False, qfilp={'s': 10, 'u': 4.7})[source]

Correct the baseline automatically on the real part of the spectrum, then retrieve the imaginary part through Hilbert transform.

Parameters:
nint

Number of coefficients of the polynomial baseline

limstuple or None

Limits for the region on which to compute the baseline, in ppm

alphafloat

The threshold will be set as thr = alpha * np.std(np.gradient(data))

qfilbool

Choose whether to apply a filter on the solvent region (True) or not (False)

qfilpdict

Parameters to be used to compute the filter if qfil=True. Keys: * ‘u’ = center of the filter in ppm * ‘s’ = width of the filter in Hz

Returns:
baseline1darray

Employed baseline for correction

acme(**method_kws)[source]

Automatic phase correction based on entropy minimization. It calculates the phase angles using klassez.processing.acme() specified in method, then calls self.adjph() with those values.

Parameters:
method_kwskeyworded arguments

Additional parameters for the chosen method.

Returns:
None
add_noise(s_n=1)[source]

Adds noise to the FID, using the function klassez.sim.noisegen().

Parameters:
s_nfloat

Standard deviation of the noise

Returns:
None
adjph(p0=None, p1=None, pv=None, update=True, reference=None)[source]

Adjusts the phases of the spectrum according to the given parameters, or interactively if they are left as default. Calls for klassez.processing.ps().

Parameters:
p0float or None

0-th order phase correction /°

p1float or None

1-st order phase correction /°

pvfloat or None

1-st order pivot /ppm

updatebool

Choose if you want to update the procs dictionary or not

referencelist of 1darray or Spectrum_1D object

Reference spectrum to be used for phasing. Can be also given as [ppm, spectrum]

Returns:
valuestuple

(p0, p1, pivot)

apk(alpha=3, winsize=50, ap1=True, seethrough=False, update=True)[source]

Automatic phase correction with klassez.processing.apk().

Parameters:
alphafloat

Factor that multiplies the std of the spectrum to set the threshold

winsizefloat

Minimum size of the window that can contain peaks /Hz

ap1bool

True to adjust both zero and first order, False for only phase zero

seethroughbool

If True, draws a series of diagnostic figures to see what the algorithm is doing

updatebool

Update the procs dictionary

Returns:
None
basl(from_procs=False, phase=True)[source]

Apply the baseline correction by subtracting self.baseline from self.S. Then, self.S is unpacked in self.r and self.i

Parameters:
from_procsbool

If True, computes the baseline using the polynomion model reading self.procs['basl_c'] as coefficients

phasebool

Choose if to apply the same phase correction of the spectrum to the baseline. This should be done if the baseline was computed before the phase adjustment!

blp(pred=8, order=8)[source]

Call klassez.processing.blp() on self.fid for the application of backward linear prediction to the data. Important for Oxford benchtop data, where you have to predict 8 points to have a usable spectrum.

Parameters:
predint

Number of points to be predicted

orderint

Number of coefficients to be used for the prediction

Nint

Number of FID points to be used for calculation; used to decrease computation time

Returns:
None
cal(offset=None, isHz=False, update=True, from_procs=True, *, ref=None)[source]

Calibrates the ppm and frequency scale according to a given value, or interactively. Calls klassez.processing.calibration().

Parameters:
offsetfloat or None

scale shift value

isHzbool

True if offset is in frequency units, False if offset is in ppm

updatebool

Choose if to update the procs dictionary or not

from_procsbool

Read the parameters from the procs dictionary

reflist of 1darray or Spectrum_1D object

Reference spectrum to be used for calibration. If list, [ppm scale, spectrum]

Returns:
None
convdta(scaling=1)[source]

Call klassez.processing.convdta() using self.acqus['GRPDLY']

Note

It is better to use klassez.Spectra.Spectrum_1D.pknl(), convdta often causes baseline distortions

integrate(filename=None, lims=None, use_bas=False)[source]

Integrate the spectrum with a dedicated GUI. Calls klassez.anal.integrate() and writes in self.integrals with keys [ppm1:ppm2] The values are saved in <filename>.igrl.

Parameters:
filenamestr

The integral values will be saved in <filename>.igrl. If None, <self.filename> will be used instead.

Returns:
None
inv_process()[source]

Performs the inverse processing of the spectrum according to the given parameters. Overwrites the S attribute!! Calls klassez.processing.inv_fp().

mc()[source]

Calculates the magnitude of the spectrum and overwrites self.S, self.r, self.i

\[\text{mag}_S = \sqrt{\Re\{S\}^2 + \Im\{S\}^2}\]
pknl()[source]

Reverses the effect of the digital filter by applying a first order phase correction. If the S attribute exists, the processing is applied on the processed data. Otherwise, the correction is performed on the FID. This function calls klassez.processing.pknl() with the parameter grpdly read from the acqus dictionary.

plot(fqscale=False, name=None)[source]

Plots the real part of the spectrum in an interactive panel for inspection.

Parameters:
fqscalebool

Display using frequency scale instead of ppm

namestr

Filename for the figure. If None, self.filename is used

process(interactive=False)[source]

Performs the processing of the FID. The parameters are read from self.procs. Calls klassez.gui.interactive_fp() or klassez.processing.fp() using self.acqus and self.procs Writes the result is self.S, then unpacks it in self.r and self.i Calculates frequency and ppm scales. Also initializes self.F with klassez.fit.Voigt_Fit class using the current parameters.

Parameters:
interactivebool

True if you want to open the interactive panel, False to read the parameters from self.procs.

Returns:
None
qfil(u=None, s=None, from_procs=True, fqscale=False)[source]

Gaussian filter to suppress signals. Tries to read self.procs['qfil'], which is

{ 'u': u, 's': s }

Otherwise, these are set interactively by klassez.gui.interactive_qfil() and then added to self.procs.

Parameters:
ufloat

Position of the filter /ppm

sfloat

Width (standard deviation) of the filter /ppm

from_procsbool

Tries to read the values from self.procs

fqscalebool

True to use the frequency scale, False for the ppm scale.

Returns:
None
read_integrals(filename, n=-1)[source]

Reads the integrals in the .igrl file named filename, and stores the result in self.integrals

Parameters:
filenamestr

Path to the filename to be read

nint

Number of performed integrating procedure to be read. Default: last one. The breakpoints are lines that start with “!”. For this reason, n=0 returns an empty dictionary, hence the first attempt is n=1.

Returns:
None
read_procs(other_dir=None)[source]

Reads the procs dictionary from a file named filename.procs in the same directory of the input file.

Parameters:
other_dirstr or None

Different location for the procs dictionary to look into. If None, self.datadir is used instead.

Warning

Do not put the trailing slash!

Returns:
procs: dict

Dictionary of processing parameters

rpbc(**rpbc_kws)[source]

Computes the phase angles and the baseline using klassez.processing.rpbc() on self.S. Then applies the phase correction and subtracts the baseline, automatically. The procs dictionary is then updated and saved. The polynomial baseline is computed according to the given coefficients and stored in self.baseline

Parameters:
rpbc_kwskeyworded arguments

See klassez.processing.rpbc() for details.

Returns:
None
scan(ns=1, s_n=1)[source]

Simulates the acquisition of ns scans, by adding a different realization of noise at each iteration. The function is supposed to start with the FID without noise at all. If not, the results will be biased. For reproducible results, fix the seed!

Parameters:
nsint

Number of scans to accumulate

s_nfloat

Standard deviation of the noise for each scan

Returns:
None
to_vf(filename=None, Hs=None, fvf=True)[source]

Transform a simulated spectrum in a .ivf or .fvf file to be used in a deconvolution procedure. To do this, it reads the peak parameters saved in self.acqus. The number of signals is determined by acqus['amplitudes']. Multiplets are splitted according to their Js, and saved as components.

Parameters:
filenamestr or None

Path to the filename to be saved, without extension. If None, self.filename is used

Hsint or None

Number of nuclei the spectrum integrates for. If None, the sum of the amplitudes is used.

fvfbool

If True, adds the ‘.fvf’ extension to the filename, if False, adds ‘.ivf’

to_wav(filename=None, cutoff=None, rate=44100)[source]

Converts the FID in an audio file by using klasse.misc.data2wav().

Parameters:
filenamestr

Path where to save the file. If None, self.filename is used

cutofffloat

Clipping limits for the FID

rateint

Sampling rate in samples/sec

Returns:
None
write_acqus(other_dir=None)[source]

Write the acqus dictionary in a file named <self.filename>.acqus. Calls klassez.misc.write_acqus_1D()

Parameters:
other_dirstr or None

Different location for the acqus dictionary to write into. If None, self.datadir is used instead.

Returns:
None
write_integrals(other_dir=None)[source]

Write the integrals in a file named {self.filename}.igrl. The default path is self.datadir.

Parameters:
other_dirstr or None

Different location for the integrals file to write into. If None, self.datadir is used instead.

Returns:
None
write_procs(other_dir=None)[source]

Writes the actual procs dictionary in a file named filename.procs in the same directory of the input file.

Parameters:
other_dirstr or None

Different location for the procs dictionary to write into. If None, self.datadir is used instead.

Warning

Do not put the trailing slash!

static write_ser(ser, acqus, path=None, filename=None)[source]

Writes a real/complex array in binary format. Calls klassez.misc.write_ser`(). Be sure that acqus contains the BYTORDA and DTYPA keys.

Parameters:
serndarray

Array that you want to convert in binary format.

acqusdict

Dictionary of acquisition parameters. It must contain BYTORDA and DTYPA.

pathstr

Path where to save the binary file.

Returns:
None
class klassez.Spectra.Spectrum_2D(in_file, spect='bruker', pv=False, isexp=True)[source]

Bases: object

Class: 2D NMR spectrum

Attributes:
datadirstr

Path to the input file/dataset directory

filenamestr

Base of the name of the file, without extensions

fid2darray

FID

acqusdict

Dictionary of acqusition parameters

ngdicdict

Created only if it is an experimental spectrum. Generated by nmrglue.<spectrometer>.read(), contains all the information on the spectrometer and on the spectrum.

procsdict

Dictionary of processing parameters

eaeflagint

If FnMODE='Echo-Antiecho', keeps track of the manipulation of the data so to not repeat the same process twice

S2darray

Normal getter for self.S attribute

rr2darray

Real part F2, real part F1

ii2darray

Imaginary part F2, imaginary part F1

ir2darray

Real part F2, imaginary part F1. Only exist if F1 is acquired in phase-sensitive mode

ri2darray

Imaginary part F2, real part F1. Only exist if F1 is acquired in phase-sensitive mode

freq_f11darray

Frequency scale of the indirect dimension, in Hz

freq_f21darray

Frequency scale of the direct dimension, in Hz

ppm_f11darray

ppm scale of the indirect dimension

ppm_f21darray

ppm scale of the direct dimension

trf1dict

Projections of the indirect dimension, as 1darrays. Keys: ‘ppm_f2’ where they were taken

trf2dict

Projections of the direct dimension, as 1darrays. Keys: ‘ppm_f1’ where they were taken

Trf1dict

Projections of the indirect dimension, as pSpectrum_1D objects. Keys: ‘ppm_f2’ where they were taken

Trf2dict

Projections of the direct dimension, as pSpectrum_1D objects. Keys: ‘ppm_f1’ where they were taken

integralsdict

Dictionary where to save the regions and values of the integrals.

Methods

add_noise([s_n])

Adds noise to the FID, using the function klassez.sim.noisegen().

adjph([p01, p11, pv1, p02, p12, pv2, update])

Adjusts the phases of the spectrum according to the given parameters, or interactively if they are left as default.

cal([offset, isHz, update, from_procs, ...])

Calibration of the ppm and frequency scales according to a given value, or interactively.

calf1([value, isHz, update, from_procs, ref])

Calibrates the ppm and frequency scale of the indirect dimension according to a given value, or interactively.

calf2([value, isHz, update, from_procs, ref])

Calibrates the ppm and frequency scale of the direct dimension according to a given value, or interactively.

convdta([scaling])

Calls klassez.processing.convdta() to compensate for the group delay.

eae()

Calls klassez.processing.eae() to shuffle the data and make a States-like FID.

integrate(**kwargs)

Integrates the spectrum with a dedicated GUI.

inv_process()

Performs the inverse processing of the spectrum according to the given parameters.

mc()

Computes the magnitude of the spectrum on self.S.

pknl()

Reverses the effect of the digital filter by applying a first order phase correction.

plot([fqscale, Neg, lvl0, name])

Plots the real part of the spectrum (self.rr).

process([interactive])

Performs the full processing of the FID on both dimensions.

projf1(a[, b])

Calculates the sum trace of the indirect dimension, from a ppm to b ppm in F2.

projf2(a[, b])

Calculates the sum trace of the direct dimension, from a ppm to b ppm in F1.

qfil([which, u, s, from_procs, fqscale, ...])

Gaussian filter to suppress signals.

read_procs([other_dir])

Reads the procs dictionary from a file named "filename.procs" in the same directory of the input file.

scan([ns, s_n])

Simulates the acquisition of ns scans, by adding a different realization of noise at each iteration.

splitcomb([J])

Applies the IPAP virtual decoupling scheme by calling klassez.processing.splitcomb`() with appropriate parameters.

strip([xlim, ylim])

Perform the strip transform in F2 with xlim and on F1 with ylim.

to_wav([filename, cutoff, rate])

Converts the FID in an audio file by using klassez.misc.data2wav().

write_acqus([other_dir])

Write the acqus dictionary in a file named "filename.acqus".

write_integrals([other_dir])

Write the integrals in a file named "{self.filename}.int".

write_pdata([path, procno])

Writes a real/complex array in binary format in <path>/pdata/<procno>.

write_procs([other_dir])

Writes the actual procs dictionary in a file named "filename.procs" in the same directory of the input file.

write_ser(ser, acqus[, path, filename])

Writes a real/complex array in binary format.

xf1()

Process only the indirect dimension.

xf2()

Process only the direct dimension.

property S: ndarray[source]

Normal getter for self.S attribute

__init__(in_file, spect='bruker', pv=False, isexp=True)[source]

Initialize the class.

Parameters:
in_filestr

path to file to read, or to the folder of the spectrum

spectstr

Data file format. Allowed: 'bruker' only

pvbool

True if you want to use pseudo-voigt lineshapes for simulation, False for Voigt

isexpbool

True if this is an experimental dataset, False if it is simulated

add_noise(s_n=1)[source]

Adds noise to the FID, using the function klassez.sim.noisegen().

Parameters:
s_nfloat

Standard deviation of the noise

adjph(p01=None, p11=None, pv1=None, p02=None, p12=None, pv2=None, update=True)[source]

Adjusts the phases of the spectrum according to the given parameters, or interactively if they are left as default.

The non-interactive workflow is to apply klassez.processing.ps() on F2, transpose according to FnMODE, apply klassez.processing.ps() on F1, transpose back. If FnMODE='No', the phase correction is applied only on F2, as it should be done in a pseudo-2D experiment. Once self.S was updated and unpacked, the phase values are added to the procs dictionary to keep track of multiple phase adjustments.

Parameters:
p01float or None

0-th order phase correction /° of the indirect dimension

p11float or None

1-st order phase correction /° of the indirect dimension

pv1float or None

1-st order pivot /ppm of the indirect dimension

p02float or None

0-th order phase correction /° of the direct dimension

p12float or None

1-st order phase correction /° of the direct dimension

pv2float or None

1-st order pivot /ppm of the direct dimension

updatebool

Choose if to update the procs dictionary or not

Returns:
None
cal(offset=[None, None], isHz=False, update=True, from_procs=True, *, ref1=None, ref2=None)[source]

Calibration of the ppm and frequency scales according to a given value, or interactively. In this latter case, a reference peak must be chosen.

Parameters:
offsettuple

(scale shift F1, scale shift F2)

isHztuple of bool

True if offset is in frequency units, False if offset is in ppm

updatebool

Choose if to update the procs dictionary or not

from_procsbool

Read the parameters from the procs dictionary

ref1list of 1darray

Reference ppm scale and spectrum to be used as reference for calibration of F1 [ppm, spectrum]

ref2list of 1darray

Reference ppm scale and spectrum to be used as reference for calibration of F2 [ppm, spectrum]

Returns:
None
calf1(value=None, isHz=False, update=True, from_procs=True, *, ref=None)[source]

Calibrates the ppm and frequency scale of the indirect dimension according to a given value, or interactively. Calls self.cal() on F1 only.

Parameters:
valuefloat or None

scale shift value

isHzbool

True if offset is in frequency units, False if offset is in ppm

updatebool

Choose if to update the procs dictionary or not

from_procsbool

Read the parameters from the procs dictionary

reflist of 1darray

Reference ppm scale and spectrum to be used as reference for calibration [ppm, spectrum]

Returns:
None
calf2(value=None, isHz=False, update=True, from_procs=True, *, ref=None)[source]

Calibrates the ppm and frequency scale of the direct dimension according to a given value, or interactively. Calls self.cal() on F2 only

Parameters:
valuefloat or None

scale shift value

isHzbool

True if offset is in frequency units, False if offset is in ppm

updatebool

Choose if to update the procs dictionary or not

from_procsbool

Read the parameters from the procs dictionary

reflist of 1darray

Reference ppm scale and spectrum to be used as reference for calibration [ppm, spectrum]

Returns:
None
convdta(scaling=1)[source]

Calls klassez.processing.convdta() to compensate for the group delay. It does not always work, depends on TopSpin version and planets alignment.

Warning

Better to use klassez.Spectra.Spectrum_2D.pknl()

Parameters:
scalingfloat

Scaling factor for processingconvdta.

eae()[source]

Calls klassez.processing.eae() to shuffle the data and make a States-like FID. Sets self.eaeflag to 0.

integrate(**kwargs)[source]

Integrates the spectrum with a dedicated GUI. Stores the results in self.integral. Calls klassez.anal.integrate_2D()

Parameters:
kwargs: keyworded arguments

Additional parameters for klassez.anal.integrate_2D()

Returns:
None
inv_process()[source]

Performs the inverse processing of the spectrum according to the given parameters. Overwrites the S attribute!! Calls klassez.processing.inv_xfb().

mc()[source]

Computes the magnitude of the spectrum on self.S. Then, updates rr, ri, ir, ii.

pknl()[source]

Reverses the effect of the digital filter by applying a first order phase correction. If the S attribute exists, the processing is applied on the processed data. Otherwise, the correction is performed on the FID. This function calls klassez.processing.pknl() with the parameter grpdly read from the acqus dictionary.

plot(fqscale=False, Neg=True, lvl0=0.2, name=None)[source]

Plots the real part of the spectrum (self.rr). Use the mouse scroll to adjust the contour starting level.

Parameters:
fqscalebool

Display using frequency scale instead of ppm

Negbool

Plot (True) or not (False) the negative contours.

lvl0float

Starting contour value with respect to the maximum of the spectrum

namestr

Name of the figure. If None, self.filename is used.

process(interactive=False, **int_kwargs)[source]

Performs the full processing of the FID on both dimensions. The parameters are read from self.procs. If FnMODE='Echo-Antiecho' and you did not call self.eae() before, the FID is converted to States-TPPI with klassez.processing.eae() before to start. If interactive=True, calls klassez.gui.interactive_xfb() with int_kwargs, else calls klassez.processing.xfb().

The complex/hypercomplex spectrum is stored in self.S, then unpacked into self.rr, self.ri, self.ir, self.ii. If FnMODE='Echo-Antiecho', a phase correction of -90 degrees is applied on the indirect dimension.

Parameters:
interactivebool

True if you want to open the interactive panel, False to read the parameters from self.procs.

int_kwargskeyworded arguments

Additional parameters for klassez.gui.interactive_xfb(), if interactive=True.

Returns:
None
projf1(a, b=None)[source]

Calculates the sum trace of the indirect dimension, from a ppm to b ppm in F2. Store the trace in the dictionary self.trf1 and as pSpectrum_1D in self.Trf1. The key is 'a' or 'a:b' with two decimal figures.

Calls klassez.anal.get_trace() on self.rr with column=True

Parameters:
afloat

ppm F2 value where to extract the trace.

bfloat or None.

If it is None, extract the trace in a. Else, sum from a to b in F2.

Returns:
None
projf2(a, b=None)[source]

Calculates the sum trace of the direct dimension, from a ppm to b ppm in F1. Store the trace in the dictionary self.trf2 and as pSpectrum_1D in self.Trf2. The key is 'a' or 'a:b' with two decimal figures.

Calls klassez.anal.get_trace() on self.rr with column=False

Parameters:
afloat

ppm F1 value where to extract the trace.

bfloat or None.

If it is None, extract the trace in a. Else, sum from a to b in F1.

Returns:
None
qfil(which=None, u=None, s=None, from_procs=True, fqscale=False, *, SFO=None, O1P=None)[source]

Gaussian filter to suppress signals. Tries to read self.procs['qfil'], which is { 'u': u, 's': s } Otherwise, these are set interactively by klassez.gui.interactive_qfil() and then added to self.procs.

Parameters:
whichint or None

Index of the F2 trace to be used for klassez.gui.interactive_qfil(). If None, a suitable trace can be selected using klassez.anal.select_traces().

ufloat

Position /ppm

sfloat

Width (standard deviation) /Hz

from_procsbool

Read the parameters from the procs dictionary

fqscalebool

True to use the frequency scale, False for the ppm scale.

SFOfloat

Nucleus Larmor frequency to use for the conversion to Hz. If None, self.acqus['SFO2'] is used by default.

O1Pfloat

Carrier position in ppm. If None, self.acqus['o2p'] is used by default.

Returns:
None
read_procs(other_dir=None)[source]

Reads the procs dictionary from a file named “filename.procs” in the same directory of the input file.

Parameters:
other_dirstr or None

Different location for the procs dictionary to look into. If None, self.datadir is used instead.

Warning

Do not put the trailing slash!

Returns:
procsdict

Dictionary of processing parameters

scan(ns=1, s_n=1)[source]

Simulates the acquisition of ns scans, by adding a different realization of noise at each iteration. The function is supposed to start with the FID without noise at all. If not, the results will be biased. For reproducible results, fix the seed!

Parameters:
nsint

Number of scans to accumulate

s_nfloat

Standard deviation of the noise for each scan

Returns:
None
splitcomb(J=53.8)[source]

Applies the IPAP virtual decoupling scheme by calling klassez.processing.splitcomb`() with appropriate parameters. Replaces the FID.

Parameters:
Jfloat

Scalar coupling constant, in Hz, of the coupling to be suppressed.

Returns:
None
strip(xlim=None, ylim=None)[source]

Perform the strip transform in F2 with xlim and on F1 with ylim. The frequency and ppm scales are updated as well. The pivot for phase correction is moved to the center of the new scale. The imaginary parts are reconstructed via Hilbert transform.

Parameters:
xlimtuple or None

Limits in F2 in ppm

ylimtuple or None

Limits in F1 in ppm

Returns:
None
to_wav(filename=None, cutoff=None, rate=44100)[source]

Converts the FID in an audio file by using klassez.misc.data2wav().

Parameters:
filenamestr

Path where to save the file. If None, self.filename is used

cutofffloat

Clipping limits for the FID

rateint

Sampling rate in samples/sec

Returns:
None
write_acqus(other_dir=None)[source]

Write the acqus dictionary in a file named “filename.acqus”. Calls klassez.misc.write_acqus_1D()

Parameters:
other_dir: str or None

Different location for the acqus dictionary to write into. If None, self.datadir is used instead.

Returns:
None
write_integrals(other_dir=None)[source]

Write the integrals in a file named "{self.filename}.int".

Parameters:
other_dirstr or None

Different location for the integrals file to write into. If None, self.datadir is used instead.

write_pdata(path=None, procno=666)[source]

Writes a real/complex array in binary format in <path>/pdata/<procno>. Calls misc.write_ser. Be sure that acqus contains the BYTORDA and DTYPA keys. Calls klassez.misc.write_ser(). Be sure that acqus contains the BYTORDA and DTYPA keys.

Parameters:
path: str

Directory where to save the files. If None, self.datadir is used.

procno: int or str

Folder

Returns:
None
write_procs(other_dir=None)[source]

Writes the actual procs dictionary in a file named "filename.procs" in the same directory of the input file.

Parameters:
other_dir: str or None

Different location for the procs dictionary to write into. If None, self.datadir is used instead.

Warning

Do not put the trailing slash!

static write_ser(ser, acqus, path=None, filename=None)[source]

Writes a real/complex array in binary format. Calls klassez.misc.write_ser(). Be sure that acqus contains the BYTORDA and DTYPA keys.

Parameters:
serndarray

Array that you want to convert in binary format.

acqusdict

Dictionary of acquisition parameters. It must contain BYTORDA and DTYPA.

pathstr

Path where to save the binary file.

Returns:
None
xf1()[source]

Process only the indirect dimension. Transposes the spectrum in hypermode or normally if FnMODE != 'QF', 'QF-nofreq' or 'No', then calls for klassez.processing.fp() using self.procs[keys][0], finally transposes it back. The result is stored in self.S, then self.rr and self.ii are written. freq_f2 and ppm_f2 are assigned with the indexes of the indirect evolutions.

xf2()[source]

Process only the direct dimension. Calls klassez.processing.fp() using self.procs[keys][1] The result is stored in self.S, then self.rr and self.ii are written. self.freq_f1 and self.ppm_f1 are assigned with the indexes of the transients.

class klassez.Spectra.pDOSY(in_file, acqus, datadir, ppm_scale=None, indirect_scale=None, p=None, ngdic=None)[source]

Bases: DOSY

Plane of a klassez.Spectra.DOSY_T1.

Attributes:
datadir: str

Path to the input file/dataset directory

filename: str

Base of the name of the file, without extensions

fid: 2darray

FID.

acqus: dict

Dictionary of acqusition parameters

ngdic: dict

Created only if it is an experimental spectrum. Generated by nmrglue.bruker.read(), contains all the information on the spectrometer and on the spectrum.

S: 2darray

Complex spectrum

rr: 2darray

Real part F2, real part F1

ii: 2darray

Imaginary part F2, imaginary part F1

freq_f1: 1darray

Indeces of the experiments, works as placeholder

freq_f2: 1darray

Frequency scale of the direct dimension, in Hz

ppm_f1: 1darray

Indirect scale, as passed to the klassez.Spectra.pDOSY.__init__() method

ppm_f2: 1darray

ppm scale of the direct dimension

trf1: dict

Projections of the indirect dimension, as 1darrays . Keys: 'ppm_f2' where they were taken

trf2: dict

Projections of the direct dimension, as 1darrays . Keys: 'ppm_f1' where they were taken

Trf1: dict

Projections of the indirect dimension, as pSpectrum_1D objects. Keys: ‘ppm_f2’ where they were taken

Trf2: dict

Projections of the direct dimension, as pSpectrum_1D objects. Keys: ‘ppm_f1’ where they were taken

integrals: dict

Dictionary where to save the regions and values of the integrals.

Dfit.DosyFit object

Fitting object created when integrals are read or instanced.

Methods

abs([n, lims, alpha, qfil, qfilp])

Correct the baseline automatically on the real part of the spectrum, then retrieve the imaginary part through Hilbert transform.

abs_v2([n, lims, alpha, winsize, qfil, qfilp])

Correct the baseline automatically on the real part of the spectrum, then retrieve the imaginary part through Hilbert transform.

add_noise([s_n])

Adds noise to the FID, using the function klassez.sim.noisegen().

adjph([expno, p0, p1, pv, update])

Adjusts the phases of the spectrum according to the given parameters, or interactively if they are left as default.

align([lims, u_off, ref_idx])

Aligns the spectrum to a reference signal in the reference spectrum (default: first one).

basl([from_procs, phase])

Apply baseline correction to the whole pseudo-2D by subtracting self.baseline from self.S.

cal([offset, isHz, update, from_procs, ref])

Calibration of the ppm and frequency scales according to a given value, or interactively.

calf1([value, isHz, update, from_procs, ref])

Calibrates the ppm and frequency scale of the indirect dimension according to a given value, or interactively.

calf2([value, isHz, update, from_procs, ref])

Calibrates the ppm and frequency scale of the direct dimension according to a given value, or interactively.

convdta([scaling])

Calls processing.convdta

diffplot([what, xlims, filename, ext, dpi, dim])

Makes a plot of the diffusion coefficients, with error bars, as a function of the integrated regions.

eae()

Calls klassez.processing.eae() to shuffle the data and make a States-like FID.

integrate(*args, **kws)

Performs the same integration procedure of the parent class, which sets the self.integrals attribute.

inv_process()

Performs the inverse processing of the spectrum according to the given parameters.

mc()

Computes the magnitude of the spectrum on self.S.

mount([fids, filename, newacqus])

Replaces the FID of the experiment with a custom one, made by stacking 1D experiments.

pknl()

Reverses the effect of the digital filter by applying a first order phase correction.

plot([fqscale, Neg, lvl0, Y_label, name])

Plots the real part of the spectrum (self.rr).

plot_md([which, lims])

Plot a number of experiments, superimposed.

plot_stacked([which, lims])

Plot a number of experiments, stacked.

process()

Process the data as in a normal klassez.Spectra.Pseudo_2D object.

projf1(a[, b])

Calculates the sum trace of the indirect dimension, from a ppm to b ppm in F2.

projf2(a[, b])

Calculates the sum trace of the direct dimension, from a ppm to b ppm in F1.

qfil([which, u, s, from_procs, fqscale])

Gaussian filter to suppress signals.

read_integrals(*args, **kws)

Reads a .igrl file as well as its father class, which sets the self.integrals attribute.

read_procs([other_dir])

Reads the procs dictionary from a file named "filename.procs" in the same directory of the input file.

rpbc([ref_exp])

Computes the phase angles and the baseline using klassez.processing.rpbc() on self.S.

scan([ns, s_n])

Simulates the acquisition of ns scans, by adding a different realization of noise at each iteration.

splitcomb([J])

Applies the IPAP virtual decoupling scheme by calling klassez.processing.splitcomb`() with appropriate parameters.

strip([xlim])

Perform the strip transform in F2 with xlim.

to_wav([filename, cutoff, rate])

Converts the FID in an audio file by using klasse.misc.data2wav().

write_acqus([other_dir])

Write the acqus dictionary in a file named "filename.acqus".

write_integrals([other_dir])

Write the integrals in a file named {self.filename}.igrl.

write_pdata([path, procno])

Writes a real/complex array in binary format in <path>/pdata/<procno>.

write_procs()

Overwrites the original function to NOT EVER save a procs file

write_ser(ser, acqus[, path, filename])

Writes a real/complex array in binary format.

xf1()

Process only the indirect dimension.

xf2()

Process only the direct dimension.

__init__(in_file, acqus, datadir, ppm_scale=None, indirect_scale=None, p=None, ngdic=None)[source]

Initialize the class with the already processed spectrum and a few other parameters.

Parameters:
in_file2darray

Processed spectrum

acqusdict

Acquisition dictionary in the format of the one of klassez.Spectra.DOSY_T1

datadirstr

Location of the original 3D spectrum

ppm_scale1darray or None

PPM scale of the direct dimension to be used. If None, it is computed from acqus

indirect_scale: 1darray

Scale for the indirect dimension. Important for correct display and fitting.

pint or str

It will be added to self.filename in order to not overwite the original files

write_procs()[source]

Overwrites the original function to NOT EVER save a procs file

class klassez.Spectra.pSpectrum_1D(in_file, acqus=None, procs=None, istrace=False, filename='T')[source]

Bases: Spectrum_1D

Subclass of klassez.Spectra.Spectrum_1D that allows to handle processed 1D NMR spectra. Useful when dealing with traces of 2D spectra. Shares the same attributes with klassez.Spectra.Spectrum_1D .

Of course, there is no fid attribute.

Attributes:
S

Normal getter for self.S attribute

Methods

abs([n, lims, alpha, qfil, qfilp])

Correct the baseline automatically on the real part of the spectrum, then retrieve the imaginary part through Hilbert transform.

abs_v2([n, lims, alpha, winsize, qfil, qfilp])

Correct the baseline automatically on the real part of the spectrum, then retrieve the imaginary part through Hilbert transform.

acme(**method_kws)

Automatic phase correction based on entropy minimization.

add_noise([s_n])

Adds noise to the FID, using the function klassez.sim.noisegen().

adjph([p0, p1, pv, update, reference])

Adjusts the phases of the spectrum according to the given parameters, or interactively if they are left as default.

apk([alpha, winsize, ap1, seethrough, update])

Automatic phase correction with klassez.processing.apk().

basl([from_procs, phase])

Apply the baseline correction by subtracting self.baseline from self.S.

blp([pred, order])

Call klassez.processing.blp() on self.fid for the application of backward linear prediction to the data.

cal([offset, isHz, update, from_procs, ref])

Calibrates the ppm and frequency scale according to a given value, or interactively.

convdta([scaling])

Call klassez.processing.convdta() using self.acqus['GRPDLY']

integrate([filename, lims, use_bas])

Integrate the spectrum with a dedicated GUI.

inv_process()

Performs the inverse processing of the spectrum according to the given parameters.

mc()

Calculates the magnitude of the spectrum and overwrites self.S, self.r, self.i

pknl()

Reverses the effect of the digital filter by applying a first order phase correction.

plot([fqscale, name])

Plots the real part of the spectrum in an interactive panel for inspection.

process([interactive])

Performs the processing of the FID.

qfil([u, s, from_procs, fqscale])

Gaussian filter to suppress signals.

read_integrals(filename[, n])

Reads the integrals in the .igrl file named filename, and stores the result in self.integrals

read_procs([other_dir])

Reads the procs dictionary from a file named filename.procs in the same directory of the input file.

rpbc(**rpbc_kws)

Computes the phase angles and the baseline using klassez.processing.rpbc() on self.S.

scan([ns, s_n])

Simulates the acquisition of ns scans, by adding a different realization of noise at each iteration.

to_vf([filename, Hs, fvf])

Transform a simulated spectrum in a .ivf or .fvf file to be used in a deconvolution procedure.

to_wav([filename, cutoff, rate])

Converts the FID in an audio file by using klasse.misc.data2wav().

write_acqus([other_dir])

Write the acqus dictionary in a file named <self.filename>.acqus.

write_integrals([other_dir])

Write the integrals in a file named {self.filename}.igrl.

write_procs([other_dir])

Writes the actual procs dictionary in a file named filename.procs in the same directory of the input file.

write_ser(ser, acqus[, path, filename])

Writes a real/complex array in binary format.

__init__(in_file, acqus=None, procs=None, istrace=False, filename='T')[source]

Initialize the class.

Parameters:
in_filestr or 1darray

If istrace=True, in_file is the NMR spectrum. Else, it is the directory of the processed data. Only supports Bruker format!

acqusdict or None

If istrace=True, you must supply the associated acqus dictionary. Else, it is not necessary as it is read from the input directory

procsdict or None

You can pass the dictionary of processing parameters, if you want. Otherwise, it is initialized with standard values.

istracebool

Declare the object as trace extracted from a 2D (True) or as true experimental spectrum (False)

filenamestr

If istrace=True, this will be the filename of self.acqus and self.procs

class klassez.Spectra.pSpectrum_2D(in_file)[source]

Bases: Spectrum_2D

Subclass of klassez.Spectra.Spectrum_2D that allows to handle processed 2D NMR spectra. Only supports Bruker format.

Attributes:
datadirstr

Path to the input file/dataset directory

filenamestr

Base of the name of the file, without extensions

acqusdict

Dictionary of acqusition parameters

ngdicdict

Generated by nmrglue.bruker.read(), contains all the information on the spectrometer and on the spectrum.

procsdict

Dictionary of processing parameters

S2darray

Normal getter for self.S attribute

rr2darray

Real part F2, real part F1

ii2darray

Imaginary part F2, imaginary part F1

ir2darray

Real part F2, imaginary part F1. Only exist if F1 is acquired in phase-sensitive mode

ri2darray

Imaginary part F2, real part F1. Only exist if F1 is acquired in phase-sensitive mode

freq_f11darray

Frequency scale of the indirect dimension, in Hz

freq_f21darray

Frequency scale of the direct dimension, in Hz

ppm_f11darray

ppm scale of the indirect dimension

ppm_f21darray

ppm scale of the direct dimension

trf1dict

Projections of the indirect dimension, as 1darrays. Keys: ‘ppm_f2’ where they were taken

trf2dict

Projections of the direct dimension, as 1darrays. Keys: ‘ppm_f1’ where they were taken

Trf1dict

Projections of the indirect dimension, as pSpectrum_1D objects. Keys: ‘ppm_f2’ where they were taken

Trf2dict

Projections of the direct dimension, as pSpectrum_1D objects. Keys: ‘ppm_f1’ where they were taken

integralsdict

Dictionary where to save the regions and values of the integrals.

Methods

add_noise([s_n])

Adds noise to the FID, using the function klassez.sim.noisegen().

adjph([p01, p11, pv1, p02, p12, pv2, update])

Adjusts the phases of the spectrum according to the given parameters, or interactively if they are left as default.

cal([offset, isHz, update, from_procs, ...])

Calibration of the ppm and frequency scales according to a given value, or interactively.

calf1([value, isHz, update, from_procs, ref])

Calibrates the ppm and frequency scale of the indirect dimension according to a given value, or interactively.

calf2([value, isHz, update, from_procs, ref])

Calibrates the ppm and frequency scale of the direct dimension according to a given value, or interactively.

convdta([scaling])

Calls klassez.processing.convdta() to compensate for the group delay.

eae()

Calls klassez.processing.eae() to shuffle the data and make a States-like FID.

integrate(**kwargs)

Integrates the spectrum with a dedicated GUI.

inv_process()

Performs the inverse processing of the spectrum according to the given parameters.

mc()

Computes the magnitude of the spectrum on self.S.

pknl()

Reverses the effect of the digital filter by applying a first order phase correction.

plot([fqscale, Neg, lvl0, name])

Plots the real part of the spectrum (self.rr).

process([interactive])

Performs the full processing of the FID on both dimensions.

projf1(a[, b])

Calculates the sum trace of the indirect dimension, from a ppm to b ppm in F2.

projf2(a[, b])

Calculates the sum trace of the direct dimension, from a ppm to b ppm in F1.

qfil([which, u, s, from_procs, fqscale, ...])

Gaussian filter to suppress signals.

read_procs([other_dir])

Reads the procs dictionary from a file named "filename.procs" in the same directory of the input file.

scan([ns, s_n])

Simulates the acquisition of ns scans, by adding a different realization of noise at each iteration.

splitcomb([J])

Applies the IPAP virtual decoupling scheme by calling klassez.processing.splitcomb`() with appropriate parameters.

strip([xlim, ylim])

Perform the strip transform in F2 with xlim and on F1 with ylim.

to_wav([filename, cutoff, rate])

Converts the FID in an audio file by using klassez.misc.data2wav().

write_acqus([other_dir])

Write the acqus dictionary in a file named "filename.acqus".

write_integrals([other_dir])

Write the integrals in a file named "{self.filename}.int".

write_pdata([path, procno])

Writes a real/complex array in binary format in <path>/pdata/<procno>.

write_procs([other_dir])

Writes the actual procs dictionary in a file named "filename.procs" in the same directory of the input file.

write_ser(ser, acqus[, path, filename])

Writes a real/complex array in binary format.

xf1()

Process only the indirect dimension.

xf2()

Process only the direct dimension.

__init__(in_file)[source]

Initialize the class.

Parameters:
in_filestr

Path to the spectrum. Here, the ‘pdata/#’ folder must be specified.

klassez.Spectra.wf0 = {'gb': 0.1, 'gb_gm': 0.1, 'gc': 0, 'lb': 5, 'lb_gm': 0, 'mode': None, 'ssb': 2, 'sw': None}[source]

Classes for the management of NMR data.