ANAL Module
This package contains function for the analysis of spectra.
- klassez.anal.get_trace(data, ppm_f2, ppm_f1, a, b=None, column=True)[source]
Takes as input a 2D dataset and the ppm scales of direct and indirect dimensions respectively. Calculates the projection on the given axis summing from
a(ppm) tob(ppm). Default: indirect dimension projection (i.e.column=True), change it to False for the direct dimension projection.- Parameters:
- data2darray
Spectrum of which to extract the projections
- ppm_f21darray
ppm scale of the direct dimension
- ppm_f11darray
ppm scale of the indirect dimension
- afloat
The ppm value from which to start extracting the projection.
- bfloat, optional
If provided, the ppm value at which to stop extracting the projection. Otherwise, returns only the
atrace.- columnbool
If True, extracts the F1 projection. If False, extracts the F2 projection.
- Returns:
- y1darray
Computed projection
- klassez.anal.integral_2D(ppm_f1, t_f1, SFO1, ppm_f2, t_f2, SFO2, u_1=None, fwhm_1=200, utol_1=0.5, u_2=None, fwhm_2=200, utol_2=0.5, plot_result=False)[source]
Calculate the integral of a 2D peak. The idea is to extract the traces correspondent to the peak center and fit them with a gaussian function in each dimension. Then, once got the intensity of each of the two gaussians, multiply them together in order to obtain the 2D integral. This procedure should be equivalent to what CARA does.
Note
In development!!!
- Parameters:
- ppm_f11darray
PPM scale of the indirect dimension
- t_f11darray
Trace of the indirect dimension, real part
- SFO1float
Larmor frequency of the nucleus in the indirect dimension
- ppm_f21darray
PPM scale of the direct dimension
- t_f21darray
Trace of the direct dimension, real part
- SFO2float
Larmor frequency of the nucleus in the direct dimension
- u_1float
Chemical shift in F1 /ppm. Defaults to the center of the scale
- fwhm_1float
Starting FWHM /Hz in the indirect dimension
- utol_1float
Allowed tolerance for u_1 during the fit. (u_1-utol_1, u_1+utol_1)
- u_2float
Chemical shift in F2 /ppm. Defaults to the center of the scale
- fwhm_2float
Starting FWHM /Hz in the direct dimension
- utol_2float
Allowed tolerance for u_2 during the fit. (u_2-utol_2, u_2+utol_2)
- plot_resultbool
True to show how the program fitted the traces.
- Returns:
- I_totfloat
Computed integral.
- klassez.anal.integrate(ppm0, data0, SFO1, filename='integrals', X_label='$\\delta\\,$F1 /ppm', dx=1)[source]
Allows interactive integration of a NMR spectrum through a dedicated GUI. Returns the values as a dictionary, where the keys are the selected regions truncated to the 3nd decimal figure. The values are saved in the
<filename>.igrlfile.In the GUI, draw the integration region around the peak. The shape of the integral function appears in red in that region, and the value of the integral is reported under the “current integral” label on the right side. The integral can be corrected with a baseline, that is the straight line that connects the border of the integration window. It can be activated and deactivated using the checkbox on the right side. Press “ADD” to save the integral value. Upon pressing, the integral function becomes green and the value appears on top of the figure. To remove an integral from the list, first click on the corresponding value on the top to select it: the number and the integral function should become purple. Then, click on the “REMOVE” button. Use the right click to reset the selection.
At the end of the procedure, click on the “SAVE” button to write the .igrl file.
- Parameters:
- ppm1darray
PPM scale of the spectrum
- data1darray
Spectrum to be integrated.
- SFO1float
Larmor frequency of the observed nucleus. For conversion to the correct integration scale.
- filenamestr
Name for the .igrl file to be written. Without extension!
- X_labelstr
Label of the x-axis
- dxfloat
Correction for the integral values. It should be
dx = 2 * dw
- Returns:
- abs_valsdict
Dictionary containing the values of the integrated peaks.
See also
- klassez.anal.integrate_2D(ppm_f1, ppm_f2, data, SFO1, SFO2, fwhm_1=200, fwhm_2=200, utol_1=0.5, utol_2=0.5, plot_result=False)[source]
Function to select and integrate 2D peaks of a spectrum, using dedicated GUIs. Calls integral_2D to do the dirty job.
Error
Old function!! Legacy
- Parameters:
- ppm_f11darray
PPM scale of the indirect dimension
- ppm_f21darray
PPM scale of the direct dimension
- data2darray
real part of the spectrum
- SFO1float
Larmor frequency of the nucleus in the indirect dimension
- SFO2float
Larmor frequency of the nucleus in the direct dimension
- fwhm_1float
Starting FWHM /Hz in the indirect dimension
- fwhm_2float
Starting FWHM /Hz in the direct dimension
- utol_1float
Allowed tolerance for u_1 during the fit. (u_1-utol_1, u_1+utol_1)
- utol_2float
Allowed tolerance for u_2 during the fit. (u_2-utol_2, u_2+utol_2)
- plot_resultbool
True to show how the program fitted the traces.
- Returns:
- Idict
Computed integrals. The keys are
'<ppm f1>:<ppm f2>'with 2 decimal figures.
- klassez.anal.integrate_p2D(ppm0, data0, SFO1, ref=0, indirect_scale=None, filename='integrals', X_label='$\\delta\\,$F1 /ppm', dx=1)[source]
Allows interactive integration of a (series of) NMR spectrum through a dedicated GUI. Returns the values as a dictionary, where the keys are the selected regions truncated to the 3nd decimal figure. The values are saved in the
<filename>.igrlfile.In the GUI, draw the integration region around the peak. The shape of the integral function appears in red in that region, and the value of the integral is reported under the “current integral” label on the right side. Both are referred to the
ref-th row ofdata. The trend of the integrals appear in the inset plot at the bottom left corner. The integral can be corrected with a baseline, that is the straight line that connects the border of the integration window. It can be activated and deactivated using the checkbox on the right side. Press “ADD” to save the integral values. Upon pressing, the integral function becomes green and the value appears on top of the figure. To remove an integral from the list, first click on the corresponding value on the top to select it: the number and the integral function should become purple. Then, click on the “REMOVE” button. Use the right click to reset the selection.At the end of the procedure, click on the “SAVE” button to write the .igrl file.
- Parameters:
- ppm1darray
PPM scale of the spectrum
- data1darray
Spectrum to be integrated.
- SFO1float
Larmor frequency of the observed nucleus. For conversion to the correct integration scale.
- refint
Index of the transient to be used as reference when drawing the functions
- indirect_scale1darray
Scale of the indirect dimension, if any. If
None, 1, 2, 3 … are used.- filenamestr
Name for the .igrl file to be written. Without extension!
- X_labelstr
Label of the x-axis
- dxfloat
Correction for the integral values. It should be
dx = 2 * dw
- Returns:
- abs_valsdict
Dictionary containing the values of the integrated peaks.
See also
- klassez.anal.noise_std(y)[source]
Calculates the standard deviation of the noise using the Bruker formula:
Taken \(y\) as an array of \(N\) points, and \(y[i]\) its i-th entry:
\[\sigma_N = \frac{1}{\sqrt{r-1}} \sqrt{ \sum_{k=0}^{r-1} (y[k]^2) - \frac{1}{r} [ ( \sum_{k=0}^{r-1} y[k] )^2 + \frac{3}{r^2 -1}( \sum_{k=0}^{r / 2 - 1} (k+1) (y[r/ 2 + k] - y[r/ 2 - k -1 ] ) )^2 ] }\]- Parameters:
- y1darray
The spectral region you would like to use to calculate the standard deviation of the noise.
- Returns:
- noisestdfloat
The standard deviation of the noise.
- klassez.anal.read_igrl(filename, n=-1)[source]
Reads a .igrl file, containing the integrals of either one or a series of spectra. The file is separated and unpacked into a dictionary, each of which contains the integration windows with three decimal figures as keys and the integrals as their associated value. If present, the indirect timescale is also read and returned.
- 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:
- dicdict
Integrals
- indirect_scale1darray or None
If there is a line that starts with
'x = ', it is interpreted as the scale for the indirect dimension. If there is not,Noneis returned.
See also
klassez.fit.write_igrl()
- klassez.anal.select_for_integration(ppm_f1, ppm_f2, data, Neg=True)[source]
Select the peaks of a 2D spectrum to integrate. First, select the area where your peak is located by dragging the red square. Then, select the center of the peak by right_clicking. Finally, click ‘ADD’ to store the peak. Repeat the procedure for as many peaks as you want.
- Parameters:
- ppm_f11darray
ppm scale of the indirect dimension
- ppm_f21darray
ppm scale of the direct dimension
- data2darray
Spectrum
- Negbool
Choose if to show the negative contours ( True) or not ( False )
- Returns:
- peakslist of dict
For each peak there are two keys, ‘f1’ and ‘f2’, whose meaning is obvious. For each of these keys, you have ‘u’: center of the peak /ppm, and ‘lim’: the limits of the square you drew before.
- klassez.anal.select_traces(ppm_f1, ppm_f2, data, Neg=True)[source]
Select traces from a 2D spectrum, save the coordinates in a list. Left click to select a point, right click to remove it.
- Parameters:
- ppm_f11darray
ppm scale of the indirect dimension
- ppm_f21darray
ppm scale of the direct dimension
- data2darray
Spectrum
- Negbool
Choose if to show the negative contours ( True) or not ( False )
- Returns:
- coordlist
List containing the
[x,y]coordinates of the selected points.
- klassez.anal.snr(x, data, s_reg=None, n_reg=None, gui=False)[source]
Computes the signal to noise ratio of a 1D spectrum as height of the signal over twice the noise standard deviation. If you are not sure about what to put into
s_regandn_reg, use the interactive interface by settinggui=True. The values will be suggested.- Parameters:
- x1darray
Scale of the spectrum to use. The values in
n_regare searched according to this scale- data1darray
The spectrum of which you want to compute the SNR
- s_regfloat or tuple
If
float, uses this value as maximum signal. Iftuple, the maximum value within thes_regregion is used as maximum signal. In this case, the limits of such region must be given according tox. IfNone, it is selected as the maximum value indata- n_reglist or tuple, optional
If provided, contains the points that delimit the noise region. Otherwise, the whole spectrum is used.
- guibool
Set it to
Trueto ignores_regandn_reg, and use the GUI for the interactive estimation.
- Returns:
- snrfloat
The SNR of the spectrum
- klassez.anal.snr_2D(x_f1, x_f2, data, s_reg=None, n_reg=None, gui=False)[source]
Computes the signal to noise ratio of a 2D spectrum as the height of the signal divided by twice the standard deviation of the noise, for each dimension. If you are not sure about what to put into
s_regandn_reg, use the interactive interface by settinggui=True. The values will be suggested.- Parameters:
- x_f11darray
PPM scale of the spectrum for the indirect dimension
- x_f21darray
PPM scale of the spectrum for the direct dimension
- data2darray
Spectrum of which you want to compute the SNR
- s_regfloat or list of tuple
If
float, uses this value as maximum signal. IfNone, it is selected as the maximum value indataOtherwise, you have to provide the limits to draw a rectangle ondataas[(f2_sx, f2_dx), (f1_sx, f1_dx)]; the maximum signal is the highest point within this region.- n_reglist or tuple
Contains the coordinates at which to extract empty traces for the evaluation of the noise standard deviation. It should be provided as
[v2, v1], meaning that the noise-only trace of the indirect dimension will be taken atv2onx_f2, and the noise-only trace of the direct dimension will be taken atv1onx_f1. Leaving this parameter anNonewill open the interactive panel, and thuss_regwill be ignored.- guibool
Set it to
Trueto ignores_regandn_reg, and use the GUI for the interactive estimation.
- Returns:
- snr_f1float
The SNR of the indirect dimension
- snr_f2float
The SNR of the direct dimension
- klassez.anal.snr_gui(x, y)[source]
GUI for the evaluation of the Signal to Noise Ratio of a 1D spectrum.
Select “Signal” on the top right corner and drag a region to highlight the reference signal approximate position. The detected point appears as a blue X.
Then, select “Noise”. Drag a signal-free region, i.e. where there is only noise. This will be used for the estimation of the noise standard deviation. The noise level will be highlighted in the figure by two red dashed lines. If these lines do not visually match the noise level, it is most likely there is a signal included in the noise region.
When both the signal and the noise are present, the SNR will be computed. The selection can be refined as many times as one wants, until the figure panel is closed. Close the figure to return the values, and to print the used
s_regandn_regto be given toklassez.anal.snr().- Parameters:
- x1darray
PPM scale of the spectrum
- y1darray
Spectrum
- Returns:
- snrfloat
Estimated signal to noise ratio.
- klassez.anal.snr_gui_2D(x_f1, x_f2, yy)[source]
GUI for the evaluation of the Signal to Noise Ratio of a 2D spectrum.
Select “Signal” on the top right corner and drag a rectangle to highlight the reference signal height. The detected point appears as a blue X.
Then, select “Noise”. A red cross-cursor will appear. Find a position where you can extract a signal-free region, i.e. where there is only noise. Double click with the left button of the mouse to extract the projection in that point: they will appear as red traces. These will be used for the estimation of the noise standard deviation.
When both the signal and the noise are present, the SNR will be computed. The selection can be refined as many times as one wants, until the figure panel is closed. Close the figure to return the values, and to print the used
s_regandn_regto be given toklassez.anal.snr_2D().- Parameters:
- x_f11darray
PPM scale of the spectrum for the indirect dimension
- x_f21darray
PPM scale of the spectrum for the direct dimension
- yy2darray
Spectrum
- Returns:
- snr_f1float
Estimated signal to noise ratio in the indirect dimension.
- snr_f2float
Estimated signal to noise ratio in the direct dimension.
- klassez.anal.write_igrl(filename, dic, indirect_scale=None, header=False)[source]
Write a section in a integral report file, which shows the integrated regions and the values of the peaks. It allows
- Parameters:
- filenamestr
Path to the file to be written
- dicdict
Dictionary of integral values. The keys are ‘ppm1:ppm2’ and the associated values are the integrals, as floats or as sequences.
- indirect_scale1darray
Scale of the indirect dimension. To be used in the future for fitting
- headerbool
If True, adds a “!” starting line to separate fit trials
- Returns:
- None