Utilities for calculating and applying affine orientations
OrientationError | |
aff2axcodes(aff[, labels, tol]) | axis direction codes for affine aff |
apply_orientation(arr, ornt) | Apply transformations implied by ornt to the first |
axcodes2ornt(axcodes[, labels]) | Convert axis codes axcodes to an orientation |
flip_axis(arr[, axis]) | Flip contents of axis in array arr |
inv_ornt_aff(ornt, shape) | Affine transform reversing transforms implied in ornt |
io_orientation(affine[, tol]) | Orientation of input axes in terms of output axes for affine |
ornt2axcodes(ornt[, labels]) | Convert orientation ornt to labels for axis directions |
ornt_transform(start_ornt, end_ornt) | Return the orientation that transforms from start_ornt to end_ornt. |
axis direction codes for affine aff
Parameters: | aff : (N,M) array-like
labels : optional, None or sequence of (2,) sequences
tol : None or float
|
---|---|
Returns: | axcodes : (N,) tuple
|
Examples
>>> aff = [[0,1,0,10],[-1,0,0,20],[0,0,1,30],[0,0,0,1]]
>>> aff2axcodes(aff, (('L','R'),('B','F'),('D','U')))
('B', 'R', 'U')
Apply transformations implied by ornt to the first n axes of the array arr
Parameters: | arr : array-like of data with ndim >= n ornt : (n,2) orientation array
|
---|---|
Returns: | t_arr : ndarray
|
Convert axis codes axcodes to an orientation
Parameters: | axcodes : (N,) tuple
labels : optional, None or sequence of (2,) sequences
|
---|---|
Returns: | ornt : (N,2) array-like
|
Examples
>>> axcodes2ornt(('F', 'L', 'U'), (('L','R'),('B','F'),('D','U')))
array([[ 1., 1.],
[ 0., -1.],
[ 2., 1.]])
Flip contents of axis in array arr
flip_axis is the same transform as np.flipud, but for any axis. For example flip_axis(arr, axis=0) is the same transform as np.flipud(arr), and flip_axis(arr, axis=1) is the same transform as np.fliplr(arr)
Parameters: | arr : array-like axis : int, optional
|
---|---|
Returns: | farr : array
|
Examples
>>> a = np.arange(6).reshape((2,3))
>>> a
array([[0, 1, 2],
[3, 4, 5]])
>>> flip_axis(a, axis=0)
array([[3, 4, 5],
[0, 1, 2]])
>>> flip_axis(a, axis=1)
array([[2, 1, 0],
[5, 4, 3]])
Affine transform reversing transforms implied in ornt
Imagine you have an array arr of shape shape, and you apply the transforms implied by ornt (more below), to get tarr. tarr may have a different shape shape_prime. This routine returns the affine that will take a array coordinate for tarr and give you the corresponding array coordinate in arr.
Parameters: | ornt : (p, 2) ndarray
shape : length p sequence
|
---|---|
Returns: | transform_affine : (p + 1, p + 1) ndarray
|
Notes
If a row in ornt contains NaN, this means that the input row does not influence the output space, and is thus effectively dropped from the output space. In that case one tarr coordinate maps to many arr coordinates, we can’t invert the transform, and we raise an error
Orientation of input axes in terms of output axes for affine
Valid for an affine transformation from p dimensions to q dimensions (affine.shape == (q + 1, p + 1)).
The calculated orientations can be used to transform associated arrays to best match the output orientations. If p > q, then some of the output axes should be considered dropped in this orientation.
Parameters: | affine : (q+1, p+1) ndarray-like
tol : {None, float}, optional
|
---|---|
Returns: | orientations : (p, 2) ndarray
|
Convert orientation ornt to labels for axis directions
Parameters: | ornt : (N,2) array-like
labels : optional, None or sequence of (2,) sequences
|
---|---|
Returns: | axcodes : (N,) tuple
|
Examples
>>> ornt2axcodes([[1, 1],[0,-1],[2,1]], (('L','R'),('B','F'),('D','U')))
('F', 'L', 'U')
Return the orientation that transforms from start_ornt to end_ornt.
Parameters: | start_ornt : (n,2) orientation array
end_ornt : (n,2) orientation array
|
---|---|
Returns: | orientations : (p, 2) ndarray
|