Warning

You are reading the documentation related to the development version. Go here if you are looking for the documentation of the stable release.

spectrochempy.NDDataset

class NDDataset(data=None, coordset=None, coordunits=None, coordtitles=None, **kwargs)[source]

The main N-dimensional dataset class used by SpectroChemPy.

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 dimensions can have coordinates also 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 kind of objects (str, datetime, ndarray or other NDDataset‘s, etc…).

Parameters
  • data (array-like) – Data array contained in the object. The data can be a list, a tuple, a ndarray, a subclass of ndarray, another NDDataset or a Coord object. Any size or shape of data is accepted. If not given, an empty NDDataset will be inited. At the initialisation the provided data will be eventually cast to a ndarray. If the provided objects is passed which already contains some mask, or units, these elements will be used if possible to accordingly set those of the created object. If possible, the provided data will not be copied for data input, but will be passed by reference, so you should make a copy of the data before passing them if that’s the desired behavior or set the copy argument to True.

  • coordset (CoordSet instance, optional) – It contains the coordinates for the different dimensions of the data. if CoordSet is provided, it must specify the coord and labels for all dimensions of the data. Multiple coord‘s can be specified in a CoordSet instance for each dimension.

  • coordunits (list, optional, default: None) – A list of units corresponding to the dimensions in the order of the coordset.

  • coordtitles (list, optional, default: None) – A list of titles corresponding of the dimensions in the order of the coordset.

  • **kwargs – Optional keyword parameters (see Other Parameters).

Other Parameters
  • dtype (str or dtype, optional, default: np.float64) – If specified, the data will be cast to this dtype, else the data will be cast to float64 or complex128.

  • dims (list of str, optional) – If specified the list must have a length equal to the number od data dimensions (ndim) and the elements must be taken among x,y,z,u,v,w or t. If not specified, the dimension names are automatically attributed in this order.

  • name (str, optional) – A user-friendly name for this object. If not given, the automatic id given at the object creation will be used as a name.

  • labels (array-like of objects, optional) – Labels for the data. labels can be used only for 1D-datasets. The labels array may have an additional dimension, meaning several series of labels for the same data. The given array can be a list, a tuple, a ndarray , a ndarray-like, a NDArray or any subclass of NDArray .

  • mask (array-like of bool or NOMASK , optional) – Mask for the data. The mask array must have the same shape as the data. The given array can be a list, a tuple, or a ndarray . Each values in the array must be False where the data are valid and True when they are not (like in numpy masked arrays). If data is already a MaskedArray , or any array object (such as a NDArray or subclass of it), providing a mask here, will cause the mask from the masked array to be ignored.

  • units (Unit instance or str, optional) – Units of the data. If data is a Quantity then units is set to the unit of the data; if a unit is also explicitly provided an error is raised. Handling of units use the pint package.

  • timezone (datetime.tzinfo, optional) – The timezone where the data were created. If not specified, the local timezone is assumed.

  • title (str, optional) – The title of the data dimension. The title attribute should not be confused with the name . The title attribute is used for instance for labelling plots of the data. It is optional but recommended to give a title to each ndarray data.

  • dlabel (str, optional) – Alias of title .

  • meta (dict-like object, optional) – Additional metadata for this object. Must be dict-like but no further restriction is placed on meta.

  • author (str, optional) – Name(s) of the author(s) of this dataset. By default, name of the computer note where this dataset is created.

  • description (str, optional) – An optional description of the nd-dataset. A shorter alias is desc .

  • origin (str, optional) – Origin of the data: Name of organization, address, telephone number, name of individual contributor, etc., as appropriate.

  • roi (list) – Region of interest (ROI) limits.

  • history (str, optional) – A string to add to the object history.

  • copy (bool, optional) – Perform a copy of the passed object. Default is False.

See also

Coord

Explicit coordinates object.

CoordSet

Set of coordinates.

Notes

The underlying array in a NDDataset object can be accessed through the data attribute, which will return a conventional ndarray.

Attributes Summary

II

The array with imaginary-imaginary component of hypercomplex 2D data.

IR

The array with imaginary-real component of hypercomplex 2D data .

RI

The array with real-imaginary component of hypercomplex 2D data .

RR

The array with real component in both dimension of hypercomplex 2D data .

T

Transposed NDDataset .

acquisition_date

Acquisition date.

author

Creator of the dataset (str).

ax

The main matplotlib axe associated to this dataset.

axT

The matplotlib axe associated to the transposed dataset.

axec

Matplotlib colorbar axe associated to this dataset.

axecT

Matplotlib colorbar axe associated to the transposed dataset.

axex

Matplotlib projection x axe associated to this dataset.

axey

Matplotlib projection y axe associated to this dataset.

comment

Provides a comment (Alias to the description attribute).

coordnames

List of the Coord names.

coordset

CoordSet instance.

coordtitles

List of the Coord titles.

coordunits

List of the Coord units.

created

Creation date object (Datetime).

data

The data array.

description

Provides a description of the underlying data (str).

dimensionless

True if the data array is dimensionless - Readonly property (bool).

dims

Names of the dimensions (list).

directory

Current directory for this dataset.

divider

Matplotlib plot divider.

dtype

Return the data type.

fig

Matplotlib figure associated to this dataset.

fignum

Matplotlib figure associated to this dataset.

filename

Current filename for this dataset.

filetype

Type of current file.

has_complex_dims

True if at least one of the data array dimension is complex.

has_data

True if the data array is not empty.

has_defined_name

True is the name has been defined (bool).

has_units

True if the data array have units - Readonly property (bool).

history

Describes the history of actions made on this array (List of strings).

id

Object identifier - Readonly property (str).

imag

The array with imaginary component of the data .

is_1d

True if the data array has only one dimension (bool).

is_complex

True if the 'data' are complex (Readonly property).

is_empty

True if the data array is empty or size=0, and if no label are present.

is_float

True if the data are real values - Readonly property (bool).

is_integer

True if the data are integer values - Readonly property (bool).

is_interleaved

True if the data array is hypercomplex with interleaved data.

is_labeled

True if the data array have labels - Readonly property (bool).

is_masked

True if the data array has masked values.

is_quaternion

True if the data array is hypercomplex .

labels

An array of labels for data (ndarray of str).

limits

Range of the data.

local_timezone

Return the local timezone.

m

Data array (ndarray).

magnitude

Data array (ndarray).

mask

Mask for the data (ndarray of bool).

masked_data

The actual masked data array - Readonly property (numpy.ma.ndarray).

meta

Additional metadata (Meta).

modeldata

ndarray - models data.

modified

Date of modification (readonly property).

name

A user-friendly name (str).

ndaxes

A dictionary containing all the axes of the current figures.

ndim

The number of dimensions of the data array (Readonly property).

origin

Origin of the data.

parent

Project instance.

preferences

Meta instance object - Additional metadata.

real

The array with real component of the data .

roi

Region of interest (ROI) limits (list).

shape

A tuple with the size of each dimension - Readonly property.

size

Size of the underlying data array - Readonly property (int).

suffix

Filename suffix.

timezone

Return the timezone information.

title

An user-friendly title (str).

umasked_data

The actual array with mask and unit (Quantity).

unitless

bool - True if the data does not have units (Readonly property).

units

Unit - The units of the data.

value

Alias of values .

values

Quantity - The actual values (data, units) contained in this object (Readonly property).

Methods Summary

abs(dataset[, dtype])

Calculate the absolute value of the given NDDataset element-wise.

absolute(dataset[, dtype])

Calculate the absolute value of the given NDDataset element-wise.

add_coordset(*coords[, dims])

Add one or a set of coordinates from a dataset.

align(dataset, *others, **kwargs)

Align individual NDDataset along given dimensions using various methods.

all(dataset[, dim, keepdims])

Test whether all array elements along a given axis evaluate to True.

amax(dataset[, dim, keepdims])

Return the maximum of the dataset or maxima along given dimensions.

amin(dataset[, dim, keepdims])

Return the maximum of the dataset or maxima along given dimensions.

any(dataset[, dim, keepdims])

Test whether any array element along a given axis evaluates to True.

arange([start, stop, step, dtype])

Return evenly spaced values within a given interval.

argmax(dataset[, dim])

Indexes of maximum of data along axis.

argmin(dataset[, dim])

Indexes of minimum of data along axis.

around(dataset[, decimals])

Evenly round to the given number of decimals.

asfortranarray()

Make data and mask (ndim >= 1) laid out in Fortran order in memory.

asls(dataset[, lamb, asymmetry, tol, max_iter])

Asymmetric Least Squares Smoothing baseline correction.

astype([dtype])

Cast the data to a specified type.

atleast_2d([inplace])

Expand the shape of an array to make it at least 2D.

autosub(dataset, ref, *ranges[, dim, ...])

Automatic subtraction of a reference to the dataset.

average(dataset[, dim, weights, keepdims])

Compute the weighted average along the specified axis.

bartlett()def bartlett(dataset, **kwargs)

Calculate Bartlett apodization (triangular window with end points at zero).

basc(dataset, *ranges, **kwargs)

Compute a baseline corrected dataset using the Baseline class processor.

blackmanharris()def blackmanharris(dataset, ...)

Calculate a minimum 4-term Blackman-Harris apodization.

clip(dataset[, a_min, a_max])

Clip (limit) the values in a dataset.

close_figure()

Close a Matplotlib figure associated to this dataset.

component([select])

Take selected components of an hypercomplex array (RRR, RIR, ...).

concatenate(*datasets, **kwargs)

Concatenation of NDDataset objects along a given axis.

conj(dataset[, dim])

Conjugate of the NDDataset in the specified dimension.

conjugate(dataset[, dim])

Conjugate of the NDDataset in the specified dimension.

coord([dim])

Return the coordinates along the given dimension.

coordmax(dataset[, dim])

Find coordinates of the maximum of data along axis.

coordmin(dataset[, dim])

Find oordinates of the mainimum of data along axis.

copy([deep, keepname])

Make a disconnected copy of the current object.

cs(dataset[, pts, neg])

Circular shift.

cumsum(dataset[, dim, dtype])

Return the cumulative sum of the elements along a given axis.

dc(dataset, **kwargs)

Time domain baseline correction.

delete_coordset()

Delete all coordinate settings.

denoise(dataset[, ratio])

Denoise the data using a PCA method.

despike(dataset[, size, delta])

Remove convex spike from the data using the katsumoto-ozaki procedure.

detrend(dataset[, order, breakpoints])

Remove polynomial trend along a dimension from dataset.

diag(dataset[, offset])

Extract a diagonal or construct a diagonal array.

diagonal(dataset[, offset, dim, dtype])

Return the diagonal of a 2D array.

dot(a, b[, strict, out])

Return the dot product of two NDDatasets.

download_nist_ir(CAS[, index])

Upload IR spectra from NIST webbook

dump(filename, **kwargs)

Save the current object into compressed native spectrochempy format.

em([lb, shifted, lb, shifted])

Calculate exponential apodization.

empty(shape[, dtype])

Return a new NDDataset of given shape and type, without initializing entries.

empty_like(dataset[, dtype])

Return a new uninitialized NDDataset .

eye(N[, M, k, dtype])

Return a 2-D array with ones on the diagonal and zeros elsewhere.

fft(dataset[, size, sizeff, inv, ppm])

Apply a complex fast fourier transform.

find_peaks(dataset[, height, window_length, ...])

Wrapper and extension of scpy.signal.find_peaks.

fromfunction(cls, function[, shape, dtype, ...])

Construct a nddataset by executing a function over each coordinate.

fromiter(iterable[, dtype, count])

Create a new 1-dimensional array from an iterable object.

fsh(dataset, pts, **kwargs)

Frequency shift by Fourier transform.

fsh2(dataset, pts, **kwargs)

Frequency Shift by Fourier transform.

full(shape[, fill_value, dtype])

Return a new NDDataset of given shape and type, filled with fill_value .

full_like(dataset[, fill_value, dtype])

Return a NDDataset of fill_value.

general_hamming([alpha])

Calculate generalized Hamming apodization.

geomspace(start, stop[, num, endpoint, dtype])

Return numbers spaced evenly on a log scale (a geometric progression).

get_axis(*args, **kwargs)

Helper function to determine an axis index whatever the syntax used (axis index or dimension names).

get_baseline(dataset, *ranges, **kwargs)

Compute a baseline using the Baseline class processor.

get_labels([level])

Get the labels at a given level.

gm([gb, lb, shifted, gb, lb, shifted])

Calculate lorentz-to-gauss apodization.

hamming(dataset, **kwargs)

Calculate generalized Hamming (== Happ-Genzel) apodization.

hann(dataset, **kwargs)

Return a Hann window.

ht(dataset[, N])

Hilbert transform.

identity(n[, dtype])

Return the identity NDDataset of a given shape.

ifft(dataset[, size])

Apply a inverse fast fourier transform.

is_units_compatible(other)

Check the compatibility of units with another object.

ito(other[, force])

Inplace scaling to different units.

ito_base_units()

Inplace rescaling to base units.

ito_reduced_units()

Quantity scaled in place to reduced units, inplace.

linspace(cls, start, stop[, num, endpoint, ...])

Return evenly spaced numbers over a specified interval.

load(filename, **kwargs)

Open data from a '*.scp' (NDDataset) or '*.pscp' (Project) file.

load_iris()

Upload the classical "iris" dataset.

logspace(cls, start, stop[, num, endpoint, ...])

Return numbers spaced evenly on a log scale.

ls(dataset[, pts])

Left shift and zero fill.

max(dataset[, dim, keepdims])

Return the maximum of the dataset or maxima along given dimensions.

mc(dataset)

Modulus calculation.

mean(dataset[, dim, dtype, keepdims])

Compute the arithmetic mean along the specified axis.

min(dataset[, dim, keepdims])

Return the maximum of the dataset or maxima along given dimensions.

ones(shape[, dtype])

Return a new NDDataset of given shape and type, filled with ones.

ones_like(dataset[, dtype])

Return NDDataset of ones.

pipe(func, *args, **kwargs)

Apply func(self, *args, **kwargs).

pk(dataset[, phc0, phc1, exptc, pivot])

Linear phase correction.

pk_exp(dataset[, phc0, pivot, exptc])

Exponential Phase Correction.

plot([method])

Generic plot function.

plot_1D(_PLOT1D_DOC)def plot_1D(dataset[, ...])

Plot of one-dimensional data.

plot_2D(_PLOT2D_DOC)def plot_2D(dataset[, ...])

Plot of 2D array.

plot_3D(_PLOT3D_DOC)def plot_3D(dataset[, ...])

Plot of 2D array as 3D plot

plot_bar(dataset, *args, **kwargs)

Plot a 1D dataset with bars.

plot_image(dataset, *args, **kwargs)

Plot a 2D dataset as an image plot.

plot_map(dataset, *args, **kwargs)

Plot a 2D dataset as a contoured map.

plot_multiple(datasets[, method, pen, ...])

Plot a series of 1D datasets as a scatter plot with optional lines between markers.

plot_pen(dataset, *args, **kwargs)

Plot a 1D dataset with solid pen by default.

plot_scatter(dataset, *args, **kwargs)

Plot a 1D dataset as a scatter plot (points can be added on lines).

plot_scatter_pen(dataset, *args, **kwargs)

Plot a 1D dataset with solid pen by default.

plot_stack(dataset, *args, **kwargs)

Plot a 2D dataset as a stack plot.

plot_surface(dataset, *args, **kwargs)

Plot a 2D dataset as a a 3D-surface.

plot_waterfall(dataset, *args, **kwargs)

Plot a 2D dataset as a a 3D-waterfall plot.

ps(dataset)

Power spectrum.

ptp(dataset[, dim, keepdims])

Range of values (maximum - minimum) along a dimension.

qsin(dataset[, ssb])

Equivalent to sp , with pow = 2 (squared sine bell apodization window).

random([size, dtype])

Return random floats in the half-open interval [0.0, 1.0).

read(*paths, **kwargs)

Generic read method.

read_carroucell([directory])

Open .spa files in a directory after a carroucell experiment.

read_csv(*paths, **kwargs)

Open a .csv file or a list of .csv files.

read_ddr(*paths, **kwargs)

Open a Surface Optics Corps.

read_dir([directory])

Read an entire directory.

read_hdr(*paths, **kwargs)

Open a Surface Optics Corps.

read_jcamp(*paths, **kwargs)

Open Infrared JCAMP-DX files with extension .jdx or .dx.

read_labspec(*paths, **kwargs)

Read a single Raman spectrum or a series of Raman spectra.

read_mat(*paths, **kwargs)

Read a matlab file with extension .mat and return its content as a list.

read_matlab(*paths, **kwargs)

Read a matlab file with extension .mat and return its content as a list.

read_omnic(*paths, **kwargs)

Open a Thermo Nicolet OMNIC file.

read_opus(*paths, **kwargs)

Open Bruker OPUS file(s).

read_quadera(*paths, **kwargs)

Read a Pfeiffer Vacuum's QUADERA mass spectrometer software file with extension .asc.

read_sdr(*paths, **kwargs)

Open a Surface Optics Corps.

read_soc(*paths, **kwargs)

Read a Surface Optics Corps.

read_spa(*paths, **kwargs)

Open a Thermo Nicolet file or a list of files with extension .spa.

read_spc(*paths, **kwargs)

Read GRAMS/Thermo Scientific Galactic files or a list of files with extension .spc.

read_spg(*paths, **kwargs)

Open a Thermo Nicolet file or a list of files with extension .spg.

read_srs(*paths, **kwargs)

Open a Thermo Nicolet file or a list of files with extension .srs .

read_topspin(*paths, **kwargs)

Open Bruker TOPSPIN (NMR) dataset.

read_wdf(*paths, **kwargs)

Read a single Raman spectrum or a series of Raman spectra.

read_wire(*paths, **kwargs)

Read a single Raman spectrum or a series of Raman spectra.

read_zip(*paths, **kwargs)

Open a zipped list of data files.

remove_masks()

Remove all masks previously set on this array.

roll(dataset[, pts, neg])

Roll dimensions.

round(dataset[, decimals])

Evenly round to the given number of decimals.

round_(dataset[, decimals])

Evenly round to the given number of decimals.

rs(dataset[, pts])

Right shift and zero fill.

rubberband(dataset)

Rubberband baseline correction.

save(**kwargs)

Save the current object in SpectroChemPy format.

save_as([filename])

Save the current NDDataset in SpectroChemPy format (*.scp).

savgol(dataset[, size, order])

Savitzky-Golay filter.

savgol_filter(*args, **kwargs)

Savitzky-Golay filter.

set_complex([inplace])

Set the object data as complex.

set_coordset(*args, **kwargs)

Set one or more coordinates at once.

set_coordtitles(*args, **kwargs)

Set titles of the one or more coordinates.

set_coordunits(*args, **kwargs)

Set units of the one or more coordinates.

set_hypercomplex([inplace])

Alias of set_quaternion.

set_quaternion([inplace])

Alias of set_quaternion.

simps([replace])

An alias of simpson kept for backwards compatibility.

simpson(dataset, *args, **kwargs)

Integrate using the composite Simpson's rule.

sine(dataset, *args, **kwargs)

Strictly equivalent to sp .

sinm(dataset[, ssb])

Equivalent to sp , with pow = 1 (sine bell apodization window).

smooth(dataset[, size, window])

Smooth the data using a window with requested size.

snip(dataset[, snip_width])

Simple Non-Iterative Peak (SNIP) detection algorithm

sort(**kwargs)

Return the dataset sorted along a given dimension.

sp([ssb, pow, ssb, pow])

Calculate apodization with a Sine window multiplication.

squeeze(*dims[, inplace])

Remove single-dimensional entries from the shape of a NDDataset.

stack(*datasets)

Stack of NDDataset objects along a new dimension.

std(dataset[, dim, dtype, ddof, keepdims])

Compute the standard deviation along the specified axis.

sum(dataset[, dim, dtype, keepdims])

Sum of array elements over a given axis.

swapaxes(dim1, dim2[, inplace])

Alias of swapdims .

swapdims(dim1, dim2[, inplace])

Interchange two dimensions of a NDDataset.

take(indices, **kwargs)

Take elements from an array.

to(other[, inplace, force])

Return the object with data rescaled to different units.

to_array()

Return a numpy masked array.

to_base_units([inplace])

Return an array rescaled to base units.

to_reduced_units([inplace])

Return an array scaled in place to reduced units.

to_xarray()

Convert a NDDataset instance to an DataArray object.

transpose(*dims[, inplace])

Permute the dimensions of a NDDataset.

trapezoid(dataset, **kwargs)

Integrate using the composite trapezoidal rule.

trapz([replace])

An alias of trapezoid kept for backwards compatibility.

triang()def triang(dataset, **kwargs)

Calculate triangular apodization with non-null extremities and maximum value normalized to 1.

var(dataset[, dim, dtype, ddof, keepdims])

Compute the variance along the specified axis.

whittaker(dataset[, lamb, order])

Smooth the data using the Whittaker smoothing algorithm.

write(dataset[, filename])

Write the current dataset.

write_csv(*args, **kwargs)

Write a dataset in CSV format.

write_excel(*args, **kwargs)

This method is an alias of write_excel .

write_jcamp(*args, **kwargs)

Write a dataset in JCAMP-DX format.

write_mat(*args, **kwargs)

This method is an alias of write_matlab .

write_matlab(*args, **kwargs)

This method is an alias of write_matlab .

write_xls(*args, **kwargs)

This method is an alias of write_excel .

zeros(shape[, dtype])

Return a new NDDataset of given shape and type, filled with zeros.

zeros_like(dataset[, dtype])

Return a NDDataset of zeros.

zf(dataset[, size, mid])

Zero fill to given size.

zf_auto(dataset[, mid])

Zero fill to next largest power of two.

zf_double(dataset, n[, mid])

Zero fill by doubling original data size once or multiple times.

zf_size(dataset[, size, mid])

Zero fill to given size.

Attributes Documentation

II

The array with imaginary-imaginary component of hypercomplex 2D data.

(Readonly property).

IR

The array with imaginary-real component of hypercomplex 2D data .

(Readonly property).

RI

The array with real-imaginary component of hypercomplex 2D data .

(Readonly property).

RR

The array with real component in both dimension of hypercomplex 2D data .

This readonly property is equivalent to the real property.

T

Transposed NDDataset .

The same object is returned if ndim is less than 2.

acquisition_date

Acquisition date.

author

Creator of the dataset (str).

ax

The main matplotlib axe associated to this dataset.

axT

The matplotlib axe associated to the transposed dataset.

axec

Matplotlib colorbar axe associated to this dataset.

axecT

Matplotlib colorbar axe associated to the transposed dataset.

axex

Matplotlib projection x axe associated to this dataset.

axey

Matplotlib projection y axe associated to this dataset.

comment

Provides a comment (Alias to the description attribute).

coordnames

List of the Coord names.

Read only property.

coordset

CoordSet instance.

Contains the coordinates of the various dimensions of the dataset. It’s a readonly property. Use set_coords to change one or more coordinates at once.

coordtitles

List of the Coord titles.

Read only property. Use set_coordtitle to eventually set titles.

coordunits

List of the Coord units.

Read only property. Use set_coordunits to eventually set units.

created

Creation date object (Datetime).

data

The data array.

If there is no data but labels, then the labels are returned instead of data.

description

Provides a description of the underlying data (str).

dimensionless

True if the data array is dimensionless - Readonly property (bool).

See also

unitless

True if data has no units.

has_units

True if data has units.

Notes

Dimensionless is different of unitless which means no unit.

dims

Names of the dimensions (list).

The name of the dimensions are ‘x’, ‘y’, ‘z’…. depending on the number of dimension.

directory

Current directory for this dataset.

ReadOnly property - automatically set when the filename is updated if it contains a parent on its path.

divider

Matplotlib plot divider.

dtype

Return the data type.

fig

Matplotlib figure associated to this dataset.

fignum

Matplotlib figure associated to this dataset.

filename

Current filename for this dataset.

filetype

Type of current file.

has_complex_dims

True if at least one of the data array dimension is complex.

(Readonly property).

has_data

True if the data array is not empty.

has_defined_name

True is the name has been defined (bool).

has_units

True if the data array have units - Readonly property (bool).

See also

unitless

True if the data has no unit.

dimensionless

True if the data have dimensionless units.

history

Describes the history of actions made on this array (List of strings).

id

Object identifier - Readonly property (str).

imag

The array with imaginary component of the data .

(Readonly property).

is_1d

True if the data array has only one dimension (bool).

is_complex

True if the ‘data’ are complex (Readonly property).

is_empty

True if the data array is empty or size=0, and if no label are present.

Readonly property (bool).

is_float

True if the data are real values - Readonly property (bool).

is_integer

True if the data are integer values - Readonly property (bool).

is_interleaved

True if the data array is hypercomplex with interleaved data.

(Readonly property).

is_labeled

True if the data array have labels - Readonly property (bool).

is_masked

True if the data array has masked values.

(Readonly property).

is_quaternion

True if the data array is hypercomplex .

(Readonly property).

labels

An array of labels for data (ndarray of str).

An array of objects of any type (but most generally string), with the last dimension size equal to that of the dimension of data. Note that’s labelling is possible only for 1D data. One classical application is the labelling of coordinates to display informative strings instead of numerical values.

limits

Range of the data.

local_timezone

Return the local timezone.

m

Data array (ndarray).

If there is no data but labels, then the labels are returned instead of data.

magnitude

Data array (ndarray).

If there is no data but labels, then the labels are returned instead of data.

mask

Mask for the data (ndarray of bool).

masked_data

The actual masked data array - Readonly property (numpy.ma.ndarray).

meta

Additional metadata (Meta).

modeldata

ndarray - models data.

Data eventually generated by modelling of the data.

modified

Date of modification (readonly property).

name

A user-friendly name (str).

When no name is provided, the id of the object is returned instead.

ndaxes

A dictionary containing all the axes of the current figures.

ndim

The number of dimensions of the data array (Readonly property).

origin

Origin of the data.

e.g. spectrometer or software

parent

Project instance.

The parent project of the dataset.

preferences

Meta instance object - Additional metadata.

real

The array with real component of the data .

(Readonly property).

roi

Region of interest (ROI) limits (list).

shape

A tuple with the size of each dimension - Readonly property.

The number of data element on each dimension (possibly complex). For only labelled array, there is no data, so it is the 1D and the size is the size of the array of labels.

size

Size of the underlying data array - Readonly property (int).

The total number of data elements (possibly complex or hypercomplex in the array).

suffix

Filename suffix.

Read Only property - automatically set when the filename is updated if it has a suffix, else give the default suffix for the given type of object.

timezone

Return the timezone information.

A timezone’s offset refers to how many hours the timezone is from Coordinated Universal Time (UTC).

In spectrochempy, all datetimes are stored in UTC, so that conversion must be done during the display of these datetimes using tzinfo.

title

An user-friendly title (str).

When the title is provided, it can be used for labeling the object, e.g., axe title in a matplotlib plot.

umasked_data

The actual array with mask and unit (Quantity).

(Readonly property).

unitless

bool - True if the data does not have units (Readonly property).

units

Unit - The units of the data.

value

Alias of values .

values

Quantity - The actual values (data, units) contained in this object (Readonly property).

Methods Documentation

abs(dataset, dtype=None)[source]

Calculate the absolute value of the given NDDataset element-wise.

abs is a shorthand for this function. For complex input, a + ib, the absolute value is \(\sqrt{ a^2 + b^2}\) .

Parameters
  • dataset (NDDataset or array-like) – Input array or object that can be converted to an array.

  • dtype (dtype) – The type of the output array. If dtype is not given, infer the data type from the other input arguments.

Returns

NDDataset – The absolute value of each element in dataset.

absolute(dataset, dtype=None)[source]

Calculate the absolute value of the given NDDataset element-wise.

abs is a shorthand for this function. For complex input, a + ib, the absolute value is \(\sqrt{ a^2 + b^2}\) .

Parameters
  • dataset (NDDataset or array-like) – Input array or object that can be converted to an array.

  • dtype (dtype) – The type of the output array. If dtype is not given, infer the data type from the other input arguments.

Returns

NDDataset – The absolute value of each element in dataset.

add_coordset(*coords, dims=None, **kwargs)[source]

Add one or a set of coordinates from a dataset.

Parameters
  • *coords (iterable) – Coordinates object(s).

  • dims (list) – Name of the coordinates.

  • **kwargs – Optional keyword parameters passed to the coordset.

align(dataset, *others, **kwargs)[source]

Align individual NDDataset along given dimensions using various methods.

Parameters
  • dataset (NDDataset) – Dataset on which we want to align other objects.

  • *others (NDDataset) – Objects to align.

  • dim (str. Optional, default=’x’) – Along which axis to perform the alignment.

  • dims (list of str, optional, default=None) – Align along all dims defined in dims (if dim is also defined, then dims have higher priority).

  • method (enum [‘outer’, ‘inner’, ‘first’, ‘last’, ‘interpolate’], optional, default=’outer’) – Which method to use for the alignment.

    If align is defined :

    • ‘outer’ means that a union of the different coordinates is achieved (missing values are masked).

    • ‘inner’ means that the intersection of the coordinates is used.

    • ‘first’ means that the first dataset is used as reference.

    • ‘last’ means that the last dataset is used as reference.

    • ‘interpolate’ means that interpolation is performed relative to the first dataset.

  • interpolate_method (enum [‘linear’,’pchip’]. Optional, default=’linear’) – Method of interpolation to performs for the alignment.

  • interpolate_sampling (‘auto’, int or float. Optional, default=’auto’) – Values:

    • ‘auto’ : sampling is determined automatically from the existing data.

    • int : if an integer values is specified, then the sampling interval for the interpolated data will be split in this number of points.

    • float : If a float value is provided, it determines the interval between the interpolated data.

  • coord (Coord , optional, default=None) – Coordinates to use for alignment. Ignore those corresponding to the dimensions to align.

  • copy (bool, optional, default=True) – If False then the returned objects will share memory with the original objects, whenever it is possible : in principle only if reindexing is not necessary.

Returns

tuple of NDDataset – Same objects as datasets with dimensions aligned.

Raises

ValueError – Issued when the dimensions given in dim or dims argument are not compatibles (units, titles, etc.).

all(dataset, dim=None, keepdims=False)[source]

Test whether all array elements along a given axis evaluate to True.

Parameters
  • dataset (array_like) – Input array or object that can be converted to an array.

  • dim (None or int or str, optional) – Axis or axes along which a logical AND reduction is performed. The default (axis=None ) is to perform a logical AND over all the dimensions of the input array. axis may be negative, in which case it counts from the last to the first axis.

  • keepdims (bool, optional) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array. If the default value is passed, then keepdims will not be passed through to the all method of sub-classes of ndarray , however any non-default value will be. If the sub-class’ method does not implement keepdims any exceptions will be raised.

Returns

all – A new boolean or array is returned unless out is specified, in which case a reference to out is returned.

See also

any

Test whether any element along a given axis evaluates to True.

Notes

Not a Number (NaN), positive infinity and negative infinity evaluate to True because these are not equal to zero.

amax(dataset, dim=None, keepdims=False, **kwargs)[source]

Return the maximum of the dataset or maxima along given dimensions.

Parameters
  • dataset (array_like) – Input array or object that can be converted to an array.

  • dim (None or int or dimension name or tuple of int or dimensions, optional) – Dimension or dimensions along which to operate. By default, flattened input is used. If this is a tuple, the maximum is selected over multiple dimensions, instead of a single dimension or all the dimensions as before.

  • keepdims (bool, optional) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.

Returns

amax – Maximum of the data. If dim is None, the result is a scalar value. If dim is given, the result is an array of dimension ndim - 1 .

See also

amin

The minimum value of a dataset along a given dimension, propagating NaNs.

minimum

Element-wise minimum of two datasets, propagating any NaNs.

maximum

Element-wise maximum of two datasets, propagating any NaNs.

fmax

Element-wise maximum of two datasets, ignoring any NaNs.

fmin

Element-wise minimum of two datasets, ignoring any NaNs.

argmax

Return the indices or coordinates of the maximum values.

argmin

Return the indices or coordinates of the minimum values.

Notes

For dataset with complex or hypercomplex type type, the default is the value with the maximum real part.

