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
.
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 * # strongly discouraged
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.
However instead of the second syntax, one can always use the following way to import objects or functions:
In [5]: from spectrochempy import NDDataset
In [6]: nd = NDDataset()
The NDDataset Object
The NDDataset
is the main object use by SpectroChemPy
.
Like numpy.ndarray
s, 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 User’s Guide & Tutorials for more information about such possible applications.
The main N-dimensional dataset class used by |
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 [7]: import numpy as np
In [8]: X = np.random.random((4,4))
In [9]: nd = NDDataset(X)
The above code in SpectroChemPy
can be simplified using the random
creation method:
In [10]: X = NDDataset.random((4,4))
(see the User’s Guide & Tutorials 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). |
Select data in a NDDataset
Take elements from an array. |
Import/export
Import a NDataset from external source
Open data from a '.scp' (NDDataset) or '.pscp' (Project) file. |
|
Read data from various file formats. |
|
Open |
|
Open a |
|
Open a Surface Optics Corps. |
|
Read an entire directory. |
|
Open a Surface Optics Corps. |
|
Open Infrared |
|
Read a single Raman spectrum or a series of Raman spectra. |
|
Read a single Raman spectrum or a series of Raman spectra. |
|
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 |
|
Open a Surface Optics Corps. |
|
Read a Surface Optics Corps. |
|
Open a Thermo Nicolet file or a list of files with extension |
|
Read GRAMS/Thermo Scientific Galactic files 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 |
|
Upload the classical "iris" dataset. |
|
Upload IR spectra from NIST webbook. |
Export a NDDataset
Save dataset in native .scp format. |
|
Save the current NDDataset in SpectroChemPy format (.scp). |
|
Write the current dataset. |
|
Write a dataset in CSV format. |
|
This method is an alias of |
|
Write a dataset in JCAMP-DX format. |
|
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 |
Plotting
Plot the dataset using the specified method. |
|
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. |
|
Force the |
Processing
Transpose-like operations
Permute the dimensions of a NDDataset. |
|
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. |
|
Singular Value Decomposition (SVD). |
|
Ordinary least squares Linear Regression (LSTSQ). |
|
Non-Negative least squares Linear Regression (NNLS). |
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. |
|
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. |
|
Compute a baseline using the Baseline class processor. |
|
Compute a baseline corrected dataset using the Baseline class processor. |
|
Remove polynomial trend along a dimension from dataset. |
|
Asymmetric Least Squares Smoothing baseline correction. |
|
Perform Simple Non-Iterative Peak (SNIP) detection algorithm. |
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. |
Phasing
Linear phase correction. |
|
Exponential Phase Correction. |
Time-domain processing
Offset correction
Time domain baseline correction. |
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. |
Apodization
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 |
Smoothing, filtering, denoising
Filters/smoothers processor. |
|
Savitzky-Golay filter. |
|
Smooth the data using a window with requested size. |
|
Smooth the data using the Whittaker smoothing algorithm. |
|
Denoise the data using a PCA method. |
|
Remove spikes from the data. |
Alignment, interpolation
Align individual |
|
Miscellaneous
Apply func(self, *args, **kwargs). |
Analysis
Linear regression
Ordinary least squares Linear Regression (LSTSQ). |
|
Non-Negative least squares Linear Regression (NNLS). |
Non-linear optimization and curve fit
Non-linear Least-Square Optimization and Curve-Fitting. |
Partial Least Square regression
Partial Least Squares regression (PLSRegression). |
Evolving factor analysis
Evolving Factor Analysis (EFA). |
Integral inversion solver for spectroscopic data
Integral inversion solver for spectroscopic data (IRIS). |
|
Define a kernel matrix of Fredholm equation of the 1st kind. |
Multivariate Curve Resolution - Alternating Least Squares
Multivariate Curve Resolution Alternating Least Squares (MCRALS). |
Independant Component Analysis
Fast algorithm for Independent Component Analysis (FastICA). |
Non-Negative Matrix Factorization
Non-Negative Matrix Factorization (NMF). |
Singular value decomposition and Principal component analysis
Principal Component Anamysis (PCA). |
|
Singular Value Decomposition (SVD). |
SIMPLe to use Interactive Self-modeling Mixture Analysis
SIMPLe to use Interactive Self-modeling Mixture Analysis (SIMPLISMA). |
Utilities
Lineshape 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). |
Find peaks
Find and analyze peaks in spectroscopic data with advanced filtering options. |
Kinetic
An object which stores a reaction network of elementary reactions. |
|
PFR reactor as a CSTR in series. |
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
Set the logging level for SpectroChemPy. |
|
Get current logging level. |
|
Format a debug message. |
|
Format an info message. |
|
Format a warning message. |
|
Format an 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. |