Inheritance diagram for nipy.core.reference.coordinate_system:
CoordinateSystems are used to represent the space in which the image resides.
A CoordinateSystem contains named coordinates, one for each dimension and a coordinate dtype. The purpose of the CoordinateSystem is to specify the name and order of the coordinate axes for a particular space. This allows one to compare two CoordinateSystems to determine if they are equal.
Bases: object
Class to create similar coordinate maps of different dimensions
Methods
__call__(N[, name, coord_dtype]) | Create coordinate system of length N |
coord_sys_klass |
Create a coordsys maker with given axis coord_names
Parameters: | coord_names : iterable
name : string, optional
coord_dtype : np.dtype, optional
|
---|
Examples
>>> cmkr = CoordSysMaker('ijk', 'a name')
>>> print(cmkr(2))
CoordinateSystem(coord_names=('i', 'j'), name='a name', coord_dtype=float64)
>>> print(cmkr(3))
CoordinateSystem(coord_names=('i', 'j', 'k'), name='a name', coord_dtype=float64)
alias of CoordinateSystem
Bases: object
An ordered sequence of named coordinates of a specified dtype.
A coordinate system is defined by the names of the coordinates, (attribute coord_names) and the numpy dtype of each coordinate value (attribute coord_dtype). The coordinate system can also have a name.
>>> names = ['first', 'second', 'third']
>>> cs = CoordinateSystem(names, 'a coordinate system', np.float)
>>> cs.coord_names
('first', 'second', 'third')
>>> cs.name
'a coordinate system'
>>> cs.coord_dtype
dtype('float64')
The coordinate system also has a dtype which is the composite numpy dtype, made from the (names, coord_dtype).
>>> dtype_template = [(name, np.float) for name in cs.coord_names]
>>> dtype_should_be = np.dtype(dtype_template)
>>> cs.dtype == dtype_should_be
True
Two CoordinateSystems are equal if they have the same dtype and the same names and the same name.
>>> another_cs = CoordinateSystem(names, 'not irrelevant', np.float)
>>> cs == another_cs
False
>>> cs.dtype == another_cs.dtype
True
>>> cs.name == another_cs.name
False
Methods
coord_dtype | |
index(coord_name) | Return the index of a given named coordinate. |
similar_to(other) | Similarity is defined by self.dtype, ignoring name |
Create a coordinate system with a given name and coordinate names.
The CoordinateSystem has two dtype attributes:
Parameters: | coord_names : iterable
name : string, optional
coord_dtype : np.dtype, optional
|
---|
Examples
>>> c = CoordinateSystem('ij', name='input')
>>> print(c)
CoordinateSystem(coord_names=('i', 'j'), name='input', coord_dtype=float64)
>>> c.coord_dtype
dtype('float64')
alias of float64
Return the index of a given named coordinate.
>>> c = CoordinateSystem('ij', name='input')
>>> c.index('i')
0
>>> c.index('j')
1
Similarity is defined by self.dtype, ignoring name
Parameters: | other : CoordinateSystem
|
---|---|
Returns: | tf: bool : |
Test if obj has the CoordinateSystem API
Parameters: | obj : object
|
---|---|
Returns: | tf : bool
|
Examples
>>> is_coordsys(CoordinateSystem('xyz'))
True
>>> is_coordsys(CoordSysMaker('ikj'))
False
Test if obj has the CoordSysMaker API
Parameters: | obj : object
|
---|---|
Returns: | tf : bool
|
Examples
>>> is_coordsys_maker(CoordSysMaker('ikj'))
True
>>> is_coordsys_maker(CoordinateSystem('xyz'))
False
Create the product of a sequence of CoordinateSystems.
The coord_dtype of the result will be determined by safe_dtype.
Parameters: | *coord_systems : sequence of CoordinateSystem name : str
|
---|---|
Returns: | product_coord_system : CoordinateSystem |
Examples
>>> c1 = CoordinateSystem('ij', 'input', coord_dtype=np.float32)
>>> c2 = CoordinateSystem('kl', 'input', coord_dtype=np.complex)
>>> c3 = CoordinateSystem('ik', 'in3')
>>> print(product(c1, c2))
CoordinateSystem(coord_names=('i', 'j', 'k', 'l'), name='product', coord_dtype=complex128)
>>> print(product(c1, c2, name='another name'))
CoordinateSystem(coord_names=('i', 'j', 'k', 'l'), name='another name', coord_dtype=complex128)
>>> product(c2, c3)
Traceback (most recent call last):
...
ValueError: coord_names must have distinct names
Determine a dtype to safely cast all of the given dtypes to.
Safe dtypes are valid numpy dtypes or python types which can be cast to numpy dtypes. See numpy.sctypes for a list of valid dtypes. Composite dtypes and string dtypes are not safe dtypes.
Parameters: | dtypes : sequence of np.dtype |
---|---|
Returns: | dtype : np.dtype |
Examples
>>> c1 = CoordinateSystem('ij', 'input', coord_dtype=np.float32)
>>> c2 = CoordinateSystem('kl', 'input', coord_dtype=np.complex)
>>> safe_dtype(c1.coord_dtype, c2.coord_dtype)
dtype('complex128')
>>> # Strings are invalid dtypes
>>> safe_dtype(type('foo'))
Traceback (most recent call last):
...
TypeError: dtype must be valid numpy dtype int, uint, float, complex or object
>>> # Check for a valid dtype
>>> myarr = np.zeros(2, np.float32)
>>> myarr.dtype.isbuiltin
1
>>> # Composite dtypes are invalid
>>> mydtype = np.dtype([('name', 'S32'), ('age', 'i4')])
>>> myarr = np.zeros(2, mydtype)
>>> myarr.dtype.isbuiltin
0
>>> safe_dtype(mydtype)
Traceback (most recent call last):
...
TypeError: dtype must be valid numpy dtype int, uint, float, complex or object