GUI Module

This package contains graphical user interfaces for doing various tasks.

klassez.gui.edit_vf(S_in, ppm_scale, regions, t_AQ, SFO1=701.125, o1p=0, filename='edited', ext='ivf')[source]

Allows for interactive modification of either initial guesses or fit results, read by .vf files.

The GUI displays the experimental spectrum in black and the total model function in blue. The already-modelled regions are highlighted by a green vertical span.

Double-click with the left button of the mouse on a region to select it: from green it will become violet. To change the limits of the region, press the “Change Window Limits” button. The highlighted region will become red, and you can drag it to adjust the position of the window limits. Press the button again to store the new values.

To edit the model of a region, after you selected it, press the “UNLOCK” button. The peaks that contribute to that region gets unpacked, and become editable. Use the slider to move between the various components, and the mouse scroll to change the model parameters. Use the “+” and “-” buttons to add or remove components. Press “LOCK” to save your modification. Press “RESET” to restore the region model as it was before pressing “UNLOCK”.

To add a new region, select the region of the spectrum you want to fit by focusing the zoom on it using the lens button. Then, press the “New Region” button, that will become yellow. Add and move the components as you would do to edit a pre-existing region. Press “LOCK” to save the new region.

To remove a region, UNLOCK it and remove all the components, then press “LOCK”. The associated green span will disappear.

At the end, press “SAVE and EXIT” to write the edited .vf file and close the GUI.

Keyboard shortcuts:

  • “increase sensitivity” : ‘>’

  • “decrease sensitivity” : ‘<’

  • mouse scroll up: ‘up arrow key’

  • mouse scroll down: ‘down arrow key’

  • “add a component”: ‘+’

  • “remove the active component”: ‘-’

  • “change component, forward”: ‘page up’

  • “change component, backward”: ‘page down’

Parameters:
S_in1darray

Experimental spectrum

ppm_scale1darray

PPM scale of the spectrum

regionlist of dict

Regions containing the starting point, as read from klassez.fit.read_vf()

t_AQ1darray

Acquisition timescale

SFO1float

Nucleus Larmor frequency /MHz

o1pfloat

Carrier frequency /ppm

filenamestr or Path

Path to the filename where to save the information. The extension (for convention, 'ivf' or .fvf) can be specified through ext

extstr

Extension for the file, so that the final filename will be <filename>.<ext>

Returns:
None
klassez.gui.gen_iguess_2D(ppm_f1, ppm_f2, tr1, tr2, u1, u2, acqus, fwhm0=100, procs=None)[source]

Generate the initial guess for the fit of a 2D signal. The employes model is the one of a 2D Voigt signal, acquired with the States-TPPI scheme in the indirect dimension (i.e. klassez.sim.t_2DVoigt()). The program allows for the inclusion of up to 10 components for the signal, in order to improve the fit. The acqus dictionary must contain the following keys:

  • t1: acquisition timescale in the indirect dimension (States)

  • t2: acquisition timescale in the direct dimension

  • SFO1: Larmor frequency of the nucleus in the indirect dimension

  • SFO2: Larmor frequency of the nucleus in the direct dimension

  • o1p: carrier position in the indirect dimension /ppm

  • o2p: carrier position in the direct dimension /ppm

The signals will be processed according to the values in the procs dictionary, if given; otherwise, they will be just zero-filled up to the data size (i.e. (len(ppm_f1), len(ppm_f2)) ).

Parameters:
ppm_f11darray

ppm scale for the indirect dimension

ppm_f21darray

ppm scale for the direct dimension

tr11darray

Trace of the original 2D peak in the indirect dimension

tr21darray

Trace of the original 2D peak in the direct dimension

u1float

Chemical shift of the original 2D peak in the indirect dimension /ppm

u2float

Chemical shift of the original 2D peak in the direct dimension /ppm

acqusdict

Dictionary of acquisition parameters

fwhm0float

Initial value for FWHM in both dimensions

procsdict

Dictionary of processing parameters

Returns:
final_parameters2darray

