spectrochempy.CoordSet
- class CoordSet(*coords, **kwargs)[source]
A collection of Coord objects for a NDArray object with validation.
This object is an iterable containing a collection of Coord objects.
- Parameters:
*coords (
NDArray
,NDArray
subclass orCoordSet
sequence of objects.) – If an instance of CoordSet is found, instead of an array, this means that all coordinates in this coords describe the same axis. It is assumed that the coordinates are passed in the order of the dimensions of a nD numpy array ( row-major order), i.e., for a 3d object : ‘z’, ‘y’, ‘x’.**kwargs – Additional keyword parameters (see Other Parameters).
- Other Parameters:
x (
NDArray
,NDArray
subclass orCoordSet
) – A single coordinate associated to the ‘x’-dimension. If a coord was already passed in the argument, this will overwrite the previous. It is thus not recommended to simultaneously use both way to initialize the coordinates to avoid such conflicts.y, z, u, … (
NDArray
,NDArray
subclass orCoordSet
) – Same asx
for the others dimensions.dims (list of string, optional) – Names of the dims to use corresponding to the coordinates. If not given, standard names are used: x, y, …
copy (bool, optional) – Perform a copy of the passed object. Default is True.
See also
Examples
>>> from spectrochempy import Coord, CoordSet
Define 4 coordinates, with two for the same dimension
>>> coord0 = Coord.linspace(10., 100., 5, units='m', title='distance') >>> coord1 = Coord.linspace(20., 25., 4, units='K', title='temperature') >>> coord1b = Coord.linspace(1., 10., 4, units='millitesla', title='magnetic field') >>> coord2 = Coord.linspace(0., 1000., 6, units='hour', title='elapsed time')
Now create a coordset
>>> cs = CoordSet(t=coord0, u=coord2, v=[coord1, coord1b])
Display some coordinates
>>> cs.u Coord: [float64] hr (size: 6)
>>> cs.v CoordSet: [_1:temperature, _2:magnetic field]
>>> cs.v_1 Coord: [float64] K (size: 4)
Attributes Summary
Chars that can be used for dimension name (list).
Coordinates in the coordset (list).
Default coordinates (Coord).
True if the name has been defined (bool).
Object identifier (Readonly property).
True if there is no coords defined (bool).
Returns True if one of the coords is labeled.
True if the coords define a single dimension (bool).
Labels of the coordinates in the current coordset (list).
Names of the coords in the current coords (list - read only property).
Sizes of the coord object for each dimension (int or tuple of int).
Sizes of the coord object for each dimension (int or tuple of int).
Titles of the coords in the current coords (list).
Units of the coords in the current coords (list).
Methods Summary
copy
([keepname])Make a disconnected copy of the current coords.
keys
()Alias for names.
select
(val)Select the default coord index.
set
(*args, **kwargs)Set one or more coordinates in the current CoordSet.
set_titles
(*args, **kwargs)Set one or more coord title at once.
set_units
(*args, **kwargs)Set one or more coord units at once.
to_dict
()Return a dict of the coordinates from the coordset.
update
(**kwargs)Update a specific coordinates in the CoordSet.
Attributes Documentation
- available_names
Chars that can be used for dimension name (list).
It returns DEFAULT_DIM_NAMES less those already in use.
- coords
Coordinates in the coordset (list).
- default
Default coordinates (Coord).
- has_defined_name
True if the name has been defined (bool).
- id
Object identifier (Readonly property).
- is_empty
True if there is no coords defined (bool).
- is_labeled
Returns True if one of the coords is labeled.
- is_same_dim
True if the coords define a single dimension (bool).
- labels
Labels of the coordinates in the current coordset (list).
- names
Names of the coords in the current coords (list - read only property).
- size
Sizes of the coord object for each dimension (int or tuple of int).
(readonly property). If the set is for a single dimension return a single size as all coordinates must have the same.
- sizes
Sizes of the coord object for each dimension (int or tuple of int).
(readonly property). If the set is for a single dimension return a single size as all coordinates must have the same.
- titles
Titles of the coords in the current coords (list).
- units
Units of the coords in the current coords (list).
Methods Documentation
- copy(keepname=False)[source]
Make a disconnected copy of the current coords.
- Returns:
object – an exact copy of the current object
- keys()[source]
Alias for names.
- Returns:
out (list) – list of all coordinates names (including reference to other coordinates).
- set_titles(*args, **kwargs)[source]
Set one or more coord title at once.
- Parameters:
args (str(s)) – The list of titles to apply to the set of coordinates (they must be given according to the coordinate’s name alphabetical order.
**kwargs – Keyword attribution of the titles. The keys must be valid names among the coordinate’s name list. This is the recommended way to set titles as this will be less prone to errors.
Notes
If the args are not named, then the attributions are made in coordinate’s name alphabetical order : e.g, the first title will be for the
x
coordinates, the second for they
, etc.
- set_units(*args, **kwargs)[source]
Set one or more coord units at once.
- Parameters:
*args (str(s)) – The list of units to apply to the set of coordinates (they must be given according to the coordinate’s name alphabetical order.
**kwargs – Keyword attribution of the units. The keys must be valid names among the coordinate’s name list. This is the recommended way to set units as this will be less prone to errors.
force (bool, optional, default=False) – Whether or not the new units must be compatible with the current units. See the
Coord
.`to` method.
Notes
If the args are not named, then the attributions are made in coordinate’s name alphabetical order : e.g, the first units will be for the
x
coordinates, the second for they
, etc.
Examples using spectrochempy.CoordSet