Public API reference¶
The SpectroChemPy API publicly exposes many objects and functions. They are listed below exhaustively. What is not listed here is reserved for developers and should not normally be necessary for normal use of SpectroChemPy .
Table of Contents
Loading the API¶
To use the API, you must import it using one of the following syntax:
In [1]: import spectrochempy as scp # Recommended!
In [2]: nd = scp.NDDataset()
In [3]: from spectrochempy import *
In [4]: nd = NDDataset()
With the second syntax, as often in python, the access to objects/functions can be greatly simplified. For example,
we can use NDDataset
without a prefix instead of scp.NDDataset
which is the first syntax) but there is always a risk
of overwriting some variables or functions already present in the namespace. Therefore, the first syntax is generally
highly recommended.
The NDDataset Object¶
The NDDataset is the main object use by SpectroChemPy .
Like numpy ndarrays, NDDataset have the capability to be sliced, sorted and subject to mathematical operations.
But, in addition, NDDataset may have units, can be masked and each dimension can also have coordinated with units. This make NDDataset aware of unit compatibility, e.g.,, for binary operation such as additions or subtraction or during the application of mathematical operations. In addition or in replacement of numerical data for coordinates, NDDataset can also have labeled coordinates where labels can be different kinds of objects (strings, datetime, numpy nd.ndarray or other NDDatasets, etc…).
This offers a lot of flexibility in using NDDatasets that, we hope, will be useful for applications. See the Tutorials for more information about such possible applications.
The main N-dimensional dataset class used by SpectroChemPy . |
Creating NDDataset¶
A NDDataset
can be created using the NDDataset
class constructor, for instance here we create a dataset from a
random two-dimensional array:
In [5]: import numpy as np
In [6]: X = np.random.random((4,4))
In [7]: nd = NDDataset(X)
The above code in SpectroChemPy can be simplified using the random
creation method:
In [8]: X = NDDataset.random((4,4))
(see the User’s Guide for a large set of examples on how to use this constructor.)
Many SpectroChemPy methods mimics numpy equivalent, but output a NDDataset object.
Basic creation methods¶
Return a new |
|
Return a new |
|
Return a new |
|
Return a new |
|
Return a new uninitialized |
|
Return a |
|
Return |
|
Return a |
|
Return a 2-D array with ones on the diagonal and zeros elsewhere. |
|
Return the identity |
|
Return random floats in the half-open interval [0.0, 1.0). |
|
Extract a diagonal or construct a diagonal array. |
Creation from existing data¶
Make a disconnected copy of the current object. |
|
Construct a nddataset by executing a function over each coordinate. |
|
Create a new 1-dimensional array from an iterable object. |
Creation from numerical ranges¶
Return evenly spaced values within a given interval. |
|
Return evenly spaced numbers over a specified interval. |
|
Return numbers spaced evenly on a log scale. |
|
Return numbers spaced evenly on a log scale (a geometric progression). |
Creation from from external sources¶
Open data from a '*.scp' (NDDataset) or '.pscp' (Project) file. |
|
Generic read method. |
|
Open .spa files in a directory after a carroucell experiment. |
|
Open a Surface Optics Corps. |
|
Read an entire directory. |
|
Open a Surface Optics Corps. |
|
Open Infrared JCAMP-DX files with extension |
|
Read a single Raman spectrum or a series of Raman spectra. |
|
Read a matlab file with extension |
|
Read a matlab file with extension |
|
Open a Thermo Nicolet OMNIC file. |
|
Open Bruker OPUS file(s). |
|
Read a Pfeiffer Vacuum's QUADERA® mass spectrometer software file with extension |
|
Download and read files or an entire directory on github spectrochempy_data repository. |
|
Open a Surface Optics Corps. |
|
Open a Surface Optics Corps. |
|
Open a Thermo Nicolet file or a list of files with extension |
|
Open a Thermo Nicolet file or a list of files with extension |
|
Open a Thermo Nicolet file or a list of files with extension |
|
Open a Thermo Nicolet file or a list of files with extension |
|
Open Bruker TOPSPIN (NMR) dataset. |
|
Open a zipped list of data files. |
|
Open .spa files in a directory after a carroucell experiment. |
|
Upload IR spectra from NIST webbook |
Export a NDDataset¶
Save the current object in SpectroChemPy format. |
|
Write the current dataset. |
|
Write a dataset in CSV format. |
|
This method is an alias of |
|
This method is an alias of |
|
This method is an alias of |
|
This method is an alias of |
|
This method is an alias of |
|
This method is an alias of |
|
Return a numpy masked array. |
|
Convert a NDDataset instance to an |
Select data in a NDDataset¶
Take elements from an array. |
Plotting functions¶
Generic plot function. |
|
Plot of one-dimensional data. |
|
Plot a 1D dataset with solid pen by default. |
|
Plot a 1D dataset as a scatter plot (points can be added on lines). |
|
Plot a 1D dataset with solid pen by default. |
|
Plot a 2D dataset as a stacked plot with its transposition in a second axe. |
|
Plot a 1D dataset with bars. |
|
Plot of 2D array. |
|
Plot a 2D dataset as a contoured map. |
|
Plot a 2D dataset as a stack plot. |
|
Plot a 2D dataset as an image plot. |
|
Plot of 2D array as 3D plot |
|
Plot a 2D dataset as a a 3D-surface. |
|
Plot a 2D dataset as a a 3D-waterfall plot. |
|
Plot a series of 1D datasets as a scatter plot with optional lines between markers. |
|
Generate a figure with multiple axes arranged in array (n rows, n columns). |
|
Plot a multiplot with 2D image type plots. |
|
Plot a multiplot with 1D linetype plots. |
|
Plot a multiplot with 2D map type plots. |
|
Plot a multiplot with 1D scatter type plots. |
|
Plot a multiplot with 2D stack type plots. |
|
Plot a 2D dataset as a stacked plot with its transposition in a second axe. |
|
Method to force the |
Processing¶
Transpose-like oprations¶
Permute the dimensions of a NDDataset. |
|
Transposed |
|
Interchange two dimensions of a NDDataset. |
Changing number of dimensions¶
Remove single-dimensional entries from the shape of a NDDataset. |
Changing type¶
Set the object data as complex. |
|
Alias of set_quaternion. |
|
Alias of set_quaternion. |
Joining or splitting datasets¶
Concatenation of |
|
Stack of |
Indexing¶
Extract a diagonal or construct a diagonal array. |
|
Return the diagonal of a 2D array. |
|
Take elements from an array. |
Sorting¶
Return the dataset sorted along a given dimension. |
Minimum and maximum¶
Indexes of minimum of data along axis. |
|
Indexes of maximum of data along axis. |
|
Find oordinates of the mainimum of data along axis. |
|
Find coordinates of the maximum of data along axis. |
|
Return the maximum of the dataset or maxima along given dimensions. |
|
Return the maximum of the dataset or maxima along given dimensions. |
|
Return the maximum of the dataset or maxima along given dimensions. |
|
Return the maximum of the dataset or maxima along given dimensions. |
|
Range of values (maximum - minimum) along a dimension. |
Clipping and rounding¶
Clip (limit) the values in a dataset. |
|
Evenly round to the given number of decimals. |
|
Evenly round to the given number of decimals. |
Algebra¶
Return the dot product of two NDDatasets. |
|
Performs a Singular Value Decomposition of a dataset. |
|
Least-squares solution to a linear matrix equation. |
|
Least-squares solution to a linear matrix equation with non-negativity constraints. |
Logic functions¶
Test whether all array elements along a given axis evaluate to True. |
|
Test whether any array element along a given axis evaluates to True. |
Sums, integal, difference¶
Sum of array elements over a given axis. |
|
Return the cumulative sum of the elements along a given axis. |
|
An alias of |
|
Integrate using the composite trapezoidal rule. |
|
Integrate using the composite Simpson's rule. |
Complex¶
The array with real component of the |
|
The array with imaginary component of the |
|
The array with real component in both dimension of hypercomplex 2D |
|
The array with real-imaginary component of hypercomplex 2D |
|
The array with imaginary-real component of hypercomplex 2D |
|
The array with imaginary-imaginary component of hypercomplex 2D data. |
|
Take selected components of an hypercomplex array (RRR, RIR, ...). |
|
Conjugate of the NDDataset in the specified dimension. |
|
Conjugate of the NDDataset in the specified dimension. |
|
Calculate the absolute value of the given NDDataset element-wise. |
|
Calculate the absolute value of the given NDDataset element-wise. |
Masks¶
Remove all masks previously set on this array. |
Units manipulation¶
Return the object with data rescaled to different units. |
|
Return an array rescaled to base units. |
|
Return an array scaled in place to reduced units. |
|
Inplace scaling to different units. |
|
Inplace rescaling to base units. |
|
Quantity scaled in place to reduced units, inplace. |
|
Check the compatibility of units with another object. |
|
Set a NMR context relative to the given Larmor frequency. |
mathematical operations¶
Modulus calculation. |
|
Power spectrum. |
Statistical operations¶
Compute the arithmetic mean along the specified axis. |
|
Compute the weighted average along the specified axis. |
|
Compute the standard deviation along the specified axis. |
|
Sum of array elements over a given axis. |
|
Compute the variance along the specified axis. |
Baseline correction¶
Baseline Correction processor. |
|
Launch a GUI for baseline corrections. |
|
Automatic subtraction of a reference to the dataset. |
|
Alias of |
|
Automatic baseline correction. |
|
Compute a baseline correction using the BaselineCorrection processor. |
|
Remove linear trend along dim from dataset. |
|
Time domain baseline correction. |
Fourier transform¶
Apply a complex fast fourier transform. |
|
Apply a inverse fast fourier transform. |
|
Hilbert transform. |
|
Frequency shift by Fourier transform. |
|
Frequency Shift by Fourier transform. |
Zero-filling¶
Zero fill to given size. |
|
Zero fill to next largest power of two. |
|
Zero fill by doubling original data size once or multiple times. |
|
Zero fill to given size. |
Rolling¶
Circular shift. |
|
Left shift and zero fill. |
|
Roll dimensions. |
|
Right shift and zero fill. |
Phasing¶
Linear phase correction. |
|
Exponential Phase Correction. |
Smoothing, apodization¶
Apply a Savitzky-Golay filter to a NDDataset. |
|
Smooth the data using a window with requested size. |
|
Calculate Bartlett apodization (triangular window with end points at zero). |
|
Calculate a minimum 4-term Blackman-Harris apodization. |
|
Calculate generalized Hamming (== Happ-Genzel) apodization. |
|
Calculate generalized Hamming apodization. |
|
Return a Hann window. |
|
Calculate triangular apodization with non-null extremities and maximum value normalized to 1. |
|
Calculate exponential apodization. |
|
Calculate lorentz-to-gauss apodization. |
|
Calculate apodization with a Sine window multiplication. |
|
Strictly equivalent to |
|
Equivalent to |
|
Equivalent to |
Alignment, interpolation¶
Align individual |
|
Miscellaneous¶
Fitting¶
Fit a 1D or 2D dataset, or a list of datasets. |
|
This class allow some manipulation of the parameter list for modelling. |
|
Allow passing a dictionary of parameters with additional properties to the fit function. |
|
Use non-linear least squares to fit a function, |
|
Least-squares solution to a linear matrix equation. |
|
Least-squares solution to a linear matrix equation with non-negativity constraints. |
Fitting models¶
Normalized 1D gaussian function. |
|
A standard Lorentzian function (also known as the Cauchy distribution). |
|
A Voigt model constructed as the convolution of a |
|
An asymmetric Voigt model. |
|
A Sigmoid function. |
|
Arbitrary-degree polynomial (degree limited to 10, however). |
Analysis¶
Wrapper and extension of scpy.signal.find_peaks(). |
|
Evolving Factor Analysis. |
|
Principal Component Analysis. |
|
Performs a Non Negative Matrix Factorization of a |
|
SIMPLe to use Interactive Self-modeling Mixture Analysis. |
|
Performs MCR-ALS of a dataset knowing the initial C or St matrix. |
|
Integral inversion solver for spectroscopic data. |
|
Compute kernel of Fredholm equation of the 1st kind. |
Project management¶
A manager for projects, datasets and scripts. |
Scripting¶
This is rather experimental
Executable scripts. |
|
Execute a given project script in the current context. |
|
Execute all scripts in a project following their priority. |
Utilities¶
Logging¶
Formatted debug message. |
|
Formatted info message. |
|
Formatted warning message. |
|
Formatted error message. |
Misc¶
print the versions of spectrochempy and its dependencies |
File¶
IPyWidgets interface for picking files. |
|
Clean a path or a series of path in order to be compatible with windows and unix-based system. |