hqs_nmr.analysis.preprocessing

NMR spectra preprocessing routines for experimental data.

Functions

automatic_phase_correction(spectrum[, order])

Perform a phase correction of a spectrum.

crop_spectrum(spectrum[, crop_threshold, ...])

Crop the spectrum to the area where there is spectral weight.

manual_phase_correction(x, greens_function, ...)

Perform a phase correction up to arbitrary order.

prepare_experimental_data(experimental_spectrum)

Prepare experimental data for postprocessing.

remove_peak(spectrum, bounds)

Puts the intensity between the bounds to zero.

hqs_nmr.analysis.preprocessing.manual_phase_correction(x: ndarray, greens_function: ndarray, omegas_ppm: ndarray) ndarray

Perform a phase correction up to arbitrary order.

The applied phase is defined as exp(i x_0 + i x_1 omega + i x_2 omega^2 + …).

Parameters:
  • x – Vector storing the parameters for the phase correction. The correction is performed up to the order defined by the length of x.

  • greens_function – Green’s function which can be obtained via the -1j times the Hilbert transform.

  • omegas_ppm – Frequency grid associated with the spectrum.

Returns:

The phase adapted spectrum.

hqs_nmr.analysis.preprocessing.automatic_phase_correction(spectrum: datatypes.NMRExperimentalSpectrum1D, order: int = 1) datatypes.NMRExperimentalSpectrum1D

Perform a phase correction of a spectrum.

Parameters:
  • spectrum – Spectrum for which to perform a phase correction.

  • order – Order to which the phase correction should be performed. Defaults to 1 (corresponds to linear).

Returns:

Copy of the input spectrum object with the phase adapted spectrum.

hqs_nmr.analysis.preprocessing.remove_peak(spectrum: datatypes.NMRExperimentalSpectrum1D, bounds: tuple[float, float]) datatypes.NMRExperimentalSpectrum1D

Puts the intensity between the bounds to zero.

Parameters:
  • spectrum – Spectrum to adapt.

  • bounds – Bounds between which the spectrum is to be put to zero.

Returns:

Copy of the input spectrum object with the intensities within bounds put to zero.

hqs_nmr.analysis.preprocessing.crop_spectrum(spectrum: datatypes.NMRExperimentalSpectrum1D, crop_threshold: float | None = None, crop_buffer_ppm: float = 0.15) datatypes.NMRExperimentalSpectrum1D

Crop the spectrum to the area where there is spectral weight.

Parameters:
  • spectrum – Spectrum to be cropped.

  • crop_threshold – Intensities above this threshold are not cropped. If set to None, 1% of the maximum intensity is used as threshold. Defaults to None.

  • crop_buffer_ppm – On the left and right of the area identified via crop_threshold an additional buffer is employed. Defaults to 0.15.

Returns:

Copy of the input spectrum object with cropped intensities and frequencies.

hqs_nmr.analysis.preprocessing.prepare_experimental_data(experimental_spectrum: datatypes.NMRExperimentalSpectrum1D, number_spins: int | None = None, crop_threshold: float | None = None, crop_buffer_ppm: float = 0.15, order: int = 1) datatypes.NMRExperimentalSpectrum1D

Prepare experimental data for postprocessing.

Performs a baseline correction, normalization and phase correction of the data. Additionally crops the spectrum to the relevant frequency range.

The results of this method can be improved by first removing the reference and solvent peaks using for example the remove_peak method.

Parameters:
  • experimental_spectrum – Object storing the experimental spectrum.

  • number_spins – Number of spins in the molecule that coincide with the reference isotope. If defined the spectrum is normed to this number. If None the spectrum is normed to 1. Defaults to None.

  • crop_threshold – Intensities above this threshold are not cropped. If set to None, 1% of the maximum intensity is used as threshold. Defaults to None.

  • crop_buffer_ppm – On the left and right of the area identified via crop_threshold an additional buffer is employed. Defaults to 0.15.

  • order – Order to which the phase correction should be performed. Defaults to 1 (corresponds to linear).

Returns:

Object storing a copy of the experimental spectrum with the preparation steps applied.