amin(dataset, dim=None, keepdims=False, **kwargs)[source]

Return the maximum of the dataset or maxima along given dimensions.

Parameters
  • dataset (array_like) – Input array or object that can be converted to an array.

  • dim (None or int or dimension name or tuple of int or dimensions, optional) – Dimension or dimensions along which to operate. By default, flattened input is used. If this is a tuple, the minimum is selected over multiple dimensions, instead of a single dimension or all the dimensions as before.

  • keepdims (bool, optional) – If this is set to True, the dimensions which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.

Returns

amin – Minimum of the data. If dim is None, the result is a scalar value. If dim is given, the result is an array of dimension ndim - 1 .

See also

amax

The maximum value of a dataset along a given dimension, propagating NaNs.

minimum

Element-wise minimum of two datasets, propagating any NaNs.

maximum

Element-wise maximum of two datasets, propagating any NaNs.

fmax

Element-wise maximum of two datasets, ignoring any NaNs.

fmin

Element-wise minimum of two datasets, ignoring any NaNs.

argmax

Return the indices or coordinates of the maximum values.

argmin

Return the indices or coordinates of the minimum values.

any(dataset, dim=None, keepdims=False)[source]

Test whether any array element along a given axis evaluates to True.

Returns single boolean unless dim is not None

Parameters
  • dataset (array_like) – Input array or object that can be converted to an array.

  • dim (None or int or tuple of ints, optional) – Axis or axes along which a logical OR reduction is performed. The default (axis=None ) is to perform a logical OR over all the dimensions of the input array. axis may be negative, in which case it counts from the last to the first axis.

  • keepdims (bool, optional) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array. If the default value is passed, then keepdims will not be passed through to the any method of sub-classes of ndarray , however any non-default value will be. If the sub-class’ method does not implement keepdims any exceptions will be raised.

Returns

any – A new boolean or ndarray is returned.

See also

all

Test whether all array elements along a given axis evaluate to True.

arange(start=0, stop=None, step=None, dtype=None, **kwargs)[source]

Return evenly spaced values within a given interval.

Values are generated within the half-open interval [start, stop).

Parameters
  • start (number, optional) – Start of interval. The interval includes this value. The default start value is 0.

  • stop (number) – End of interval. The interval does not include this value, except in some cases where step is not an integer and floating point round-off affects the length of out. It might be prefereble to use inspace in such case.

  • step (number, optional) – Spacing between values. For any output out, this is the distance between two adjacent values, out[i+1] - out[i]. The default step size is 1. If step is specified as a position argument, start must also be given.

  • dtype (dtype) – The type of the output array. If dtype is not given, infer the data type from the other input arguments.

  • **kwargs – Keywords argument used when creating the returned object, such as units, name, title, …

Returns

arange – Array of evenly spaced values.

See also

linspace

Evenly spaced numbers with careful handling of endpoints.

Examples

>>> scp.arange(1, 20.0001, 1, units='s', name='mycoord')
NDDataset: [float64] s (size: 20)
argmax(dataset, dim=None)[source]

Indexes of maximum of data along axis.

argmin(dataset, dim=None)[source]

Indexes of minimum of data along axis.

around(dataset, decimals=0)[source]

Evenly round to the given number of decimals.

Parameters
  • dataset (NDDataset) – Input dataset.

  • decimals (int, optional) – Number of decimal places to round to (default: 0). If decimals is negative, it specifies the number of positions to the left of the decimal point.

Returns

rounded_array – NDDataset containing the rounded values. The real and imaginary parts of complex numbers are rounded separately. The result of rounding a float is a float. If the dataset contains masked data, the mask remain unchanged.

See also

numpy.round, around, spectrochempy.round, spectrochempy.around, methods., ceil, fix, floor, rint, trunc

asfortranarray()[source]

Make data and mask (ndim >= 1) laid out in Fortran order in memory.

asls(dataset, lamb=1e5, asymmetry=0.05, tol=1e-3, max_iter=50)[source]

Asymmetric Least Squares Smoothing baseline correction.

This method is based on the work of Eilers and Boelens ([Eilers and Boelens, 2005]).

Parameters
  • dataset (NDDataset) – The input data.

  • lamb (float, optional, default:1e5) – The smoothness parameter for the AsLS method. Larger values make the baseline stiffer. Values should be in the range (0, 1e9)

  • asymmetry (float, optional, default:0.05,) – The asymmetry parameter for the AsLS method. It is typically between 0.001 and 0.1. 0.001 gives almost the same fit as the unconstrained least squares.

  • tol = `float`, optional, default (1e-3) – The tolerance parameter for the AsLS method. Smaller values make the fitting better but potentially increases the number of iterations and the running time. Values should be in the range (0, 1).

  • max_iter = `int`, optional, default (50) – Maximum number of AsLS iteration.

Returns

NDDataset – The baseline corrected dataset.

See also

Baseline

Manual baseline correction processor.

get_baseline

Compuute a baseline using the Baseline class.

basc

Make a baseline correction using the Baseline class.

snip

Perform a Simple Non-Iterative Peak (SNIP) detection algorithm.

rubberband

Perform a Rubberband baseline correction.

autosub

Perform an automatic subtraction of reference.

detrend

Remove polynomial trend along a dimension from dataset.

astype(dtype=None, **kwargs)[source]

Cast the data to a specified type.

Parameters

dtype (str or dtype) – Typecode or data-type to which the array is cast.

atleast_2d(inplace=False)[source]

Expand the shape of an array to make it at least 2D.

Parameters

inplace (bool, optional, default=`False`) – Flag to say that the method return a new object (default) or not (inplace=True).

Returns

NDDataset – The input array, but with dimensions increased.

See also

squeeze

The inverse operation, removing singleton dimensions.

autosub(dataset, ref, *ranges, dim='x', method='vardiff', return_coefs=False, inplace=False)[source]

Automatic subtraction of a reference to the dataset.

The subtraction coefficient are adjusted to either minimise the variance of the subtraction (method = ‘vardiff’) which will minimize peaks due to ref or minimize the sum of squares of the subtraction (method = ‘ssdiff’).

Parameters
  • dataset (NDDataset) – Dataset to which we want to subtract the reference data.

  • ref (NDDataset) – 1D reference data, with a size matching the axis to subtract. (axis parameter). # TODO : optionally use title of axis.

  • *ranges (pair(s) of values) – Any number of pairs is allowed. Coord range(s) in which the variance is minimized.

  • dim (str or int , optional, default=’x’) – Tells on which dimension to perform the subtraction. If dim is an integer it refers to the axis index.

  • method (str, optional, default=’vardiff’) – ‘vardiff’: minimize the difference of the variance. ‘ssdiff’: minimize the sum of squares difference of sum of squares.

  • return_coefs (bool , optional, default=`False`) – Returns the table of coefficients.

  • inplace (bool , optional, default=`False`) – True if the subtraction is done in place. In this case we do not need to catch the function output.

Returns

  • out (NDDataset) – The subtracted dataset.

  • coefs (ndarray .) – The table of subtraction coefficients (only if return_coefs is set to True ).

See also

Baseline

Manual baseline corrections.

abc

Automatic baseline corrections.

Examples

>>> path_A = 'irdata/nh4y-activation.spg'
>>> A = scp.read(path_A, protocol='omnic')
>>> ref = A[0, :]  # let's subtrack the first row
>>> B = A.autosub(ref, [3900., 3700.], [1600., 1500.], inplace=False)
>>> B
NDDataset: [float64]  a.u. (shape: (y:55, x:5549))
average(dataset, dim=None, weights=None, keepdims=False)[source]

Compute the weighted average along the specified axis.

Parameters
  • dataset (array_like) – Array containing data to be averaged.

  • dim (None or int or dimension name or tuple of int or dimensions, optional) – Dimension or dimensions along which to operate. By default, flattened input is used. If this is a tuple, the minimum is selected over multiple dimensions, instead of a single dimension or all the dimensions as before.

  • weights (array_like, optional) – An array of weights associated with the values in dataset . Each value in a contributes to the average according to its associated weight. The weights array can either be 1-D (in which case its length must be the size of dataset along the given axis) or of the same shape as dataset . If weights=None , then all data in dataset are assumed to have a weight equal to one. The 1-D calculation is:

    avg = sum(a * weights) / sum(weights)
    

    The only constraint on weights is that sum(weights) must not be 0.

Returns

average, – Return the average along the specified axis.

Raises
  • ZeroDivisionError – When all weights along axis are zero. See numpy.ma.average for a version robust to this type of error.

  • TypeError – When the length of 1D weights is not the same as the shape of a along axis.

See also

mean

Compute the arithmetic mean along the specified axis.

Examples

>>> nd = scp.read('irdata/nh4y-activation.spg')
>>> nd
NDDataset: [float64] a.u. (shape: (y:55, x:5549))
>>> scp.average(nd)
<Quantity(1.25085858, 'absorbance')>
>>> m = scp.average(nd, dim='y')
>>> m
NDDataset: [float64] a.u. (size: 5549)
>>> m.x
Coord: [float64] cm⁻¹ (size: 5549)
>>> m = scp.average(nd, dim='y', weights=np.arange(55))
>>> m.data
array([   1.789,    1.789, ...,    1.222,     1.22])
bartlett()def bartlett(dataset, **kwargs)[source]

Calculate Bartlett apodization (triangular window with end points at zero).

For multidimensional NDDataset, the apodization is by default performed on the last dimension.

The data in the last dimension MUST be time-domain or dimensionless, otherwise an error is raised.

The Bartlett window is defined as

\[w(n) = \frac{2}{M-1} (\frac{M-1}{2} - |n - \frac{M-1}{2}|)\]

where M is the number of point of the input dataset.

Parameters
  • dataset (Dataset) – Input dataset.

  • **kwargs – Additional keyword parameters (see Other Parameters).

Returns

  • apodized – Dataset.

  • apod_arr – The apodization array only if ‘retapod’ is True.

Other Parameters
  • dim (str or int, keyword parameter, optional, default=’x’) – Specify on which dimension to apply the apodization method. If dim is specified as an integer it is equivalent to the usual axis numpy parameter.

  • inv (bool, keyword parameter, optional, default=False) – True for inverse apodization.

  • rev (bool, keyword parameter, optional, default=False) – True to reverse the apodization before applying it to the data.

  • inplace (bool, keyword parameter, optional, default=False) – True if we make the transform inplace. If False, the function return a new dataset.

  • retapod (bool, keyword parameter, optional, default=False) – True to return the apodization array along with the apodized object.

See also

triang

A triangular window that does not touch zero at the ends.

basc(dataset, *ranges, **kwargs)[source]

Compute a baseline corrected dataset using the Baseline class processor.

If no ranges is provided, the features limits are used. See Baseline for detailed information on the parameters.

Parameters
  • dataset (a NDDataset instance) – The dataset where to correct the baseline.

  • *ranges (a variable number of pair-tuples) – The regions taken into account for the manual baseline correction.

  • **kwargs – Optional keyword parameters (see Baseline Parameters for a detailed information).

Returns

NDDataset – The computed baseline corrected dataset

See also

Baseline

Manual baseline correction processor.

get_baseline

Compuute a baseline using the Baseline class.

asls

Perform an Asymmetric Least Squares Smoothing baseline correction.

snip

Perform a Simple Non-Iterative Peak (SNIP) detection algorithm.

rubberband

Perform a Rubberband baseline correction.

autosub

Perform an automatic subtraction of reference.

detrend

Remove polynomial trend along a dimension from dataset.

Notes

For more flexibility and functionality, it is advised to use the Baseline class processor instead.

blackmanharris()def blackmanharris(dataset, **kwargs)[source]

Calculate a minimum 4-term Blackman-Harris apodization.

For multidimensional NDDataset, the apodization is by default performed on the last dimension.

The data in the last dimension MUST be time-domain or dimensionless, otherwise an error is raised.

Parameters

dataset (dataset) – Input dataset.

Returns

  • apodized – Dataset.

  • apod_arr – The apodization array only if ‘retapod’ is True.

  • **kwargs – Additional keyword parameters (see Other Parameters)

Other Parameters
  • dim (str or int, keyword parameter, optional, default=’x’) – Specify on which dimension to apply the apodization method. If dim is specified as an integer it is equivalent to the usual axis numpy parameter.

  • inv (bool, keyword parameter, optional, default=False) – True for inverse apodization.

  • rev (bool, keyword parameter, optional, default=False) – True to reverse the apodization before applying it to the data.

  • inplace (bool, keyword parameter, optional, default=False) – True if we make the transform inplace. If False, the function return a new datase

  • retapod (bool, keyword parameter, optional, default=False) – True to return the apodization array along with the apodized object.

clip(dataset, a_min=None, a_max=None, **kwargs)[source]

Clip (limit) the values in a dataset.

Given an interval, values outside the interval are clipped to the interval edges. For example, if an interval of [0, 1] is specified, values smaller than 0 become 0, and values larger than 1 become 1.

No check is performed to ensure a_min < a_max .

Parameters
  • dataset (array_like) – Input array or object that can be converted to an array.

  • a_min (scalar or array_like or None) – Minimum value. If None, clipping is not performed on lower interval edge. Not more than one of a_min and a_max may be None.

  • a_max (scalar or array_like or None) – Maximum value. If None, clipping is not performed on upper interval edge. Not more than one of a_min and a_max may be None. If a_min or a_max are array_like, then the three arrays will be broadcasted to match their shapes.

Returns

clip – An array with the elements of a , but where values < a_min are replaced with a_min , and those > a_max with a_max .

close_figure()[source]

Close a Matplotlib figure associated to this dataset.

component(select='REAL')[source]

Take selected components of an hypercomplex array (RRR, RIR, …).

Parameters

select (str, optional, default=’REAL’) – If ‘REAL’, only real component in all dimensions will be selected. ELse a string must specify which real (R) or imaginary (I) component has to be selected along a specific dimension. For instance, a string such as ‘RRI’ for a 2D hypercomplex array indicated that we take the real component in each dimension except the last one, for which imaginary component is preferred.

Returns

component – Component of the complex or hypercomplex array.

concatenate(*datasets, **kwargs)[source]

Concatenation of NDDataset objects along a given axis.

Any number of NDDataset objects can be concatenated (by default the last on the last dimension). For this operation to be defined the following must be true :

  1. all inputs must be valid NDDataset objects;

  2. units of data must be compatible

  3. concatenation is along the axis specified or the last one;

  4. along the non-concatenated dimensions, shapes must match.

Parameters
  • *datasets (positional NDDataset arguments) – The dataset(s) to be concatenated to the current dataset. The datasets must have the same shape, except in the dimension corresponding to axis (the last, by default).

  • **kwargs – Optional keyword parameters (see Other Parameters).

Returns

out – A NDDataset created from the contenations of the NDDataset input objects.

Other Parameters
  • dims (str, optional, default=’x’) – The dimension along which the operation is applied.

  • axis (int, optional) – The axis along which the operation is applied.

See also

stack

Stack of NDDataset objects along a new dimension.

Examples

>>> A = scp.read('irdata/nh4y-activation.spg', protocol='omnic')
>>> B = scp.read('irdata/nh4y-activation.scp')
>>> C = scp.concatenate(A[10:], B[3:5], A[:10], axis=0)
>>> A[10:].shape, B[3:5].shape, A[:10].shape, C.shape
((45, 5549), (2, 5549), (10, 5549), (57, 5549))

or

>>> D = A.concatenate(B, B, axis=0)
>>> A.shape, B.shape, D.shape
((55, 5549), (55, 5549), (165, 5549))
>>> E = A.concatenate(B, axis=1)
>>> A.shape, B.shape, E.shape
((55, 5549), (55, 5549), (55, 11098))
conj(dataset, dim='x')[source]

Conjugate of the NDDataset in the specified dimension.

Parameters
  • dataset (array_like) – Input array or object that can be converted to an array.

  • dim (int, str, optional, default=(0,)) – Dimension names or indexes along which the method should be applied.

Returns

conjugated – Same object or a copy depending on the inplace flag.

See also

conj, real, imag, RR, RI, IR, II, part, set_complex, is_complex

conjugate(dataset, dim='x')[source]

Conjugate of the NDDataset in the specified dimension.

Parameters
  • dataset (array_like) – Input array or object that can be converted to an array.

  • dim (int, str, optional, default=(0,)) – Dimension names or indexes along which the method should be applied.

Returns

conjugated – Same object or a copy depending on the inplace flag.

See also

conj, real, imag, RR, RI, IR, II, part, set_complex, is_complex

coord(dim='x')[source]

Return the coordinates along the given dimension.

Parameters

dim (int or str) – A dimension index or name, default index = x . If an integer is provided, it is equivalent to the axis parameter for numpy array.

Returns

Coord – Coordinates along the given axis.

coordmax(dataset, dim=None)[source]

Find coordinates of the maximum of data along axis.

coordmin(dataset, dim=None)[source]

Find oordinates of the mainimum of data along axis.

copy(deep=True, keepname=False, **kwargs)[source]

Make a disconnected copy of the current object.

Parameters
  • deep (bool, optional) – If True a deepcopy is performed which is the default behavior.

  • keepname (bool) – If True keep the same name for the copied object.

Returns

object – An exact copy of the current object.

Examples

>>> nd1 = scp.NDArray([1. + 2.j, 2. + 3.j])
>>> nd1
NDArray: [complex128] unitless (size: 2)
>>> nd2 = nd1
>>> nd2 is nd1
True
>>> nd3 = nd1.copy()
>>> nd3 is not nd1
True
cs(dataset, pts=0.0, neg=False, **kwargs)[source]

Circular shift.

For multidimensional NDDataset, the shift is by default performed on the last dimension.

Parameters
  • dataset (nddataset) – NDDataset to be shifted.

  • pts (int) – Number of points toshift.

  • neg (bool) – True to negate the shifted points.

Returns

dataset – Dataset shifted.

Other Parameters
  • dim (str or int, keyword parameter, optional, default=’x’) – Specify on which dimension to apply the shift method. If dim is specified as an integer it is equivalent to the usual axis numpy parameter.

  • inplace (bool, keyword parameter, optional, default=False) – True if we make the transform inplace. If False, the function return a new dataset.

See also

roll

shift without zero filling.

cumsum(dataset, dim=None, dtype=None)[source]

Return the cumulative sum of the elements along a given axis.

Parameters
  • dataset (array_like) – Calculate the cumulative sum of these values.

  • dim (None or int or dimension name , optional) – Dimension or dimensions along which to operate. By default, flattened input is used.

  • dtype (dtype, optional) – Type to use in computing the standard deviation. For arrays of integer type the default is float64, for arrays of float types it is the same as the array type.

Returns

sum – A new array containing the cumulative sum.

See also

sum

Sum array elements.

trapezoid

Integration of array values using the composite trapezoidal rule.

diff

Calculate the n-th discrete difference along given axis.

Examples

>>> nd = scp.read('irdata/nh4y-activation.spg')
>>> nd
NDDataset: [float64] a.u. (shape: (y:55, x:5549))
>>> scp.sum(nd)
<Quantity(381755.783, 'absorbance')>
>>> scp.sum(nd, keepdims=True)
NDDataset: [float64] a.u. (shape: (y:1, x:1))
>>> m = scp.sum(nd, dim='y')
>>> m
NDDataset: [float64] a.u. (size: 5549)
>>> m.data
array([   100.7,    100.7, ...,       74,    73.98])
dc(dataset, **kwargs)[source]

Time domain baseline correction.

Parameters
  • dataset (nddataset) – The time domain daatset to be corrected.

  • kwargs (dict, optional) – Additional parameters.

Returns

dc – DC corrected array.

Other Parameters

len (float, optional) – Proportion in percent of the data at the end of the dataset to take into account. By default, 25%.

delete_coordset()[source]

Delete all coordinate settings.

denoise(dataset, ratio=99.8, **kwargs)[source]

Denoise the data using a PCA method.

Work only on 2D dataset.

Parameters
  • dataset (NDDataset or a ndarray-like object) – Input object. Must have two dimensions.

  • ratio (float, optional, default: 99.8%) – Ratio of variance explained in %. The number of components selected for reconstruction is chosen automatically such that the amount of variance that needs to be explained is greater than the percentage specified by ratio .

  • **kwargs – Optional keyword parameters (see Other Parameters).

Returns

NDDataset – Denoised 2D dataset

Other Parameters
  • dim (str or int, optional, default=’x’.) – Specify on which dimension to apply this method. If dim is specified as an integer it is equivalent to the usual axis numpy parameter.

  • log_level (int, optional, default: “WARNING”) – Set the logging level for the method.

despike(dataset, size=9, delta=2)[source]

Remove convex spike from the data using the katsumoto-ozaki procedure.

The method can be used to remove cosmic ray peaks from a spectrum.

The present implementation is based on the method is described in Katsumoto and Ozaki [2003]:

  • In the first step, the moving-average method is employed to detect the spike noise. The moving-average window should contain several data points along the abscissa that are larger than those of the spikes in the spectrum. If a window contains a spike, the value on the ordinate for the spike will show an anomalous deviation from the average for this window.

  • In the second step, each data point value identified as noise is replaced by the moving-averaged value.

  • In the third step, the moving-average process is applied to the new data set made by the second step.

  • In the fourth step, the spikes are identified by comparing the differences between the original spectra and the moving-averaged spectra calculated in the third step.

As a result, the proposed method realizes the reduction of convex spikes.

Parameters
  • dataset (NDDataset or a ndarray-like object) – Input object.

  • size (int, optional, default: 9) – Size of the moving average window.

  • delta (float, optional, default: 2) – Set the threshold for the detection of spikes. A spike is detected if its value is greater than delta times the standard deviation of the difference between the original and the smoothed data.

Returns

NDdataset – The despike dataset

detrend(dataset, order='linear', breakpoints=[], **kwargs)[source]

Remove polynomial trend along a dimension from dataset.

Depending on the ``order``parameter, detrend removes the best-fit polynomial line (in the least squares sense) from the data and returns the remaining data.

Parameters
  • dataset (NDDataset) – The input data.

  • order (non-negative int or a str among [‘constant’, ‘linear’, ‘quadratic’, ‘cubic’], optional, default:’linear’) – The order of the polynomial trend.

    • If order=0 or 'constant' , the mean of data is subtracted to remove a shift trend.

    • If order=1 or 'linear' (default), the best straight-fit line is subtracted from data to remove a linear trend (drift).

    • If order=2 or order=quadratic , the best fitted nth-degree polynomial line is subtracted from data to remove a quadratic polynomial trend.

    • order=n can also be used to remove any nth-degree polynomial trend.

  • breakpoints (array_like, optional) – Breakpoints to define piecewise segments of the data, specified as a vector containing coordinate values or indices indicating the location of the breakpoints. Breakpoints are useful when you want to compute separate trends for different segments of the data.

Returns

NDDataset – The detrended dataset.

See also

Baseline

Manual baseline correction processor.

get_baseline

Compuute a baseline using the Baseline class.

basc

Make a baseline correction using the Baseline class.

asls

Perform an Asymmetric Least Squares Smoothing baseline correction.

snip

Perform a Simple Non-Iterative Peak (SNIP) detection algorithm.

rubberband

Perform a Rubberband baseline correction.

autosub

Perform an automatic subtraction of reference.

diag(dataset, offset=0, **kwargs)[source]

Extract a diagonal or construct a diagonal array.

See the more detailed documentation for numpy.diagonal if you use this function to extract a diagonal and wish to write to the resulting array; whether it returns a copy or a view depends on what version of numpy you are using.

Parameters
  • dataset (array_like) – If dataset is a 2-D array, return a copy of its k-th diagonal. If dataset is a 1-D array, return a 2-D array with v on the k-th. diagonal.

  • offset (int, optional) – Diagonal in question. The default is 0. Use offset>0 for diagonals above the main diagonal, and offset<0 for diagonals below the main diagonal.

Returns

diag – The extracted diagonal or constructed diagonal array.

diagonal(dataset, offset=0, dim='x', dtype=None, **kwargs)[source]

Return the diagonal of a 2D array.

As we reduce a 2D to a 1D we must specified which is the dimension for the coordinates to keep!.

Parameters
  • dataset (NDDataset or array-like) – Object from which to extract the diagonal.

  • offset (int, optional) – Offset of the diagonal from the main diagonal. Can be positive or negative. Defaults to main diagonal (0).

  • dim (str, optional) – Dimension to keep for coordinates. By default it is the last (-1, x or another name if the default dimension name has been modified).

  • dtype (dtype, optional) – The type of the returned array.

  • **kwargs – Additional keyword parameters to be passed to the NDDataset constructor.

Returns

diagonal – The diagonal of the input array.

See also

diag

Extract a diagonal or construct a diagonal array.

Examples

>>> nd = scp.full((2, 2), 0.5, units='s', title='initial')
>>> nd
NDDataset: [float64] s (shape: (y:2, x:2))
>>> nd.diagonal(title='diag')
NDDataset: [float64] s (size: 2)
dot(a, b, strict=True, out=None)[source]

Return the dot product of two NDDatasets.

This function is the equivalent of numpy.dot that takes NDDataset as input

Note

Works only with 2-D arrays at the moment.

Parameters
  • a, b (masked_array_like) – Inputs arrays.

  • strict (bool, optional) – Whether masked data are propagated (True) or set to 0 (False) for the computation. Default is False. Propagating the mask means that if a masked value appears in a row or column, the whole row or column is considered masked.

  • out (masked_array, optional) – Output argument. This must have the exact kind that would be returned if it was not used. In particular, it must have the right type, must be C-contiguous, and its dtype must be the dtype that would be returned for dot(a,b) . This is a performance feature. Therefore, if these conditions are not met, an exception is raised, instead of attempting to be flexible.

See also

numpy.dot

Equivalent function for ndarrays.

numpy.ma.dot

Equivalent function for masked ndarrays.

download_nist_ir(CAS, index='all')[source]

Upload IR spectra from NIST webbook

