Basic Data Objects¶
-
class
nmrpy.data_objects.
Fid
(*args, **kwargs)[source]¶ The basic FID (Free Induction Decay) class contains all the data for a single spectrum (
data
), and the necessary methods to process these data.-
baseline_correct
(deg=2)[source]¶ Perform baseline correction by fitting specified baseline points (stored in
_bl_ppm
) with polynomial of specified degree (stored in_bl_ppm
) and subtract this polynomial fromdata
.Parameters: deg – degree of fitted polynomial
-
baseliner
()[source]¶ Instantiate a baseline-correction GUI widget. Right-click-dragging defines a range. Ctrl-Right click deletes previously selected range. Indices selected are stored in
_bl_ppm
, which is used for baseline-correction (seebaseline_correction()
).
-
data
¶ The spectral data. This is the primary object upon which the processing and analysis functions work.
-
deconv
(method='leastsq', frac_gauss=0.0)[source]¶ Deconvolute
data
object by fitting a series of peaks to the spectrum. These peaks are generated using the parameters inpeaks
.ranges
splitsdata
up into smaller portions. This significantly speeds up deconvolution time.Parameters: - frac_gauss – (0-1) determines the Gaussian fraction of the peaks. Setting this argument to None will fit this parameter as well.
- method –
The fitting method to use. Default is ‘leastsq’, the Levenberg-Marquardt algorithm, which is usually sufficient. Additional options include:
Nelder-Mead (nelder)
L-BFGS-B (l-bfgs-b)
Conjugate Gradient (cg)
Powell (powell)
Newton-CG (newton)
-
deconvoluted_integrals
¶ An array of integrals for each deconvoluted peak.
-
emhz
(lb=5.0)[source]¶ Apply exponential line-broadening to data array
data
.Parameters: lb – degree of line-broadening in Hz.
-
classmethod
from_data
(data)[source]¶ Instantiate a new
Fid
object by providing a spectral data object as argument. Eg.fid = Fid.from_data(data)
-
ft
()[source]¶ Fourier Transform the data array
data
.Calculates the Discrete Fourier Transform using the Fast Fourier Transform algorithm as implemented in NumPy (Cooley, James W., and John W. Tukey, 1965, ‘An algorithm for the machine calculation of complex Fourier series,’ Math. Comput. 19: 297-301.)
-
peakpick
(thresh=0.1)[source]¶ Attempt to automatically identify peaks. Picked peaks are assigned to
peaks
.Parameters: thresh – fractional threshold for peak-picking
-
peakpicker
()[source]¶ Instantiate a peak-picking GUI widget. Left-clicking selects a peak. Right-click-dragging defines a range. Ctrl-left click deletes nearest peak; ctrl-right click deletes range. Peaks are stored in
peaks
; ranges are stored inranges
: both are used for deconvolution (seedeconv()
).
-
phase_correct
(method='leastsq')[source]¶ Automatically phase-correct
data
by minimising total absolute area.Parameters: method – The fitting method to use. Default is ‘leastsq’, the Levenberg-Marquardt algorithm, which is usually sufficient. Additional options include:
Nelder-Mead (nelder)
L-BFGS-B (l-bfgs-b)
Conjugate Gradient (cg)
Powell (powell)
Newton-CG (newton)
-
plot_deconv
(**kwargs)[source]¶ Plot
data
with deconvoluted peaks overlaid.Parameters: - upper_ppm – upper spectral bound in ppm
- lower_ppm – lower spectral bound in ppm
- lw – linewidth of plot
- colour – colour of the plot
- peak_colour – colour of the deconvoluted peaks
- residual_colour – colour of the residual signal after subtracting deconvoluted peaks
-
plot_ppm
(**kwargs)[source]¶ Plot
data
.Parameters: - upper_ppm – upper spectral bound in ppm
- lower_ppm – lower spectral bound in ppm
- lw – linewidth of plot
- colour – colour of the plot
-
-
class
nmrpy.data_objects.
FidArray
(*args, **kwargs)[source]¶ This object collects several
Fid
objects into an array, and it contains all the processing methods necessary for bulk processing of these FIDs. It should be considered the parent object for any project. The class methodsfrom_path()
andfrom_data()
will instantiate a newFidArray
object from a Varian/Bruker .fid path or an iterable of data respectively. EachFid
object in the array will appear as an attribute ofFidArray
with a unique ID of the form ‘fidXX’, where ‘XX’ is an increasing integer .-
add_fid
(fid)[source]¶ Add an
Fid
object to thisFidArray
, using a unique id.Parameters: fid – an Fid
instance
-
add_fids
(fids)[source]¶ Add a list of
Fid
objects to thisFidArray
.Parameters: fids – a list of Fid
instances
-
baseline_correct_fids
(deg=2)[source]¶ Apply baseline-correction to all
Fid
objects owned by thisFidArray
Parameters: deg – degree of the baseline polynomial (see baseline_correct()
)
-
baseliner_fids
()[source]¶ Instantiate a baseline-correction GUI widget. Right-click-dragging defines a range. Ctrl-Right click deletes previously selected range. Indices selected are stored in
_bl_ppm
, which is used for baseline-correction (seebaseline_correction()
).
-
deconv_fids
(mp=True, cpus=None, method='leastsq', frac_gauss=0.0)[source]¶ Apply deconvolution to all
Fid
objects owned by thisFidArray
, using thepeaks
andranges
attribute of each respectiveFid
.Parameters: - method – see
phase_correct()
- mp – parallelise the phasing process over multiple processors, significantly reduces computation time
- cpus – defines number of CPUs to utilise if ‘mp’ is set to True, default is n-1 cores
- method – see
-
deconvoluted_integrals
¶ Collected
deconvoluted_integrals
-
del_fid
(fid_id)[source]¶ Delete an
Fid
object belonging to thisFidArray
, using a unique id.Parameters: fid_id – a string id for an Fid
-
emhz_fids
(lb=5.0)[source]¶ Apply line-broadening (apodisation) to all
nmrpy.~data_objects.Fid
objects owned by thisFidArray
Parameters: lb – degree of line-broadening in Hz.
-
classmethod
from_data
(data)[source]¶ Instantiate a new
FidArray
object from a 2D data set of spectral arrays.Parameters: data – a 2D data array
-
classmethod
from_path
(fid_path='.', file_format=None)[source]¶ Instantiate a new
FidArray
object from a .fid directory.Parameters: - fid_path – filepath to .fid directory
- file_format – ‘varian’ or ‘bruker’, usually unnecessary
-
ft_fids
(mp=True, cpus=None)[source]¶ Fourier-transform all FIDs.
Parameters: - mp – parallelise over multiple processors, significantly reducing computation time
- cpus – defines number of CPUs to utilise if ‘mp’ is set to True
-
get_fid
(id)[source]¶ Return an
Fid
object owned by this object, identified by unique ID. Eg.:fid12 = fid_array.get_fid('fid12')
Parameters: id – a string id for an Fid
-
get_integrals_from_traces
()[source]¶ Returns a dictionary of integral values for all
Fid
objects calculated from trace dictionaryintegral_traces
.
-
get_masked_integrals
()[source]¶ After peakpicker_traces() and deconv_fids() this function returns a masked integral array.
-
integral_traces
¶ Returns the dictionary of integral traces generated by
select_integral_traces()
.
-
peakpicker
(fid_number=None, assign_only_to_index=True, voff=0.02)[source]¶ Instantiate peak-picker widget for
data
, and apply selectedpeaks
andranges
to allFid
objects owned by thisFidArray
. Seepeakpicker()
.Parameters:
-
peakpicker_traces
(voff=0.02, lw=1)[source]¶ Instantiates a widget to pick peaks and ranges employing a polygon shape (or ‘trace’). This is useful for picking peaks that are subject to drift and peaks that appear (or disappear) during the course of an experiment.
Parameters: - voff – vertical offset fraction (0.01)
- lw – linewidth of plot (1)
-
phase_correct_fids
(method='leastsq', mp=True, cpus=None)[source]¶ Apply automatic phase-correction to all
Fid
objects owned by thisFidArray
Parameters: - method – see
phase_correct()
- mp – parallelise the phasing process over multiple processors, significantly reducing computation time
- cpus – defines number of CPUs to utilise if ‘mp’ is set to True
- method – see
-
plot_array
(**kwargs)[source]¶ Plot
data
.Parameters: - upper_index – upper index of array (None)
- lower_index – lower index of array (None)
- upper_ppm – upper spectral bound in ppm (None)
- lower_ppm – lower spectral bound in ppm (None)
- lw – linewidth of plot (0.5)
- azim – starting azimuth of plot (-90)
- elev – starting elevation of plot (40)
- filled – True=filled vertices, False=lines (False)
- show_zticks – show labels on z axis (False)
- labels – under development (None)
- colour – plot spectra with colour spectrum, False=black (True)
- filename – save plot to .pdf file (None)
-
plot_deconv_array
(**kwargs)[source]¶ Plot all
data
with deconvoluted peaks overlaid.Parameters: - upper_index – upper index of Fids to plot
- lower_index – lower index of Fids to plot
- upper_ppm – upper spectral bound in ppm
- lower_ppm – lower spectral bound in ppm
- data_colour – colour of the plotted data (‘k’)
- summed_peak_colour – colour of the plotted summed peaks (‘r’)
- residual_colour – colour of the residual signal after subtracting deconvoluted peaks (‘g’)
- data_filled – fill state of the plotted data (False)
- summed_peak_filled – fill state of the plotted summed peaks (True)
- residual_filled – fill state of the plotted residuals (False)
- figsize – [x, y] size of plot ([15, 7.5])
- lw – linewidth of plot (0.3)
- azim – azimuth of 3D axes (-90)
- elev – elevation of 3D axes (20)
-
ps_fids
(p0=0.0, p1=0.0)[source]¶ Apply manual phase-correction to all
Fid
objects owned by thisFidArray
Parameters: - p0 – Zero order phase in degrees
- p1 – First order phase in degrees
-
save_to_file
(filename=None)[source]¶ Save
FidArray
object to file, including all objects owned.Parameters: filename – filename to save FidArray
to
-
select_integral_traces
(voff=0.02, lw=1)[source]¶ Instantiate a trace-selection widget to identify deconvoluted peaks. This can be useful when data are subject to drift. Selected traces on the data array are translated into a set of nearest deconvoluted peaks, and saved in a dictionary:
integral_traces
.Parameters: - voff – vertical offset fraction (0.01)
- lw – linewidth of plot (1)
-
t
¶ An array of the acquisition time for each FID.
-