spectrochempy.Coord

class Coord(**kwargs)[source]

Explicit coordinates for a dataset along a given axis.

The coordinates of a NDDataset can be created using the Coord object. This is a single dimension array with either numerical (float) values or labels (str, Datetime objects, or any other kind of objects) to represent the coordinates. Only a one numerical axis can be defined, but labels can be multiple.

Parameters
  • data (ndarray, tuple or list) – The actual data array contained in the Coord object. The given array (with a single dimension) can be a list, a tuple, a ndarray , or a ndarray-like object. If an object is passed that contains labels, or units, these elements will be used 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 the data before passing it in the object constructor if that’s the desired behavior or set the copy argument to True.

  • **kwargs – Optional keywords parameters. See other parameters.

Other Parameters
  • dtype (str or dtype, optional, default=np.float64) – If specified, the data will be casted to this dtype, else the type of the data will be used.

  • dims (list of chars, optional.) – if specified the list must have a length equal to the number od data dimensions (ndim) and the chars must be taken among 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 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 .

  • 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.

  • title (str, optional) – The title of the dimension. It will later be used for instance for labelling plots of the data. It is optional but recommended to give a title to each ndarray.

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

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

  • linear (bool, optional) – If set to True, the coordinate is considered as a LinearCoord object.

  • offset (float, optional) – Only used is linear is True. If omitted a value of 0.0 is taken for the coordinate offset.

  • increment (float, optional) – Only used if linear is true. If omitted a value of 1.0 is taken for the coordinate increment.

See also

NDDataset

Main SpectroChemPy object: an array with masks, units and coordinates.

LinearCoord

linear coordinates.

Examples

We first import the object from the api :

>>> from spectrochempy import Coord

We then create a numpy ndarray and use it as the numerical data axis of our new Coord object :

>>> c0 = Coord.arange(1., 12., 2., title='frequency', units='Hz')
>>> c0
Coord: [float64] Hz (size: 6)

We can take a series of str to create a non numerical but labelled axis :

>>> tarr = list('abcdef')
>>> tarr
['a', 'b', 'c', 'd', 'e', 'f']
>>> c1 = Coord(labels=tarr, title='mylabels')
>>> c1
Coord: [labels] [  a   b   c   d   e   f] (size: 6)

Methods

Coord.amax(dataset[, dim, keepdims])

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

Coord.amin(dataset[, dim, keepdims])

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

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

Return evenly spaced values within a given interval.

Coord.around(dataset[, decimals])

Evenly round to the given number of decimals.

Coord.astype([dtype])

Cast the data to a specified type.

Coord.copy([deep, keepname])

Make a disconnected copy of the current object.

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

Construct a nddataset by executing a function over each coordinate.

Coord.fromiter(iterable[, dtype, count])

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

Coord.geomspace(start, stop[, num, ...])

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

Coord.get_labels([level])

Get the labels at a given level.

Coord.is_units_compatible(other)

Check the compatibility of units with another object.

Coord.ito(other[, force])

Inplace scaling to different units.

Coord.ito_base_units()

Inplace rescaling to base units.

Coord.ito_reduced_units()

Quantity scaled in place to reduced units, inplace.

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

Return evenly spaced numbers over a specified interval.

Coord.loc2index(loc)

Return the index corresponding to a given location.

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

Return numbers spaced evenly on a log scale.

Coord.max(dataset[, dim, keepdims])

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

Coord.min(dataset[, dim, keepdims])

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

Coord.ptp(dataset[, dim, keepdims])

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

Coord.round(dataset[, decimals])

Evenly round to the given number of decimals.

Coord.round_(dataset[, decimals])

Evenly round to the given number of decimals.

Coord.to(other[, inplace, force])

Return the object with data rescaled to different units.

Coord.to_base_units([inplace])

Return an array rescaled to base units.

Coord.to_reduced_units([inplace])

Return an array scaled in place to reduced units.

Attributes

Coord.data

The data array (ndarray).

Coord.dimensionless

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

Coord.dtype

Data type (np.dtype).

Coord.filename

Current filename for this dataset (Pathlib object).

Coord.has_data

True if the data array is not empty and size > 0.

Coord.has_defined_name

True is the name has been defined (bool).

Coord.has_units

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

Coord.id

Object identifier - Readonly property (str).

Coord.is_empty

True if the data array is empty or size=0, and if no label are present - Readonly property (bool).

Coord.is_float

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

Coord.is_integer

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

Coord.is_labeled

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

Coord.labels

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

Coord.limits

Range of the data (list).

Coord.linear

Flag to specify if the data can be constructed using a linear variation (bool).

Coord.m

The data array (ndarray).

Coord.magnitude

The data array (ndarray).

Coord.meta

Additional metadata (Meta).

Coord.name

A user-friendly name (str).

Coord.offset

Starting value for linear array

Coord.reversed

bool - Whether the axis is reversed (readonly property).

Coord.roi

Region of interest (ROI) limits (list).

Coord.size

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

Coord.spacing

Return coordinates spacing.

Coord.title

An user friendly title (str).

Coord.umasked_data

The actual array with mask and unit (Quantity).

Coord.unitless

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

Coord.units

Unit - The units of the data.

Coord.value

Alias of values.

Coord.values

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

data

The data array (ndarray).

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

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

-----, None

dtype

Data type (np.dtype).

filename

Current filename for this dataset (Pathlib object).

has_data

True if the data array is not empty and size > 0.

(Readonly property).

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.

id

Object identifier - Readonly property (str).

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_labeled

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

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 (list).

linear

Flag to specify if the data can be constructed using a linear variation (bool).

m

The data array (ndarray).

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

magnitude

The data array (ndarray).

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

meta

Additional metadata (Meta).

name

A user-friendly name (str).

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

offset

Starting value for linear array

reversed

bool - Whether the axis is reversed (readonly property).

roi

Region of interest (ROI) limits (list).

size

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

spacing

Return coordinates spacing.

It will be a scalar if the coordinates are uniformly spaced, else an array of the different spacings

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).

Examples using spectrochempy.Coord

EFA analysis (Keller and Massart original example)

EFA analysis (Keller and Massart original example)

2D-IRIS analysis example

2D-IRIS analysis example

NDDataset coordinates example

NDDataset coordinates example

NDDataset creation and plotting example

NDDataset creation and plotting example

Loading an IR (omnic SPG) experimental file

Loading an IR (omnic SPG) experimental file