spectrochempy.Coord¶
- class Coord(**kwargs)[source]¶
Explicit coordinates for a dataset along a given axis.
The coordinates of a
NDDataset
can be created using theCoord
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, andarray
, or andarray
-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 fordata
input, but will be passed by reference, so you should make a copy thedata
before passing it in the object constructor if that’s the desired behavior or set thecopy
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, andarray
, a ndarray-like, aNDArray
or any subclass ofNDArray
.units (|Unit| instance or str, optional) – Units of the data. If data is a
Quantity
thenunits
is set to the unit of thedata
; 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 numericaldata
axis of our newCoord
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.
Inplace rescaling to base 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
True if the
data
array is dimensionless - Readonly property (bool).Data type (np.dtype).
Current filename for this dataset (
Pathlib
object).True if the
data
array is not empty and size > 0.True is the name has been defined (bool).
True if the
data
array have units - Readonly property (bool).Object identifier - Readonly property (str).
True if the
data
array is empty or size=0, and if no label are present - Readonly property (bool).True if the
data
are real values - Readonly property (bool).True if the
data
are integer values - Readonly property (bool).True if the
data
array have labels - Readonly property (bool).Range of the data (list).
Flag to specify if the data can be constructed using a linear variation (bool).
Additional metadata (
Meta
).A user-friendly name (str).
Starting value for linear array
bool - Whether the axis is reversed (readonly property).
Region of interest (ROI) limits (list).
Size of the underlying
data
array - Readonly property (int).Return coordinates spacing.
An user friendly title (str).
The actual array with mask and unit (
Quantity
).bool
- True if thedata
does not haveunits
(Readonly property).Unit
- The units of the data.Alias of
values
.Quantity
- The actual values (data, units) contained in this object (Readonly property).- data¶
-
If there is no data but labels, then the labels are returned instead of data.
- dtype¶
Data type (np.dtype).
- filename¶
Current filename for this dataset (
Pathlib
object).
- 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).
- 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¶
-
If there is no data but labels, then the labels are returned instead of data.
- magnitude¶
-
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).
- 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).
- units¶
Unit
- The units of the data.
- values¶
Quantity
- The actual values (data, units) contained in this object (Readonly property).
Examples using spectrochempy.Coord
¶
EFA analysis (Keller and Massart original example)
NDDataset creation and plotting example
Loading an IR (omnic SPG) experimental file