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_2DClass: 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::
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, from_procs])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.baselinefromself.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.integralsattribute.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_2Dobject.projf1(a[, b])Calculates the sum trace of the indirect dimension, from
appm tobppm in F2.projf2(a[, b])Calculates the sum trace of the direct dimension, from
appm tobppm 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.integralsattribute.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()onself.S.scan([ns, s_n])Simulates the acquisition of
nsscans, 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
acqusdictionary 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
procsdictionary 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_2Dobject. Then, reads the difflist file and stores it in theself.difflistattribute.
- 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. IfNone, 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
See also
- integrate(*args, **kws)[source]
Performs the same integration procedure of the parent class, which sets the
self.integralsattribute. Then, uses it to either create or update theself.DDosyFit object.
- process()[source]
Process the data as in a normal
klassez.Spectra.Pseudo_2Dobject. Then, replacesself.ppm_f1with theself.difflist.See also
- read_integrals(*args, **kws)[source]
Reads a .igrl file as well as its father class, which sets the
self.integralsattribute. Then, uses it to either create or update theself.Dklassez.fit.DosyFitobject.
- class klassez.Spectra.DOSY_T1(in_file)[source]
Bases:
objectClass: 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 differentd20.- 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.Stheidx-th plane (python numbering) on the directiondim.integrate([filename])Create the attribute
self.Dasklassez.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.procsin the same directory of the input file.write_procs([other_dir])Writes the actual
procsdictionary 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
dimdirection- expno: int
Index of the experiment (python numbering) of the extracted plane to use in the interactive panel
- dimstr
If
'31', the directivefromplaneis relative to the F3-F1 direction. If'32', the directivefromplaneis 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::
- getplane(idx, dim='31')[source]
Extract from
self.Stheidx-th plane (python numbering) on the directiondim. Keeps a reference to it as the attributeself._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.pDOSYobject
- integrate(filename=None)[source]
Create the attribute
self.Dasklassez.fit.DosyFit_pp3D, and integrate the planes along the 31 direction.- Parameters:
- filenamestr or None
Custom filename for data and plots. If
None,self.filenameis 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.filenameis used.
- process()[source]
Process only the direct dimension. Calls
klassez.processing.fp()on each transient. The parameters are read from theprocsdictionary.See also
- read_procs(other_dir=None)[source]
Reads the procs dictionary from a file named
filename.procsin the same directory of the input file.- Parameters:
- other_dirstr or None
Different location for the procs dictionary to look into. If None,
self.datadiris 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
procsdictionary in a file named"filename.procs"in the same directory of the input file.- Parameters:
- other_dir: str or None
Different location for the
procsdictionary to write into. If None,self.datadiris used instead.Warning
Do not put the trailing slash!
- class klassez.Spectra.Pseudo_2D(in_file, pv=False, isexp=True)[source]
Bases:
Spectrum_2DSubclass of
klassez.Spectra.Spectrum_2Dto 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_1Dobjects. Keys: ‘ppm_f2’ where they were taken- Trf2: dict
Projections of the direct dimension, as
pSpectrum_1Dobjects. 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, from_procs])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.baselinefromself.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
appm tobppm in F2.projf2(a[, b])Calculates the sum trace of the direct dimension, from
appm tobppm 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 inself.integralsread_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()onself.S.scan([ns, s_n])Simulates the acquisition of
nsscans, 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
acqusdictionary 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
procsdictionary 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, 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
See also
- 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, from_procs=True)[source]
Aligns the spectrum to a reference signal in the reference spectrum (default: first one).
- Parameters:
- limstuple or None
Reference signal region, in ppm. If None, you can select it interactively.
- u_offfloat
Maximum displacement allowed, in ppm
- ref_idxint
Index of the spectrum to be used as a reference (python numbering)
- from_procsbool
If
True, read the values fromself.procsand applies it. Else, it performs the whole process of calibration.
- Returns:
- None
- basl(from_procs=False, phase=True)[source]
Apply baseline correction to the whole pseudo-2D by subtracting
self.baselinefromself.S. Then,self.Sis unpacked inself.rrandself.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()
- 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 inself.integralswith 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. IfNone,<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. Thefidattribute is overwritten. The key ‘TD1’ of theacqusdictionary 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
See also
- 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.filenameis 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 theprocsdictionary.See also
- projf1(a, b=None)[source]
Calculates the sum trace of the indirect dimension, from
appm tobppm in F2. Store the trace in the dictionaryself.trf1and aspSpectrum_1Dinself.Trf1. The key is'a'or'a:b'with two decimal figures.Calls
klassez.anal.get_trace()onself.rrwithcolumn=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 fromatobin F2.
- Returns:
- None
See also
- projf2(a, b=None)[source]
Calculates the sum trace of the direct dimension, from
appm tobppm in F1. Store the trace in the dictionaryself.trf2and aspSpectrum_1Dinself.Trf2. The key is'a'or'a:b'with two decimal figures.Calls
klassez.anal.get_trace()onself.rrwithcolumn=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 fromatobin F1.
- Returns:
- None
See also
- 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 byklassez.gui.interactive_qfil()and then added toself.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 usingklassez.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 inself.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=0returns an empty dictionary, hence the first attempt isn=1.
- Returns:
- None
See also
- rpbc(ref_exp=0, **rpbc_kws)[source]
Computes the phase angles and the baseline using
klassez.processing.rpbc()onself.S. Then applies the phase correction and subtracts the baseline, automatically, to all experiments of the pseudo-2D. Theprocsdictionary is then updated and saved. The polynomial baseline is computed according to the given coefficients and stored inself.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
See also
- scan(ns=1, s_n=1)[source]
Simulates the acquisition of
nsscans, 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
See also
- 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.filenameis used- cutofffloat
Clipping limits for the FID
- rateint
Sampling rate in samples/sec
- Returns:
- None
See also
- class klassez.Spectra.Spectrum_1D(in_file, pv=False, isexp=True, spect='bruker')[source]
Bases:
objectClass: 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
S1darrayNormal getter for
self.Sattribute- 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.baselinefromself.S.blp([pred, order])Call
klassez.processing.blp()onself.fidfor 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()usingself.acqus['GRPDLY']integrate([filename, lims, use_bas])Integrate the spectrum with a dedicated GUI.
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.ipknl()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 inself.integralsread_procs([other_dir])Reads the procs dictionary from a file named
filename.procsin the same directory of the input file.rpbc(**rpbc_kws)Computes the phase angles and the baseline using
klassez.processing.rpbc()onself.S.scan([ns, s_n])Simulates the acquisition of
nsscans, 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.procsin the same directory of the input file.write_ser(ser, acqus[, path, filename])Writes a real/complex array in binary format.
- Returns:
- None
See also
- __init__(in_file, pv=False, isexp=True, spect='bruker')[source]
Initialize the class. Simulation of the dataset (i.e.
isexp=False) employsklasez.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 callsself.adjph()with those values.- Parameters:
- method_kwskeyworded arguments
Additional parameters for the chosen method.
- Returns:
- None
See also
- 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
See also
- 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
See also
- basl(from_procs=False, phase=True)[source]
Apply the baseline correction by subtracting
self.baselinefromself.S. Then,self.Sis unpacked inself.randself.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()onself.fidfor 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
See also
- 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
offsetis in frequency units, False ifoffsetis 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
See also
- convdta(scaling=1)[source]
Call
klassez.processing.convdta()usingself.acqus['GRPDLY']Note
It is better to use
klassez.Spectra.Spectrum_1D.pknl(),convdtaoften causes baseline distortionsSee also
- integrate(filename=None, lims=None, use_bas=False)[source]
Integrate the spectrum with a dedicated GUI. Calls
klassez.anal.integrate()and writes inself.integralswith keys[ppm1:ppm2]The values are saved in<filename>.igrl.- Parameters:
- filenamestr
The integral values will be saved in
<filename>.igrl. IfNone,<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
Sattribute!! Callsklassez.processing.inv_fp().See also
- 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
Sattribute exists, the processing is applied on the processed data. Otherwise, the correction is performed on the FID. This function callsklassez.processing.pknl()with the parametergrpdlyread from theacqusdictionary.See also
- 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.filenameis used
- process(interactive=False)[source]
Performs the processing of the FID. The parameters are read from
self.procs. Callsklassez.gui.interactive_fp()orklassez.processing.fp()usingself.acqusandself.procsWrites the result isself.S, then unpacks it inself.randself.iCalculates frequency and ppm scales. Also initializesself.Fwithklassez.fit.Voigt_Fitclass 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 toself.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
See also
- read_integrals(filename, n=-1)[source]
Reads the integrals in the .igrl file named
filename, and stores the result inself.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=0returns an empty dictionary, hence the first attempt isn=1.
- Returns:
- None
See also
- read_procs(other_dir=None)[source]
Reads the procs dictionary from a file named
filename.procsin the same directory of the input file.- Parameters:
- other_dirstr or None
Different location for the procs dictionary to look into. If None,
self.datadiris 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()onself.S. Then applies the phase correction and subtracts the baseline, automatically. Theprocsdictionary is then updated and saved. The polynomial baseline is computed according to the given coefficients and stored inself.baseline- Parameters:
- rpbc_kwskeyworded arguments
See
klassez.processing.rpbc()for details.
- Returns:
- None
See also
- scan(ns=1, s_n=1)[source]
Simulates the acquisition of
nsscans, 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
See also
- 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 byacqus['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.filenameis 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.filenameis used- cutofffloat
Clipping limits for the FID
- rateint
Sampling rate in samples/sec
- Returns:
- None
See also
- write_acqus(other_dir=None)[source]
Write the acqus dictionary in a file named
<self.filename>.acqus. Callsklassez.misc.write_acqus_1D()- Parameters:
- other_dirstr or None
Different location for the acqus dictionary to write into. If None,
self.datadiris used instead.
- Returns:
- None
See also
- write_integrals(other_dir=None)[source]
Write the integrals in a file named
{self.filename}.igrl. The default path isself.datadir.- Parameters:
- other_dirstr or None
Different location for the integrals file to write into. If None,
self.datadiris used instead.
- Returns:
- None
See also
- write_procs(other_dir=None)[source]
Writes the actual procs dictionary in a file named
filename.procsin the same directory of the input file.- Parameters:
- other_dirstr or None
Different location for the procs dictionary to write into. If None,
self.datadiris 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 thatacquscontains 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
See also
- class klassez.Spectra.Spectrum_2D(in_file, spect='bruker', pv=False, isexp=True)[source]
Bases:
objectClass: 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 twiceS2darrayNormal getter for
self.Sattribute- 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_1Dobjects. Keys: ‘ppm_f2’ where they were taken- Trf2dict
Projections of the direct dimension, as
pSpectrum_1Dobjects. 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.
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
appm tobppm in F2.projf2(a[, b])Calculates the sum trace of the direct dimension, from
appm tobppm 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
nsscans, 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
xlimand on F1 withylim.to_wav([filename, cutoff, rate])Converts the FID in an audio file by using
klassez.misc.data2wav().write_acqus([other_dir])Write the
acqusdictionary 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
procsdictionary 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, 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 toFnMODE, applyklassez.processing.ps()on F1, transpose back. IfFnMODE='No', the phase correction is applied only on F2, as it should be done in a pseudo-2D experiment. Onceself.Swas 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
offsetis in frequency units, False ifoffsetis in ppm- updatebool
Choose if to update the
procsdictionary or not- from_procsbool
Read the parameters from the
procsdictionary- 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
offsetis in frequency units, False ifoffsetis in ppm- updatebool
Choose if to update the
procsdictionary or not- from_procsbool
Read the parameters from the
procsdictionary- reflist of 1darray
Reference ppm scale and spectrum to be used as reference for calibration
[ppm, spectrum]
- Returns:
- None
See also
- 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
offsetis in frequency units, False ifoffsetis in ppm- updatebool
Choose if to update the
procsdictionary or not- from_procsbool
Read the parameters from the
procsdictionary- reflist of 1darray
Reference ppm scale and spectrum to be used as reference for calibration
[ppm, spectrum]
- Returns:
- None
See also
- 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. Setsself.eaeflagto 0.
- integrate(**kwargs)[source]
Integrates the spectrum with a dedicated GUI. Stores the results in
self.integral. Callsklassez.anal.integrate_2D()- Parameters:
- kwargs: keyworded arguments
Additional parameters for
klassez.anal.integrate_2D()
- Returns:
- None
See also
- inv_process()[source]
Performs the inverse processing of the spectrum according to the given parameters. Overwrites the
Sattribute!! Callsklassez.processing.inv_xfb().
- mc()[source]
Computes the magnitude of the spectrum on
self.S. Then, updatesrr,ri,ir,ii.See also
- pknl()[source]
Reverses the effect of the digital filter by applying a first order phase correction. If the
Sattribute exists, the processing is applied on the processed data. Otherwise, the correction is performed on the FID. This function callsklassez.processing.pknl()with the parametergrpdlyread from theacqusdictionary.See also
- 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.filenameis used.
- process(interactive=False, **int_kwargs)[source]
Performs the full processing of the FID on both dimensions. The parameters are read from
self.procs. IfFnMODE='Echo-Antiecho'and you did not callself.eae()before, the FID is converted to States-TPPI withklassez.processing.eae()before to start. Ifinteractive=True, callsklassez.gui.interactive_xfb()withint_kwargs, else callsklassez.processing.xfb().The complex/hypercomplex spectrum is stored in
self.S, then unpacked intoself.rr,self.ri,self.ir,self.ii. IfFnMODE='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(), ifinteractive=True.
- Returns:
- None
- projf1(a, b=None)[source]
Calculates the sum trace of the indirect dimension, from
appm tobppm in F2. Store the trace in the dictionaryself.trf1and aspSpectrum_1Dinself.Trf1. The key is'a'or'a:b'with two decimal figures.Calls
klassez.anal.get_trace()onself.rrwithcolumn=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 fromatobin F2.
- Returns:
- None
See also
- projf2(a, b=None)[source]
Calculates the sum trace of the direct dimension, from
appm tobppm in F1. Store the trace in the dictionaryself.trf2and aspSpectrum_1Dinself.Trf2. The key is'a'or'a:b'with two decimal figures.Calls
klassez.anal.get_trace()onself.rrwithcolumn=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 fromatobin F1.
- Returns:
- None
See also
- 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 byklassez.gui.interactive_qfil()and then added toself.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 usingklassez.anal.select_traces().- ufloat
Position /ppm
- sfloat
Width (standard deviation) /Hz
- from_procsbool
Read the parameters from the
procsdictionary- 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
procsdictionary to look into. If None,self.datadiris 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
nsscans, 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
See also
- 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
See also
- strip(xlim=None, ylim=None)[source]
Perform the strip transform in F2 with
xlimand on F1 withylim. 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
See also
- write_acqus(other_dir=None)[source]
Write the
acqusdictionary in a file named “filename.acqus”. Callsklassez.misc.write_acqus_1D()- Parameters:
- other_dir: str or None
Different location for the
acqusdictionary to write into. If None,self.datadiris used instead.
- Returns:
- None
See also
- 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.datadiris 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. Callsklassez.misc.write_ser(). Be sure thatacquscontains the BYTORDA and DTYPA keys.- Parameters:
- path: str
Directory where to save the files. If None,
self.datadiris used.- procno: int or str
Folder
- Returns:
- None
See also
- write_procs(other_dir=None)[source]
Writes the actual
procsdictionary in a file named"filename.procs"in the same directory of the input file.- Parameters:
- other_dir: str or None
Different location for the
procsdictionary to write into. If None,self.datadiris 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 thatacquscontains 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
See also
- xf1()[source]
Process only the indirect dimension. Transposes the spectrum in hypermode or normally if
FnMODE != 'QF','QF-nofreq'or'No', then calls forklassez.processing.fp()usingself.procs[keys][0], finally transposes it back. The result is stored inself.S, thenself.rrandself.iiare written.freq_f2andppm_f2are assigned with the indexes of the indirect evolutions.
- xf2()[source]
Process only the direct dimension. Calls
klassez.processing.fp()usingself.procs[keys][1]The result is stored inself.S, thenself.rrandself.iiare written.self.freq_f1andself.ppm_f1are assigned with the indexes of the transients.See also
- class klassez.Spectra.pDOSY(in_file, acqus, datadir, ppm_scale=None, indirect_scale=None, p=None, ngdic=None)[source]
Bases:
DOSYPlane 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_1Dobjects. Keys: ‘ppm_f2’ where they were taken- Trf2: dict
Projections of the direct dimension, as
pSpectrum_1Dobjects. 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, from_procs])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.baselinefromself.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.integralsattribute.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_2Dobject.projf1(a[, b])Calculates the sum trace of the indirect dimension, from
appm tobppm in F2.projf2(a[, b])Calculates the sum trace of the direct dimension, from
appm tobppm 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.integralsattribute.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()onself.S.scan([ns, s_n])Simulates the acquisition of
nsscans, 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
acqusdictionary 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>.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 fromacqus- indirect_scale: 1darray
Scale for the indirect dimension. Important for correct display and fitting.
- pint or str
It will be added to
self.filenamein order to not overwite the original files
- class klassez.Spectra.pSpectrum_1D(in_file, acqus=None, procs=None, istrace=False, filename='T')[source]
Bases:
Spectrum_1DSubclass of
klassez.Spectra.Spectrum_1Dthat allows to handle processed 1D NMR spectra. Useful when dealing with traces of 2D spectra. Shares the same attributes withklassez.Spectra.Spectrum_1D.Of course, there is no
fidattribute.See also
- Attributes:
SNormal getter for
self.Sattribute
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.baselinefromself.S.blp([pred, order])Call
klassez.processing.blp()onself.fidfor 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()usingself.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.ipknl()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 inself.integralsread_procs([other_dir])Reads the procs dictionary from a file named
filename.procsin the same directory of the input file.rpbc(**rpbc_kws)Computes the phase angles and the baseline using
klassez.processing.rpbc()onself.S.scan([ns, s_n])Simulates the acquisition of
nsscans, 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.procsin 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_fileis 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
acqusdictionary. 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 ofself.acqusandself.procs
- class klassez.Spectra.pSpectrum_2D(in_file)[source]
Bases:
Spectrum_2DSubclass of
klassez.Spectra.Spectrum_2Dthat 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
S2darrayNormal getter for
self.Sattribute- 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_1Dobjects. Keys: ‘ppm_f2’ where they were taken- Trf2dict
Projections of the direct dimension, as
pSpectrum_1Dobjects. 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
appm tobppm in F2.projf2(a[, b])Calculates the sum trace of the direct dimension, from
appm tobppm 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
nsscans, 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
xlimand on F1 withylim.to_wav([filename, cutoff, rate])Converts the FID in an audio file by using
klassez.misc.data2wav().write_acqus([other_dir])Write the
acqusdictionary 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
procsdictionary 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.
- 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.