NIPY logo

Site Navigation

NIPY Community

Table Of Contents

Previous topic

core.reference.slices

Next topic

core.transforms.affines

This Page

core.reference.spaces

Module: core.reference.spaces

Inheritance diagram for nipy.core.reference.spaces:

Useful neuroimaging coordinate map makers and utilities

Classes

AffineError

class nipy.core.reference.spaces.AffineError

Bases: nipy.core.reference.spaces.SpaceError

__init__()

x.__init__(...) initializes x; see help(type(x)) for signature

args
message

AxesError

class nipy.core.reference.spaces.AxesError

Bases: nipy.core.reference.spaces.SpaceError

__init__()

x.__init__(...) initializes x; see help(type(x)) for signature

args
message

SpaceError

class nipy.core.reference.spaces.SpaceError

Bases: exceptions.Exception

__init__()

x.__init__(...) initializes x; see help(type(x)) for signature

args
message

SpaceTypeError

class nipy.core.reference.spaces.SpaceTypeError

Bases: nipy.core.reference.spaces.SpaceError

__init__()

x.__init__(...) initializes x; see help(type(x)) for signature

args
message

Functions

nipy.core.reference.spaces.is_xyz_affable(coordmap, name2xyz=None)

Return True if the coordap has an xyz affine

Parameters :

coordmap : CoordinateMap instance

Coordinate map to test

name2xyz : None or mapping

Object such that name2xyz[ax_name] returns ‘x’, or ‘y’ or ‘z’ or raises a KeyError for a str ax_name. None means use module default.

Returns :

tf : bool

True if coordmap has an xyz affine, False otherwise

Examples

>>> cmap = vox2mni(np.diag([2,3,4,5,1]))
>>> cmap
AffineTransform(
   function_domain=CoordinateSystem(coord_names=('i', 'j', 'k', 'l'), name='array', coord_dtype=float64),
   function_range=CoordinateSystem(coord_names=('mni-x', 'mni-y', 'mni-z', 't'), name='mni', coord_dtype=float64),
   affine=array([[ 2.,  0.,  0.,  0.,  0.],
                 [ 0.,  3.,  0.,  0.,  0.],
                 [ 0.,  0.,  4.,  0.,  0.],
                 [ 0.,  0.,  0.,  5.,  0.],
                 [ 0.,  0.,  0.,  0.,  1.]])
)
>>> is_xyz_affable(cmap)
True
>>> time0_cmap = cmap.reordered_domain([3,0,1,2])
>>> time0_cmap
AffineTransform(
   function_domain=CoordinateSystem(coord_names=('l', 'i', 'j', 'k'), name='array', coord_dtype=float64),
   function_range=CoordinateSystem(coord_names=('mni-x', 'mni-y', 'mni-z', 't'), name='mni', coord_dtype=float64),
   affine=array([[ 0.,  2.,  0.,  0.,  0.],
                 [ 0.,  0.,  3.,  0.,  0.],
                 [ 0.,  0.,  0.,  4.,  0.],
                 [ 5.,  0.,  0.,  0.,  0.],
                 [ 0.,  0.,  0.,  0.,  1.]])
)
>>> is_xyz_affable(time0_cmap)
False
nipy.core.reference.spaces.xyz_affine(coordmap, name2xyz=None)

Return voxel to XYZ affine for coordmap

Parameters :

coordmap : CoordinateMap instance

name2xyz : None or mapping

Object such that name2xyz[ax_name] returns ‘x’, or ‘y’ or ‘z’ or raises a KeyError for a str ax_name. None means use module default.

Returns :

xyz_aff : (4,4) array

voxel to X, Y, Z affine mapping

Raises :

SpaceTypeError : if this is not an affine coordinate map

AxesError : if not all of x, y, z recognized in coordmap range

AffineError : if axes dropped from the affine contribute to x, y, z

coordinates :

Examples

>>> cmap = vox2mni(np.diag([2,3,4,5,1]))
>>> cmap
AffineTransform(
   function_domain=CoordinateSystem(coord_names=('i', 'j', 'k', 'l'), name='array', coord_dtype=float64),
   function_range=CoordinateSystem(coord_names=('mni-x', 'mni-y', 'mni-z', 't'), name='mni', coord_dtype=float64),
   affine=array([[ 2.,  0.,  0.,  0.,  0.],
                 [ 0.,  3.,  0.,  0.,  0.],
                 [ 0.,  0.,  4.,  0.,  0.],
                 [ 0.,  0.,  0.,  5.,  0.],
                 [ 0.,  0.,  0.,  0.,  1.]])
)
>>> xyz_affine(cmap)
array([[ 2.,  0.,  0.,  0.],
       [ 0.,  3.,  0.,  0.],
       [ 0.,  0.,  4.,  0.],
       [ 0.,  0.,  0.,  1.]])
nipy.core.reference.spaces.xyz_order(coordsys, name2xyz=None)

Vector of orders for sorting coordsys axes in xyz first order

Parameters :

coordsys : CoordinateSystem instance

name2xyz : None or mapping

Object such that name2xyz[ax_name] returns ‘x’, or ‘y’ or ‘z’ or raises a KeyError for a str ax_name. None means use module default.

Returns :

xyz_order : list

Ordering of axes to get xyz first ordering. See the examples.

Raises :

AxesError : if there are not all of x, y and z axes

Examples

>>> from nipy.core.api import CoordinateSystem
>>> xyzt_cs = mni_cs(4) # coordsys with t (time) last
>>> xyzt_cs
CoordinateSystem(coord_names=('mni-x', 'mni-y', 'mni-z', 't'), name='mni', coord_dtype=float64)
>>> xyz_order(xyzt_cs)
[0, 1, 2, 3]
>>> tzyx_cs = CoordinateSystem(xyzt_cs.coord_names[::-1], 'reversed')
>>> tzyx_cs
CoordinateSystem(coord_names=('t', 'mni-z', 'mni-y', 'mni-x'), name='reversed', coord_dtype=float64)
>>> xyz_order(tzyx_cs)
[3, 2, 1, 0]