Matrix of dimension (# signals, 6) that contains, for each row: v1(Hz), v2(Hz), fwhm1(Hz), fwhm2(Hz), A, b

fit_intervaltuple of tuple

Fitting window. ( (left_f1, right_f1), (left_f2, right_f2) )

klassez.gui.get_region(ppmscale, S, fig_title='Region Selector')[source]

Interactively select the spectral region to be fitted. Returns the border ppm values.

Parameters:
ppmscale1darray

The ppm scale of the spectrum

S1darray

The spectrum to be trimmed

fig_titlestr

Title for the interactive figure panel

Returns:
reg_limslist of tuple

Limits on ppmscale selected by the GUI.

klassez.gui.interactive_basl_windows(ppm, data)[source]

Allows for interactive partitioning of a spectrum in windows. Double left click to add a bar, double right click to remove it. Returns the location of the red bars as a list.

Parameters:
ppm1darray

PPM scale of the spectrum

data1darray

Spectrum to be partitioned

Returns:
coordlist

List containing the coordinates of the windows, plus ppm[0] and ppm[-1]

klassez.gui.interactive_echo_param(data0)[source]

Interactive plot that allows to select the parameters needed to process a CPMG-like FID. Use the TextBox or the arrow keys to adjust the values. You can call klassez.processing.sum_echo_train() or klassez.processing.split_echo_train() by starring the return statement of this function, i.e.:

processing.sum_echo_train(data0, *interactive_echo_train(data0))

as they are in the correct order to be used in this way.

Parameters:
data0ndarray

CPMG FID

Returns:
nint

Distance between one echo and the next one

n_echoesint

Number of echoes to sum/split

i_pint

Offset points from the start of the FID

klassez.gui.interactive_fp(fid0, acqus, procs)[source]

Perform the processing of a 1D NMR spectrum interactively. The GUI offers the opportunity to test different window functions, as well as different tdeff values and final sizes. The active parameters appear as blue text.

Warning

The rendering can be very slow. Use with great care.

Error

To be checked, might not work as expected

Parameters:
fid01darray

FID to process

acqusdict

Dictionary of acquisition parameters

procsdict

Dictionary of processing parameters

Returns:
pdata1darray

Processed spectrum

procsdict

Updated dictionary of processing parameters.

klassez.gui.interactive_phase_1D(ppmscale, S, reference=None)[source]

This function allow to adjust the phase of 1D spectra interactively. Use the mouse scroll to regulate the values. Press the “Z” key to toggle between automatic and manual adjustment of the window.

Parameters:
ppmscale1darray

ppm scale of the spectrum. Used to regulate the pivot position

S1darray

Spectrum to be phased. Must be complex!

referencelist of 1darray or Spectrum_1D object

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

Returns:
phased_data1darray

Phased spectrum

final_values: tuple

(p0, p1, pivot)

klassez.gui.interactive_phase_2D(ppm_f1, ppm_f2, S, hyper=True)[source]

Interactively adjust the phases of a 2D spectrum. First select the traces you want to use as reference, then use the mouse scroll to adjust the phase angles. S must be complex or hypercomplex, so BEFORE TO UNPACK with klassez.processing.unpack_2D()

Parameters:
ppm_f11darray

ppm scale of the indirect dimension

ppm_f21darray

ppm scale of the direct dimension

S2darray

Data to be phase-adjusted

hyperbool

True if S is hypercomplex, False if S is just complex

Returns:
S2darray

Phased data

final_values_f1tuple

(p0_f1, p1_f1, pivot_f1)

final_values_f2tuple

(p0_f2, p1_f2, pivot_f2)

klassez.gui.interactive_qfil(ppm, data_in, SFO1)[source]

Interactive function to design a gaussian filter with the aim of suppressing signals in the spectrum. You can adjust position and width of the filter scrolling with the mouse.

If you want to use the frequency scale instead of the ppm one, pass the scale as ppm and set SFO1=1. When using these values for klassez.processing.qfil(), remember to pass the same scale and SFO1!

Parameters:
ppm1darray

ppm scale of the spectrum

data_in1darray

Spectrum on which to apply the filter.

SFO1float

Spectrometer Larmor frequency

Returns:
ufloat

Position of the gaussian filter /ppm

sfloat

Width of the gaussian filter (FWHM) /Hz

klassez.gui.interactive_smoothing(x, y, cmap='RdBu')[source]

Interpolate the given data with a 3rd-degree spline. Type the desired smoothing factor in the box and see the outcome directly on the figure. When the panel is closed, the smoothed function is returned.

Warning

Extremely slow rendering!!! There is a problem that must be fixed somewhen.

Parameters:
x1darray

Scale of the data

y1darray

Data to be smoothed

cmapstr

Name of the colormap to be used to represent the weights. Must be present in CM

Returns:
sx1darray

Location of the spline points

sy1darray

Smoothed y

s_ffloat

Employed smoothing factor for the spline

weights1darray

Weights vector

klassez.gui.interactive_xfb(fid0, acqus, procs, lvl0=0.1, show_cnt=True)[source]

Perform the processing of a 2D NMR spectrum interactively. The GUI offers the opportunity to test different window functions, as well as different tdeff values and final sizes. The active parameters appear as blue text. When changing the parameters, give it some time to compute.

Warning

Extremely slow rendering! Use with care

Parameters:
fid02darray

FID to process

acqusdict

Dictionary of acquisition parameters

procsdict

Dictionary of processing parameters

lvl0float

Starting level of the contours

show_cntbool

Choose if to display data using contours (True) or heatmap (False)

Returns:
pdata2darray

Processed spectrum

procsdict

Updated dictionary of processing parameters

klassez.gui.make_iguess(S_in, ppm_scale, t_AQ, SFO1=701.125, o1p=0, filename='i_guess')[source]

Creates the initial guess for a lineshape deconvolution fitting procedure, using a dedicated GUI. The GUI displays the experimental spectrum in black and the total function in blue. First, select the region of the spectrum you want to fit by focusing the zoom on it using the lens button. Then, use the “+” button to add components to the spectrum. The black column of text under the textbox will be colored with the same color of the active peak. Use the mouse scroll to adjust the parameters of the active peak. Write a number in the “Group” textbox to mark the components of the same multiplet. Group 0 identifies independent peaks, not part of a multiplet (default). The sensitivity of the mouse scroll can be regulated using the “up arrow” and “down arrow” buttons. The active peak can be changed in any moment using the slider.

The baseline can be computed first by initializing the x-scale on the selected window through the “SET BASL” button. The informer light next to the button becomes green if it is properly set. The baseline coefficients can be set with the mouse scroll analogously to any other parameter.

When you are satisfied with your fit, press “SAVE” to write the information in the output file. Then, the GUI is brought back to the initial situation, and the region you were working on will be marked with a green rectangle. You can repeat the procedure as many times as you wish, to prepare the guess on multiple spectral windows.

Keyboard shortcuts:

  • “increase sensitivity” : ‘>’

  • “decrease sensitivity” : ‘<’

  • mouse scroll up: ‘up arrow key’

  • mouse scroll down: ‘down arrow key’

  • “add a component”: ‘+’

  • “remove the active component”: ‘-’

  • “change component, forward”: ‘page up’

  • “change component, backward”: ‘page down’

Parameters:
S_in1darray

Experimental spectrum

ppm_scale1darray

PPM scale of the spectrum

t_AQ1darray

Acquisition timescale

SFO1float

Nucleus Larmor frequency /MHz

o1pfloat

Carrier frequency /ppm

filenamestr or Path

Path to the filename where to save the information. The ‘.ivf’ extension is added automatically.

Returns:
None
klassez.gui.make_iguess_P2D(S_in, ppm_scale, expno, t_AQ, SFO1=701.125, o1p=0, filename='i_guess')[source]

Creates the initial guess for a lineshape deconvolution fitting procedure of a pseudo-2D experiment, using a dedicated GUI. It will be donw on only one experiment of the whole pseudo-2D. The GUI displays the experimental spectrum in black and the total function in blue. First, select the region of the spectrum you want to fit by focusing the zoom on it using the lens button. Then, use the “+” button to add components to the spectrum. The black column of text under the textbox will be colored with the same color of the active peak. Use the mouse scroll to adjust the parameters of the active peak. Write a number in the “Group” textbox to mark the components of the same multiplet. Group 0 identifies independent peaks, not part of a multiplet (default). The sensitivity of the mouse scroll can be regulated using the “up arrow” and “down arrow” buttons. The active peak can be changed in any moment using the slider.

When you are satisfied with your fit, press “SAVE” to write the information in the output file. Then, the GUI is brought back to the initial situation, and the region you were working on will be marked with a green rectangle. You can repeat the procedure as many times as you wish, to prepare the guess on multiple spectral windows.

Keyboard shortcuts:

  • “increase sensitivity” : ‘>’

  • “decrease sensitivity” : ‘<’

  • mouse scroll up: ‘up arrow key’

  • mouse scroll down: ‘down arrow key’

  • “add a component”: ‘+’

  • “remove the active component”: ‘-’

  • “change component, forward”: ‘page up’

  • “change component, backward”: ‘page down’

Parameters:
S_in1darray

Experimental spectrum

ppm_scale1darray

PPM scale of the spectrum

expnoint

Index of experiment of the pseudo 2D on which to compute the initial guess, in python numbering

t_AQ1darray

Acquisition timescale

SFO1float

Nucleus Larmor frequency /MHz

o1pfloat

Carrier frequency /ppm

filenamestr

Path to the filename where to save the information. The ‘.ivf’ extension is added automatically.

klassez.gui.make_iguess_auto(ppm, data, SW, SFO1, o1p, filename='iguess')[source]

GUI to create a .ivf file, used as initial guess for Voigt_Fit. The computation of the peak positions and linewidths employs scipy.signal.find_peaks and scipy.signal.peak_widths, respectively. In addition, peak features may be added manually by clicking with the left button twice. Unwanted features can be removed with right clicks. If the FWHM of a peak cannot be computed automatically, a dummy FWHM of 1 Hz is assigned automatically. The file <filename>.ivf is written upon pressing the SAVE button. Press Z to activate/deactivate the cursor snap.

Parameters:
ppm1darray

PPM scale of the spectrum

data1darray

real part of the spectrum to fit

SWfloat

Spectral width /Hz

SFO1float

Nucleus Larmor Frequency /MHz

o1pfloat

Carrier position /ppm

filenamestr or Path

Path to the file where to save the initial guess. The .ivf extension is added automatically.

Returns:
None
klassez.gui.make_iguess_dosy_panel(x, label, y, model, model_args, diff_c_0=1e-10, filename='dosy_fit')[source]

Make the initial guess for the fit of a DOSY profile by using a GUI to visually adjust the value of the diffusion coefficient and the number of components to use.

The goal is to try to match the thin solid blue line to the trend of the black dots.

Use the mouse scroll to modify the values and redraw the figure. The radio buttons at the bottom will make you choose if to edit the diffusion coefficient or the fraction of the given component. The sensitivity can be modified by using the radiobutton as well (coarse/fine) or using the up/down buttons.

Use the + button to add a component. Use the - button to remove a the currently selected component. You can use the slider to change the active component. The headers above the current values of diffusion coefficient and fraction will appear of the same color as the active component.

The intensity to match the model with the experimental data is computed and applied automatically. Disabling this option will allow you to play with the values more freely. There is also the option to include an offset, however this should be used only in case of severe systematic errors during the integration procedure.

Upon pressing the “SAVE” button, a section of the <filename>.idy file will be written and the GUI will close.

Parameters:
x1darray

Independent variable for the model (usually the gradient list)

labelstr

Identifier for the region, typically the integration window or peak number

y1darray

Integrated dosy profile

modelcallable

Functional model for the DOSY profile. Signature:

def model(x, diffc, **model_args):
    return 1darray
model_argsdict of keyworded arguments

Additional parameters for model.

diff_c_0float

Default initial value for the diffusion coefficient, in m^2/s

filenamestr

The output file of the procedure will be <filename>.idy

Returns:
None
klassez.gui.make_polynomion_baseline(ppm, data, limits)[source]

Interactive baseline correction with 4th degree polynomion.

Parameters:
ppm1darray

PPM scale of the spectrum

data1darray

spectrum

limitstuple

Window limits (left, right).

Returns:
modestr

Baseline correction mode: 'polynomion' as default, 'spline' if you press the button

C_f1darray or str

Baseline polynomion coefficients, or 'callintsmooth' if you press the spline button