Parameters
  • CAS (int or str) – the CAS number, can be given as “XXXX-XX-X” (str), “XXXXXXX” (str), XXXXXXX (int)

  • index (str or int or tuple of ints) – If set to ‘all’ (default, import all available spectra for the compound corresponding to the index, or a single spectrum, or selected spectra.

Returns

list of NDDataset or NDDataset – The dataset(s).

See also

read

Read data from experimental data.

dump(filename, **kwargs)[source]

Save the current object into compressed native spectrochempy format.

Parameters

filename (str of pathlib object) – File name where to save the current object.

em(lb="Hz", shifted="us")def em(dataset, lb=1, shifted=0, **kwargs)[source]

Calculate exponential apodization.

For multidimensional NDDataset, the apodization is by default performed on the last dimension.

The data in the last dimension MUST be time-domain, or an error is raised.

Functional form of apodization window :

\[em(t) = \exp(- e (t-t_0) )\]

where

\[e = \pi * lb\]
Parameters
  • dataset (Dataset) – Input dataset.

  • lb (float or Quantity , optional, default=1 Hz) – Exponential line broadening, If it is not a quantity with units, it is assumed to be a broadening expressed in Hz.

  • shifted (float or quantity , optional, default=0 us) – Shift the data time origin by this amount. If it is not a quantity it is assumed to be expressed in the data units of the last dimension.

Returns

  • apodized – Dataset.

  • apod_arr – The apodization array only if ‘retapod’ is True.

Other Parameters
  • dim (str or int, keyword parameter, optional, default=’x’) – Specify on which dimension to apply the apodization method. If dim is specified as an integer it is equivalent to the usual axis numpy parameter.

  • inv (bool, keyword parameter, optional, default=False) – True for inverse apodization.

  • rev (bool, keyword parameter, optional, default=False) – True to reverse the apodization before applying it to the data.

  • inplace (bool, keyword parameter, optional, default=False) – True if we make the transform inplace. If False, the function return a new dataset.

  • retapod (bool, keyword parameter, optional, default=False) – True to return the apodization array along with the apodized object.

empty(shape, dtype=None, **kwargs)[source]

Return a new NDDataset of given shape and type, without initializing entries.

Parameters
  • shape (int or tuple of int) – Shape of the empty array.

  • dtype (data-type, optional) – Desired output data-type.

  • **kwargs – Optional keyword parameters (see Other Parameters).

Returns

empty – Array of uninitialized (arbitrary) data of the given shape, dtype, and order. Object arrays will be initialized to None.

Other Parameters
  • units (str or ur instance) – Units of the returned object. If not provided, try to copy from the input object.

  • coordset (list or Coordset object) – Coordinates for the returned object. If not provided, try to copy from the input object.

See also

zeros_like

Return an array of zeros with shape and type of input.

ones_like

Return an array of ones with shape and type of input.

empty_like

Return an empty array with shape and type of input.

full_like

Fill an array with shape and type of input.

zeros

Return a new array setting values to zero.

ones

Return a new array setting values to 1.

full

Fill a new array.

Notes

empty , unlike zeros , does not set the array values to zero, and may therefore be marginally faster. On the other hand, it requires the user to manually set all the values in the array, and should be used with caution.

Examples

>>> scp.empty([2, 2], dtype=int, units='s')
NDDataset: [int64] s (shape: (y:2, x:2))
empty_like(dataset, dtype=None, **kwargs)[source]

Return a new uninitialized NDDataset .

The returned NDDataset have the same shape and type as a given array. Units, coordset, … can be added in kwargs.

Parameters
  • dataset (NDDataset or array-like) – Object from which to copy the array structure.

  • dtype (data-type, optional) – Overrides the data type of the result.

  • **kwargs – Optional keyword parameters (see Other Parameters).

Returns

emptylike – Array of fill_value with the same shape and type as dataset .

Other Parameters
  • units (str or ur instance) – Units of the returned object. If not provided, try to copy from the input object.

  • coordset (list or Coordset object) – Coordinates for the returned object. If not provided, try to copy from the input object.

See also

full_like

Return an array with a given fill value with shape and type of the

input.

ones_like

Return an array of ones with shape and type of input.

zeros_like

Return an array of zeros with shape and type of input.

empty

Return a new uninitialized array.

ones

Return a new array setting values to one.

zeros

Return a new array setting values to zero.

full

Fill a new array.

Notes

This function does not initialize the returned array; to do that use for instance zeros_like , ones_like or full_like instead. It may be marginally faster than the functions that do set the array values.

eye(N, M=None, k=0, dtype=float, **kwargs)[source]

Return a 2-D array with ones on the diagonal and zeros elsewhere.

Parameters
  • N (int) – Number of rows in the output.

  • M (int, optional) – Number of columns in the output. If None, defaults to N .

  • k (int, optional) – Index of the diagonal: 0 (the default) refers to the main diagonal, a positive value refers to an upper diagonal, and a negative value to a lower diagonal.

  • dtype (data-type, optional) – Data-type of the returned array.

  • **kwargs – Other parameters to be passed to the object constructor (units, coordset, mask …).

Returns

eye – NDDataset of shape (N,M) An array where all elements are equal to zero, except for the k-th diagonal, whose values are equal to one.

See also

identity

Equivalent function with k=0.

diag

Diagonal 2-D NDDataset from a 1-D array specified by the user.

Examples

>>> scp.eye(2, dtype=int)
NDDataset: [float64] unitless (shape: (y:2, x:2))
>>> scp.eye(3, k=1, units='km').values
<Quantity([[       0        1        0]
 [       0        0        1]
 [       0        0        0]], 'kilometer')>
fft(dataset, size=None, sizeff=None, inv=False, ppm=True, **kwargs)[source]

Apply a complex fast fourier transform.

For multidimensional NDDataset, the apodization is by default performed on the last dimension.

The data in the last dimension MUST be in time-domain (or without dimension) or an error is raised.

To make reverse Fourier transform, i.e., from frequency to time domain, use the ifft transform (or equivalently, the inv=True parameters.

Parameters
  • dataset (NDDataset) – The dataset on which to apply the fft transformation.

  • size (int, optional) – Size of the transformed dataset dimension - a shorter parameter is si . by default, the size is the closest power of two greater than the data size.

  • sizeff (int, optional) – The number of effective data point to take into account for the transformation. By default it is equal to the data size, but may be smaller.

  • inv (bool, optional, default=False) – If True, an inverse Fourier transform is performed - size parameter is not taken into account.

  • ppm (bool, optional, default=True) – If True, and data are from NMR, then a ppm scale is calculated instead of frequency.

  • **kwargs – Optional keyword parameters (see Other Parameters).

Returns

out – Transformed NDDataset .

Other Parameters
  • dim (str or int, optional, default=’x’.) – Specify on which dimension to apply this method. If dim is specified as an integer it is equivalent to the usual axis numpy parameter.

  • inplace (bool, optional, default=False.) – True if we make the transform inplace. If False, the function return a new object

  • tdeff (int, optional) – Alias of sizeff (specific to NMR). If both sizeff and tdeff are passed, sizeff has the priority.

See also

ifft

Inverse Fourier transform.

find_peaks(dataset, height=None, window_length=3, threshold=None, distance=None, prominence=None, width=None, wlen=None, rel_height=0.5, plateau_size=None, use_coord=True)[source]

Wrapper and extension of scpy.signal.find_peaks.

Find peaks inside a 1D NDDataset based on peak properties. This function finds all local maxima by simple comparison of neighbouring values. Optionally, a subset of these peaks can be selected by specifying conditions for a peak’s properties.

Warning

This function may return unexpected results for data containing NaNs. To avoid this, NaNs should either be removed or replaced.

Parameters
  • dataset (NDDataset) – A 1D NDDataset or a 2D NDdataset with len(X.y) == 1 .

  • height (float or array-like, optional, default: None) – Required height of peaks. Either a number, None , an array matching x or a 2-element sequence of the former. The first element is always interpreted as the minimal and the second, if supplied, as the maximal required height.

  • window_length (int, default: 5) – The length of the filter window used to interpolate the maximum. window_length must be a positive odd integer. If set to one, the actual maximum is returned.

  • threshold (float or array-like, optional) – Required threshold of peaks, the vertical distance to its neighbouring samples. Either a number, None , an array matching x or a 2-element sequence of the former. The first element is always interpreted as the minimal and the second, if supplied, as the maximal required threshold.

  • distance (float, optional) – Required minimal horizontal distance in samples between neighbouring peaks. Smaller peaks are removed first until the condition is fulfilled for all remaining peaks.

  • prominence (float or array-like, optional) – Required prominence of peaks. Either a number, None , an array matching x or a 2-element sequence of the former. The first element is always interpreted as the minimal and the second, if supplied, as the maximal required prominence.

  • width (float or array-like, optional) – Required width of peaks in samples. Either a number, None , an array matching x or a 2-element sequence of the former. The first element is always interpreted as the minimal and the second, if supplied, as the maximal required width. Floats are interpreted as width measured along the ‘x’ Coord; ints are interpreted as a number of points.

  • wlen (int or float, optional) – Used for calculation of the peaks prominences, thus it is only used if one of the arguments prominence or width is given. Floats are interpreted as measured along the ‘x’ Coord; ints are interpreted as a number of points. See argument len` in peak_prominences of the scipy documentation for a full description of its effects.

  • rel_height (float, optional,) – Used for calculation of the peaks width, thus it is only used if width is given. See argument rel_height in peak_widths of the scipy documentation for a full description of its effects.

  • plateau_size (float or array-like, optional) – Required size of the flat top of peaks in samples. Either a number, None , an array matching x or a 2-element sequence of the former. The first element is always interpreted as the minimal and the second, if supplied as the maximal required plateau size. Floats are interpreted as measured along the ‘x’ Coord; ints are interpreted as a number of points.

  • use_coord (bool, optional) – Set whether the x Coord (when it exists) should be used instead of indices for the positions and width. If True, the units of the other parameters are interpreted according to the coordinates.

Returns

  • peaks (ndarray) – Indices of peaks in dataset that satisfy all given conditions.

  • properties (dict) – A dictionary containing properties of the returned peaks which were calculated as intermediate results during evaluation of the specified conditions:

    • peak_heights

      If height is given, the height of each peak in dataset .

    • left_thresholds, right_thresholds

      If threshold is given, these keys contain a peaks vertical distance to its neighbouring samples.

    • prominences, right_bases, left_bases

      If prominence is given, these keys are accessible. See scipy.signal.peak_prominences for a full description of their content.

    • width_heights, left_ips, right_ips

      If width is given, these keys are accessible. See scipy.signal.peak_widths for a full description of their content.

    • plateau_sizes, left_edges’, ‘right_edges’

      If plateau_size is given, these keys are accessible and contain the indices of a peak’s edges (edges are still part of the plateau) and the calculated plateau sizes.

    To calculate and return properties without excluding peaks, provide the open interval (None, None) as a value to the appropriate argument (excluding distance).

Warns

PeakPropertyWarning – Raised if a peak’s properties have unexpected values (see peak_prominences and peak_widths ).

See also

find_peaks_cwt

In scipy.signal: Find peaks using the wavelet transformation.

peak_prominences

In scipy.signal: Directly calculate the prominence of peaks.

peak_widths

In scipy.signal: Directly calculate the width of peaks.

Notes

In the context of this function, a peak or local maximum is defined as any sample whose two direct neighbours have a smaller amplitude. For flat peaks (more than one sample of equal amplitude wide) the index of the middle sample is returned (rounded down in case the number of samples is even). For noisy signals the peak locations can be off because the noise might change the position of local maxima. In those cases consider smoothing the signal before searching for peaks or use other peak finding and fitting methods (like scipy.signal.find_peaks_cwt ).

Some additional comments on specifying conditions:

  • Almost all conditions (excluding distance) can be given as half-open or closed intervals, e.g 1 or (1, None) defines the half-open interval \([1, \infty]\) while (None, 1) defines the interval \([-\infty, 1]\). The open interval (None, None) can be specified as well, which returns the matching properties without exclusion of peaks.

  • The border is always included in the interval used to select valid peaks.

  • For several conditions the interval borders can be specified with arrays matching dataset in shape which enables dynamic constrains based on the sample position.

  • The conditions are evaluated in the following order: plateau_size , height , threshold , distance , prominence , width . In most cases this order is the fastest one because faster operations are applied first to reduce the number of peaks that need to be evaluated later.

  • While indices in peaks are guaranteed to be at least distance samples apart, edges of flat peaks may be closer than the allowed distance .

  • Use wlen to reduce the time it takes to evaluate the conditions for prominence or width if dataset is large or has many local maxima (see scipy.signal.peak_prominences).

Examples

>>> dataset = scp.read("irdata/nh4y-activation.spg")
>>> X = dataset[0, 1800.0:1300.0]
>>> peaks, properties = X.find_peaks(height=1.5, distance=50.0, width=0.0)
>>> len(peaks.x)
2
>>> peaks.x.values
<Quantity([    1644     1455], 'centimeter^-1')>
>>> properties["peak_heights"][0]
<Quantity(2.26663446, 'absorbance')>
>>> properties["widths"][0]
<Quantity(38.729003, 'centimeter^-1')>
fromfunction(cls, function, shape=None, dtype=float, units=None, coordset=None, **kwargs)[source]

Construct a nddataset by executing a function over each coordinate.

The resulting array therefore has a value fn(x, y, z) at coordinate (x, y, z) .

Parameters
  • function (callable) – The function is called with N parameters, where N is the rank of shape or from the provided CoordSet .

  • shape ((N,) tuple of ints, optional) – Shape of the output array, which also determines the shape of the coordinate arrays passed to function . It is optional only if CoordSet is None.

  • dtype (data-type, optional) – Data-type of the coordinate arrays passed to function . By default, dtype is float.

  • units (str, optional) – Dataset units. When None, units will be determined from the function results.

  • coordset (CoordSet instance, optional) – If provided, this determine the shape and coordinates of each dimension of the returned NDDataset . If shape is also passed it will be ignored.

  • **kwargs – Other kwargs are passed to the final object constructor.

Returns

fromfunction – The result of the call to function is passed back directly. Therefore the shape of fromfunction is completely determined by function .

See also

fromiter

Make a dataset from an iterable.

Examples

Create a 1D NDDataset from a function

>>> func1 = lambda t, v: v * t
>>> time = scp.Coord.arange(0, 60, 10, units='min')
>>> d = scp.fromfunction(func1, v=scp.Quantity(134, 'km/hour'), coordset=scp.CoordSet(t=time))
>>> d.dims
['t']
>>> d
NDDataset: [float64] km (size: 6)
fromiter(iterable, dtype=np.float64, count=-1, **kwargs)[source]

Create a new 1-dimensional array from an iterable object.

Parameters
  • iterable (iterable object) – An iterable object providing data for the array.

  • dtype (data-type) – The data-type of the returned array.

  • count (int, optional) – The number of items to read from iterable. The default is -1, which means all data is read.

  • **kwargs – Other kwargs are passed to the final object constructor.

Returns

fromiter – The output nddataset.

See also

fromfunction

Construct a nddataset by executing a function over each coordinate.

Notes

Specify count to improve performance. It allows fromiter to pre-allocate the

output array, instead of resizing it on demand.

Examples

>>> iterable = (x * x for x in range(5))
>>> d = scp.fromiter(iterable, float, units='km')
>>> d
NDDataset: [float64] km (size: 5)
>>> d.data
array([       0,        1,        4,        9,       16])
fsh(dataset, pts, **kwargs)[source]

Frequency shift by Fourier transform. Negative signed phase correction.

For multidimensional NDDataset, the shift is by default performed on the last dimension.

Parameters
  • data (ndarray) – Array of NMR data.

  • pts (float) – Number of points to frequency shift the data. Positive value will shift the spectrum to the right, negative values to the left.

Returns

dataset – dataset shifted.

Other Parameters
  • dim (str or int, keyword parameter, optional, default=’x’) – Specify on which dimension to apply the shift method. If dim is specified as an integer it is equivalent to the usual axis numpy parameter.

  • inplace (bool, keyword parameter, optional, default=False) – True if we make the transform inplace. If False, the function return a new dataset.

See also

ls, rs, cs, roll, fsh2

fsh2(dataset, pts, **kwargs)[source]

Frequency Shift by Fourier transform. Positive signed phase correction.

For multidimensional NDDataset, the shift is by default performed on the last dimension.

Parameters
  • data (ndarray) – Array of NMR data.

  • pts (float) – Number of points to frequency shift the data. Positive value will shift the spectrum to the right, negative values to the left.

Returns

dataset – dataset shifted.

Other Parameters
  • dim (str or int, keyword parameter, optional, default=’x’) – Specify on which dimension to apply the shift method. If dim is specified as an integer it is equivalent to the usual axis numpy parameter.

  • inplace (bool, keyword parameter, optional, default=False) – True if we make the transform inplace. If False, the function return a new dataset.

See also

ls, rs, cs, roll, fsh2

full(shape, fill_value=0.0, dtype=None, **kwargs)[source]

Return a new NDDataset of given shape and type, filled with fill_value .

Parameters
  • shape (int or sequence of ints) – Shape of the new array, e.g., (2, 3) or 2 .

  • fill_value (scalar) – Fill value.

  • dtype (data-type, optional) – The desired data-type for the array, e.g., np.int8 . Default is fill_value.dtype.

  • **kwargs – Optional keyword parameters (see Other Parameters).

Returns

full – Array of fill_value .

Other Parameters
  • units (str or ur instance) – Units of the returned object. If not provided, try to copy from the input object.

  • coordset (list or Coordset object) – Coordinates for the returned object. If not provided, try to copy from the input object.

See also

zeros_like

Return an array of zeros with shape and type of input.

ones_like

Return an array of ones with shape and type of input.

empty_like

Return an empty array with shape and type of input.

full_like

Fill an array with shape and type of input.

zeros

Return a new array setting values to zero.

ones

Return a new array setting values to one.

empty

Return a new uninitialized array.

Examples

>>> scp.full((2, ), np.inf)
NDDataset: [float64] unitless (size: 2)
>>> scp.NDDataset.full((2, 2), 10, dtype=np.int)
NDDataset: [int64] unitless (shape: (y:2, x:2))
full_like(dataset, fill_value=0.0, dtype=None, **kwargs)[source]

Return a NDDataset of fill_value.

The returned NDDataset have the same shape and type as a given array. Units, coordset, … can be added in kwargs

Parameters
  • dataset (NDDataset or array-like) – Object from which to copy the array structure.

  • fill_value (scalar) – Fill value.

  • dtype (data-type, optional) – Overrides the data type of the result.

  • **kwargs – Optional keyword parameters (see Other Parameters).

Returns

fulllike – Array of fill_value with the same shape and type as dataset .

Other Parameters
  • units (str or ur instance) – Units of the returned object. If not provided, try to copy from the input object.

  • coordset (list or Coordset object) – Coordinates for the returned object. If not provided, try to copy from the input object.

See also

zeros_like

Return an array of zeros with shape and type of input.

ones_like

Return an array of ones with shape and type of input.

empty_like

Return an empty array with shape and type of input.

zeros

Return a new array setting values to zero.

ones

Return a new array setting values to one.

empty

Return a new uninitialized array.

full

Fill a new array.

Examples

3 possible ways to call this method

  1. from the API

>>> x = np.arange(6, dtype=int)
>>> scp.full_like(x, 1)
NDDataset: [float64] unitless (size: 6)
  1. as a classmethod

>>> x = np.arange(6, dtype=int)
>>> scp.NDDataset.full_like(x, 1)
NDDataset: [float64] unitless (size: 6)
  1. as an instance method

>>> scp.NDDataset(x).full_like(1, units='km')
NDDataset: [float64] km (size: 6)
general_hamming(alpha=None)def general_hamming(dataset, alpha, **kwargs)[source]

Calculate generalized Hamming apodization.

For multidimensional NDDataset, the apodization is by default performed on the last dimension.

The data in the last dimension MUST be time-domain or dimensionless, otherwise an error is raised.

Functional form of apodization window :

\[w(n) = \alpha - \left(1 - \alpha\right) \cos\left(\frac{2\pi{n}}{M-1}\right) \qquad 0 \leq n \leq M-1\]

where M is the number of point of the input dataset.

Both the common Hamming window and Hann window are special cases of the generalized Hamming window with \(\alpha\) = 0.54 and :math:alpha = 0.5, respectively

Parameters
  • dataset (array.) – Input dataset.

  • alpha (float) – The window coefficient, :math:alpha.

  • **kwargs – Optional keyword parameters (see Other Parameters).

Returns

  • apodized – Dataset.

  • apod_arr – The apodization array only if ‘retapod’ is True.

Other Parameters
  • dim (str or int, keyword parameter, optional, default=’x’) – Specify on which dimension to apply the apodization method. If dim is specified as an integer it is equivalent to the usual axis numpy parameter.

  • inv (bool, keyword parameter, optional, default=False) – True for inverse apodization.

  • rev (bool, keyword parameter, optional, default=False) – True to reverse the apodization before applying it to the data.

  • inplace (bool, keyword parameter, optional, default=False) – True if we make the transform inplace. If False, the function return a new dataset.

  • retapod (bool, keyword parameter, optional, default=False) – True to return the apodization array along with the apodized object.

geomspace(start, stop, num=50, endpoint=True, dtype=None, **kwargs)[source]

Return numbers spaced evenly on a log scale (a geometric progression).

This is similar to logspace , but with endpoints specified directly. Each output sample is a constant multiple of the previous.

Parameters
  • start (number) – The starting value of the sequence.

  • stop (number) – The final value of the sequence, unless endpoint is False. In that case, num + 1 values are spaced over the interval in log-space, of which all but the last (a sequence of length num ) are returned.

  • num (int, optional) – Number of samples to generate. Default is 50.

  • endpoint (bool, optional) – If true, stop is the last sample. Otherwise, it is not included. Default is True.

  • dtype (dtype) – The type of the output array. If dtype is not given, infer the data type from the other input arguments.

  • **kwargs – Keywords argument used when creating the returned object, such as units, name, title, …

Returns

geomspacenum samples, equally spaced on a log scale.

See also

logspace

Similar to geomspace, but with endpoints specified using log and base.

linspace

Similar to geomspace, but with arithmetic instead of geometric progression.

arange

Similar to linspace, with the step size specified instead of the number of samples.

get_axis(*args, **kwargs)[source]

Helper function to determine an axis index whatever the syntax used (axis index or dimension names).

Parameters
  • dim, axis, dims (str, int, or list of str or index) – The axis indexes or dimensions names - they can be specified as argument or using keyword ‘axis’, ‘dim’ or ‘dims’.

  • negative_axis (bool, optional, default=False) – If True a negative index is returned for the axis value (-1 for the last dimension, etc…).

  • allows_none (bool, optional, default=False) – If True, if input is none then None is returned.

  • only_first (bool, optional, default: True) – By default return only information on the first axis if dim is a list. Else, return a list for axis and dims information.

Returns

  • axis (int) – The axis indexes.

  • dim (str) – The axis name.

get_baseline(dataset, *ranges, **kwargs)[source]

Compute a baseline using the Baseline class processor.

If no ranges is provided, the features limits are used. See Baseline for detailed information on the parameters.

Parameters
  • dataset (a NDDataset instance) – The dataset where to calculate the baseline.

  • *ranges (a variable number of pair-tuples) – The regions taken into account for the manual baseline correction.

  • **kwargs – Optional keyword parameters (see Baseline Parameters for a detailed information).

Returns

NDDataset – The computed baseline

See also

Baseline

Manual baseline correction processor.

basc

Make a baseline correction using the Baseline class.

asls

Perform an Asymmetric Least Squares Smoothing baseline correction.

snip

Perform a Simple Non-Iterative Peak (SNIP) detection algorithm.

rubberband

Perform a Rubberband baseline correction.

autosub

Perform an automatic subtraction of reference.

detrend

Remove polynomial trend along a dimension from dataset.

Notes

For more flexibility and functionality, it is advised to use the Baseline class processor instead.

get_labels(level=0)[source]

Get the labels at a given level.

Used to replace data when only labels are provided, and/or for labeling axis in plots.

Parameters

level (int, optional, default:0) – Label level.

Returns

ndarray – The labels at the desired level or None.

gm(gb="Hz", lb="Hz", shifted="us")def gm(dataset, gb=1, lb=0, shifted=0, **kwargs)[source]

Calculate lorentz-to-gauss apodization.

Functional form of apodization window :

\[gm(t) = \exp(e - g^2 )\]

where :

\[e = \pi * lb * (t - t0)\]

and

\[g = 0.6 * \pi * gb * (t - t0)\]
Parameters
  • dataset (ndarray) – Dataset we want to apodize using an Lorentz Multiplication.

  • lb (float or quantity , optional, default=0 Hz) – Inverse exponential width. If it is not a quantity with units, it is assumed to be a broadening expressed in Hz.

  • gb (float or quantity , optional, default=1 Hz) – Gaussian broadening width. If it is not a quantity with units, it is assumed to be a broadening expressed in Hz.

  • shifted (float or quantity , optional, default=0 us) – Shift the data time origin by this amount. If it is not a quantity it is assumed to be expressed in the data units of the last dimension.

Returns

  • apodized – Dataset.

  • apod_arr – The apodization array only if ‘retapod’ is True.

Other Parameters
  • dim (str or int, keyword parameter, optional, default=’x’) – Specify on which dimension to apply the apodization method. If dim is specified as an integer it is equivalent to the usual axis numpy parameter.

  • inv (bool, keyword parameter, optional, default=False) – True for inverse apodization.

  • rev (bool, keyword parameter, optional, default=False) – True to reverse the apodization before applying it to the data.

  • inplace (bool, keyword parameter, optional, default=False) – True if we make the transform inplace. If False, the function return a new dataset

  • retapod (bool, keyword parameter, optional, default=False) – True to return the apodization array along with the apodized object.

hamming(dataset, **kwargs)[source]

Calculate generalized Hamming (== Happ-Genzel) apodization.

For multidimensional NDDataset, the apodization is by default performed on the last dimension.

The data in the last dimension MUST be time-domain or dimensionless, otherwise an error is raised.

Functional form of apodization window :

\[w(n) = \alpha - (1 - \alpha)\cos(\frac{2\pi n}{M-1})\qquad 0\leq n\leq M-1\]

where M is the number of point of the input dataset and :math:alpha = 0.54.

Parameters
  • dataset (array) – Input dataset.

  • **kwargs – Optional keyword parameters (see Other Parameters).

Returns

  • apodized – Dataset.

  • apod_arr – The apodization array only if ‘retapod’ is True.

Other Parameters
  • dim (str or int, keyword parameter, optional, default=’x’.) – Specify on which dimension to apply the apodization method. If dim is specified as an integer it is equivalent to the usual axis numpy parameter.

  • inv (bool, keyword parameter, optional, default=False.) – True for inverse apodization.

  • rev (bool, keyword parameter, optional, default=False.) – True to reverse the apodization before applying it to the data.

  • inplace (bool, keyword parameter, optional, default=False.) – True if we make the transform inplace. If False, the function return a new dataset

  • retapod (bool, keyword parameter, optional, default=False) – True to return the apodization array along with the apodized object

See also

general_hamming, hann

hann(dataset, **kwargs)[source]

Return a Hann window.

For multidimensional NDDataset, the apodization is by default performed on the last dimension.

The data in the last dimension MUST be time-domain or dimensionless, otherwise an error is raised.

Functional form of apodization window :

\[w(n) = \alpha - (1 - \alpha) \cos(\frac{2\pi{n}}{M-1}) \qquad 0 \leq n \leq M-1\]

where M is the number of point of the input dataset and \(\alpha\) = 0.5

Parameters
  • dataset (NDDataset) – Input dataset.

  • **kwargs – Optional keyword parameters (see Other Parameters).

Returns

  • apodized – Dataset.

  • apod_arr – The apodization array only if ‘retapod’ is True.

Other Parameters
  • dim (str or int, keyword parameter, optional, default=’x’.) – Specify on which dimension to apply the apodization method. If dim is specified as an integer it is equivalent to the usual axis numpy parameter.

  • inv (bool, keyword parameter, optional, default=False.) – True for inverse apodization.

  • rev (bool, keyword parameter, optional, default=False.) – True to reverse the apodization before applying it to the data.

  • inplace (bool, keyword parameter, optional, default=False.) – True if we make the transform inplace. If False, the function return a new dataset

  • retapod (bool, keyword parameter, optional, default=False) – True to return the apodization array along with the apodized object

ht(dataset, N=None)[source]

Hilbert transform.

Reconstruct imaginary data via hilbert transform. Copied from NMRGlue (BSD3 licence).

Parameters
  • data (ndarrat) – Array of NMR data.

  • N (int or None) – Number of Fourier components.

Returns

ndata (ndarray) – NMR data which has been Hilvert transformed.

identity(n, dtype=None, **kwargs)[source]

Return the identity NDDataset of a given shape.

The identity array is a square array with ones on the main diagonal.

Parameters
  • n (int) – Number of rows (and columns) in n x n output.

  • dtype (data-type, optional) – Data-type of the output. Defaults to float .

  • **kwargs – Other parameters to be passed to the object constructor (units, coordset, mask …).

Returns

identityn x n array with its main diagonal set to one, and all other elements 0.

See also

eye

Almost equivalent function.

diag

Diagonal 2-D array from a 1-D array specified by the user.

Examples

>>> scp.identity(3).data
array([[       1,        0,        0],
       [       0,        1,        0],
       [       0,        0,        1]])
ifft(dataset, size=None, **kwargs)[source]

Apply a inverse fast fourier transform.

For multidimensional NDDataset, the apodization is by default performed on the last dimension.

The data in the last dimension MUST be in frequency (or without dimension) or an error is raised.

To make direct Fourier transform, i.e., from frequency to time domain, use the fft transform.

Parameters
  • dataset (NDDataset) – The dataset on which to apply the fft transformation.

  • size (int, optional) – Size of the transformed dataset dimension - a shorter parameter is si . by default, the size is the closest power of two greater than the data size.

  • **kwargs – Optional keyword parameters (see Other Parameters).

Returns

out – Transformed NDDataset .

Other Parameters
  • dim (str or int, optional, default=’x’.) – Specify on which dimension to apply this method. If dim is specified as an integer it is equivalent to the usual axis numpy parameter.

  • inplace (bool, optional, default=False.) – True if we make the transform inplace. If False, the function return a new object

See also

fft

Direct Fourier transform.

is_units_compatible(other)[source]

Check the compatibility of units with another object.

Parameters

other (ndarray) – The ndarray object for which we want to compare units compatibility.

Returns

result – True if units are compatible.

Examples

>>> nd1 = scp.NDDataset([1. + 2.j, 2. + 3.j], units='meters')
>>> nd1
NDDataset: [complex128] m (size: 2)
>>> nd2 = scp.NDDataset([1. + 2.j, 2. + 3.j], units='seconds')
>>> nd1.is_units_compatible(nd2)
False
>>> nd1.ito('minutes', force=True)
>>> nd1.is_units_compatible(nd2)
True
>>> nd2[0].values * 60. == nd1[0].values
True
ito(other, force=False)[source]

Inplace scaling to different units. (same as to with inplace= True).

Parameters
  • other (Unit , Quantity or str) – Destination units.

  • force (bool, optional, default=`False`) – If True the change of units is forced, even for incompatible units.

See also

to

Rescaling of the current object data to different units.

to_base_units

Rescaling of the current object data to different units.

ito_base_units

Inplace rescaling of the current object data to different units.

to_reduced_units

Rescaling to reduced units.

ito_reduced_units

Rescaling to reduced units.

ito_base_units()[source]

Inplace rescaling to base units.

See also

to

Rescaling of the current object data to different units.

ito

Inplace rescaling of the current object data to different units.

to_base_units

Rescaling of the current object data to different units.

to_reduced_units

Rescaling to redunced units.

ito_reduced_units

Inplace rescaling to reduced units.

ito_reduced_units()[source]

Quantity scaled in place to reduced units, inplace.

Scaling to reduced units means one unit per dimension. This will not reduce compound units (e.g., ‘J/kg’ will not be reduced to m**2/s**2).

See also

to

Rescaling of the current object data to different units.

ito

Inplace rescaling of the current object data to different units.

to_base_units

Rescaling of the current object data to different units.

ito_base_units

Inplace rescaling of the current object data to different units.

to_reduced_units

Rescaling to reduced units.

linspace(cls, start, stop, num=50, endpoint=True, retstep=False, dtype=None, **kwargs)[source]

Return evenly spaced numbers over a specified interval.

Returns num evenly spaced samples, calculated over the interval [start, stop]. The endpoint of the interval can optionally be excluded.

Parameters
  • start (array_like) – The starting value of the sequence.

  • stop (array_like) – The end value of the sequence, unless endpoint is set to False. In that case, the sequence consists of all but the last of num + 1 evenly spaced samples, so that stop is excluded. Note that the step size changes when endpoint is False.

  • num (int, optional) – Number of samples to generate. Default is 50. Must be non-negative.

  • endpoint (bool, optional) – If True, stop is the last sample. Otherwise, it is not included. Default is True.

  • retstep (bool, optional) – If True, return (samples, step), where step is the spacing between samples.

  • dtype (dtype, optional) – The type of the array. If dtype is not given, infer the data type from the other input arguments.

  • **kwargs – Keywords argument used when creating the returned object, such as units,

    name, title, …

Returns

  • linspace (ndarray) – There are num equally spaced samples in the closed interval [start, stop] or the half-open interval [start, stop) (depending on whether endpoint is True or False).

  • step (float, optional) – Only returned if retstep is True Size of spacing between samples.

classmethod load(filename, **kwargs)[source]

Open data from a ‘*.scp’ (NDDataset) or ‘*.pscp’ (Project) file.

Parameters
  • filename (str , pathlib or file objects) – The name of the file to read (or a file objects).

  • **kwargs – Optional keyword parameters (see Other Parameters).

Other Parameters

content (str, optional) – The optional content of the file(s) to be loaded as a binary string.

See also

read

Import dataset from various orgines.

save

Save the current dataset.

Notes

Adapted from numpy.load .

Examples

>>> nd1 = scp.read('irdata/nh4y-activation.spg')
>>> f = nd1.save()
>>> f.name
'nh4y-activation.scp'
>>> nd2 = scp.load(f)

Alternatively, this method can be called as a class method of NDDataset or Project object:

>>> from spectrochempy import *
>>> nd2 = NDDataset.load(f)
load_iris()[source]

Upload the classical “iris” dataset.

The “IRIS” dataset is a classical example for machine learning. It is read from the scikit-learn package.

Returns

dataset – The IRIS dataset.

See also

read

Read data from experimental data.

logspace(cls, start, stop, num=50, endpoint=True, base=10.0, dtype=None, **kwargs)[source]

Return numbers spaced evenly on a log scale.

In linear space, the sequence starts at base ** start (base to the power of start ) and ends with base ** stop (see endpoint below).

Parameters
  • start (array_like) – base ** start is the starting value of the sequence.

  • stop (array_like) – base ** stop is the final value of the sequence, unless endpoint is False. In that case, num + 1 values are spaced over the interval in log-space, of which all but the last (a sequence of length num ) are returned.

  • num (int, optional) – Number of samples to generate. Default is 50.

  • endpoint (bool, optional) – If true, stop is the last sample. Otherwise, it is not included. Default is True.

  • base (float, optional) – The base of the log space. The step size between the elements in ln(samples) / ln(base) (or log_base(samples) ) is uniform. Default is 10.0.

  • dtype (dtype) – The type of the output array. If dtype is not given, infer the data type from the other input arguments.

  • **kwargs – Keywords argument used when creating the returned object, such as units, name, title, …

Returns

logspacenum samples, equally spaced on a log scale.

See also

arange

Similar to linspace, with the step size specified instead of the number of samples. Note that, when used with a float endpoint, the endpoint may or may not be included.

linspace

Similar to logspace, but with the samples uniformly distributed in linear space, instead of log space.

geomspace

Similar to logspace, but with endpoints specified directly.

ls(dataset, pts=0.0, **kwargs)[source]

Left shift and zero fill.

For multidimensional NDDataset, the shift is by default performed on the last dimension.

Parameters
  • dataset (nddataset) – NDDataset to be left-shifted.

  • pts (int) – Number of points to right shift.

Returns

NDDataset – Modified dataset.

Other Parameters
  • dim (str or int, keyword parameter, optional, default=’x’) – Specify on which dimension to apply the shift method. If dim is specified as an integer it is equivalent to the usual axis numpy parameter.

  • inplace (bool, keyword parameter, optional, default=False) – True if we make the transform inplace. If False, the function return a new dataset.

See also

roll

shift without zero filling.

max(dataset, dim=None, keepdims=False, **kwargs)[source]

Return the maximum of the dataset or maxima along given dimensions.

Parameters
  • dataset (array_like) – Input array or object that can be converted to an array.

  • dim (None or int or dimension name or tuple of int or dimensions, optional) – Dimension or dimensions along which to operate. By default, flattened input is used. If this is a tuple, the maximum is selected over multiple dimensions, instead of a single dimension or all the dimensions as before.

  • keepdims (bool, optional) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.

Returns

amax – Maximum of the data. If dim is None, the result is a scalar value. If dim is given, the result is an array of dimension ndim - 1 .

See also

amin

The minimum value of a dataset along a given dimension, propagating NaNs.

minimum

Element-wise minimum of two datasets, propagating any NaNs.

maximum

Element-wise maximum of two datasets, propagating any NaNs.

fmax

Element-wise maximum of two datasets, ignoring any NaNs.

fmin

Element-wise minimum of two datasets, ignoring any NaNs.

argmax

Return the indices or coordinates of the maximum values.

argmin

Return the indices or coordinates of the minimum values.

Notes

For dataset with complex or hypercomplex type type, the default is the value with the maximum real part.

mc(dataset)[source]

Modulus calculation.

Calculates sqrt(real^2 + imag^2)

mean(dataset, dim=None, dtype=None, keepdims=False)[source]

Compute the arithmetic mean along the specified axis.

Returns the average of the array elements. The average is taken over the flattened array by default, otherwise over the specified axis.

Parameters
  • dataset (array_like) – Array containing numbers whose mean is desired.

  • dim (None or int or dimension name, optional) – Dimension or dimensions along which to operate.

  • dtype (data-type, optional) – Type to use in computing the mean. For integer inputs, the default is float64; for floating point inputs, it is the same as the input dtype.

  • keepdims (bool, optional) – If this is set to True, the dimensions which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.

Returns

mean – A new array containing the mean values.

See also

average

Weighted average.

std

Standard deviation values along axis.

var

Variance values along axis.

Notes

The arithmetic mean is the sum of the elements along the axis divided by the number of elements.

Examples

>>> nd = scp.read('irdata/nh4y-activation.spg')
>>> nd
NDDataset: [float64] a.u. (shape: (y:55, x:5549))
>>> scp.mean(nd)
<Quantity(1.25085858, 'absorbance')>
>>> scp.mean(nd, keepdims=True)
NDDataset: [float64] a.u. (shape: (y:1, x:1))
>>> m = scp.mean(nd, dim='y')
>>> m
NDDataset: [float64] a.u. (size: 5549)
>>> m.x
Coord: [float64] cm⁻¹ (size: 5549)
min(dataset, dim=None, keepdims=False, **kwargs)[source]

Return the maximum of the dataset or maxima along given dimensions.

Parameters
  • dataset (array_like) – Input array or object that can be converted to an array.

  • dim (None or int or dimension name or tuple of int or dimensions, optional) – Dimension or dimensions along which to operate. By default, flattened input is used. If this is a tuple, the minimum is selected over multiple dimensions, instead of a single dimension or all the dimensions as before.

  • keepdims (bool, optional) – If this is set to True, the dimensions which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.

Returns

amin – Minimum of the data. If dim is None, the result is a scalar value. If dim is given, the result is an array of dimension ndim - 1 .

See also

amax

The maximum value of a dataset along a given dimension, propagating NaNs.

minimum

Element-wise minimum of two datasets, propagating any NaNs.

maximum

Element-wise maximum of two datasets, propagating any NaNs.

fmax

Element-wise maximum of two datasets, ignoring any NaNs.

fmin

Element-wise minimum of two datasets, ignoring any NaNs.

argmax

Return the indices or coordinates of the maximum values.

argmin

Return the indices or coordinates of the minimum values.

ones(shape, dtype=None, **kwargs)[source]

Return a new NDDataset of given shape and type, filled with ones.

Parameters
  • shape (int or sequence of ints) – Shape of the new array, e.g., (2, 3) or 2 .

  • dtype (data-type, optional) – The desired data-type for the array, e.g., numpy.int8 . Default is

  • **kwargs – Optional keyword parameters (see Other Parameters).

Returns

ones – Array of ones .

Other Parameters
  • units (str or ur instance) – Units of the returned object. If not provided, try to copy from the input object.

  • coordset (list or Coordset object) – Coordinates for the returned object. If not provided, try to copy from the input object.

See also

zeros_like

Return an array of zeros with shape and type of input.

ones_like

Return an array of ones with shape and type of input.

empty_like

Return an empty array with shape and type of input.

full_like

Fill an array with shape and type of input.

zeros

Return a new array setting values to zero.

empty

Return a new uninitialized array.

full

Fill a new array.

Examples

>>> nd = scp.ones(5, units='km')
>>> nd
NDDataset: [float64] km (size: 5)
>>> nd.values
<Quantity([       1        1        1        1        1], 'kilometer')>
>>> nd = scp.ones((5,), dtype=np.int, mask=[True, False, False, False, True])
>>> nd
NDDataset: [int64] unitless (size: 5)
>>> nd.values
masked_array(data=[  --,        1,        1,        1,   --],
             mask=[  True,   False,   False,   False,   True],
       fill_value=999999)
>>> nd = scp.ones((5,), dtype=np.int, mask=[True, False, False, False, True], units='joule')
>>> nd
NDDataset: [int64] J (size: 5)
>>> nd.values
<Quantity([  --        1        1        1   --], 'joule')>
>>> scp.ones((2, 2)).values
array([[       1,        1],
       [       1,        1]])
ones_like(dataset, dtype=None, **kwargs)[source]

Return NDDataset of ones.

The returned NDDataset have the same shape and type as a given array. Units, coordset, … can be added in kwargs.

Parameters
  • dataset (NDDataset or array-like) – Object from which to copy the array structure.

  • dtype (data-type, optional) – Overrides the data type of the result.

  • **kwargs – Optional keyword parameters (see Other Parameters).

Returns

oneslike – Array of 1 with the same shape and type as dataset .

Other Parameters
  • units (str or ur instance) – Units of the returned object. If not provided, try to copy from the input object.

  • coordset (list or Coordset object) – Coordinates for the returned object. If not provided, try to copy from the input object.

See also

full_like

Return an array with a given fill value with shape and type of the

input.

zeros_like

Return an array of zeros with shape and type of input.

empty_like

Return an empty array with shape and type of input.

zeros

Return a new array setting values to zero.

ones

Return a new array setting values to one.

empty

Return a new uninitialized array.

full

Fill a new array.

Examples

>>> x = np.arange(6)
>>> x = x.reshape((2, 3))
>>> x = scp.NDDataset(x, units='s')
>>> x
NDDataset: [float64] s (shape: (y:2, x:3))
>>> scp.ones_like(x, dtype=float, units='J')
NDDataset: [float64] J (shape: (y:2, x:3))
pipe(func, *args, **kwargs)[source]

Apply func(self, *args, **kwargs).

Parameters
  • func (function) – Function to apply to the NDDataset . *args` , and **kwargs are passed into func . Alternatively a (callable, data_keyword) tuple where data_keyword is a string indicating the keyword of callable that expects the array object.

  • *args – Positional arguments passed into func .

  • **kwargs – Keyword arguments passed into func .

Returns

pipe – The return type of func .

Notes

Use pipe when chaining together functions that expect a NDDataset .

pk(dataset, phc0=0.0, phc1=0.0, exptc=0.0, pivot=0.0, **kwargs)[source]

Linear phase correction.

For multidimensional NDDataset, the phase is by default applied on the last dimension.

Parameters
  • dataset (nddataset) – Input dataset.

  • phc0 (float or Quantity , optional, default=0 degree) – Zero order phase in degrees.

  • phc1 (float or Quantity , optional, default=0 degree) – First order phase in degrees.

  • exptc (float or Quantity , optional, default=0 us) – Exponential decay constant. If not 0, phc1 is ignored.

  • pivot (float or Quantity , optional, default=0 in units of the x coordinate) – Units if any must be compatible with last dimension units.

Returns

phased – Dataset.

Other Parameters
  • dim (str or int, keyword parameter, optional, default=’x’.) – Specify on which dimension to apply the phase. If dim is specified as an integer it is equivalent to the usual axis numpy parameter.

  • inv (bool, keyword parameter, optional, default=False.) – True for inverse phasing.

  • inplace (bool, keyword parameter, optional, default=False.) – True if we make the transform inplace. If False, the function return a new dataset.

See also

ps_exp

Exponential Phase Correction.

pk

Automatic or manual phasing.

pk_exp(dataset, phc0=0.0, pivot=0.0, exptc=0.0, **kwargs)[source]

Exponential Phase Correction.

For multidimensional NDDataset, the phase is by default applied on the last dimension.

Parameters
  • dataset (nddataset) – Input dataset.

  • phc0 (float or Quantity , optional, default=0 degree) – Zero order phase in degrees.

  • exptc (float or Quantity , optional, default=0 us) – Exponential decay constant.

Returns

phased – Dataset.

Other Parameters
  • dim (str or int, keyword parameter, optional, default=’x’.) – Specify on which dimension to apply the phase. If dim is specified as an integer it is equivalent to the usual axis numpy parameter.

  • inv (bool, keyword parameter, optional, default=False.) – True for inverse phasing.

  • inplace (bool, keyword parameter, optional, default=False.) – True if we make the transform inplace. If False, the function return a new dataset.

See also

ps

Linear Phase Correction.

pk

Automatic or manual phasing.

plot(method=None, **kwargs)[source]

Generic plot function.

This apply to a NDDataset but actually delegate the work to a plotter defined by the keyword parameter method .

Parameters
  • method (str, optional, default: “generic”) – Specify with plot method to use.

  • **kwargs – Any optional parameters to pass to the plot method. See plot_1D, plot_2D and plot_3D for a list of possible arguments.

Returns

axe – The axe instance on which the plot has bee performed.

Examples

For 1D data, the default plot is done with method scatter

>>> nd = scp.NDDataset([1, 2, 3])
>>> _ = nd.plot()  # default to method="scatter"

or >>> _ = nd.plot(method=”scatter”)

Equivalently, one can also specify the method to use as follow: >>> _ = nd.plot_scatter() >>> _ = nd.plot_1D()

For

plot_1D(_PLOT1D_DOC)def plot_1D(dataset, method=None, **kwargs)[source]

Plot of one-dimensional data.

Parameters
  • dataset (NDDataset) – Source of data to plot.

  • method (str, optional, default: dataset.preference.method_1D) – The method can be one among pen , bar , scatter or scatter+pen . Default values is pen , i.e., solid lines are drawn. This default can be changed using dataset.preference.method_1D . To draw a Bar graph, use method bar . For a Scatter plot, use method scatter . For pen and scatter simultaneously, use method scatter+pen .

  • **kwargs – Optional keyword parameters (see Other Parameters).

Other Parameters
  • ax (Axe, optional) – Axe where to plot. If not specified, create a new one.

  • style (str, optional, default: dataset.preferences.style (scpy)) – Matplotlib stylesheet (use available_style to get a list of available styles for plotting.

  • use_plotly (bool, optional, default: preferences.use_plotly (False)) – Should we use plotly instead of matplotlib for plotting.

  • twinx (Axes instance, optional, default: None) – If this is not None, then a twin axes will be created with a common x dimension.

  • clear (bool, optional, default: True) – If false, hold the current figure and ax until a new plot is performed.

  • reverse (bool or None [optional, default=None/False) – In principle, coordinates run from left to right, except for wavenumbers (e.g., FTIR spectra) or ppm (e.g., NMR), that spectrochempy will try to guess. But if reverse is set, then this is the setting which will be taken into account.

  • data_only (bool, optional, default: False) – Only the plot is done. No addition of axes or label specifications.

  • imag (bool, optional, default: False) – Show imaginary component for complex data. By default the real component is displayed.

  • show_complex (bool, optional, default: False) – Show both real and imaginary component for complex data. By default only the real component is displayed.

  • figsize (tuple, optional, default is (3.4, 1.7)) – figure size.

  • dpi (int, optional) – the number of pixel per inches.

  • xlim (tuple, optional) – limit on the horizontal axis.

  • zlim or ylim (tuple, optional) – limit on the vertical axis.

  • color or c (color, optional, default: auto) – color of the line.

  • linewidth or lw (float, optional, default: auto) – line width.

  • linestyle or ls (str, optional, default: auto) – line style definition.

  • marker, m (str, optional, default: auto) – marker type for scatter plot. If marker != “” then the scatter type of plot is chosen automatically.

  • markeredgecolor or mec (color, optional)

  • markeredgewidth or mew (float, optional)

  • markerfacecolor or mfc (color, optional)

  • markersize or ms (float, optional)

  • markevery (None or int)

  • title (str) – Title of the plot (or subplot) axe.

  • plottitle (bool, optional, default: False) – Use the name of the dataset as title. Works only if title is not defined

  • xlabel (str, optional) – label on the horizontal axis.

  • zlabel or ylabel (str, optional) – label on the vertical axis.

  • uselabel_x (bool, optional) – use x coordinate label as x tick labels

  • show_z (bool, optional, default: True) – should we show the vertical axis.

  • show_zero (bool, optional) – show the zero basis.

  • show_mask (bool, optional) – Should we display the mask using colored area.

  • plot_model (Bool,) – plot model data if available.

  • modellinestyle or modls (str) – line style of the model.

  • offset (float) – offset of the model individual lines.

  • commands (str,) – matplotlib commands to be executed.

  • output (str,) – name of the file to save the figure.

  • vshift (float, optional) – vertically shift the line from its baseline.

plot_2D(_PLOT2D_DOC)def plot_2D(dataset, method=None, **kwargs)[source]

Plot of 2D array.

Parameters
  • dataset (NDDataset) – The dataset to plot.

  • method ([‘stack’, ‘map’, ‘image’] , optional) – The method of plot of the dataset, which will determine the plotter to use. Default method is given ‘stack’ but this can be changed using dataset.preference.method_2D .

  • **kwargs – Optional keyword parameters (see Other Parameters).

Other Parameters
  • ax (|Axes| instance. Optional) – The axe where to plot. The default is the current axe or to create a new one if is None.

  • clear (bool, optional, default=`True`) – Should we plot on the ax previously used or create a new figure?.

  • figsize (tuple, optional) – The figure size expressed as a tuple (w,h) in inch.

  • fontsize (int, optional) – The font size in pixels, default is 10 (or read from preferences).

  • style (str)

  • autolayout (bool , optional, default=True) – if True, layout will be set automatically.

  • output (str) – A string containing a path to a filename. The output format is deduced from the extension of the filename. If the filename has no extension, the value of the rc parameter savefig.format is used.

  • dpi ([ None | scalar > 0]) – The resolution in dots per inch. If None it will default to the value savefig.dpi in the matplotlibrc file.

  • colorbar

  • transposed

  • clear

  • ax

  • twinx

  • use_plotly (bool, optional) – Should we use plotly instead of mpl for plotting. Default to preferences.use_plotly (default=False)

  • data_only (bool [optional, default=`False`]) – Only the plot is done. No addition of axes or label specifications (current if any or automatic settings are kept.

  • method (str [optional among map , stack , image, surface or 3D]) – The type of plot,

  • projections (bool [optional, default=False])

  • style (str, optional, default=’notebook’) – Matplotlib stylesheet (use available_style to get a list of available styles for plotting

  • reverse (bool or None [optional, default=None) – In principle, coordinates run from left to right, except for wavenumbers (e.g., FTIR spectra) or ppm (e.g., NMR), that spectrochempy will try to guess. But if reverse is set, then this is the setting which will be taken into account.

  • x_reverse (bool or None [optional, default=None)

plot_3D(_PLOT3D_DOC)def plot_3D(dataset, method="surface", **kwargs)[source]

Plot of 2D array as 3D plot

Parameters
  • dataset (NDDataset) – The dataset to plot.

  • method ([‘surface’, ‘waterfall’] , optional) – The method of plot of the dataset, which will determine the plotter to use. Default is stack.

  • **kwargs – Optional keyword parameters (see Other Parameters).

Other Parameters
  • ax (|Axes| instance. Optional) – The axe where to plot. The default is the current axe or to create a new one if is None.

  • figsize (tuple, optional) – The figure size expressed as a tuple (w,h) in inch.

  • fontsize (int, optional) – The font size in pixels, default is 10 (or read from preferences).

  • autolayout (bool , optional, default=True) – if True, layout will be set automatically.

  • dpi ([ None | scalar > 0]) – The resolution in dots per inch. If None it will default to the value savefig.dpi in the matplotlibrc file.

  • colorbar

  • method (str [optional among surface , waterfall , …]) – The type of plot,

  • style (str, optional, default=’notebook’) – Matplotlib stylesheet (use available_style to get a list of available styles for plotting

  • reverse (bool or None [optional, default=None) – In principle, coordinates run from left to right, except for wavenumbers (e.g., FTIR spectra) or ppm (e.g., NMR), that spectrochempy will try to guess. But if reverse is set, then this is the setting which will be taken into account.

  • x_reverse (bool or None [optional, default=None)

  • y_reverse (bool or None [optional, default=None)

plot_bar(dataset, *args, **kwargs)[source]

Plot a 1D dataset with bars.

Alias of plot (with method argument set to bar .

Parameters
  • dataset (NDDataset) – The dataset to plot.

  • **kwargs – Optional keyword parameters (see Other Parameters).

Other Parameters
  • ax (Axe, optional) – Axe where to plot. If not specified, create a new one.

  • style (str, optional, default: dataset.preferences.style (scpy)) – Matplotlib stylesheet (use available_style to get a list of available styles for plotting.

  • use_plotly (bool, optional, default: preferences.use_plotly (False)) – Should we use plotly instead of matplotlib for plotting.

  • twinx (Axes instance, optional, default: None) – If this is not None, then a twin axes will be created with a common x dimension.

  • clear (bool, optional, default: True) – If false, hold the current figure and ax until a new plot is performed.

  • reverse (bool or None [optional, default=None/False) – In principle, coordinates run from left to right, except for wavenumbers (e.g., FTIR spectra) or ppm (e.g., NMR), that spectrochempy will try to guess. But if reverse is set, then this is the setting which will be taken into account.

  • data_only (bool, optional, default: False) – Only the plot is done. No addition of axes or label specifications.

  • imag (bool, optional, default: False) – Show imaginary component for complex data. By default the real component is displayed.

  • show_complex (bool, optional, default: False) – Show both real and imaginary component for complex data. By default only the real component is displayed.

  • figsize (tuple, optional, default is (3.4, 1.7)) – figure size.

  • dpi (int, optional) – the number of pixel per inches.

  • xlim (tuple, optional) – limit on the horizontal axis.

  • zlim or ylim (tuple, optional) – limit on the vertical axis.

  • color or c (color, optional, default: auto) – color of the line.

  • linewidth or lw (float, optional, default: auto) – line width.

  • linestyle or ls (str, optional, default: auto) – line style definition.

  • marker, m (str, optional, default: auto) – marker type for scatter plot. If marker != “” then the scatter type of plot is chosen automatically.

  • markeredgecolor or mec (color, optional)

  • markeredgewidth or mew (float, optional)

  • markerfacecolor or mfc (color, optional)

  • markersize or ms (float, optional)

  • markevery (None or int)

  • title (str) – Title of the plot (or subplot) axe.

  • plottitle (bool, optional, default: False) – Use the name of the dataset as title. Works only if title is not defined

  • xlabel (str, optional) – label on the horizontal axis.

  • zlabel or ylabel (str, optional) – label on the vertical axis.

  • uselabel_x (bool, optional) – use x coordinate label as x tick labels

  • show_z (bool, optional, default: True) – should we show the vertical axis.

  • show_zero (bool, optional) – show the zero basis.

  • show_mask (bool, optional) – Should we display the mask using colored area.

  • plot_model (Bool,) – plot model data if available.

  • modellinestyle or modls (str) – line style of the model.

  • offset (float) – offset of the model individual lines.

  • commands (str,) – matplotlib commands to be executed.

  • output (str,) – name of the file to save the figure.

  • vshift (float, optional) – vertically shift the line from its baseline.

plot_image(dataset, *args, **kwargs)[source]

Plot a 2D dataset as an image plot.

Alias of plot_2D (with method argument set to image ).

Parameters
  • dataset (NDDataset) – The dataset to plot.

  • **kwargs – Optional keyword parameters (see Other Parameters).

Other Parameters
  • ax (|Axes| instance. Optional) – The axe where to plot. The default is the current axe or to create a new one if is None.

  • clear (bool, optional, default=`True`) – Should we plot on the ax previously used or create a new figure?.

  • figsize (tuple, optional) – The figure size expressed as a tuple (w,h) in inch.

  • fontsize (int, optional) – The font size in pixels, default is 10 (or read from preferences).

  • style (str)

  • autolayout (bool , optional, default=True) – if True, layout will be set automatically.

  • output (str) – A string containing a path to a filename. The output format is deduced from the extension of the filename. If the filename has no extension, the value of the rc parameter savefig.format is used.

  • dpi ([ None | scalar > 0]) – The resolution in dots per inch. If None it will default to the value savefig.dpi in the matplotlibrc file.

  • colorbar

  • transposed

  • clear

  • ax

  • twinx

  • use_plotly (bool, optional) – Should we use plotly instead of mpl for plotting. Default to preferences.use_plotly (default=False)

  • data_only (bool [optional, default=`False`]) – Only the plot is done. No addition of axes or label specifications (current if any or automatic settings are kept.

  • method (str [optional among map , stack , image, surface or 3D]) – The type of plot,

  • projections (bool [optional, default=False])

  • style (str, optional, default=’notebook’) – Matplotlib stylesheet (use available_style to get a list of available styles for plotting

  • reverse (bool or None [optional, default=None) – In principle, coordinates run from left to right, except for wavenumbers (e.g., FTIR spectra) or ppm (e.g., NMR), that spectrochempy will try to guess. But if reverse is set, then this is the setting which will be taken into account.

  • x_reverse (bool or None [optional, default=None)

plot_map(dataset, *args, **kwargs)[source]

Plot a 2D dataset as a contoured map.

Alias of plot_2D (with method argument set to map .

Parameters
  • dataset (NDDataset) – The dataset to plot.

  • **kwargs – Optional keyword parameters (see Other Parameters).

Other Parameters
  • ax (|Axes| instance. Optional) – The axe where to plot. The default is the current axe or to create a new one if is None.

  • clear (bool, optional, default=`True`) – Should we plot on the ax previously used or create a new figure?.

  • figsize (tuple, optional) – The figure size expressed as a tuple (w,h) in inch.

  • fontsize (int, optional) – The font size in pixels, default is 10 (or read from preferences).

  • style (str)

  • autolayout (bool , optional, default=True) – if True, layout will be set automatically.

  • output (str) – A string containing a path to a filename. The output format is deduced from the extension of the filename. If the filename has no extension, the value of the rc parameter savefig.format is used.

  • dpi ([ None | scalar > 0]) – The resolution in dots per inch. If None it will default to the value savefig.dpi in the matplotlibrc file.

  • colorbar

  • transposed

  • clear

  • ax

  • twinx

  • use_plotly (bool, optional) – Should we use plotly instead of mpl for plotting. Default to preferences.use_plotly (default=False)

  • data_only (bool [optional, default=`False`]) – Only the plot is done. No addition of axes or label specifications (current if any or automatic settings are kept.

  • method (str [optional among map , stack , image, surface or 3D]) – The type of plot,

  • projections (bool [optional, default=False])

  • style (str, optional, default=’notebook’) – Matplotlib stylesheet (use available_style to get a list of available styles for plotting

  • reverse (bool or None [optional, default=None) – In principle, coordinates run from left to right, except for wavenumbers (e.g., FTIR spectra) or ppm (e.g., NMR), that spectrochempy will try to guess. But if reverse is set, then this is the setting which will be taken into account.

  • x_reverse (bool or None [optional, default=None)

plot_multiple(datasets, method='scatter', pen=True, labels=None, marker='AUTO', color='AUTO', ls='AUTO', lw=1, shift=0, **kwargs)[source]

Plot a series of 1D datasets as a scatter plot with optional lines between markers.

Parameters
  • datasets (list of 1D NDDataset) – NDdatasets to plot.

  • method (str among [scatter, pen]) – Method to use for plotting.

  • pen (bool, optional, default: True) – If method is scatter, this flag tells to draw also the lines between the marks.

  • labels (a list of str, optional) – Labels used for the legend. The length of the list must be equal to the number of datasets to plot.

  • marker (str, list` os str or AUTO, optional, default: ‘AUTO’) – Marker type for scatter plot. If marker is not provided then the scatter type of plot is chosen automatically.

  • color (str, list` os str or AUTO, optional, default: ‘AUTO’) – Color of the lines. If color is not provided then the color of the lines is chosen automatically.

  • ls (str, list os str or AUTO, optional, default: ‘AUTO’) – Line style definition. If ls is not provided then the line style is chosen automatically.

  • lw (float, list`of  `floats, optional, default: 1.0) – Line width. If lw is not provided then the line width is chosen automatically.

  • shift (float, list`of  `floats, optional, default: 0.0) – Vertical shift of the lines.

  • **kwargs – Other parameters that will be passed to the plot1D function.

plot_pen(dataset, *args, **kwargs)[source]

Plot a 1D dataset with solid pen by default.

Alias of plot (with method argument set to pen .

Parameters
  • dataset (NDDataset) – The dataset to plot.

  • **kwargs – Optional keyword parameters (see Other Parameters).

Other Parameters
  • ax (Axe, optional) – Axe where to plot. If not specified, create a new one.

  • style (str, optional, default: dataset.preferences.style (scpy)) – Matplotlib stylesheet (use available_style to get a list of available styles for plotting.

  • use_plotly (bool, optional, default: preferences.use_plotly (False)) – Should we use plotly instead of matplotlib for plotting.

  • twinx (Axes instance, optional, default: None) – If this is not None, then a twin axes will be created with a common x dimension.

  • clear (bool, optional, default: True) – If false, hold the current figure and ax until a new plot is performed.

  • reverse (bool or None [optional, default=None/False) – In principle, coordinates run from left to right, except for wavenumbers (e.g., FTIR spectra) or ppm (e.g., NMR), that spectrochempy will try to guess. But if reverse is set, then this is the setting which will be taken into account.

  • data_only (bool, optional, default: False) – Only the plot is done. No addition of axes or label specifications.

  • imag (bool, optional, default: False) – Show imaginary component for complex data. By default the real component is displayed.

  • show_complex (bool, optional, default: False) – Show both real and imaginary component for complex data. By default only the real component is displayed.

  • figsize (tuple, optional, default is (3.4, 1.7)) – figure size.

  • dpi (int, optional) – the number of pixel per inches.

  • xlim (tuple, optional) – limit on the horizontal axis.

  • zlim or ylim (tuple, optional) – limit on the vertical axis.

  • color or c (color, optional, default: auto) – color of the line.

  • linewidth or lw (float, optional, default: auto) – line width.

  • linestyle or ls (str, optional, default: auto) – line style definition.

  • marker, m (str, optional, default: auto) – marker type for scatter plot. If marker != “” then the scatter type of plot is chosen automatically.

  • markeredgecolor or mec (color, optional)

  • markeredgewidth or mew (float, optional)

  • markerfacecolor or mfc (color, optional)

  • markersize or ms (float, optional)

  • markevery (None or int)

  • title (str) – Title of the plot (or subplot) axe.

  • plottitle (bool, optional, default: False) – Use the name of the dataset as title. Works only if title is not defined

  • xlabel (str, optional) – label on the horizontal axis.

  • zlabel or ylabel (str, optional) – label on the vertical axis.

  • uselabel_x (bool, optional) – use x coordinate label as x tick labels

  • show_z (bool, optional, default: True) – should we show the vertical axis.

  • show_zero (bool, optional) – show the zero basis.

  • show_mask (bool, optional) – Should we display the mask using colored area.

  • plot_model (Bool,) – plot model data if available.

  • modellinestyle or modls (str) – line style of the model.

  • offset (float) – offset of the model individual lines.

  • commands (str,) – matplotlib commands to be executed.

  • output (str,) – name of the file to save the figure.

  • vshift (float, optional) – vertically shift the line from its baseline.

plot_scatter(dataset, *args, **kwargs)[source]

Plot a 1D dataset as a scatter plot (points can be added on lines).

Alias of plot (with method argument set to scatter .

Parameters
  • dataset (NDDataset) – The dataset to plot.

  • **kwargs – Optional keyword parameters (see Other Parameters).

Other Parameters
  • ax (Axe, optional) – Axe where to plot. If not specified, create a new one.

  • style (str, optional, default: dataset.preferences.style (scpy)) – Matplotlib stylesheet (use available_style to get a list of available styles for plotting.

  • use_plotly (bool, optional, default: preferences.use_plotly (False)) – Should we use plotly instead of matplotlib for plotting.

  • twinx (Axes instance, optional, default: None) – If this is not None, then a twin axes will be created with a common x dimension.

  • clear (bool, optional, default: True) – If false, hold the current figure and ax until a new plot is performed.

  • reverse (bool or None [optional, default=None/False) – In principle, coordinates run from left to right, except for wavenumbers (e.g., FTIR spectra) or ppm (e.g., NMR), that spectrochempy will try to guess. But if reverse is set, then this is the setting which will be taken into account.

  • data_only (bool, optional, default: False) – Only the plot is done. No addition of axes or label specifications.

  • imag (bool, optional, default: False) – Show imaginary component for complex data. By default the real component is displayed.

  • show_complex (bool, optional, default: False) – Show both real and imaginary component for complex data. By default only the real component is displayed.

  • figsize (tuple, optional, default is (3.4, 1.7)) – figure size.

  • dpi (int, optional) – the number of pixel per inches.

  • xlim (tuple, optional) – limit on the horizontal axis.

  • zlim or ylim (tuple, optional) – limit on the vertical axis.

  • color or c (color, optional, default: auto) – color of the line.

  • linewidth or lw (float, optional, default: auto) – line width.

  • linestyle or ls (str, optional, default: auto) – line style definition.

  • marker, m (str, optional, default: auto) – marker type for scatter plot. If marker != “” then the scatter type of plot is chosen automatically.

  • markeredgecolor or mec (color, optional)

  • markeredgewidth or mew (float, optional)

  • markerfacecolor or mfc (color, optional)

  • markersize or ms (float, optional)

  • markevery (None or int)

  • title (str) – Title of the plot (or subplot) axe.

  • plottitle (bool, optional, default: False) – Use the name of the dataset as title. Works only if title is not defined

  • xlabel (str, optional) – label on the horizontal axis.

  • zlabel or ylabel (str, optional) – label on the vertical axis.

  • uselabel_x (bool, optional) – use x coordinate label as x tick labels

  • show_z (bool, optional, default: True) – should we show the vertical axis.

  • show_zero (bool, optional) – show the zero basis.

  • show_mask (bool, optional) – Should we display the mask using colored area.

  • plot_model (Bool,) – plot model data if available.

  • modellinestyle or modls (str) – line style of the model.

  • offset (float) – offset of the model individual lines.

  • commands (str,) – matplotlib commands to be executed.

  • output (str,) – name of the file to save the figure.

  • vshift (float, optional) – vertically shift the line from its baseline.

plot_scatter_pen(dataset, *args, **kwargs)[source]

Plot a 1D dataset with solid pen by default.

Alias of plot (with method argument set to scatter_pen .

Parameters
  • dataset (NDDataset) – The dataset to plot.

  • **kwargs – Optional keyword parameters (see Other Parameters).

Other Parameters
  • ax (Axe, optional) – Axe where to plot. If not specified, create a new one.

  • style (str, optional, default: dataset.preferences.style (scpy)) – Matplotlib stylesheet (use available_style to get a list of available styles for plotting.

  • use_plotly (bool, optional, default: preferences.use_plotly (False)) – Should we use plotly instead of matplotlib for plotting.

  • twinx (Axes instance, optional, default: None) – If this is not None, then a twin axes will be created with a common x dimension.

  • clear (bool, optional, default: True) – If false, hold the current figure and ax until a new plot is performed.

  • reverse (bool or None [optional, default=None/False) – In principle, coordinates run from left to right, except for wavenumbers (e.g., FTIR spectra) or ppm (e.g., NMR), that spectrochempy will try to guess. But if reverse is set, then this is the setting which will be taken into account.

  • data_only (bool, optional, default: False) – Only the plot is done. No addition of axes or label specifications.

  • imag (bool, optional, default: False) – Show imaginary component for complex data. By default the real component is displayed.

  • show_complex (bool, optional, default: False) – Show both real and imaginary component for complex data. By default only the real component is displayed.

  • figsize (tuple, optional, default is (3.4, 1.7)) – figure size.

  • dpi (int, optional) – the number of pixel per inches.

  • xlim (tuple, optional) – limit on the horizontal axis.

  • zlim or ylim (tuple, optional) – limit on the vertical axis.

  • color or c (color, optional, default: auto) – color of the line.

  • linewidth or lw (float, optional, default: auto) – line width.

  • linestyle or ls (str, optional, default: auto) – line style definition.

  • marker, m (str, optional, default: auto) – marker type for scatter plot. If marker != “” then the scatter type of plot is chosen automatically.

  • markeredgecolor or mec (color, optional)

  • markeredgewidth or mew (float, optional)

  • markerfacecolor or mfc (color, optional)

  • markersize or ms (float, optional)

  • markevery (None or int)

  • title (str) – Title of the plot (or subplot) axe.

  • plottitle (bool, optional, default: False) – Use the name of the dataset as title. Works only if title is not defined

  • xlabel (str, optional) – label on the horizontal axis.

  • zlabel or ylabel (str, optional) – label on the vertical axis.

  • uselabel_x (bool, optional) – use x coordinate label as x tick labels

  • show_z (bool, optional, default: True) – should we show the vertical axis.

  • show_zero (bool, optional) – show the zero basis.

  • show_mask (bool, optional) – Should we display the mask using colored area.

  • plot_model (Bool,) – plot model data if available.

  • modellinestyle or modls (str) – line style of the model.

  • offset (float) – offset of the model individual lines.

  • commands (str,) – matplotlib commands to be executed.

  • output (str,) – name of the file to save the figure.

  • vshift (float, optional) – vertically shift the line from its baseline.

plot_stack(dataset, *args, **kwargs)[source]

Plot a 2D dataset as a stack plot.

Alias of plot_2D (with method argument set to stack ).

Parameters
  • dataset (NDDataset) – The dataset to plot.

  • **kwargs – Optional keyword parameters (see Other Parameters).

Other Parameters
  • ax (|Axes| instance. Optional) – The axe where to plot. The default is the current axe or to create a new one if is None.

  • clear (bool, optional, default=`True`) – Should we plot on the ax previously used or create a new figure?.

  • figsize (tuple, optional) – The figure size expressed as a tuple (w,h) in inch.

  • fontsize (int, optional) – The font size in pixels, default is 10 (or read from preferences).

  • style (str)

  • autolayout (bool , optional, default=True) – if True, layout will be set automatically.

  • output (str) – A string containing a path to a filename. The output format is deduced from the extension of the filename. If the filename has no extension, the value of the rc parameter savefig.format is used.

  • dpi ([ None | scalar > 0]) – The resolution in dots per inch. If None it will default to the value savefig.dpi in the matplotlibrc file.

  • colorbar

  • transposed

  • clear

  • ax

  • twinx

  • use_plotly (bool, optional) – Should we use plotly instead of mpl for plotting. Default to preferences.use_plotly (default=False)

  • data_only (bool [optional, default=`False`]) – Only the plot is done. No addition of axes or label specifications (current if any or automatic settings are kept.

  • method (str [optional among map , stack , image, surface or 3D]) – The type of plot,

  • projections (bool [optional, default=False])

  • style (str, optional, default=’notebook’) – Matplotlib stylesheet (use available_style to get a list of available styles for plotting

  • reverse (bool or None [optional, default=None) – In principle, coordinates run from left to right, except for wavenumbers (e.g., FTIR spectra) or ppm (e.g., NMR), that spectrochempy will try to guess. But if reverse is set, then this is the setting which will be taken into account.

  • x_reverse (bool or None [optional, default=None)

plot_surface(dataset, *args, **kwargs)[source]

Plot a 2D dataset as a a 3D-surface.

Alias of plot_3D (with method argument set to surface ).

Parameters
  • dataset (NDDataset) – The dataset to plot.

  • **kwargs – Optional keyword parameters (see Other Parameters).

Other Parameters
  • ax (|Axes| instance. Optional) – The axe where to plot. The default is the current axe or to create a new one if is None.

  • figsize (tuple, optional) – The figure size expressed as a tuple (w,h) in inch.

  • fontsize (int, optional) – The font size in pixels, default is 10 (or read from preferences).

  • autolayout (bool , optional, default=True) – if True, layout will be set automatically.

  • dpi ([ None | scalar > 0]) – The resolution in dots per inch. If None it will default to the value savefig.dpi in the matplotlibrc file.

  • colorbar

  • method (str [optional among surface , waterfall , …]) – The type of plot,

  • style (str, optional, default=’notebook’) – Matplotlib stylesheet (use available_style to get a list of available styles for plotting

  • reverse (bool or None [optional, default=None) – In principle, coordinates run from left to right, except for wavenumbers (e.g., FTIR spectra) or ppm (e.g., NMR), that spectrochempy will try to guess. But if reverse is set, then this is the setting which will be taken into account.

  • x_reverse (bool or None [optional, default=None)

  • y_reverse (bool or None [optional, default=None)

plot_waterfall(dataset, *args, **kwargs)[source]

Plot a 2D dataset as a a 3D-waterfall plot.

Alias of plot_2D (with method argument set to waterfall ).

Parameters
  • dataset (NDDataset) – The dataset to plot.

  • **kwargs – Optional keyword parameters (see Other Parameters).

Other Parameters
  • ax (|Axes| instance. Optional) – The axe where to plot. The default is the current axe or to create a new one if is None.

  • figsize (tuple, optional) – The figure size expressed as a tuple (w,h) in inch.

  • fontsize (int, optional) – The font size in pixels, default is 10 (or read from preferences).

  • autolayout (bool , optional, default=True) – if True, layout will be set automatically.

  • dpi ([ None | scalar > 0]) – The resolution in dots per inch. If None it will default to the value savefig.dpi in the matplotlibrc file.

  • colorbar

  • method (str [optional among surface , waterfall , …]) – The type of plot,

  • style (str, optional, default=’notebook’) – Matplotlib stylesheet (use available_style to get a list of available styles for plotting

  • reverse (bool or None [optional, default=None) – In principle, coordinates run from left to right, except for wavenumbers (e.g., FTIR spectra) or ppm (e.g., NMR), that spectrochempy will try to guess. But if reverse is set, then this is the setting which will be taken into account.

  • x_reverse (bool or None [optional, default=None)

  • y_reverse (bool or None [optional, default=None)

ps(dataset)[source]

Power spectrum. Squared version.

Calculated real^2+imag^2

ptp(dataset, dim=None, keepdims=False)[source]

Range of values (maximum - minimum) along a dimension.

The name of the function comes from the acronym for ‘peak to peak’ .

Parameters
  • dim (None or int or dimension name, optional) – Dimension along which to find the peaks. If None, the operation is made on the first dimension.

  • keepdims (bool, optional) – If this is set to True, the dimensions which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input dataset.

Returns

ptp – A new dataset holding the result.

qsin(dataset, ssb=1, **kwargs)[source]

Equivalent to sp , with pow = 2 (squared sine bell apodization window).

random(size=None, dtype=None, **kwargs)[source]

Return random floats in the half-open interval [0.0, 1.0).

Results are from the “continuous uniform” distribution over the stated interval.

Note

To sample \(\mathrm{Uniform}[a, b)\) with \(b > a\), multiply the output of random by (b-a) and add a, i.e.: \((b - a) * \mathrm{random}() + a\).

Parameters
  • size (int or tuple of ints, optional) – Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. Default is None, in which case a single value is returned.

  • dtype (dtype, optional) – Desired dtype of the result, only float64 and float32 are supported. The default value is np.float64.

  • **kwargs – Keywords argument used when creating the returned object, such as units, name, title, etc…

Returns

random – Array of random floats of shape size (unless size=None, in which case a single float is returned).

read(*paths, **kwargs)[source]

Generic read method.

This method is generally able to load experimental files based on extensions.

Parameters
  • *paths (str, Path object objects or valid urls, optional) – The data source(s) can be specified by the name or a list of name for the file(s) to be loaded:

    • e.g., ( filename1, filename2, …, **kwargs )*

    If the list of filenames are enclosed into brackets:

    • e.g., ( [ filename1, filename2, … ], **kwargs )

    The returned datasets are merged to form a single dataset, except if merge is set to False.

    If a source is not provided (i.e., no paths , nor content), a dialog box will be opened to select files.

  • **kwargs (keyword parameters, optional) – See Other Parameters.

Returns

object (NDDataset or list of NDDataset) – The returned dataset(s).

Other Parameters
  • protocol (str, optional) – Protocol used for reading. It can be one of {'scp', 'omnic', 'opus', 'topspin', 'matlab', 'jcamp', 'csv', 'excel'}. If not provided, the correct protocol is inferred (whenever it is possible) from the filename extension.

  • directory (Path object objects or valid urls, optional) – From where to read the files.

  • merge (bool, optional, default: False) – If True and several filenames or a directory have been provided as arguments, then a single NDDataset with merged (stacked along the first dimension) is returned.

  • sortbydate (bool, optional, default: True) – Sort multiple filename by acquisition date.

  • description (str, optional) – A Custom description.

  • origin (one of {'omnic', 'tga'}, optional) – Used when reading with the CSV protocol. In order to properly interpret CSV file it can be necessary to set the origin of the spectra. Up to now only 'omnic' and 'tga' have been implemented.

  • csv_delimiter (str, optional, default: csv_delimiter) – Set the column delimiter in CSV file.

  • content (bytes object, optional) – Instead of passing a filename for further reading, a bytes content can be directly provided as bytes objects. The most convenient way is to use a dictionary. This feature is particularly useful for a GUI Dash application to handle drag and drop of files into a Browser.

  • iterdir (bool, optional, default: True) – If True and no filename was provided, all files present in the provided directory are returned (and merged if merge is True. It is assumed that all the files correspond to current reading protocol.

    Changed in version 0.6.2: iterdir replace the deprecated listdir argument.

  • recursive (bool, optional, default: False) – Read also in subfolders.

  • replace_existing (bool, optional, default: False) – Used only when url are specified. By default, existing files are not replaced so not downloaded.

  • download_only (bool, optional, default: False) – Used only when url are specified. If True, only downloading and saving of the files is performed, with no attempt to read their content.

  • read_only (bool, optional, default: True) – Used only when url are specified. If True, saving of the files is performed in the current directory, or in the directory specified by the directory parameter.

See also

read_zip

Read Zip archives (containing spectrochempy readable files)

read_dir

Read an entire directory.

read_opus

Read OPUS spectra.

read_labspec

Read Raman LABSPEC spectra (.txt).

read_omnic

Read Omnic spectra (.spa, .spg, .srs).

read_soc

Read Surface Optics Corps. files (.ddr , .hdr or .sdr).

read_galactic

Read Galactic files (.spc).

read_quadera

Read a Pfeiffer Vacuum’s QUADERA mass spectrometer software file.

read_topspin

Read TopSpin Bruker NMR spectra.

read_csv

Read CSV files (.csv).

read_jcamp

Read Infrared JCAMP-DX files (.jdx, .dx).

read_matlab

Read Matlab files (.mat, .dso).

read_carroucell

Read files in a directory after a carroucell experiment.

read_wire

Read REnishaw Wire files (.wdf).

Examples

Reading a single OPUS file (providing a windows type filename relative to the default datadir )

>>> scp.read('irdata\\OPUS\\test.0000')
NDDataset: [float64] a.u. (shape: (y:1, x:2567))

Reading a single OPUS file (providing a unix/python type filename relative to the default datadir ) Note that here read_opus is called as a classmethod of the NDDataset class

>>> scp.read('irdata/OPUS/test.0000')
NDDataset: [float64] a.u. (shape: (y:1, x:2567))

Single file specified with pathlib.Path object

>>> from pathlib import Path
>>> folder = Path('irdata/OPUS')
>>> p = folder / 'test.0000'
>>> scp.read(p)
NDDataset: [float64] a.u. (shape: (y:1, x:2567))

Multiple files not merged (return a list of datasets). Note that a directory is specified

>>> le = scp.read('test.0000', 'test.0001', 'test.0002', directory='irdata/OPUS')
>>> len(le)
3
>>> le[0]
NDDataset: [float64] a.u. (shape: (y:1, x:2567))

Multiple files merged as the merge keyword is set to true

>>> scp.read('test.0000', 'test.0001', 'test.0002', directory='irdata/OPUS', merge=True)
NDDataset: [float64] a.u. (shape: (y:3, x:2567))

Multiple files to merge : they are passed as a list instead of using the keyword merge

>>> scp.read(['test.0000', 'test.0001', 'test.0002'], directory='irdata/OPUS')
NDDataset: [float64] a.u. (shape: (y:3, x:2567))

Multiple files not merged : they are passed as a list but merge is set to false

>>> le = scp.read(['test.0000', 'test.0001', 'test.0002'], directory='irdata/OPUS', merge=False)
>>> len(le)
3

Read without a filename. This has the effect of opening a dialog for file(s) selection

>>> nd = scp.read()

Read in a directory (assume that only OPUS files are present in the directory (else we must use the generic read function instead)

>>> le = scp.read(directory='irdata/OPUS')
>>> len(le)
2

Again we can use merge to stack all 4 spectra if thet have compatible dimensions.

>>> scp.read(directory='irdata/OPUS', merge=True)
[NDDataset: [float64] a.u. (shape: (y:1, x:5549)), NDDataset: [float64] a.u. (shape: (y:4, x:2567))]
read_carroucell(directory=None, **kwargs)[source]

Open .spa files in a directory after a carroucell experiment.

The files for a given sample are grouped in NDDatasets (sorted by acquisition date). The NDDatasets are returned in a list sorted by sample number. When the file containing the temperature data is present, the temperature is read and assigned as a label to each spectrum.

Parameters
  • directory (str, optional) – If not specified, opens a dialog box.

  • **kwargs (keyword parameters, optional) – See Other Parameters.

Returns

object (NDDataset or list of NDDataset) – The returned dataset(s).

Other Parameters
  • spectra (array-like of 2 int (min , max ), optional, default: None) – The first and last spectrum to be loaded as determined by their number. If None all spectra are loaded.

  • discardbg (bool, optional, default: True) – If True : do not load background (sample #9).

  • delta_clocks (int, optional, default: 0) – Difference in seconds between the clocks used for spectra and temperature acquisition. Defined as t(thermocouple clock) - t(spectrometer clock) .

See also

read

Generic reader inferring protocol from the filename extension.

read_zip

Read Zip archives (containing spectrochempy readable files)

read_dir

Read an entire directory.

read_opus

Read OPUS spectra.

read_labspec

Read Raman LABSPEC spectra (.txt).

read_omnic

Read Omnic spectra (.spa, .spg, .srs).

read_soc

Read Surface Optics Corps. files (.ddr , .hdr or .sdr).

read_galactic

Read Galactic files (.spc).

read_quadera

Read a Pfeiffer Vacuum’s QUADERA mass spectrometer software file.

read_topspin

Read TopSpin Bruker NMR spectra.

read_csv

Read CSV files (.csv).

read_jcamp

Read Infrared JCAMP-DX files (.jdx, .dx).

read_matlab

Read Matlab files (.mat, .dso).

read_wire

Read REnishaw Wire files (.wdf).

Notes

All files are expected to be present in the same directory and their filenames are expected to be in the format : X_samplename_YYY.spa and for the background files : X_BCKG_YYYBG.spa where X is the sample holder number and YYY the spectrum number.

Examples

>>> scp.read_carroucell("irdata/carroucell_samp")
no temperature file
[NDDataset: [float64] a.u. (shape: (y:6, x:11098)), NDDataset: ...
read_csv(*paths, **kwargs)[source]

Open a .csv file or a list of .csv files.

This is limited to 1D array - csv file must have two columns [index, data] without header.

Parameters
  • *paths (str, Path object objects or valid urls, optional) – The data source(s) can be specified by the name or a list of name for the file(s) to be loaded:

    • e.g., ( filename1, filename2, …, **kwargs )*

    If the list of filenames are enclosed into brackets:

    • e.g., ( [ filename1, filename2, … ], **kwargs )

    The returned datasets are merged to form a single dataset, except if merge is set to False.

    If a source is not provided (i.e., no paths , nor content), a dialog box will be opened to select files.

  • **kwargs (keyword parameters, optional) – See Other Parameters.

Returns

object (NDDataset or list of NDDataset) – The returned dataset(s).

Other Parameters
  • protocol (str, optional) – Protocol used for reading. It can be one of {'scp', 'omnic', 'opus', 'topspin', 'matlab', 'jcamp', 'csv', 'excel'}. If not provided, the correct protocol is inferred (whenever it is possible) from the filename extension.

  • directory (Path object objects or valid urls, optional) – From where to read the files.

  • merge (bool, optional, default: False) – If True and several filenames or a directory have been provided as arguments, then a single NDDataset with merged (stacked along the first dimension) is returned.

  • sortbydate (bool, optional, default: True) – Sort multiple filename by acquisition date.

  • description (str, optional) – A Custom description.

  • origin (one of {'omnic', 'tga'}, optional) – Used when reading with the CSV protocol. In order to properly interpret CSV file it can be necessary to set the origin of the spectra. Up to now only 'omnic' and 'tga' have been implemented.

  • csv_delimiter (str, optional, default: csv_delimiter) – Set the column delimiter in CSV file.

  • content (bytes object, optional) – Instead of passing a filename for further reading, a bytes content can be directly provided as bytes objects. The most convenient way is to use a dictionary. This feature is particularly useful for a GUI Dash application to handle drag and drop of files into a Browser.

  • iterdir (bool, optional, default: True) – If True and no filename was provided, all files present in the provided directory are returned (and merged if merge is True. It is assumed that all the files correspond to current reading protocol.

    Changed in version 0.6.2: iterdir replace the deprecated listdir argument.

See also

read

Generic reader inferring protocol from the filename extension.

read_zip

Read Zip archives (containing spectrochempy readable files)

read_dir

Read an entire directory.

read_opus

Read OPUS spectra.

read_labspec

Read Raman LABSPEC spectra (.txt).

read_omnic

Read Omnic spectra (.spa, .spg, .srs).

read_soc

Read Surface Optics Corps. files (.ddr , .hdr or .sdr).

read_galactic

Read Galactic files (.spc).

read_quadera

Read a Pfeiffer Vacuum’s QUADERA mass spectrometer software file.

read_topspin

Read TopSpin Bruker NMR spectra.

read_jcamp

Read Infrared JCAMP-DX files (.jdx, .dx).

read_matlab

Read Matlab files (.mat, .dso).

read_carroucell

Read files in a directory after a carroucell experiment.

read_wire

Read REnishaw Wire files (.wdf).

Examples

>>> scp.read_csv('agirdata/P350/TGA/tg.csv')
NDDataset: [float64] unitless (shape: (y:1, x:3247))

Additional information can be stored in the dataset if the origin is given (known origin for now : tga or omnic) # TODO: define some template to allow adding new origins

>>> A = scp.read_csv('agirdata/P350/TGA/tg.csv', origin='tga')

Sometimes the delimiteur needs to be adjusted

>>> prefs = scp.preferences
>>> B = scp.read_csv('irdata/IR.CSV', origin='omnic', csv_delimiter=',')
read_ddr(*paths, **kwargs)[source]

Open a Surface Optics Corps. file or a list of files with extension .ddr.

Parameters
  • *paths (str, Path object objects or valid urls, optional) – The data source(s) can be specified by the name or a list of name for the file(s) to be loaded:

    • e.g., ( filename1, filename2, …, **kwargs )*

    If the list of filenames are enclosed into brackets:

    • e.g., ( [ filename1, filename2, … ], **kwargs )

    The returned datasets are merged to form a single dataset, except if merge is set to False.

    If a source is not provided (i.e., no paths , nor content), a dialog box will be opened to select files.

  • **kwargs (keyword parameters, optional) – See Other Parameters.

Returns

object (NDDataset or list of NDDataset) – The returned dataset(s).

Other Parameters
  • return_ifg (str or None, optional) – Default value is None. When set to ‘sample’ returns the sample interferogram of the spa file if present or None if absent. When set to ‘background’ returns the backgroung interferogram of the spa file if present or None if absent.

  • protocol (str, optional) – Protocol used for reading. It can be one of {'scp', 'omnic', 'opus', 'topspin', 'matlab', 'jcamp', 'csv', 'excel'}. If not provided, the correct protocol is inferred (whenever it is possible) from the filename extension.

  • directory (Path object objects or valid urls, optional) – From where to read the files.

  • merge (bool, optional, default: False) – If True and several filenames or a directory have been provided as arguments, then a single NDDataset with merged (stacked along the first dimension) is returned.

  • sortbydate (bool, optional, default: True) – Sort multiple filename by acquisition date.

  • description (str, optional) – A Custom description.

  • origin (one of {'omnic', 'tga'}, optional) – Used when reading with the CSV protocol. In order to properly interpret CSV file it can be necessary to set the origin of the spectra. Up to now only 'omnic' and 'tga' have been implemented.

  • csv_delimiter (str, optional, default: csv_delimiter) – Set the column delimiter in CSV file.

  • content (bytes object, optional) – Instead of passing a filename for further reading, a bytes content can be directly provided as bytes objects. The most convenient way is to use a dictionary. This feature is particularly useful for a GUI Dash application to handle drag and drop of files into a Browser.

  • iterdir (bool, optional, default: True) – If True and no filename was provided, all files present in the provided directory are returned (and merged if merge is True. It is assumed that all the files correspond to current reading protocol.

    Changed in version 0.6.2: iterdir replace the deprecated listdir argument.

See also

read

Generic reader inferring protocol from the filename extension.

read_zip

Read Zip archives (containing spectrochempy readable files)

read_dir

Read an entire directory.

read_opus

Read OPUS spectra.

read_labspec

Read Raman LABSPEC spectra (.txt).

read_omnic

Read Omnic spectra (.spa, .spg, .srs).

read_soc

Read Surface Optics Corps. files (.ddr , .hdr or .sdr).

read_galactic

Read Galactic files (.spc).

read_quadera

Read a Pfeiffer Vacuum’s QUADERA mass spectrometer software file.

read_topspin

Read TopSpin Bruker NMR spectra.

read_csv

Read CSV files (.csv).

read_jcamp

Read Infrared JCAMP-DX files (.jdx, .dx).

read_matlab

Read Matlab files (.mat, .dso).

read_carroucell

Read files in a directory after a carroucell experiment.

read_wire

Read REnishaw Wire files (.wdf).

read_dir(directory=None, **kwargs)[source]

Read an entire directory.

Open a list of readable files in a and store data/metadata in a dataset or a list of datasets according to the following rules :

  • 2D spectroscopic data (e.g. valid .spg files or matlab arrays, etc…) from distinct files are stored in distinct NDdatasets.

  • 1D spectroscopic data (e.g., .spa files) in a given directory are merged into single NDDataset, providing their unique dimension are compatible. If not, an error is generated.

  • non-readable files are ignored

Parameters

directory (str or pathlib) – Folder where are located the files to read.

Returns

object (NDDataset or list of NDDataset) – The returned dataset(s). Depending on the python version, the order of the datasets in the list may change.

See also

read

Generic reader inferring protocol from the filename extension.

read_zip

Read Zip archives (containing spectrochempy readable files)

read_opus

Read OPUS spectra.

read_labspec

Read Raman LABSPEC spectra (.txt).

read_omnic

Read Omnic spectra (.spa, .spg, .srs).

read_soc

Read Surface Optics Corps. files (.ddr , .hdr or .sdr).

read_galactic

Read Galactic files (.spc).

read_quadera

Read a Pfeiffer Vacuum’s QUADERA mass spectrometer software file.

read_topspin

Read TopSpin Bruker NMR spectra.

read_csv

Read CSV files (.csv).

read_jcamp

Read Infrared JCAMP-DX files (.jdx, .dx).

read_matlab

Read Matlab files (.mat, .dso).

read_carroucell

Read files in a directory after a carroucell experiment.

read_wire

Read REnishaw Wire files (.wdf).

Examples

>>> scp.preferences.csv_delimiter = ','
>>> A = scp.read_dir('irdata')
>>> len(A)
4
>>> B = scp.read_dir()
read_hdr(*paths, **kwargs)[source]

Open a Surface Optics Corps. file or a list of files with extension .hdr.

Parameters
  • *paths (str, Path object objects or valid urls, optional) – The data source(s) can be specified by the name or a list of name for the file(s) to be loaded:

    • e.g., ( filename1, filename2, …, **kwargs )*

    If the list of filenames are enclosed into brackets:

    • e.g., ( [ filename1, filename2, … ], **kwargs )

    The returned datasets are merged to form a single dataset, except if merge is set to False.

    If a source is not provided (i.e., no paths , nor content), a dialog box will be opened to select files.

  • **kwargs (keyword parameters, optional) – See Other Parameters.

Returns

object (NDDataset or list of NDDataset) – The returned dataset(s).

Other Parameters
  • return_ifg (str or None, optional) – Default value is None. When set to ‘sample’ returns the sample interferogram of the spa file if present or None if absent. When set to ‘background’ returns the backgroung interferogram of the spa file if present or None if absent.

  • protocol (str, optional) – Protocol used for reading. It can be one of {'scp', 'omnic', 'opus', 'topspin', 'matlab', 'jcamp', 'csv', 'excel'}. If not provided, the correct protocol is inferred (whenever it is possible) from the filename extension.

  • directory (Path object objects or valid urls, optional) – From where to read the files.

  • merge (bool, optional, default: False) – If True and several filenames or a directory have been provided as arguments, then a single NDDataset with merged (stacked along the first dimension) is returned.

  • sortbydate (bool, optional, default: True) – Sort multiple filename by acquisition date.

  • description (str, optional) – A Custom description.

  • origin (one of {'omnic', 'tga'}, optional) – Used when reading with the CSV protocol. In order to properly interpret CSV file it can be necessary to set the origin of the spectra. Up to now only 'omnic' and 'tga' have been implemented.

  • csv_delimiter (str, optional, default: csv_delimiter) – Set the column delimiter in CSV file.

  • content (bytes object, optional) – Instead of passing a filename for further reading, a bytes content can be directly provided as bytes objects. The most convenient way is to use a dictionary. This feature is particularly useful for a GUI Dash application to handle drag and drop of files into a Browser.

  • iterdir (bool, optional, default: True) – If True and no filename was provided, all files present in the provided directory are returned (and merged if merge is True. It is assumed that all the files correspond to current reading protocol.

    Changed in version 0.6.2: iterdir replace the deprecated listdir argument.

See also

read

Generic reader inferring protocol from the filename extension.

read_zip

Read Zip archives (containing spectrochempy readable files)

read_dir

Read an entire directory.

read_opus

Read OPUS spectra.

read_labspec

Read Raman LABSPEC spectra (.txt).

read_omnic

Read Omnic spectra (.spa, .spg, .srs).

read_soc

Read Surface Optics Corps. files (.ddr , .hdr or .sdr).

read_galactic

Read Galactic files (.spc).

read_quadera

Read a Pfeiffer Vacuum’s QUADERA mass spectrometer software file.

read_topspin

Read TopSpin Bruker NMR spectra.

read_csv

Read CSV files (.csv).

read_jcamp

Read Infrared JCAMP-DX files (.jdx, .dx).

read_matlab

Read Matlab files (.mat, .dso).

read_carroucell

Read files in a directory after a carroucell experiment.

read_wire

Read REnishaw Wire files (.wdf).

read_jcamp(*paths, **kwargs)[source]

Open Infrared JCAMP-DX files with extension .jdx or .dx.

Limited to AFFN encoding (see McDonald and Paul A. Wilks [1988])

Parameters
  • *paths (str, Path object objects or valid urls, optional) – The data source(s) can be specified by the name or a list of name for the file(s) to be loaded:

    • e.g., ( filename1, filename2, …, **kwargs )*

    If the list of filenames are enclosed into brackets:

    • e.g., ( [ filename1, filename2, … ], **kwargs )

    The returned datasets are merged to form a single dataset, except if merge is set to False.

    If a source is not provided (i.e., no paths , nor content), a dialog box will be opened to select files.

  • **kwargs (keyword parameters, optional) – See Other Parameters.

Returns

object (NDDataset or list of NDDataset) – The returned dataset(s).

Other Parameters
  • protocol (str, optional) – Protocol used for reading. It can be one of {'scp', 'omnic', 'opus', 'topspin', 'matlab', 'jcamp', 'csv', 'excel'}. If not provided, the correct protocol is inferred (whenever it is possible) from the filename extension.

  • directory (Path object objects or valid urls, optional) – From where to read the files.

  • merge (bool, optional, default: False) – If True and several filenames or a directory have been provided as arguments, then a single NDDataset with merged (stacked along the first dimension) is returned.

  • sortbydate (bool, optional, default: True) – Sort multiple filename by acquisition date.

  • description (str, optional) – A Custom description.

  • origin (one of {'omnic', 'tga'}, optional) – Used when reading with the CSV protocol. In order to properly interpret CSV file it can be necessary to set the origin of the spectra. Up to now only 'omnic' and 'tga' have been implemented.

  • csv_delimiter (str, optional, default: csv_delimiter) – Set the column delimiter in CSV file.

  • content (bytes object, optional) – Instead of passing a filename for further reading, a bytes content can be directly provided as bytes objects. The most convenient way is to use a dictionary. This feature is particularly useful for a GUI Dash application to handle drag and drop of files into a Browser.

  • iterdir (bool, optional, default: True) – If True and no filename was provided, all files present in the provided directory are returned (and merged if merge is True. It is assumed that all the files correspond to current reading protocol.

    Changed in version 0.6.2: iterdir replace the deprecated listdir argument.

See also

read

Generic reader inferring protocol from the filename extension.

read_zip

Read Zip archives (containing spectrochempy readable files)

read_dir

Read an entire directory.

read_opus

Read OPUS spectra.

read_labspec

Read Raman LABSPEC spectra (.txt).

read_omnic

Read Omnic spectra (.spa, .spg, .srs).

read_soc

Read Surface Optics Corps. files (.ddr , .hdr or .sdr).

read_galactic

Read Galactic files (.spc).

read_quadera

Read a Pfeiffer Vacuum’s QUADERA mass spectrometer software file.

read_topspin

Read TopSpin Bruker NMR spectra.

read_csv

Read CSV files (.csv).

read_matlab

Read Matlab files (.mat, .dso).

read_carroucell

Read files in a directory after a carroucell experiment.

read_wire

Read REnishaw Wire files (.wdf).

read_labspec(*paths, **kwargs)[source]

Read a single Raman spectrum or a series of Raman spectra.

Files to open are .txt file created by Labspec software. Non-labspec .txt files are ignored (return None)

Parameters
  • *paths (str, Path object objects or valid urls, optional) – The data source(s) can be specified by the name or a list of name for the file(s) to be loaded:

    • e.g., ( filename1, filename2, …, **kwargs )*

    If the list of filenames are enclosed into brackets:

    • e.g., ( [ filename1, filename2, … ], **kwargs )

    The returned datasets are merged to form a single dataset, except if merge is set to False.

    If a source is not provided (i.e., no paths , nor content), a dialog box will be opened to select files.

  • **kwargs (keyword parameters, optional) – See Other Parameters.

Returns

object (NDDataset or list of NDDataset) – The returned dataset(s).

Other Parameters
  • protocol (str, optional) – Protocol used for reading. It can be one of {'scp', 'omnic', 'opus', 'topspin', 'matlab', 'jcamp', 'csv', 'excel'}. If not provided, the correct protocol is inferred (whenever it is possible) from the filename extension.

  • directory (Path object objects or valid urls, optional) – From where to read the files.

  • merge (bool, optional, default: False) – If True and several filenames or a directory have been provided as arguments, then a single NDDataset with merged (stacked along the first dimension) is returned.

  • sortbydate (bool, optional, default: True) – Sort multiple filename by acquisition date.

  • description (str, optional) – A Custom description.

  • origin (one of {'omnic', 'tga'}, optional) – Used when reading with the CSV protocol. In order to properly interpret CSV file it can be necessary to set the origin of the spectra. Up to now only 'omnic' and 'tga' have been implemented.

  • csv_delimiter (str, optional, default: csv_delimiter) – Set the column delimiter in CSV file.

  • content (bytes object, optional) – Instead of passing a filename for further reading, a bytes content can be directly provided as bytes objects. The most convenient way is to use a dictionary. This feature is particularly useful for a GUI Dash application to handle drag and drop of files into a Browser.

  • iterdir (bool, optional, default: True) – If True and no filename was provided, all files present in the provided directory are returned (and merged if merge is True. It is assumed that all the files correspond to current reading protocol.

    Changed in version 0.6.2: iterdir replace the deprecated listdir argument.

See also

read

Generic reader inferring protocol from the filename extension.

read_zip

Read Zip archives (containing spectrochempy readable files)

read_dir

Read an entire directory.

read_opus

Read OPUS spectra.

read_omnic

Read Omnic spectra (.spa, .spg, .srs).

read_soc

Read Surface Optics Corps. files (.ddr , .hdr or .sdr).

read_galactic

Read Galactic files (.spc).

read_quadera

Read a Pfeiffer Vacuum’s QUADERA mass spectrometer software file.

read_topspin

Read TopSpin Bruker NMR spectra.

read_csv

Read CSV files (.csv).

read_jcamp

Read Infrared JCAMP-DX files (.jdx, .dx).

read_matlab

Read Matlab files (.mat, .dso).

read_carroucell

Read files in a directory after a carroucell experiment.

read_wire

Read REnishaw Wire files (.wdf).

Examples

>>> A = scp.read_labspec('ramandata/labspec/Activation.txt')
read_mat(*paths, **kwargs)[source]

Read a matlab file with extension .mat and return its content as a list.

The array of numbers (i.e., matlab matrices) and Eigenvector’s DataSet Object (DSO, see DSO ) are returned as NDDatasets. The content not recognized by SpectroChemPy is returned as a tuple (name, object).

Parameters
  • *paths (str, Path object objects or valid urls, optional) – The data source(s) can be specified by the name or a list of name for the file(s) to be loaded:

    • e.g., ( filename1, filename2, …, **kwargs )*

    If the list of filenames are enclosed into brackets:

    • e.g., ( [ filename1, filename2, … ], **kwargs )

    The returned datasets are merged to form a single dataset, except if merge is set to False.

    If a source is not provided (i.e., no paths , nor content), a dialog box will be opened to select files.

  • **kwargs (keyword parameters, optional) – See Other Parameters.

Returns

object (NDDataset or list of NDDataset) – The returned dataset(s).

Other Parameters
  • protocol (str, optional) – Protocol used for reading. It can be one of {'scp', 'omnic', 'opus', 'topspin', 'matlab', 'jcamp', 'csv', 'excel'}. If not provided, the correct protocol is inferred (whenever it is possible) from the filename extension.

  • directory (Path object objects or valid urls, optional) – From where to read the files.

  • merge (bool, optional, default: False) – If True and several filenames or a directory have been provided as arguments, then a single NDDataset with merged (stacked along the first dimension) is returned.

  • sortbydate (bool, optional, default: True) – Sort multiple filename by acquisition date.

  • description (str, optional) – A Custom description.

  • origin (one of {'omnic', 'tga'}, optional) – Used when reading with the CSV protocol. In order to properly interpret CSV file it can be necessary to set the origin of the spectra. Up to now only 'omnic' and 'tga' have been implemented.

  • csv_delimiter (str, optional, default: csv_delimiter) – Set the column delimiter in CSV file.

  • content (bytes object, optional) – Instead of passing a filename for further reading, a bytes content can be directly provided as bytes objects. The most convenient way is to use a dictionary. This feature is particularly useful for a GUI Dash application to handle drag and drop of files into a Browser.

  • iterdir (bool, optional, default: True) – If True and no filename was provided, all files present in the provided directory are returned (and merged if merge is True. It is assumed that all the files correspond to current reading protocol.

    Changed in version 0.6.2: iterdir replace the deprecated listdir argument.

See also

read

Generic reader inferring protocol from the filename extension.

read_zip

Read Zip archives (containing spectrochempy readable files)

read_dir

Read an entire directory.

read_opus

Read OPUS spectra.

read_labspec

Read Raman LABSPEC spectra (.txt).

read_omnic

Read Omnic spectra (.spa, .spg, .srs).

read_soc

Read Surface Optics Corps. files (.ddr , .hdr or .sdr).

read_galactic

Read Galactic files (.spc).

read_quadera

Read a Pfeiffer Vacuum’s QUADERA mass spectrometer software file.

read_topspin

Read TopSpin Bruker NMR spectra.

read_csv

Read CSV files (.csv).

read_jcamp

Read Infrared JCAMP-DX files (.jdx, .dx).

read_carroucell

Read files in a directory after a carroucell experiment.

read_wire

Read REnishaw Wire files (.wdf).

Examples

>>> scp.read_matlab('matlabdata/dso.mat')
NDDataset: [float64] unitless (shape: (y:20, x:426))
read_matlab(*paths, **kwargs)[source]

Read a matlab file with extension .mat and return its content as a list.

The array of numbers (i.e., matlab matrices) and Eigenvector’s DataSet Object (DSO, see DSO ) are returned as NDDatasets. The content not recognized by SpectroChemPy is returned as a tuple (name, object).

Parameters
  • *paths (str, Path object objects or valid urls, optional) – The data source(s) can be specified by the name or a list of name for the file(s) to be loaded:

    • e.g., ( filename1, filename2, …, **kwargs )*

    If the list of filenames are enclosed into brackets:

    • e.g., ( [ filename1, filename2, … ], **kwargs )

    The returned datasets are merged to form a single dataset, except if merge is set to False.

    If a source is not provided (i.e., no paths , nor content), a dialog box will be opened to select files.

  • **kwargs (keyword parameters, optional) – See Other Parameters.

Returns

object (NDDataset or list of NDDataset) – The returned dataset(s).

Other Parameters
  • protocol (str, optional) – Protocol used for reading. It can be one of {'scp', 'omnic', 'opus', 'topspin', 'matlab', 'jcamp', 'csv', 'excel'}. If not provided, the correct protocol is inferred (whenever it is possible) from the filename extension.

  • directory (Path object objects or valid urls, optional) – From where to read the files.

  • merge (bool, optional, default: False) – If True and several filenames or a directory have been provided as arguments, then a single NDDataset with merged (stacked along the first dimension) is returned.

  • sortbydate (bool, optional, default: True) – Sort multiple filename by acquisition date.

  • description (str, optional) – A Custom description.

  • origin (one of {'omnic', 'tga'}, optional) – Used when reading with the CSV protocol. In order to properly interpret CSV file it can be necessary to set the origin of the spectra. Up to now only 'omnic' and 'tga' have been implemented.

  • csv_delimiter (str, optional, default: csv_delimiter) – Set the column delimiter in CSV file.

  • content (bytes object, optional) – Instead of passing a filename for further reading, a bytes content can be directly provided as bytes objects. The most convenient way is to use a dictionary. This feature is particularly useful for a GUI Dash application to handle drag and drop of files into a Browser.

  • iterdir (bool, optional, default: True) – If True and no filename was provided, all files present in the provided directory are returned (and merged if merge is True. It is assumed that all the files correspond to current reading protocol.

    Changed in version 0.6.2: iterdir replace the deprecated listdir argument.

See also

read

Generic reader inferring protocol from the filename extension.

read_zip

Read Zip archives (containing spectrochempy readable files)

read_dir

Read an entire directory.

read_opus

Read OPUS spectra.

read_labspec

Read Raman LABSPEC spectra (.txt).

read_omnic

Read Omnic spectra (.spa, .spg, .srs).

read_soc

Read Surface Optics Corps. files (.ddr , .hdr or .sdr).

read_galactic

Read Galactic files (.spc).

read_quadera

Read a Pfeiffer Vacuum’s QUADERA mass spectrometer software file.

read_topspin

Read TopSpin Bruker NMR spectra.

read_csv

Read CSV files (.csv).

read_jcamp

Read Infrared JCAMP-DX files (.jdx, .dx).

read_carroucell

Read files in a directory after a carroucell experiment.

read_wire

Read REnishaw Wire files (.wdf).

Examples

>>> scp.read_matlab('matlabdata/dso.mat')
NDDataset: [float64] unitless (shape: (y:20, x:426))
read_omnic(*paths, **kwargs)[source]

Open a Thermo Nicolet OMNIC file.

Open Omnic file or a list of .spg, .spa or .srs files and set data/metadata in the current dataset.

The collected metadata are: - names of spectra - acquisition dates (UTC) - units of spectra (absorbance, transmittance, reflectance, Log(1/R), Kubelka-Munk, Raman intensity, photoacoustics, volts) - units of xaxis (wavenumbers in \(cm^{-1}\), wavelengths in nm or micrometer, Raman shift in \(cm^{-1}\)) - spectra history (but only incorporated in the NDDataset if a single spa is read)

An error is generated if attempt is made to inconsistent datasets: units of spectra and xaxis, limits and number of points of the xaxis.

Parameters
  • *paths (str, Path object objects or valid urls, optional) – The data source(s) can be specified by the name or a list of name for the file(s) to be loaded:

    • e.g., ( filename1, filename2, …, **kwargs )*

    If the list of filenames are enclosed into brackets:

    • e.g., ( [ filename1, filename2, … ], **kwargs )

    The returned datasets are merged to form a single dataset, except if merge is set to False.

    If a source is not provided (i.e., no paths , nor content), a dialog box will be opened to select files.

  • **kwargs (keyword parameters, optional) – See Other Parameters.

Returns

object (NDDataset or list of NDDataset) – The returned dataset(s).

Other Parameters
  • protocol (str, optional) – Protocol used for reading. It can be one of {'scp', 'omnic', 'opus', 'topspin', 'matlab', 'jcamp', 'csv', 'excel'}. If not provided, the correct protocol is inferred (whenever it is possible) from the filename extension.

  • directory (Path object objects or valid urls, optional) – From where to read the files.

  • merge (bool, optional, default: False) – If True and several filenames or a directory have been provided as arguments, then a single NDDataset with merged (stacked along the first dimension) is returned.

  • sortbydate (bool, optional, default: True) – Sort multiple filename by acquisition date.

  • description (str, optional) – A Custom description.

  • origin (one of {'omnic', 'tga'}, optional) – Used when reading with the CSV protocol. In order to properly interpret CSV file it can be necessary to set the origin of the spectra. Up to now only 'omnic' and 'tga' have been implemented.

  • csv_delimiter (str, optional, default: csv_delimiter) – Set the column delimiter in CSV file.

  • content (bytes object, optional) – Instead of passing a filename for further reading, a bytes content can be directly provided as bytes objects. The most convenient way is to use a dictionary. This feature is particularly useful for a GUI Dash application to handle drag and drop of files into a Browser.

  • iterdir (bool, optional, default: True) – If True and no filename was provided, all files present in the provided directory are returned (and merged if merge is True. It is assumed that all the files correspond to current reading protocol.

    Changed in version 0.6.2: iterdir replace the deprecated listdir argument.

See also

read_spg

Read grouped Omnic spectra.

read_spa

Read single Omnic spectra.

read_srs

Read series Omnic spectra.

read

Generic reader inferring protocol from the filename extension.

read_zip

Read Zip archives (containing spectrochempy readable files)

read_dir

Read an entire directory.

read_opus

Read OPUS spectra.

read_labspec

Read Raman LABSPEC spectra (.txt).

read_soc

Read Surface Optics Corps. files (.ddr , .hdr or .sdr).

read_galactic

Read Galactic files (.spc).

read_quadera

Read a Pfeiffer Vacuum’s QUADERA mass spectrometer software file.

read_topspin

Read TopSpin Bruker NMR spectra.

read_csv

Read CSV files (.csv).

read_jcamp

Read Infrared JCAMP-DX files (.jdx, .dx).

read_matlab

Read Matlab files (.mat, .dso).

read_carroucell

Read files in a directory after a carroucell experiment.

read_wire

Read REnishaw Wire files (.wdf).

Examples

Reading a single OMNIC file (providing a windows type filename relative to the default datadir )

>>> scp.read_omnic('irdata\\nh4y-activation.spg')
NDDataset: [float64] a.u. (shape: (y:55, x:5549))

Reading a single OMNIC file (providing a unix/python type filename relative to the default datadir ) Note that here read_omnic is called as a classmethod of the NDDataset class

>>> scp.read_omnic('irdata/nh4y-activation.spg')
NDDataset: [float64] a.u. (shape: (y:55, x:5549))

Single file specified with pathlib.Path object

>>> from pathlib import Path
>>> folder = Path('irdata')
>>> p = folder / 'nh4y-activation.spg'
>>> scp.read_omnic(p)
NDDataset: [float64] a.u. (shape: (y:55, x:5549))

The directory can also be specified independently, either as a string or a pathlib object

>>> scp.read_omnic('nh4y-activation.spg', directory=folder)
NDDataset: [float64] a.u. (shape: (y:55, x:5549))

Multiple files not merged (return a list of datasets)

>>> le = scp.read_omnic('irdata/nh4y-activation.spg', 'wodger.spg')
>>> len(le)
2
>>> le[1]
NDDataset: [float64] a.u. (shape: (y:55, x:5549))

Multiple files merged as the merge keyword is set to true

>>> scp.read_omnic('irdata/nh4y-activation.spg', 'wodger.spg', merge=True)
NDDataset: [float64] a.u. (shape: (y:57, x:5549))

Multiple files to merge : they are passed as a list (note the brakets) instead of using the keyword merge

>>> scp.read_omnic(['irdata/nh4y-activation.spg', 'wodger.spg'])
NDDataset: [float64] a.u. (shape: (y:57, x:5549))

Multiple files not merged : they are passed as a list but merge is set to false

>>> l2 = scp.read_omnic(['irdata/nh4y-activation.spg', 'wodger.spg'], merge=False)
>>> len(l2)
2

Read without a filename. This has the effect of opening a dialog for file(s) selection

>>> nd = scp.read_omnic()

Read in a directory (assume that only OPUS files are present in the directory (else we must use the generic read function instead)

>>> l3 = scp.read_omnic(directory='irdata/subdir/1-20')
>>> len(l3)
3

Again we can use merge to stack all 4 spectra if thet have compatible dimensions.

>>> scp.read_omnic(directory='irdata/subdir', merge=True)
NDDataset: [float64] a.u. (shape: (y:4, x:5549))

An example, where bytes contents are passed directly to the read_omnic method.

>>> datadir = scp.preferences.datadir
>>> filename1 = datadir / 'irdata' / 'subdir' / '7_CZ0-100 Pd_101.SPA'
>>> content1 = filename1.read_bytes()
>>> filename2 = datadir / 'wodger.spg'
>>> content2 = filename2.read_bytes()
>>> listnd = scp.read_omnic({filename1.name: content1, filename2.name: content2})
>>> len(listnd)
2
>>> scp.read_omnic({filename1.name: content1, filename2.name: content2}, merge=True)
NDDataset: [float64] a.u. (shape: (y:3, x:5549))
read_opus(*paths, **kwargs)[source]

Open Bruker OPUS file(s).

Eventually group them in a single dataset. Only Absorbance spectra are extracted (“AB” field). Returns an error if dimensions are incompatibles.

Parameters
  • *paths (str, Path object objects or valid urls, optional) – The data source(s) can be specified by the name or a list of name for the file(s) to be loaded:

    • e.g., ( filename1, filename2, …, **kwargs )*

    If the list of filenames are enclosed into brackets:

    • e.g., ( [ filename1, filename2, … ], **kwargs )

    The returned datasets are merged to form a single dataset, except if merge is set to False.

    If a source is not provided (i.e., no paths , nor content), a dialog box will be opened to select files.

  • **kwargs (keyword parameters, optional) – See Other Parameters.

Returns

object (NDDataset or list of NDDataset) – The returned dataset(s).

Other Parameters
  • protocol (str, optional) – Protocol used for reading. It can be one of {'scp', 'omnic', 'opus', 'topspin', 'matlab', 'jcamp', 'csv', 'excel'}. If not provided, the correct protocol is inferred (whenever it is possible) from the filename extension.

  • directory (Path object objects or valid urls, optional) – From where to read the files.

  • merge (bool, optional, default: False) – If True and several filenames or a directory have been provided as arguments, then a single NDDataset with merged (stacked along the first dimension) is returned.

  • sortbydate (bool, optional, default: True) – Sort multiple filename by acquisition date.

  • description (str, optional) – A Custom description.

  • origin (one of {'omnic', 'tga'}, optional) – Used when reading with the CSV protocol. In order to properly interpret CSV file it can be necessary to set the origin of the spectra. Up to now only 'omnic' and 'tga' have been implemented.

  • csv_delimiter (str, optional, default: csv_delimiter) – Set the column delimiter in CSV file.

  • content (bytes object, optional) – Instead of passing a filename for further reading, a bytes content can be directly provided as bytes objects. The most convenient way is to use a dictionary. This feature is particularly useful for a GUI Dash application to handle drag and drop of files into a Browser.

  • iterdir (bool, optional, default: True) – If True and no filename was provided, all files present in the provided directory are returned (and merged if merge is True. It is assumed that all the files correspond to current reading protocol.

    Changed in version 0.6.2: iterdir replace the deprecated listdir argument.

See also

read

Generic reader inferring protocol from the filename extension.

read_zip

Read Zip archives (containing spectrochempy readable files)

read_dir

Read an entire directory.

read_labspec

Read Raman LABSPEC spectra (.txt).

read_omnic

Read Omnic spectra (.spa, .spg, .srs).

read_soc

Read Surface Optics Corps. files (.ddr , .hdr or .sdr).

read_galactic

Read Galactic files (.spc).

read_quadera

Read a Pfeiffer Vacuum’s QUADERA mass spectrometer software file.

read_topspin

Read TopSpin Bruker NMR spectra.

read_csv

Read CSV files (.csv).

read_jcamp

Read Infrared JCAMP-DX files (.jdx, .dx).

read_matlab

Read Matlab files (.mat, .dso).

read_carroucell

Read files in a directory after a carroucell experiment.

read_wire

Read REnishaw Wire files (.wdf).

Examples

Reading a single OPUS file (providing a windows type filename relative to the default datadir )

>>> scp.read_opus('irdata\\OPUS\\test.0000')
NDDataset: [float64] a.u. (shape: (y:1, x:2567))

Reading a single OPUS file (providing a unix/python type filename relative to the default datadir ) Note that here read_opus is called as a classmethod of the NDDataset class

>>> scp.NDDataset.read_opus('irdata/OPUS/test.0000')
NDDataset: [float64] a.u. (shape: (y:1, x:2567))

Single file specified with pathlib.Path object

>>> from pathlib import Path
>>> folder = Path('irdata/OPUS')
>>> p = folder / 'test.0000'
>>> scp.read_opus(p)
NDDataset: [float64] a.u. (shape: (y:1, x:2567))

Multiple files not merged (return a list of datasets). Note that a directory is specified

>>> le = scp.read_opus('test.0000', 'test.0001', 'test.0002',
>>>                    directory='irdata/OPUS')
>>> len(le)
3
>>> le[0]
NDDataset: [float64] a.u. (shape: (y:1, x:2567))

Multiple files merged as the merge keyword is set to true

>>> scp.read_opus('test.0000', 'test.0001', 'test.0002',
directory='irdata/OPUS', merge=True)
NDDataset: [float64] a.u. (shape: (y:3, x:2567))

Multiple files to merge : they are passed as a list instead of using the keyword ` merge`

>>> scp.read_opus(['test.0000', 'test.0001', 'test.0002'],
>>>               directory='irdata/OPUS')
NDDataset: [float64] a.u. (shape: (y:3, x:2567))

Multiple files not merged : they are passed as a list but merge is set to false

>>> le = scp.read_opus(['test.0000', 'test.0001', 'test.0002'],
>>>                    directory='irdata/OPUS', merge=False)
>>> len(le)
3

Read without a filename. This has the effect of opening a dialog for file(s) selection

>>> nd = scp.read_opus()

Read in a directory (assume that only OPUS files are present in the directory (else we must use the generic read function instead)

>>> le = scp.read_opus(directory='irdata/OPUS')
>>> len(le)
4

Again we can use merge to stack all 4 spectra if thet have compatible dimensions.

>>> scp.read_opus(directory='irdata/OPUS', merge=True)
NDDataset: [float64] a.u. (shape: (y:4, x:2567))
read_quadera(*paths, **kwargs)[source]

Read a Pfeiffer Vacuum’s QUADERA mass spectrometer software file with extension .asc.

Parameters
  • *paths (str, Path object objects or valid urls, optional) – The data source(s) can be specified by the name or a list of name for the file(s) to be loaded:

    • e.g., ( filename1, filename2, …, **kwargs )*

    If the list of filenames are enclosed into brackets:

    • e.g., ( [ filename1, filename2, … ], **kwargs )

    The returned datasets are merged to form a single dataset, except if merge is set to False.

    If a source is not provided (i.e., no paths , nor content), a dialog box will be opened to select files.

  • **kwargs (keyword parameters, optional) – See Other Parameters.

Returns

object (NDDataset or list of NDDataset) – The returned dataset(s).

Other Parameters
  • timestamp (bool, optional, default: True) – Returns the acquisition timestamp as Coord. If set to False, returns the time relative to the acquisition time of the data

  • protocol (str, optional) – Protocol used for reading. It can be one of {'scp', 'omnic', 'opus', 'topspin', 'matlab', 'jcamp', 'csv', 'excel'}. If not provided, the correct protocol is inferred (whenever it is possible) from the filename extension.

  • directory (Path object objects or valid urls, optional) – From where to read the files.

  • merge (bool, optional, default: False) – If True and several filenames or a directory have been provided as arguments, then a single NDDataset with merged (stacked along the first dimension) is returned.

  • sortbydate (bool, optional, default: True) – Sort multiple filename by acquisition date.

  • description (str, optional) – A Custom description.

  • origin (one of {'omnic', 'tga'}, optional) – Used when reading with the CSV protocol. In order to properly interpret CSV file it can be necessary to set the origin of the spectra. Up to now only 'omnic' and 'tga' have been implemented.

  • csv_delimiter (str, optional, default: csv_delimiter) – Set the column delimiter in CSV file.

  • content (bytes object, optional) – Instead of passing a filename for further reading, a bytes content can be directly provided as bytes objects. The most convenient way is to use a dictionary. This feature is particularly useful for a GUI Dash application to handle drag and drop of files into a Browser.

  • iterdir (bool, optional, default: True) – If True and no filename was provided, all files present in the provided directory are returned (and merged if merge is True. It is assumed that all the files correspond to current reading protocol.

    Changed in version 0.6.2: iterdir replace the deprecated listdir argument.

See also

read

Generic reader inferring protocol from the filename extension.

read_zip

Read Zip archives (containing spectrochempy readable files)

read_dir

Read an entire directory.

read_opus

Read OPUS spectra.

read_labspec

Read Raman LABSPEC spectra (.txt).

read_omnic

Read Omnic spectra (.spa, .spg, .srs).

read_soc

Read Surface Optics Corps. files (.ddr , .hdr or .sdr).

read_galactic

Read Galactic files (.spc).

read_topspin

Read TopSpin Bruker NMR spectra.

read_csv

Read CSV files (.csv).

read_jcamp

Read Infrared JCAMP-DX files (.jdx, .dx).

read_matlab

Read Matlab files (.mat, .dso).

read_carroucell

Read files in a directory after a carroucell experiment.

read_wire

Read REnishaw Wire files (.wdf).

Notes

Currently the acquisition time is that of the first channel as the timeshift of other channels are typically within few seconds, and the data of other channels are NOT interpolated Todo: check with users whether data interpolation should be made

Examples

>>> scp.read_quadera('msdata/ion_currents.asc')
NDDataset: [float64] A (shape: (y:16975, x:10))
read_sdr(*paths, **kwargs)[source]

Open a Surface Optics Corps. file or a list of files with extension .sdr.

Parameters
  • *paths (str, Path object objects or valid urls, optional) – The data source(s) can be specified by the name or a list of name for the file(s) to be loaded:

    • e.g., ( filename1, filename2, …, **kwargs )*

    If the list of filenames are enclosed into brackets:

    • e.g., ( [ filename1, filename2, … ], **kwargs )

    The returned datasets are merged to form a single dataset, except if merge is set to False.

    If a source is not provided (i.e., no paths , nor content), a dialog box will be opened to select files.

  • **kwargs (keyword parameters, optional) – See Other Parameters.

Returns

object (NDDataset or list of NDDataset) – The returned dataset(s).

Other Parameters
  • return_ifg (str or None, optional) – Default value is None. When set to ‘sample’ returns the sample interferogram of the spa file if present or None if absent. When set to ‘background’ returns the backgroung interferogram of the spa file if present or None if absent.

  • protocol (str, optional) – Protocol used for reading. It can be one of {'scp', 'omnic', 'opus', 'topspin', 'matlab', 'jcamp', 'csv', 'excel'}. If not provided, the correct protocol is inferred (whenever it is possible) from the filename extension.

  • directory (Path object objects or valid urls, optional) – From where to read the files.

  • merge (bool, optional, default: False) – If True and several filenames or a directory have been provided as arguments, then a single NDDataset with merged (stacked along the first dimension) is returned.

  • sortbydate (bool, optional, default: True) – Sort multiple filename by acquisition date.

  • description (str, optional) – A Custom description.

  • origin (one of {'omnic', 'tga'}, optional) – Used when reading with the CSV protocol. In order to properly interpret CSV file it can be necessary to set the origin of the spectra. Up to now only 'omnic' and 'tga' have been implemented.

  • csv_delimiter (str, optional, default: csv_delimiter) – Set the column delimiter in CSV file.

  • content (bytes object, optional) – Instead of passing a filename for further reading, a bytes content can be directly provided as bytes objects. The most convenient way is to use a dictionary. This feature is particularly useful for a GUI Dash application to handle drag and drop of files into a Browser.

  • iterdir (bool, optional, default: True) – If True and no filename was provided, all files present in the provided directory are returned (and merged if merge is True. It is assumed that all the files correspond to current reading protocol.

    Changed in version 0.6.2: iterdir replace the deprecated listdir argument.

See also

read

Generic reader inferring protocol from the filename extension.

read_zip

Read Zip archives (containing spectrochempy readable files)

read_dir

Read an entire directory.

read_opus

Read OPUS spectra.

read_labspec

Read Raman LABSPEC spectra (.txt).

read_omnic

Read Omnic spectra (.spa, .spg, .srs).

read_soc

Read Surface Optics Corps. files (.ddr , .hdr or .sdr).

read_galactic

Read Galactic files (.spc).

read_quadera

Read a Pfeiffer Vacuum’s QUADERA mass spectrometer software file.

read_topspin

Read TopSpin Bruker NMR spectra.

read_csv

Read CSV files (.csv).

read_jcamp

Read Infrared JCAMP-DX files (.jdx, .dx).

read_matlab

Read Matlab files (.mat, .dso).

read_carroucell

Read files in a directory after a carroucell experiment.

read_wire

Read REnishaw Wire files (.wdf).

read_soc(*paths, **kwargs)[source]

Read a Surface Optics Corps. file or a list of files with extension .ddr, .hdr or .sdr.

Parameters
  • *paths (str, Path object objects or valid urls, optional) – The data source(s) can be specified by the name or a list of name for the file(s) to be loaded:

    • e.g., ( filename1, filename2, …, **kwargs )*

    If the list of filenames are enclosed into brackets:

    • e.g., ( [ filename1, filename2, … ], **kwargs )

    The returned datasets are merged to form a single dataset, except if merge is set to False.

    If a source is not provided (i.e., no paths , nor content), a dialog box will be opened to select files.

  • **kwargs (keyword parameters, optional) – See Other Parameters.

Returns

object (NDDataset or list of NDDataset) – The returned dataset(s).

Other Parameters
  • return_ifg (str or None, optional) – Default value is None. When set to ‘sample’ returns the sample interferogram of the spa file if present or None if absent. When set to ‘background’ returns the backgroung interferogram of the spa file if present or None if absent.

  • protocol (str, optional) – Protocol used for reading. It can be one of {'scp', 'omnic', 'opus', 'topspin', 'matlab', 'jcamp', 'csv', 'excel'}. If not provided, the correct protocol is inferred (whenever it is possible) from the filename extension.

  • directory (Path object objects or valid urls, optional) – From where to read the files.

  • merge (bool, optional, default: False) – If True and several filenames or a directory have been provided as arguments, then a single NDDataset with merged (stacked along the first dimension) is returned.

  • sortbydate (bool, optional, default: True) – Sort multiple filename by acquisition date.

  • description (str, optional) – A Custom description.

  • origin (one of {'omnic', 'tga'}, optional) – Used when reading with the CSV protocol. In order to properly interpret CSV file it can be necessary to set the origin of the spectra. Up to now only 'omnic' and 'tga' have been implemented.

  • csv_delimiter (str, optional, default: csv_delimiter) – Set the column delimiter in CSV file.

  • content (bytes object, optional) – Instead of passing a filename for further reading, a bytes content can be directly provided as bytes objects. The most convenient way is to use a dictionary. This feature is particularly useful for a GUI Dash application to handle drag and drop of files into a Browser.

  • iterdir (bool, optional, default: True) – If True and no filename was provided, all files present in the provided directory are returned (and merged if merge is True. It is assumed that all the files correspond to current reading protocol.

    Changed in version 0.6.2: iterdir replace the deprecated listdir argument.

See also

read

Generic reader inferring protocol from the filename extension.

read_zip

Read Zip archives (containing spectrochempy readable files)

read_dir

Read an entire directory.

read_opus

Read OPUS spectra.

read_labspec

Read Raman LABSPEC spectra (.txt).

read_omnic

Read Omnic spectra (.spa, .spg, .srs).

read_galactic

Read Galactic files (.spc).

read_quadera

Read a Pfeiffer Vacuum’s QUADERA mass spectrometer software file.

read_topspin

Read TopSpin Bruker NMR spectra.

read_csv

Read CSV files (.csv).

read_jcamp

Read Infrared JCAMP-DX files (.jdx, .dx).

read_matlab

Read Matlab files (.mat, .dso).

read_carroucell

Read files in a directory after a carroucell experiment.

read_wire

Read REnishaw Wire files (.wdf).

read_spa(*paths, **kwargs)[source]

Open a Thermo Nicolet file or a list of files with extension .spa.

Parameters
  • *paths (str, Path object objects or valid urls, optional) – The data source(s) can be specified by the name or a list of name for the file(s) to be loaded:

    • e.g., ( filename1, filename2, …, **kwargs )*

    If the list of filenames are enclosed into brackets:

    • e.g., ( [ filename1, filename2, … ], **kwargs )

    The returned datasets are merged to form a single dataset, except if merge is set to False.

    If a source is not provided (i.e., no paths , nor content), a dialog box will be opened to select files.

  • **kwargs (keyword parameters, optional) – See Other Parameters.

Returns

object (NDDataset or list of NDDataset) – The returned dataset(s).

Other Parameters
  • protocol (str, optional) – Protocol used for reading. It can be one of {'scp', 'omnic', 'opus', 'topspin', 'matlab', 'jcamp', 'csv', 'excel'}. If not provided, the correct protocol is inferred (whenever it is possible) from the filename extension.

  • directory (Path object objects or valid urls, optional) – From where to read the files.

  • merge (bool, optional, default: False) – If True and several filenames or a directory have been provided as arguments, then a single NDDataset with merged (stacked along the first dimension) is returned.

  • sortbydate (bool, optional, default: True) – Sort multiple filename by acquisition date.

  • description (str, optional) – A Custom description.

  • origin (one of {'omnic', 'tga'}, optional) – Used when reading with the CSV protocol. In order to properly interpret CSV file it can be necessary to set the origin of the spectra. Up to now only 'omnic' and 'tga' have been implemented.

  • csv_delimiter (str, optional, default: csv_delimiter) – Set the column delimiter in CSV file.

  • content (bytes object, optional) – Instead of passing a filename for further reading, a bytes content can be directly provided as bytes objects. The most convenient way is to use a dictionary. This feature is particularly useful for a GUI Dash application to handle drag and drop of files into a Browser.

  • iterdir (bool, optional, default: True) – If True and no filename was provided, all files present in the provided directory are returned (and merged if merge is True. It is assumed that all the files correspond to current reading protocol.

    Changed in version 0.6.2: iterdir replace the deprecated listdir argument.

See also

read

Generic reader inferring protocol from the filename extension.

read_zip

Read Zip archives (containing spectrochempy readable files)

read_dir

Read an entire directory.

read_opus

Read OPUS spectra.

read_labspec

Read Raman LABSPEC spectra (.txt).

read_omnic

Read Omnic spectra (.spa, .spg, .srs).

read_soc

Read Surface Optics Corps. files (.ddr , .hdr or .sdr).

read_galactic

Read Galactic files (.spc).

read_quadera

Read a Pfeiffer Vacuum’s QUADERA mass spectrometer software file.

read_topspin

Read TopSpin Bruker NMR spectra.

read_csv

Read CSV files (.csv).

read_jcamp

Read Infrared JCAMP-DX files (.jdx, .dx).

read_matlab

Read Matlab files (.mat, .dso).

read_carroucell

Read files in a directory after a carroucell experiment.

read_wire

Read REnishaw Wire files (.wdf).

Notes

This method is an alias of read_omnic, except that the type of file is contrain to .spa.

Examples

>>> scp.read_spa('irdata/subdir/20-50/7_CZ0-100 Pd_21.SPA')
NDDataset: [float64] a.u. (shape: (y:1, x:5549))
>>> scp.read_spa(directory='irdata/subdir', merge=True)
NDDataset: [float64] a.u. (shape: (y:4, x:5549))
read_spc(*paths, **kwargs)[source]

Read GRAMS/Thermo Scientific Galactic files or a list of files with extension .spc.

Parameters
  • *paths (str, Path object objects or valid urls, optional) – The data source(s) can be specified by the name or a list of name for the file(s) to be loaded:

    • e.g., ( filename1, filename2, …, **kwargs )*

    If the list of filenames are enclosed into brackets:

    • e.g., ( [ filename1, filename2, … ], **kwargs )

    The returned datasets are merged to form a single dataset, except if merge is set to False.

    If a source is not provided (i.e., no paths , nor content), a dialog box will be opened to select files.

  • **kwargs (keyword parameters, optional) – See Other Parameters.

Returns

object (NDDataset or list of NDDataset) – The returned dataset(s).

Other Parameters
  • protocol (str, optional) – Protocol used for reading. It can be one of {'scp', 'omnic', 'opus', 'topspin', 'matlab', 'jcamp', 'csv', 'excel'}. If not provided, the correct protocol is inferred (whenever it is possible) from the filename extension.

  • directory (Path object objects or valid urls, optional) – From where to read the files.

  • merge (bool, optional, default: False) – If True and several filenames or a directory have been provided as arguments, then a single NDDataset with merged (stacked along the first dimension) is returned.

  • sortbydate (bool, optional, default: True) – Sort multiple filename by acquisition date.

  • description (str, optional) – A Custom description.

  • origin (one of {'omnic', 'tga'}, optional) – Used when reading with the CSV protocol. In order to properly interpret CSV file it can be necessary to set the origin of the spectra. Up to now only 'omnic' and 'tga' have been implemented.

  • csv_delimiter (str, optional, default: csv_delimiter) – Set the column delimiter in CSV file.

  • content (bytes object, optional) – Instead of passing a filename for further reading, a bytes content can be directly provided as bytes objects. The most convenient way is to use a dictionary. This feature is particularly useful for a GUI Dash application to handle drag and drop of files into a Browser.

  • iterdir (bool, optional, default: True) – If True and no filename was provided, all files present in the provided directory are returned (and merged if merge is True. It is assumed that all the files correspond to current reading protocol.

    Changed in version 0.6.2: iterdir replace the deprecated listdir argument.

See also

read

Generic reader inferring protocol from the filename extension.

read_zip

Read Zip archives (containing spectrochempy readable files)

read_dir

Read an entire directory.

read_opus

Read OPUS spectra.

read_labspec

Read Raman LABSPEC spectra (.txt).

read_omnic

Read Omnic spectra (.spa, .spg, .srs).

read_soc

Read Surface Optics Corps. files (.ddr , .hdr or .sdr).

read_galactic

Read Galactic files (.spc).

read_quadera

Read a Pfeiffer Vacuum’s QUADERA mass spectrometer software file.

read_topspin

Read TopSpin Bruker NMR spectra.

read_csv

Read CSV files (.csv).

read_jcamp

Read Infrared JCAMP-DX files (.jdx, .dx).

read_matlab

Read Matlab files (.mat, .dso).

read_carroucell

Read files in a directory after a carroucell experiment.

read_wire

Read REnishaw Wire files (.wdf).

Examples

>>> scp.read_spc("galacticdata/BENZENE.spc")
NDDataset: [float64] a.u. (shape: (y:1, x:1842))
read_spg(*paths, **kwargs)[source]

Open a Thermo Nicolet file or a list of files with extension .spg.

Parameters
  • *paths (str, Path object objects or valid urls, optional) – The data source(s) can be specified by the name or a list of name for the file(s) to be loaded:

    • e.g., ( filename1, filename2, …, **kwargs )*

    If the list of filenames are enclosed into brackets:

    • e.g., ( [ filename1, filename2, … ], **kwargs )

    The returned datasets are merged to form a single dataset, except if merge is set to False.

    If a source is not provided (i.e., no paths , nor content), a dialog box will be opened to select files.

  • **kwargs (keyword parameters, optional) – See Other Parameters.

Returns

object (NDDataset or list of NDDataset) – The returned dataset(s).

Other Parameters
  • protocol (str, optional) – Protocol used for reading. It can be one of {'scp', 'omnic', 'opus', 'topspin', 'matlab', 'jcamp', 'csv', 'excel'}. If not provided, the correct protocol is inferred (whenever it is possible) from the filename extension.

  • directory (Path object objects or valid urls, optional) – From where to read the files.

  • merge (bool, optional, default: False) – If True and several filenames or a directory have been provided as arguments, then a single NDDataset with merged (stacked along the first dimension) is returned.

  • sortbydate (bool, optional, default: True) – Sort multiple filename by acquisition date.

  • description (str, optional) – A Custom description.

  • origin (one of {'omnic', 'tga'}, optional) – Used when reading with the CSV protocol. In order to properly interpret CSV file it can be necessary to set the origin of the spectra. Up to now only 'omnic' and 'tga' have been implemented.

  • csv_delimiter (str, optional, default: csv_delimiter) – Set the column delimiter in CSV file.

  • content (bytes object, optional) – Instead of passing a filename for further reading, a bytes content can be directly provided as bytes objects. The most convenient way is to use a dictionary. This feature is particularly useful for a GUI Dash application to handle drag and drop of files into a Browser.

  • iterdir (bool, optional, default: True) – If True and no filename was provided, all files present in the provided directory are returned (and merged if merge is True. It is assumed that all the files correspond to current reading protocol.

    Changed in version 0.6.2: iterdir replace the deprecated listdir argument.

See also

read_spg

Read grouped Omnic spectra.

read_spa

Read single Omnic spectra.

read_srs

Read series Omnic spectra.

read

Generic reader inferring protocol from the filename extension.

read_zip

Read Zip archives (containing spectrochempy readable files)

read_dir

Read an entire directory.

read_opus

Read OPUS spectra.

read_labspec

Read Raman LABSPEC spectra (.txt).

read_soc

Read Surface Optics Corps. files (.ddr , .hdr or .sdr).

read_galactic

Read Galactic files (.spc).

read_quadera

Read a Pfeiffer Vacuum’s QUADERA mass spectrometer software file.

read_topspin

Read TopSpin Bruker NMR spectra.

read_csv

Read CSV files (.csv).

read_jcamp

Read Infrared JCAMP-DX files (.jdx, .dx).

read_matlab

Read Matlab files (.mat, .dso).

read_carroucell

Read files in a directory after a carroucell experiment.

read_wire

Read REnishaw Wire files (.wdf).

Notes

This method is an alias of read_omnic, except that the type of file is constrained to .spg.

Examples

>>> scp.read_spg('irdata/nh4y-activation.spg')
NDDataset: [float64] a.u. (shape: (y:55, x:5549))
read_srs(*paths, **kwargs)[source]

Open a Thermo Nicolet file or a list of files with extension .srs .

Currently, only the rapid scan and high speed real time series are supported.

Parameters
  • *paths (str, Path object objects or valid urls, optional) – The data source(s) can be specified by the name or a list of name for the file(s) to be loaded:

    • e.g., ( filename1, filename2, …, **kwargs )*

    If the list of filenames are enclosed into brackets:

    • e.g., ( [ filename1, filename2, … ], **kwargs )

    The returned datasets are merged to form a single dataset, except if merge is set to False.

    If a source is not provided (i.e., no paths , nor content), a dialog box will be opened to select files.

  • **kwargs (keyword parameters, optional) – See Other Parameters.

Returns

object (NDDataset or list of NDDataset) – The returned dataset(s). When return_bg is set to ‘True’, the series background is returned.

Other Parameters
  • return_bg (bool, optional) – Default value is False. When set to ‘True’ returns the series background

  • protocol (str, optional) – Protocol used for reading. It can be one of {'scp', 'omnic', 'opus', 'topspin', 'matlab', 'jcamp', 'csv', 'excel'}. If not provided, the correct protocol is inferred (whenever it is possible) from the filename extension.

  • directory (Path object objects or valid urls, optional) – From where to read the files.

  • merge (bool, optional, default: False) – If True and several filenames or a directory have been provided as arguments, then a single NDDataset with merged (stacked along the first dimension) is returned.

  • sortbydate (bool, optional, default: True) – Sort multiple filename by acquisition date.

  • description (str, optional) – A Custom description.

  • origin (one of {'omnic', 'tga'}, optional) – Used when reading with the CSV protocol. In order to properly interpret CSV file it can be necessary to set the origin of the spectra. Up to now only 'omnic' and 'tga' have been implemented.

  • csv_delimiter (str, optional, default: csv_delimiter) – Set the column delimiter in CSV file.

  • content (bytes object, optional) – Instead of passing a filename for further reading, a bytes content can be directly provided as bytes objects. The most convenient way is to use a dictionary. This feature is particularly useful for a GUI Dash application to handle drag and drop of files into a Browser.

  • iterdir (bool, optional, default: True) – If True and no filename was provided, all files present in the provided directory are returned (and merged if merge is True. It is assumed that all the files correspond to current reading protocol.

    Changed in version 0.6.2: iterdir replace the deprecated listdir argument.

See also

read

Generic reader inferring protocol from the filename extension.

read_zip

Read Zip archives (containing spectrochempy readable files)

read_dir

Read an entire directory.

read_opus

Read OPUS spectra.

read_labspec

Read Raman LABSPEC spectra (.txt).

read_omnic

Read Omnic spectra (.spa, .spg, .srs).

read_soc

Read Surface Optics Corps. files (.ddr , .hdr or .sdr).

read_galactic

Read Galactic files (.spc).

read_quadera

Read a Pfeiffer Vacuum’s QUADERA mass spectrometer software file.

read_topspin

Read TopSpin Bruker NMR spectra.

read_csv

Read CSV files (.csv).

read_jcamp

Read Infrared JCAMP-DX files (.jdx, .dx).

read_matlab

Read Matlab files (.mat, .dso).

read_carroucell

Read files in a directory after a carroucell experiment.

read_wire

Read REnishaw Wire files (.wdf).

Notes

This method is an alias of read_omnic, except that the type of file is constrained to .srs.

Examples

>>> scp.read_srs('irdata/omnic_series/rapid_scan_reprocessed.srs')
NDDataset: [float64] a.u. (shape: (y:643, x:3734))
read_topspin(*paths, **kwargs)[source]

Open Bruker TOPSPIN (NMR) dataset.

Parameters
  • *paths (str, optional) – Paths of the Bruker directories to read.

  • **kwargs (keyword parameters, optional) – See Other Parameters.

Returns

object (NDDataset or list of NDDataset) – The returned dataset(s).

Other Parameters
  • expno (int, optional) – Experiment number.

  • procno (int, optional) – Processing number.

  • use_list (bool or str, optional, default: False) – Whether to use a list to make indirect coordinates for pseudo-2D spectra (e.g., for relaxation experiments). If True the list vdlist is used. If a string, the list with the given name is used.

  • protocol (str, optional) – Protocol used for reading. It can be one of {'scp', 'omnic', 'opus', 'topspin', 'matlab', 'jcamp', 'csv', 'excel'}. If not provided, the correct protocol is inferred (whenever it is possible) from the filename extension.

  • directory (Path object objects or valid urls, optional) – From where to read the files.

  • merge (bool, optional, default: False) – If True and several filenames or a directory have been provided as arguments, then a single NDDataset with merged (stacked along the first dimension) is returned.

  • sortbydate (bool, optional, default: True) – Sort multiple filename by acquisition date.

  • description (str, optional) – A Custom description.

  • origin (one of {'omnic', 'tga'}, optional) – Used when reading with the CSV protocol. In order to properly interpret CSV file it can be necessary to set the origin of the spectra. Up to now only 'omnic' and 'tga' have been implemented.

  • csv_delimiter (str, optional, default: csv_delimiter) – Set the column delimiter in CSV file.

  • content (bytes object, optional) – Instead of passing a filename for further reading, a bytes content can be directly provided as bytes objects. The most convenient way is to use a dictionary. This feature is particularly useful for a GUI Dash application to handle drag and drop of files into a Browser.

  • iterdir (bool, optional, default: True) – If True and no filename was provided, all files present in the provided directory are returned (and merged if merge is True. It is assumed that all the files correspond to current reading protocol.

    Changed in version 0.6.2: iterdir replace the deprecated listdir argument.

See also

read

Generic reader inferring protocol from the filename extension.

read_zip

Read Zip archives (containing spectrochempy readable files)

read_dir

Read an entire directory.

read_opus

Read OPUS spectra.

read_labspec

Read Raman LABSPEC spectra (.txt).

read_omnic

Read Omnic spectra (.spa, .spg, .srs).

read_soc

Read Surface Optics Corps. files (.ddr , .hdr or .sdr).

read_galactic

Read Galactic files (.spc).

read_quadera

Read a Pfeiffer Vacuum’s QUADERA mass spectrometer software file.

read_csv

Read CSV files (.csv).

read_jcamp

Read Infrared JCAMP-DX files (.jdx, .dx).

read_matlab

Read Matlab files (.mat, .dso).

read_carroucell

Read files in a directory after a carroucell experiment.

read_wire

Read REnishaw Wire files (.wdf).

read_wdf(*paths, **kwargs)[source]

Read a single Raman spectrum or a series of Raman spectra.

Files to open are .wdf file created by Renishaw WiRe software.

Parameters
  • *paths (str, Path object objects or valid urls, optional) – The data source(s) can be specified by the name or a list of name for the file(s) to be loaded:

    • e.g., ( filename1, filename2, …, **kwargs )*

    If the list of filenames are enclosed into brackets:

    • e.g., ( [ filename1, filename2, … ], **kwargs )

    The returned datasets are merged to form a single dataset, except if merge is set to False.

    If a source is not provided (i.e., no paths , nor content), a dialog box will be opened to select files.

  • **kwargs (keyword parameters, optional) – See Other Parameters.

Returns

object (NDDataset or list of NDDataset) – The returned dataset(s).

Other Parameters
  • protocol (str, optional) – Protocol used for reading. It can be one of {'scp', 'omnic', 'opus', 'topspin', 'matlab', 'jcamp', 'csv', 'excel'}. If not provided, the correct protocol is inferred (whenever it is possible) from the filename extension.

  • directory (Path object objects or valid urls, optional) – From where to read the files.

  • merge (bool, optional, default: False) – If True and several filenames or a directory have been provided as arguments, then a single NDDataset with merged (stacked along the first dimension) is returned.

  • sortbydate (bool, optional, default: True) – Sort multiple filename by acquisition date.

  • description (str, optional) – A Custom description.

  • origin (one of {'omnic', 'tga'}, optional) – Used when reading with the CSV protocol. In order to properly interpret CSV file it can be necessary to set the origin of the spectra. Up to now only 'omnic' and 'tga' have been implemented.

  • csv_delimiter (str, optional, default: csv_delimiter) – Set the column delimiter in CSV file.

  • content (bytes object, optional) – Instead of passing a filename for further reading, a bytes content can be directly provided as bytes objects. The most convenient way is to use a dictionary. This feature is particularly useful for a GUI Dash application to handle drag and drop of files into a Browser.

  • iterdir (bool, optional, default: True) – If True and no filename was provided, all files present in the provided directory are returned (and merged if merge is True. It is assumed that all the files correspond to current reading protocol.

    Changed in version 0.6.2: iterdir replace the deprecated listdir argument.

See also

read

Generic reader inferring protocol from the filename extension.

read_zip

Read Zip archives (containing spectrochempy readable files)

read_dir

Read an entire directory.

read_opus

Read OPUS spectra.

read_labspec

Read Raman LABSPEC spectra (.txt).

read_omnic

Read Omnic spectra (.spa, .spg, .srs).

read_soc

Read Surface Optics Corps. files (.ddr , .hdr or .sdr).

read_galactic

Read Galactic files (.spc).

read_quadera

Read a Pfeiffer Vacuum’s QUADERA mass spectrometer software file.

read_topspin

Read TopSpin Bruker NMR spectra.

read_csv

Read CSV files (.csv).

read_jcamp

Read Infrared JCAMP-DX files (.jdx, .dx).

read_matlab

Read Matlab files (.mat, .dso).

read_carroucell

Read files in a directory after a carroucell experiment.

read_wire(*paths, **kwargs)[source]

Read a single Raman spectrum or a series of Raman spectra.

Files to open are .wdf file created by Renishaw WiRe software.

Parameters
  • *paths (str, Path object objects or valid urls, optional) – The data source(s) can be specified by the name or a list of name for the file(s) to be loaded:

    • e.g., ( filename1, filename2, …, **kwargs )*

    If the list of filenames are enclosed into brackets:

    • e.g., ( [ filename1, filename2, … ], **kwargs )

    The returned datasets are merged to form a single dataset, except if merge is set to False.

    If a source is not provided (i.e., no paths , nor content), a dialog box will be opened to select files.

  • **kwargs (keyword parameters, optional) – See Other Parameters.

Returns

object (NDDataset or list of NDDataset) – The returned dataset(s).

Other Parameters
  • protocol (str, optional) – Protocol used for reading. It can be one of {'scp', 'omnic', 'opus', 'topspin', 'matlab', 'jcamp', 'csv', 'excel'}. If not provided, the correct protocol is inferred (whenever it is possible) from the filename extension.

  • directory (Path object objects or valid urls, optional) – From where to read the files.

  • merge (bool, optional, default: False) – If True and several filenames or a directory have been provided as arguments, then a single NDDataset with merged (stacked along the first dimension) is returned.

  • sortbydate (bool, optional, default: True) – Sort multiple filename by acquisition date.

  • description (str, optional) – A Custom description.

  • origin (one of {'omnic', 'tga'}, optional) – Used when reading with the CSV protocol. In order to properly interpret CSV file it can be necessary to set the origin of the spectra. Up to now only 'omnic' and 'tga' have been implemented.

  • csv_delimiter (str, optional, default: csv_delimiter) – Set the column delimiter in CSV file.

  • content (bytes object, optional) – Instead of passing a filename for further reading, a bytes content can be directly provided as bytes objects. The most convenient way is to use a dictionary. This feature is particularly useful for a GUI Dash application to handle drag and drop of files into a Browser.

  • iterdir (bool, optional, default: True) – If True and no filename was provided, all files present in the provided directory are returned (and merged if merge is True. It is assumed that all the files correspond to current reading protocol.

    Changed in version 0.6.2: iterdir replace the deprecated listdir argument.

See also

read

Generic reader inferring protocol from the filename extension.

read_zip

Read Zip archives (containing spectrochempy readable files)

read_dir

Read an entire directory.

read_opus

Read OPUS spectra.

read_labspec

Read Raman LABSPEC spectra (.txt).

read_omnic

Read Omnic spectra (.spa, .spg, .srs).

read_soc

Read Surface Optics Corps. files (.ddr , .hdr or .sdr).

read_galactic

Read Galactic files (.spc).

read_quadera

Read a Pfeiffer Vacuum’s QUADERA mass spectrometer software file.

read_topspin

Read TopSpin Bruker NMR spectra.

read_csv

Read CSV files (.csv).

read_jcamp

Read Infrared JCAMP-DX files (.jdx, .dx).

read_matlab

Read Matlab files (.mat, .dso).

read_carroucell

Read files in a directory after a carroucell experiment.

read_zip(*paths, **kwargs)[source]

Open a zipped list of data files.

Parameters
  • *paths (str, Path object objects or valid urls, optional) – The data source(s) can be specified by the name or a list of name for the file(s) to be loaded:

    • e.g., ( filename1, filename2, …, **kwargs )*

    If the list of filenames are enclosed into brackets:

    • e.g., ( [ filename1, filename2, … ], **kwargs )

    The returned datasets are merged to form a single dataset, except if merge is set to False.

    If a source is not provided (i.e., no paths , nor content), a dialog box will be opened to select files.

  • **kwargs (keyword parameters, optional) – See Other Parameters.

Returns

object (NDDataset or list of NDDataset) – The returned dataset(s).

Other Parameters
  • protocol (str, optional) – Protocol used for reading. It can be one of {'scp', 'omnic', 'opus', 'topspin', 'matlab', 'jcamp', 'csv', 'excel'}. If not provided, the correct protocol is inferred (whenever it is possible) from the filename extension.

  • directory (Path object objects or valid urls, optional) – From where to read the files.

  • merge (bool, optional, default: False) – If True and several filenames or a directory have been provided as arguments, then a single NDDataset with merged (stacked along the first dimension) is returned.

  • sortbydate (bool, optional, default: True) – Sort multiple filename by acquisition date.

  • description (str, optional) – A Custom description.

  • origin (one of {'omnic', 'tga'}, optional) – Used when reading with the CSV protocol. In order to properly interpret CSV file it can be necessary to set the origin of the spectra. Up to now only 'omnic' and 'tga' have been implemented.

  • csv_delimiter (str, optional, default: csv_delimiter) – Set the column delimiter in CSV file.

  • content (bytes object, optional) – Instead of passing a filename for further reading, a bytes content can be directly provided as bytes objects. The most convenient way is to use a dictionary. This feature is particularly useful for a GUI Dash application to handle drag and drop of files into a Browser.

  • iterdir (bool, optional, default: True) – If True and no filename was provided, all files present in the provided directory are returned (and merged if merge is True. It is assumed that all the files correspond to current reading protocol.

    Changed in version 0.6.2: iterdir replace the deprecated listdir argument.

See also

read

Generic reader inferring protocol from the filename extension.

read_dir

Read an entire directory.

read_opus

Read OPUS spectra.

read_labspec

Read Raman LABSPEC spectra (.txt).

read_omnic

Read Omnic spectra (.spa, .spg, .srs).

read_soc

Read Surface Optics Corps. files (.ddr , .hdr or .sdr).

read_galactic

Read Galactic files (.spc).

read_quadera

Read a Pfeiffer Vacuum’s QUADERA mass spectrometer software file.

read_topspin

Read TopSpin Bruker NMR spectra.

read_csv

Read CSV files (.csv).

read_jcamp

Read Infrared JCAMP-DX files (.jdx, .dx).

read_matlab

Read Matlab files (.mat, .dso).

read_carroucell

Read files in a directory after a carroucell experiment.

read_wire

Read REnishaw Wire files (.wdf).

Examples

>>> A = scp.read_zip('agirdata/P350/FTIR/FTIR.zip', only=50, origin='omnic')
>>> print(A)
NDDataset: [float64]  a.u. (shape: (y:50, x:2843))
remove_masks()[source]

Remove all masks previously set on this array.

roll(dataset, pts=0.0, neg=False, **kwargs)[source]

Roll dimensions.

For multidimensional NDDataset, the shift is by default performed on the last dimension.

Parameters
  • dataset (nddataset) – Dataset to be shifted.

  • pts (int) – Number of points toshift.

  • neg (bool) – True to negate the shifted points.

Returns

dataset – Dataset shifted.

Other Parameters
  • dim (str or int, keyword parameter, optional, default=’x’) – Specify on which dimension to apply the shift method. If dim is specified as an integer it is equivalent to the usual axis numpy parameter.

  • inplace (bool, keyword parameter, optional, default=False) – True if we make the transform inplace. If False, the function return a new dataset.

See also

ls, rs, cs, fsh, fsh2

round(dataset, decimals=0)[source]

Evenly round to the given number of decimals.

Parameters
  • dataset (NDDataset) – Input dataset.

  • decimals (int, optional) – Number of decimal places to round to (default: 0). If decimals is negative, it specifies the number of positions to the left of the decimal point.

Returns

rounded_array – NDDataset containing the rounded values. The real and imaginary parts of complex numbers are rounded separately. The result of rounding a float is a float. If the dataset contains masked data, the mask remain unchanged.

See also

numpy.round, around, spectrochempy.round, spectrochempy.around, methods., ceil, fix, floor, rint, trunc

round_(dataset, decimals=0)[source]

Evenly round to the given number of decimals.

Parameters
  • dataset (NDDataset) – Input dataset.

  • decimals (int, optional) – Number of decimal places to round to (default: 0). If decimals is negative, it specifies the number of positions to the left of the decimal point.

Returns

rounded_array – NDDataset containing the rounded values. The real and imaginary parts of complex numbers are rounded separately. The result of rounding a float is a float. If the dataset contains masked data, the mask remain unchanged.

See also

numpy.round, around, spectrochempy.round, spectrochempy.around, methods., ceil, fix, floor, rint, trunc

rs(dataset, pts=0.0, **kwargs)[source]

Right shift and zero fill.

For multidimensional NDDataset, the shift is by default performed on the last dimension.

Parameters
  • dataset (nddataset) – NDDataset to be right-shifted.

  • pts (int) – Number of points to right shift.

Returns

dataset – Dataset right shifted and zero filled.

Other Parameters
  • dim (str or int, keyword parameter, optional, default=’x’) – Specify on which dimension to apply the shift method. If dim is specified as an integer it is equivalent to the usual axis numpy parameter.

  • inplace (bool, keyword parameter, optional, default=False) – True if we make the transform inplace. If False, the function return a new dataset.

See also

roll

shift without zero filling.

rubberband(dataset)[source]

Rubberband baseline correction.

The algorithm is faster than the AsLS method, but it is less controllable as there is no parameter to tune.

Parameters

dataset (NDDataset) – The input data.

Returns

NDDataset – The baseline corrected dataset.

See also

Baseline

Manual baseline correction processor.

get_baseline

Compuute a baseline using the Baseline class.

basc

Make a baseline correction using the Baseline class.

asls

Perform an Asymmetric Least Squares Smoothing baseline correction.

snip

Perform a Simple Non-Iterative Peak (SNIP) detection algorithm.

autosub

Perform an automatic subtraction of reference.

detrend

Remove polynomial trend along a dimension from dataset.

save(**kwargs)[source]

Save the current object in SpectroChemPy format.

Default extension is .scp for NDDataset’s and .pscp for

Project’s.

Parameters

**kwargs – Optional keyword parameters (see Other Parameters).

Other Parameters

confirm (bool)

See also

save_as

Save current object with a different name and/or directory.

write

Export current object to different format.

Examples

Read some data from an OMNIC file

>>> nd = scp.read_omnic('wodger.spg')
>>> assert nd.name == 'wodger'

Write it in SpectroChemPy format (.scp) (return a pathlib object)

>>> filename = nd.save()

Check the existence of the scp fie

>>> assert filename.is_file()
>>> assert filename.name == 'wodger.scp'

Remove this file

>>> filename.unlink()
save_as(filename='', **kwargs)[source]

Save the current NDDataset in SpectroChemPy format (*.scp).

Parameters
  • filename (str) – The filename of the file where to save the current dataset.

  • **kwargs – Optional keyword parameters (see Other Parameters).

Other Parameters

directory (str, optional) – If specified, the given directory and the filename will be appended.

See also

save

Save current dataset.

write

Export current dataset to different format.

Notes

Adapted from numpy.savez .

Examples

Read some data from an OMNIC file

>>> nd = scp.read_omnic('wodger.spg')
>>> assert nd.name == 'wodger'

Write it in SpectroChemPy format (.scp) (return a pathlib object)

>>> filename = nd.save_as('new_wodger')

Check the existence of the scp file

>>> assert filename.is_file()
>>> assert filename.name == 'new_wodger.scp'

Remove this file

>>> filename.unlink()
savgol(dataset, size=5, order=2, **kwargs)[source]

Savitzky-Golay filter.

Wrapper of scpy.signal.savgol(). See the documentation of this function for more details.

Parameters
  • dataset (NDDataset or array-like of shape (n_observations , n_features)) – Input data, where n_observations is the number of observations and n_features is the number of features.

  • size (positiveoddinteger, optional, default: 5) – The size of the filter window.size must be a positive odd integer.

  • order (int, optional, default=2) – The order of the polynomial used to fit the data. order must be less than size.

  • **kwargs (keyword parameters, optional) – See Other Parameters.

Returns

NDDataset – Smoothed data.

Other Parameters
  • dim (int or str, optional, default: -1,) – Dimension along which the method is applied. By default, the method is applied to the last dimension. If dim is specified as an integer it is equivalent to the usual axis numpy parameter.

  • deriv (int, optional, default: 0) – The order of the derivative to compute in the case of the Savitzky-Golay (savgol) filter. This must be a non-negative integer. The default is 0, which means to filter the data without differentiating.

  • delta (float, optional, default: 1.0) – The spacing of the samples to which the filter will be applied. This is only used if deriv > 0.

  • mode (any value of [ 'mirror' , 'constant' , 'nearest' , 'wrap' , 'interp' ], optional, default: 'interp') – The type of extension to use for the padded signal to which the filter is applied.

    • When mode is ‘constant’, the padding value is given by cval.

    • When the ‘interp’ mode is selected (the default), no extension is used. Instead, a polynomial of degree order is fit to the last size values of the edges, and this polynomial is used to evaluate the last window_length // 2 output values.

    • When mode is ‘nearest’, the last size values are repeated.

    • When mode is ‘mirror’, the padding is created by reflecting the signal about the end of the signal.

    • When mode is ‘wrap’, the signal is wrapped around on itself to create the padding.

    See scipy.signal.savgol_filter for more details on ‘mirror’, ‘constant’, ‘wrap’, and ‘nearest’.

  • cval (float, optional, default: 0.0) – Value to fill past the edges of the input if mode is ‘constant’.

  • log_level (any of ["INFO", "DEBUG", "WARNING", "ERROR"], optional, default: "WARNING") – The log level at startup. It can be changed later on using the set_log_level method or by changing the log_level attribute.

See also

Filter

Define and apply filters/smoothers using various algorithms.

smooth

Function to smooth data using various window filters.

savgol_filter

Alias of savgol

whittaker

Whittaker-Eilers filter.

Notes

Even spacing of the axis coordinates is NOT checked. Be aware that Savitzky-Golay algorithm is based on indexes, not on coordinates.

savgol_filter(*args, **kwargs)[source]

Savitzky-Golay filter.

Alias of savgol.

set_complex(inplace=False)[source]

Set the object data as complex.

When nD-dimensional array are set to complex, we assume that it is along the first dimension. Two succesives rows are merged to form a complex rows. This means that the number of row must be even If the complexity is to be applied in other dimension, either transpose/swapdims your data before applying this function in order that the complex dimension is the first in the array.

Parameters

inplace (bool, optional, default=False) – Flag to say that the method return a new object (default) or not (inplace=True).

Returns

out – Same object or a copy depending on the inplace flag.

set_coordset(*args, **kwargs)[source]

Set one or more coordinates at once.

Warning

This method replace all existing coordinates.

See also

add_coordset

Add one or a set of coordinates from a dataset.

set_coordtitles

Set titles of the one or more coordinates.

set_coordunits

Set units of the one or more coordinates.

set_coordtitles(*args, **kwargs)[source]

Set titles of the one or more coordinates.

set_coordunits(*args, **kwargs)[source]

Set units of the one or more coordinates.

set_hypercomplex(inplace=False)[source]

Alias of set_quaternion.

set_quaternion(inplace=False)[source]

Alias of set_quaternion.

simps(replace="simpson")def simps(dataset, **kwargs)[source]

An alias of simpson kept for backwards compatibility.

Integrate using the composite trapezoidal rule.

Wrapper of scpy.integrate.trapezoid.

Performs the integration along the last or given dimension.

Parameters
  • dataset (NDDataset) – Dataset to be integrated.

  • **kwargs – Additional keywords parameters. See Other Parameters.

Returns

NDDataset – Definite integral as approximated by trapezoidal rule.

Other Parameters

dim (int or str, optional, default: "x") – Dimension along which to integrate. If an integer is provided, it is equivalent to the numpy axis parameter for ndarrays.

See also

trapz

An alias of trapezoid.

simpson

Integrate using the composite simpson rule.

Example

>>> dataset = scp.read('irdata/nh4y-activation.spg')
>>> dataset[:,1250.:1800.].trapz()
NDDataset: [float64] a.u..cm^-1 (size: 55)
simpson(dataset, *args, **kwargs)[source]

Integrate using the composite Simpson’s rule.

Wrapper of scpy.integrate.simpson.

Performs the integration along the last or given dimension.

If there are an even number of samples, N, then there are an odd number of intervals (N-1), but Simpson’s rule requires an even number of intervals. The parameter ‘even’ controls how this is handled.

Parameters
  • dataset (NDDataset) – Dataset to be integrated.

  • **kwargs – Additional keywords parameters. See Other Parameters.

Returns

NDDataset – Definite integral as approximated using the composite Simpson’s rule.

Other Parameters
  • dim (int or str, optional, default: "x") – Dimension along which to integrate. If an integer is provided, it is equivalent to the numpy.axis parameter for ndarrays.

  • even (any of ['avg', 'first', 'last'}, optional, default: 'avg') –

    • 'avg' : Average two results: 1) use the first N-2 intervals with a trapezoidal rule on the last interval and 2) use the last N-2 intervals with a trapezoidal rule on the first interval.

    • 'first' : Use Simpson’s rule for the first N-2 intervals with a trapezoidal rule on the last interval.

    • 'last' : Use Simpson’s rule for the last N-2 intervals with a trapezoidal rule on the first interval.

See also

simps

An alias of simpson (Deprecated).

trapezoid

Integrate using the composite simpson rule.

Example

>>> dataset = scp.read('irdata/nh4y-activation.spg')
>>> dataset[:,1250.:1800.].simps()
NDDataset: [float64] a.u..cm^-1 (size: 55)
sine(dataset, *args, **kwargs)[source]

Strictly equivalent to sp .

Returns

NDDataset – Modified dataset.

sinm(dataset, ssb=1, **kwargs)[source]

Equivalent to sp , with pow = 1 (sine bell apodization window).

Returns

NDDataset – Modified dataset.

Returns

NDDataset – Modified dataset.

smooth(dataset, size=5, window='avg', **kwargs)[source]

Smooth the data using a window with requested size.

This method is based on the convolution of a scaled kernel window with the signal.

Parameters
  • dataset (NDDataset or array-like of shape (n_observations , n_features)) – Input data, where n_observations is the number of observations and n_features is the number of features.

  • size (positiveoddinteger, optional, default: 5) – The size of the filter window.size must be a positive odd integer.

  • window (str, optional, default:’flat’) – The type of window from ‘flat’ or ‘avg’, ‘han’ or ‘hanning’, ‘hamming’, ‘bartlett’, ‘blackman’. avg window will produce a moving average smoothing.

  • **kwargs (keyword parameters, optional) – See Other Parameters.

Returns

NDDataset – Smoothed data.

Other Parameters
  • dim (int or str, optional, default: -1,) – Dimension along which the method is applied. By default, the method is applied to the last dimension. If dim is specified as an integer it is equivalent to the usual axis numpy parameter.

  • mode (any value of [ 'mirror' , 'constant' , 'nearest' , 'wrap' , 'interp' ], optional, default: 'interp') – The type of extension to use for the padded signal to which the filter is applied.

    • When mode is ‘constant’, the padding value is given by cval.

    • When the ‘interp’ mode is selected (the default), no extension is used. Instead, a polynomial of degree order is fit to the last size values of the edges, and this polynomial is used to evaluate the last window_length // 2 output values.

    • When mode is ‘nearest’, the last size values are repeated.

    • When mode is ‘mirror’, the padding is created by reflecting the signal about the end of the signal.

    • When mode is ‘wrap’, the signal is wrapped around on itself to create the padding.

    See scipy.signal.savgol_filter for more details on ‘mirror’, ‘constant’, ‘wrap’, and ‘nearest’.

  • cval (float, optional, default: 0.0) – Value to fill past the edges of the input if mode is ‘constant’.

  • log_level (any of ["INFO", "DEBUG", "WARNING", "ERROR"], optional, default: "WARNING") – The log level at startup. It can be changed later on using the set_log_level method or by changing the log_level attribute.

See also

Filter

Define and apply filters/smoothers using various algorithms.

savgol

Savitzky-Golay filter.

savgol_filter

Alias of savgol

whittaker

Whittaker-Eilers filter.

snip(dataset, snip_width=50)[source]

Simple Non-Iterative Peak (SNIP) detection algorithm

See Ryan et al. [1988] .

Parameters
  • dataset (NDDataset) – The input data.

  • snip_width (int, optional, default:50) – The width of the window used to determine the baseline using the SNIP algorithm.

Returns

NDDataset – The baseline corrected dataset.

See also

Baseline

Manual baseline correction processor.

get_baseline

Compuute a baseline using the Baseline class.

basc

Make a baseline correction using the Baseline class.

asls

Perform an Asymmetric Least Squares Smoothing baseline correction.

rubberband

Perform a Rubberband baseline correction.

autosub

Perform an automatic subtraction of reference.

detrend

Remove polynomial trend along a dimension from dataset.

sort(**kwargs)[source]

Return the dataset sorted along a given dimension.

By default, it is the last dimension [axis=-1]) using the numeric or label values.

Parameters
  • dim (str or int, optional, default=-1) – Dimension index or name along which to sort.

  • pos (int , optional) – If labels are multidimensional - allow to sort on a define row of labels : labels[pos]. Experimental : Not yet checked.

  • by (str among [‘value’, ‘label’], optional, default=`value`) – Indicate if the sorting is following the order of labels or numeric coord values.

  • descend (bool , optional, default=`False`) – If true the dataset is sorted in a descending direction. Default is False except if coordinates are reversed.

  • inplace (bool, optional, default=`False`) – Flag to say that the method return a new object (default) or not (inplace=True).

Returns

NDDataset – Sorted dataset.

sp(ssb=None, pow=None)def sp(dataset, ssb=1, pow=1, **kwargs)[source]

Calculate apodization with a Sine window multiplication.

For multidimensional NDDataset, the apodization is by default performed on the last dimension.

Functional form of apodization window (cfBruker TOPSPIN manual):

\[sp(t) = \sin(\frac{(\pi - \phi) t }{\text{aq}} + \phi)^{pow}\]

where \(0 < t < \text{aq}\) and \(\phi = \pi ⁄ \text{sbb}\) when \(\text{ssb} \ge 2\) or \(\phi = 0\) when \(\text{ssb} < 2\)

\(\text{aq}\) is an acquisition status parameter and \(\text{ssb}\) is a processing parameter (see the ssb parameter definition below) and \(\text{pow}\) is an exponent equal to 1 for a sine bell window or 2 for a squared sine bell window.

Parameters
  • dataset (Dataset) – Dataset we want to apodize using Sine Bell or Squared Sine Bell window multiplication.

  • sbb (int or float, optional, default=1) – This processing parameter mimics the behaviour of the SSB parameter on bruker TOPSPIN software: Typical values are 1 for a pure sine function and 2 for a pure cosine function. Values greater than 2 give a mixed sine/cosine function. Note that all values smaller than 2, for example 0, have the same effect as \(\text{ssb}=1\) , namely a pure sine function.

  • pow (enum [1,2], optional, default=1) – Exponent value - If pow=2 a Squared Sine Bell window multiplication is performed.

Returns

  • apodized – Dataset.

  • apod_arr – The apodization array only if ‘retapod’ is True.

Other Parameters
  • dim (str or int, keyword parameter, optional, default=’x’) – Specify on which dimension to apply the apodization method. If dim is specified as an integer it is equivalent to the usual axis numpy parameter.

  • inv (bool, keyword parameter, optional, default=False) – True for inverse apodization.

  • rev (bool, keyword parameter, optional, default=False) – True to reverse the apodization before applying it to the data.

  • inplace (bool, keyword parameter, optional, default=False) – True if we make the transform inplace. If False, the function return a new dataset.

  • retapod (bool, keyword parameter, optional, default=False) – True to return the apodization array along with the apodized object.

squeeze(*dims, inplace=False)[source]

Remove single-dimensional entries from the shape of a NDDataset.

Parameters
  • *dims (None or int or tuple of ints, optional) – Selects a subset of the single-dimensional entries in the shape. If a dimension (dim) is selected with shape entry greater than one, an error is raised.

  • inplace (bool, optional, default=`False`) – Flag to say that the method return a new object (default) or not (inplace=True).

Returns

NDDataset – The input array, but with all or a subset of the dimensions of length 1 removed.

Raises

ValueError – If dim is not None , and the dimension being squeezed is not of length 1.

stack(*datasets)[source]

Stack of NDDataset objects along a new dimension.

Any number of NDDataset objects can be stacked. For this operation to be defined the following must be true :

  1. all inputs must be valid dataset objects,

  2. units of data and axis must be compatible (rescaling is applied automatically if necessary).

Parameters

*datasets (a series of NDDataset) – The dataset to be stacked to the current dataset.

Returns

out – A NDDataset created from the stack of the datasets datasets.

See also

concatenate

Concatenate NDDataset objects along a given dimension.

Examples

>>> A = scp.read('irdata/nh4y-activation.spg', protocol='omnic')
>>> B = scp.read('irdata/nh4y-activation.scp')
>>> C = scp.stack(A, B)
>>> print(C)
NDDataset: [float64] a.u. (shape: (z:2, y:55, x:5549))
std(dataset, dim=None, dtype=None, ddof=0, keepdims=False)[source]

Compute the standard deviation along the specified axis.

Returns the standard deviation, a measure of the spread of a distribution, of the array elements. The standard deviation is computed for the flattened array by default, otherwise over the specified axis.

Parameters
  • dataset (array_like) – Calculate the standard deviation of these values.

  • dim (None or int or dimension name , optional) – Dimension or dimensions along which to operate. By default, flattened input is used.

  • dtype (dtype, optional) – Type to use in computing the standard deviation. For arrays of integer type the default is float64, for arrays of float types it is the same as the array type.

  • ddof (int, optional) – Means Delta Degrees of Freedom. The divisor used in calculations is N - ddof , where N represents the number of elements. By default ddof is zero.

  • keepdims (bool, optional) – If this is set to True, the dimensions which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.

Returns

std – A new array containing the standard deviation.

See also

var

Variance values along axis.

mean

Compute the arithmetic mean along the specified axis.

Notes

The standard deviation is the square root of the average of the squared deviations from the mean, i.e., std = sqrt(mean(abs(x - x.mean())**2)) .

The average squared deviation is normally calculated as x.sum() / N , where N = len(x) . If, however, ddof is specified, the divisor N - ddof is used instead. In standard statistical practice, ddof=1 provides an unbiased estimator of the variance of the infinite population. ddof=0 provides a maximum likelihood estimate of the variance for normally distributed variables. The standard deviation computed in this function is the square root of the estimated variance, so even with ddof=1 , it will not be an unbiased estimate of the standard deviation per se.

Note that, for complex numbers, std takes the absolute value before squaring, so that the result is always real and nonnegative. For floating-point input, the std is computed using the same precision the input has. Depending on the input data, this can cause the results to be inaccurate, especially for float32 (see example below). Specifying a higher-accuracy accumulator using the dtype keyword can alleviate this issue.

Examples

>>> nd = scp.read('irdata/nh4y-activation.spg')
>>> nd
NDDataset: [float64] a.u. (shape: (y:55, x:5549))
>>> scp.std(nd)
<Quantity(0.807972021, 'absorbance')>
>>> scp.std(nd, keepdims=True)
NDDataset: [float64] a.u. (shape: (y:1, x:1))
>>> m = scp.std(nd, dim='y')
>>> m
NDDataset: [float64] a.u. (size: 5549)
>>> m.data
array([ 0.08521,  0.08543, ...,    0.251,   0.2537])
sum(dataset, dim=None, dtype=None, keepdims=False)[source]

Sum of array elements over a given axis.

Parameters
  • dataset (array_like) – Calculate the sum of these values.

  • dim (None or int or dimension name , optional) –

    Dimension or dimensions along which to operate. By default, flattened input

    is used.

  • dtype (dtype, optional) – Type to use in computing the standard deviation. For arrays of integer type the default is float64, for arrays of float types it is the same as the array type.

  • keepdims (bool, optional) – If this is set to True, the dimensions which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.

Returns

sum – A new array containing the sum.

See also

mean

Compute the arithmetic mean along the specified axis.

trapz

Integration of array values using the composite trapezoidal rule.

Examples

>>> nd = scp.read('irdata/nh4y-activation.spg')
>>> nd
NDDataset: [float64] a.u. (shape: (y:55, x:5549))
>>> scp.sum(nd)
<Quantity(381755.783, 'absorbance')>
>>> scp.sum(nd, keepdims=True)
NDDataset: [float64] a.u. (shape: (y:1, x:1))
>>> m = scp.sum(nd, dim='y')
>>> m
NDDataset: [float64] a.u. (size: 5549)
>>> m.data
array([   100.7,    100.7, ...,       74,    73.98])
swapaxes(dim1, dim2, inplace=False)[source]

Alias of swapdims .

swapdims(dim1, dim2, inplace=False)[source]

Interchange two dimensions of a NDDataset.

Parameters
  • dim1 (int) – First axis.

  • dim2 (int) – Second axis.

  • inplace (bool, optional, default=`False`) – Flag to say that the method return a new object (default) or not (inplace=True).

Returns

NDDataset – Swaped dataset.

See also

transpose

Transpose a dataset.

take(indices, **kwargs)[source]

Take elements from an array.

Returns

NDDataset – A sub dataset defined by the input indices.

to(other, inplace=False, force=False)[source]

Return the object with data rescaled to different units.

Parameters
  • other (Quantity or str) – Destination units.

  • inplace (bool, optional, default=`False`) – Flag to say that the method return a new object (default) or not (inplace=True).

  • force (bool, optional, default=False) – If True the change of units is forced, even for incompatible units.

Returns

rescaled

See also

ito

Inplace rescaling of the current object data to different units.

to_base_units

Rescaling of the current object data to different units.

ito_base_units

Inplace rescaling of the current object data to different units.

to_reduced_units

Rescaling to reduced_units.

ito_reduced_units

Inplace rescaling to reduced units.

Examples

>>> np.random.seed(12345)
>>> ndd = scp.NDArray(data=np.random.random((3, 3)),
...                   mask=[[True, False, False],
...                         [False, True, False],
...                         [False, False, True]],
...                   units='meters')
>>> print(ndd)
NDArray: [float64] m (shape: (y:3, x:3))

We want to change the units to seconds for instance but there is no relation with meters, so an error is generated during the change

>>> ndd.to('second')
Traceback (most recent call last):
...
pint.errors.DimensionalityError: Cannot convert from 'meter' ([length]) to
'second' ([time])

However, we can force the change

>>> ndd.to('second', force=True)
NDArray: [float64] s (shape: (y:3, x:3))

By default the conversion is not done inplace, so the original is not modified :

>>> print(ndd)
NDArray: [float64] m (shape: (y:3, x:3))
to_array()[source]

Return a numpy masked array.

Other NDDataset attributes are lost.

Returns

ndarray – The numpy masked array from the NDDataset data.

Examples

>>> dataset = scp.read('wodger.spg')
>>> a = scp.to_array(dataset)

equivalent to:

>>> a = np.ma.array(dataset)

or

>>> a = dataset.masked_data
to_base_units(inplace=False)[source]

Return an array rescaled to base units.

Parameters

inplace (bool) – If True the rescaling is done in place.

Returns

rescaled – A rescaled array.

to_reduced_units(inplace=False)[source]

Return an array scaled in place to reduced units.

Reduced units means one unit per dimension. This will not reduce compound units (e.g., ‘J/kg’ will not be reduced to m**2/s**2).

Parameters

inplace (bool) – If True the rescaling is done in place.

Returns

rescaled – A rescaled array.

to_xarray()[source]

Convert a NDDataset instance to an DataArray object.

Warning: the xarray library must be available.

Returns

object – A axrray.DataArray object.

transpose(*dims, inplace=False)[source]

Permute the dimensions of a NDDataset.

Parameters
  • *dims (sequence of dimension indexes or names, optional) – By default, reverse the dimensions, otherwise permute the dimensions according to the values given.

  • inplace (bool, optional, default=`False`) – Flag to say that the method return a new object (default) or not (inplace=True).

Returns

NDDataset – Transposed NDDataset.

See also

swapdims

Interchange two dimensions of a NDDataset.

trapezoid(dataset, **kwargs)[source]

Integrate using the composite trapezoidal rule.

Wrapper of scpy.integrate.trapezoid.

Performs the integration along the last or given dimension.

Parameters
  • dataset (NDDataset) – Dataset to be integrated.

  • **kwargs – Additional keywords parameters. See Other Parameters.

Returns

NDDataset – Definite integral as approximated by trapezoidal rule.

Other Parameters

dim (int or str, optional, default: "x") – Dimension along which to integrate. If an integer is provided, it is equivalent to the numpy axis parameter for ndarrays.

See also

trapz

An alias of trapezoid.

simpson

Integrate using the composite simpson rule.

Example

>>> dataset = scp.read('irdata/nh4y-activation.spg')
>>> dataset[:,1250.:1800.].trapz()
NDDataset: [float64] a.u..cm^-1 (size: 55)
trapz(replace="Trapezoid")def trapz(dataset, **kwargs)[source]

An alias of trapezoid kept for backwards compatibility.

Integrate using the composite trapezoidal rule.

Wrapper of scpy.integrate.trapezoid.

Performs the integration along the last or given dimension.

Parameters
  • dataset (NDDataset) – Dataset to be integrated.

  • **kwargs – Additional keywords parameters. See Other Parameters.

Returns

NDDataset – Definite integral as approximated by trapezoidal rule.

Other Parameters

dim (int or str, optional, default: "x") – Dimension along which to integrate. If an integer is provided, it is equivalent to the numpy axis parameter for ndarrays.

See also

trapz

An alias of trapezoid.

simpson

Integrate using the composite simpson rule.

Example

>>> dataset = scp.read('irdata/nh4y-activation.spg')
>>> dataset[:,1250.:1800.].trapz()
NDDataset: [float64] a.u..cm^-1 (size: 55)
triang()def triang(dataset, **kwargs)[source]

Calculate triangular apodization with non-null extremities and maximum value normalized to 1.

For multidimensional NDDataset, the apodization is by default performed on the last dimension.

The data in the last dimension MUST be time-domain or dimensionless, otherwise an error is raised.

Parameters
  • dataset (array) – Input dataset.

  • **kwargs – Optional keyword parameters (see Other Parameters).

Returns

  • apodized – Dataset.

  • apod_arr – The apodization array only if ‘retapod’ is True.

Other Parameters
  • dim (str or int, keyword parameter, optional, default=’x’.) – Specify on which dimension to apply the apodization method. If dim is specified as an integer it is equivalent to the usual axis numpy parameter.

  • inv (bool, keyword parameter, optional, default=False.) – True for inverse apodization.

  • rev (bool, keyword parameter, optional, default=False.) – True to reverse the apodization before applying it to the data.

  • inplace (bool, keyword parameter, optional, default=False.) – True if we make the transform inplace. If False, the function return a new dataset

  • retapod (bool, keyword parameter, optional, default=False) – True to return the apodization array along with the apodized object

var(dataset, dim=None, dtype=None, ddof=0, keepdims=False)[source]

Compute the variance along the specified axis.

Returns the variance of the array elements, a measure of the spread of a distribution. The variance is computed for the flattened array by default, otherwise over the specified axis.

Parameters
  • dataset (array_like) – Array containing numbers whose variance is desired.

  • dim (None or int or dimension name , optional) – Dimension or dimensions along which to operate. By default, flattened input is used.

  • dtype (dtype, optional) – Type to use in computing the standard deviation. For arrays of integer type the default is float64, for arrays of float types it is the same as the array type.

  • ddof (int, optional) – Means Delta Degrees of Freedom. The divisor used in calculations is N - ddof , where N represents the number of elements. By default ddof is zero.

  • keepdims (bool, optional) – If this is set to True, the dimensions which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.

Returns

var – A new array containing the standard deviation.

See also

std

Standard deviation values along axis.

mean

Compute the arithmetic mean along the specified axis.

Notes

The variance is the average of the squared deviations from the mean, i.e., var = mean(abs(x - x.mean())**2) .

The mean is normally calculated as x.sum() / N , where N = len(x) . If, however, ddof is specified, the divisor N - ddof is used instead. In standard statistical practice, ddof=1 provides an unbiased estimator of the variance of a hypothetical infinite population. ddof=0 provides a maximum likelihood estimate of the variance for normally distributed variables.

Note that for complex numbers, the absolute value is taken before squaring, so that the result is always real and nonnegative.

For floating-point input, the variance is computed using the same precision the input has. Depending on the input data, this can cause the results to be inaccurate, especially for float32 (see example below). Specifying a higher-accuracy accumulator using the dtype keyword can alleviate this issue.

Examples

>>> nd = scp.read('irdata/nh4y-activation.spg')
>>> nd
NDDataset: [float64] a.u. (shape: (y:55, x:5549))
>>> scp.var(nd)
<Quantity(0.652818786, 'absorbance')>
>>> scp.var(nd, keepdims=True)
NDDataset: [float64] a.u. (shape: (y:1, x:1))
>>> m = scp.var(nd, dim='y')
>>> m
NDDataset: [float64] a.u. (size: 5549)
>>> m.data
array([0.007262, 0.007299, ...,  0.06298,  0.06438])
whittaker(dataset, lamb=1.0, order=2, **kwargs)[source]

Smooth the data using the Whittaker smoothing algorithm.

This implementation based on the work by Eilers [2003] uses sparse matrices enabling high-speed processing of large input vectors.

Copyright M. H. V. Werts, 2017 (see LICENSES/WITTAKER_SMOOTH_LICENSE.rst)

Parameters
  • dataset (NDDataset or array-like of shape (n_observations , n_features)) – Input data, where n_observations is the number of observations and n_features is the number of features.

  • lamb (float, optional, default: 1.0) – Smoothing/Regularization parameter. The larger lamb, the smoother the data.

  • order (int, optional, default=2) – The difference order of the penalized least-squares.

  • **kwargs (keyword parameters, optional) – See Other Parameters.

Returns

NDdataset – Smoothed data.

Other Parameters
  • dim (int or str, optional, default: -1,) – Dimension along which the method is applied. By default, the method is applied to the last dimension. If dim is specified as an integer it is equivalent to the usual axis numpy parameter.

  • log_level (any of ["INFO", "DEBUG", "WARNING", "ERROR"], optional, default: "WARNING") – The log level at startup. It can be changed later on using the set_log_level method or by changing the log_level attribute.

See also

Filter

Define and apply filters/smoothers using various algorithms.

smooth

Function to smooth data using various window filters.

savgol

Savitzky-Golay filter.

savgol_filter

Alias of savgol

write(dataset, filename=None, **kwargs)[source]

Write the current dataset.

Parameters
  • dataset (NDDataset) – Dataset to write.

  • filename (str or pathlib object, optional) – If not provided, a dialog is opened to select a file for writing.

  • **kwargs – Optional keyword parameters (see Other Parameters).

Returns

output_path – Path of the output file.

Other Parameters
  • protocol ({‘scp’, ‘matlab’, ‘jcamp’, ‘csv’, ‘excel’}, optional) – Protocol used for writing. If not provided, the correct protocol is inferred (whnever it is possible) from the file name extension.

  • directory (str, optional) – Where to write the specified filename . If not specified, write in the current directory.

  • description (str, optional) – A Custom description.

  • csv_delimiter (str, optional) – Set the column delimiter in CSV file. By default it is the one set in SpectroChemPy Preferences .

See also

save

Generic function for saving a NDDataset in SpectroChemPy format.

Examples

write a dataset (providing a windows type filename relative to the default Datadir )

>>> nd = scp.read_opus('irdata/OPUS')
>>> f = nd.write('opus.scp') 
>>> f.name                   
'opus.scp'                   
write_csv(*args, **kwargs)[source]

Write a dataset in CSV format.

Currently only implemented for 1D datasets or ND datasets with only one dimension of length larger than one.

Parameters
  • filename (str or pathlib object, optional) – If not provided, a dialog is opened to select a file for writing.

  • protocol ({‘scp’, ‘matlab’, ‘jcamp’, ‘csv’, ‘excel’}, optional) – Protocol used for writing. If not provided, the correct protocol is inferred (whnever it is possible) from the file name extension.

  • directory (str, optional) – Where to write the specified filename . If not specified, write in the current directory.

  • description (str, optional) – A Custom description.

  • delimiter (str, optional) – Set the column delimiter in CSV file. By default it is ‘,’ or the one set in SpectroChemPy Preferences .

Returns

out (pathlib object) – Path of the saved file.

Examples

>>> ds = scp.NDDataset([1, 2, 3])
>>> f1 = ds.write_csv('myfile')
>>> ds = scp.read('irdata/nh4y-activation.spg')
>>> f2 = ds[0].write_csv('single_spectrum.csv')
write_excel(*args, **kwargs)[source]

This method is an alias of write_excel .

write_jcamp(*args, **kwargs)[source]

Write a dataset in JCAMP-DX format.

(see Published JCAMP-DX Protocols http://www.jcamp-dx.org/protocols.html#ir4.24) Up to now, only IR output is available.

Parameters
  • filename (str or pathlib object, optional) – If not provided, a dialog is opened to select a file for writing.

  • protocol ({‘scp’, ‘matlab’, ‘jcamp’, ‘csv’, ‘excel’}, optional) – Protocol used for writing. If not provided, the correct protocol is inferred (whnever it is possible) from the file name extension.

  • directory (str, optional) – Where to write the specified filename . If not specified, write in the current directory.

  • description (str, optional) – A Custom description.

Returns

out (pathlib object) – path of the saved file.

Examples

The extension will be added automatically >>> X.write_jcamp(‘myfile’)

write_mat(*args, **kwargs)[source]

This method is an alias of write_matlab .

write_matlab(*args, **kwargs)[source]

This method is an alias of write_matlab .

write_xls(*args, **kwargs)[source]

This method is an alias of write_excel .

zeros(shape, dtype=None, **kwargs)[source]

Return a new NDDataset of given shape and type, filled with zeros.

Parameters
  • shape (int or sequence of ints) – Shape of the new array, e.g., (2, 3) or 2 .

  • dtype (data-type, optional) – The desired data-type for the array, e.g., numpy.int8 . Default is numpy.float64 .

  • **kwargs – Optional keyword parameters (see Other Parameters).

Returns

zeros – Array of zeros.

Other Parameters
  • units (str or ur instance) – Units of the returned object. If not provided, try to copy from the input object.

  • coordset (list or Coordset object) – Coordinates for the returned object. If not provided, try to copy from the input object.

See also

zeros_like

Return an array of zeros with shape and type of input.

ones_like

Return an array of ones with shape and type of input.

empty_like

Return an empty array with shape and type of input.

full_like

Fill an array with shape and type of input.

ones

Return a new array setting values to 1.

empty

Return a new uninitialized array.

full

Fill a new array.

Examples

>>> nd = scp.NDDataset.zeros(6)
>>> nd
NDDataset: [float64] unitless (size: 6)
>>> nd = scp.zeros((5, ))
>>> nd
NDDataset: [float64] unitless (size: 5)
>>> nd.values
array([       0,        0,        0,        0,        0])
>>> nd = scp.zeros((5, 10), dtype=np.int, units='absorbance')
>>> nd
NDDataset: [int64] a.u. (shape: (y:5, x:10))
zeros_like(dataset, dtype=None, **kwargs)[source]

Return a NDDataset of zeros.

The returned NDDataset have the same shape and type as a given array. Units, coordset, … can be added in kwargs.

Parameters
  • dataset (NDDataset or array-like) – Object from which to copy the array structure.

  • dtype (data-type, optional) – Overrides the data type of the result.

  • **kwargs – Optional keyword parameters (see Other Parameters).

Returns

zeorslike – Array of fill_value with the same shape and type as dataset .

Other Parameters
  • units (str or ur instance) – Units of the returned object. If not provided, try to copy from the input object.

  • coordset (list or Coordset object) – Coordinates for the returned object. If not provided, try to copy from the input object.

See also

full_like

Return an array with a fill value with shape and type of the input.

ones_like

Return an array of ones with shape and type of input.

empty_like

Return an empty array with shape and type of input.

zeros

Return a new array setting values to zero.

ones

Return a new array setting values to one.

empty

Return a new uninitialized array.

full

Fill a new array.

Examples

>>> x = np.arange(6)
>>> x = x.reshape((2, 3))
>>> nd = scp.NDDataset(x, units='s')
>>> nd
NDDataset: [float64] s (shape: (y:2, x:3))
>>> nd.values
 <Quantity([[       0        1        2]
 [       3        4        5]], 'second')>
>>> nd = scp.zeros_like(nd)
>>> nd
NDDataset: [float64] s (shape: (y:2, x:3))
>>> nd.values
    <Quantity([[       0        0        0]
 [       0        0        0]], 'second')>
zf(dataset, size=None, mid=False, **kwargs)[source]

Zero fill to given size.

Parameters
  • dataset (NDDataset) – Input dataset.

  • size (int) – Size of data after zero filling.

  • mid (bool) – True to zero fill in the middle of data.

Returns

NDDataset – Modified dataset.

zf_auto(dataset, mid=False)[source]

Zero fill to next largest power of two.

Parameters
  • dataset (ndarray) – Array of NMR data.

  • mid (bool) – True to zero fill in the middle of data.

Returns

ndata (ndarray) – Zero filled array of NMR data.

zf_double(dataset, n, mid=False, **kwargs)[source]

Zero fill by doubling original data size once or multiple times.

Parameters
  • dataset (ndataset) – Array of NMR data.

  • n (int) – Number of times to double the size of the data.

  • mid (bool) – True to zero fill in the middle of data.

Returns

ndata (ndarray) – Zero filled array of NMR data.

zf_size(dataset, size=None, mid=False, **kwargs)[source]

Zero fill to given size.

Parameters
  • dataset (NDDataset) – Input dataset.

  • size (int) – Size of data after zero filling.

  • mid (bool) – True to zero fill in the middle of data.

Returns

NDDataset – Modified dataset.

Examples using spectrochempy.NDDataset

NDDataset creation and plotting example

NDDataset creation and plotting example

NDDataset coordinates example

NDDataset coordinates example

Units manipulation examples

Units manipulation examples

Reading datasets

Reading datasets

Loading an IR (omnic SPG) experimental file

Loading an IR (omnic SPG) experimental file

Loading Bruker OPUS files

Loading Bruker OPUS files

Loading of experimental 1D NMR data

Loading of experimental 1D NMR data

Loading RAMAN experimental file

Loading RAMAN experimental file

Reading Renishaw WiRE files

Reading Renishaw WiRE files

Using plot_multiple to plot several datasets on the same figure

Using plot_multiple to plot several datasets on the same figure

Introduction to the plotting librairie

Introduction to the plotting librairie

Project creation

Project creation

Exponential window multiplication

Exponential window multiplication

Sine bell and squared Sine bell window multiplication

Sine bell and squared Sine bell window multiplication

Denoising a 2D Raman spectrum

Denoising a 2D Raman spectrum

Removing cosmic ray spikes from a Raman spectrum

Removing cosmic ray spikes from a Raman spectrum

Savitky-Golay and Whittaker-Eilers smoothing of a Raman spectrum

Savitky-Golay and Whittaker-Eilers smoothing of a Raman spectrum

Analysis CP NMR spectra

Analysis CP NMR spectra

Processing NMR spectra (slicing, baseline correction, peak picking, peak fitting)

Processing NMR spectra (slicing, baseline correction, peak picking, peak fitting)

Processing Relaxation measurement

Processing Relaxation measurement

Processing RAMAN spectra

Processing RAMAN spectra

EFA example

EFA example

EFA (Keller and Massart original example)

EFA (Keller and Massart original example)

FastICA example

FastICA example

2D-IRIS analysis example

2D-IRIS analysis example

MCR-ALS example (adapted from Jaumot et al. 2005)

MCR-ALS example (adapted from Jaumot et al. 2005)

MCR-ALS with kinetic constraints

MCR-ALS with kinetic constraints

NMF analysis example

NMF analysis example

PCA example (iris dataset)

PCA example (iris dataset)

PCA analysis example

PCA analysis example

SIMPLISMA example

SIMPLISMA example

PLS regression example

PLS regression example

Fitting 1D dataset

Fitting 1D dataset

Solve a linear equation using LSTSQ

Solve a linear equation using LSTSQ

NDDataset baseline correction

NDDataset baseline correction