[Nipy-devel] coord system quickie

Matthew Brett matthew.brett@gmail....
Thu Jan 14 06:36:57 CST 2010

Hi Mike,

On Wed, Jan 13, 2010 at 4:44 PM, M Trumpis <mtrumpis@berkeley.edu> wrote:
> Hi all.. I've come across a situation where I've been provided with an
> affine transformation mapping to a rotated coordinate system such that
> {x, y, z} == {anterior, left, superior}. What (I think) I'd like to be
> able to do is create a CoordinateMap object like so:
> cmap = Affine.from_params('ijk', 'y-xz', xform) # with '-' indicating reflection

You can do this - with:

cmap = Affine.from_params('ijk', ('y', '-x', 'z', xform)

but all you are doing here, is setting the name of the output axis to
'-x' instead of 'x'.

> That way if I want to transform the CoordinateMap object to map to
> 'xyz', I can do it with reorder_output(cmap, 'xyz').

The reordering takes a set of names that you know, and reorders the
affine according to the order of the names.  In your example, the
names would be 'y', '-x', 'z', and you could reorder to '-x', 'y',
'z', but the reordering won't do any flip of 'x' - that is, the fact
that an axis has name '-x' has no relationship to the affine - it's
just a label.

> The other ways I can think of to do it would be to pre-rotate the
> affine, or to multiply the "x" row by -1, both of which strike me as
> inelegant. Any thoughts?

Well - it's possible to imagine some machinery that does try and parse
the names to look for this kind of thing, but it would introduce a
layer of extra complexity, and I think it would also mix things that
are currently separate (labels and the mapping).

I'm afraid that the best way to do what you want, is indeed something like:

cmap = Affine.from_params('ijk', ('y', 'x', 'z', np.diag([0, -1, 0, 1]) * xform)
cmap.reorder_output(cmap, 'xyz')

I think.  Happy to be corrected though,

See you,


More information about the Nipy-devel mailing list