Module Expr Str ImportFrom alias alias alias Import alias identifier Import alias identifier ClassDef bases NameLoad body Pass decorator_list FunctionDef arguments args NameParam NameParam defaults NameLoad body Expr Str Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign TupleStore NameStore NameStore TupleLoad BinOpSub SubscriptLoad AttributeLoad NameLoad attr Index Num Num BinOpSub SubscriptLoad AttributeLoad NameLoad attr Index Num Num Assign NameStore SubscriptLoad NameLoad ExtSlice Slice NameLoad Slice NameLoad Assign NameStore Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr BinOpMult NameLoad NameLoad keyword Num Assign SubscriptStore NameLoad Index CompareEq NameLoad Num Num Assign NameStore BinOpDiv NameLoad NameLoad Assign TupleStore NameStore NameStore NameStore Call AttributeLoad NameLoad attr NameLoad If CompareIs NameLoad NameLoad body Assign NameStore BinOpMult BinOpMult Call AttributeLoad NameLoad attr Call NameLoad AttributeLoad NameLoad attr AttributeLoad Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr attr Assign NameStore CompareGt NameLoad NameLoad Assign NameStore Call AttributeLoad NameLoad attr SubscriptLoad NameLoad ExtSlice Slice Index NameLoad SubscriptLoad NameLoad Index NameLoad Assign NameStore BinOpMult Call AttributeLoad NameLoad attr TupleLoad NameLoad Num keyword AttributeLoad NameLoad attr AttributeLoad NameLoad attr For NameStore Call NameLoad NameLoad body Assign NameStore SubscriptLoad NameLoad ExtSlice Slice Index NameLoad If UnaryOpNot Call AttributeLoad NameLoad attr NameLoad Num body Assign NameStore Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr NameLoad Assign SubscriptStore NameLoad Index TupleLoad NameLoad Num NameLoad Assert CompareNotEq SubscriptLoad NameLoad Index NameLoad Num If CompareLt SubscriptLoad NameLoad Index NameLoad Num body Assign SubscriptStore NameLoad Index TupleLoad NameLoad Num Num orelse Assign SubscriptStore NameLoad Index TupleLoad NameLoad Num Num Assign SubscriptStore NameLoad ExtSlice Index NameLoad Slice Num Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad If CompareNotEq AttributeLoad NameLoad attr AttributeLoad NameLoad attr body Raise Call NameLoad Str If CompareNotEq SubscriptLoad AttributeLoad NameLoad attr Index Num Num body Raise Call NameLoad BinOpMod Str TupleLoad AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad NameLoad attr NameLoad For TupleStore NameStore TupleStore NameStore NameStore Call NameLoad NameLoad body For TupleStore NameStore TupleStore NameStore NameStore Call NameLoad NameLoad body If CompareEq NameLoad NameLoad body If CompareEq NameLoad NameLoad body Assign NameStore Num orelse Assign NameStore Num Assign SubscriptStore NameLoad ExtSlice Index NameLoad Slice ListLoad NameLoad NameLoad Break orelse Raise Call NameLoad BinOpMod Str NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign NameStore SubscriptLoad AttributeLoad NameLoad attr Index Num If CompareLt AttributeLoad NameLoad attr NameLoad body Raise Call NameLoad Str If Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr SubscriptLoad NameLoad ExtSlice Slice Index Num body Raise Call NameLoad Str For TupleStore NameStore NameStore Call NameLoad SubscriptLoad NameLoad ExtSlice Slice Index Num body If CompareEq NameLoad Num body Assign NameStore Call NameLoad NameLoad keyword NameLoad Assign NameStore Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr Assign SubscriptStore NameLoad Slice NameLoad Call AttributeLoad NameLoad attr SubscriptLoad NameLoad ExtSlice Slice Index Num Assign NameStore Call AttributeLoad NameLoad attr NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Assign NameStore Call AttributeLoad NameLoad attr NameLoad If Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr NameLoad body Raise Call NameLoad Str Assign NameStore SubscriptLoad AttributeLoad NameLoad attr Index Num Assign NameStore SubscriptLoad Call AttributeLoad NameLoad attr NameLoad Slice NameLoad Assign NameStore ListComp Call NameLoad NameLoad comprehension NameStore SubscriptLoad NameLoad ExtSlice Slice Index Num Assign NameStore SubscriptLoad Call AttributeLoad NameLoad attr BinOpAdd NameLoad Num ExtSlice Index BinOpAdd NameLoad ListLoad NameLoad Slice Assign NameStore Call AttributeLoad NameLoad attr BinOpAdd Call NameLoad SubscriptLoad NameLoad ExtSlice Slice Index Num ListLoad Num Assign NameStore BinOpDiv UnaryOpUSub BinOpSub NameLoad Num Num Assign SubscriptStore NameLoad ExtSlice Slice NameLoad Index NameLoad BinOpSub BinOpMult SubscriptLoad NameLoad ExtSlice Slice Index Num NameLoad NameLoad Return Call AttributeLoad NameLoad attr NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Return Call NameLoad NameLoad NameLoad decorator_list Call AttributeLoad NameLoad attr Str FunctionDef arguments args NameParam NameParam defaults Num body Expr Str Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr Num NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad Return Call AttributeLoad NameLoad attr NameLoad Num decorator_list FunctionDef arguments args NameParam NameParam defaults NameLoad body Expr Str If CompareIs NameLoad NameLoad body Assign NameStore Call NameLoad Call NameLoad Str Str Assign NameStore ListLoad For TupleStore NameStore NameStore Call AttributeLoad NameLoad attr NameLoad body If Call AttributeLoad NameLoad attr NameLoad body Expr Call AttributeLoad NameLoad attr NameLoad Continue Assign NameStore Call NameLoad Call AttributeLoad NameLoad attr NameLoad If CompareNotEq NameLoad NameLoad body Raise Call NameLoad BinOpMod Str NameLoad orelse If CompareEq NameLoad Num body Assign NameStore SubscriptLoad SubscriptLoad NameLoad Index NameLoad Index Num orelse If CompareEq NameLoad Num body Assign NameStore SubscriptLoad SubscriptLoad NameLoad Index NameLoad Index Num orelse Raise Call NameLoad Str Expr Call AttributeLoad NameLoad attr NameLoad Return Call NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults NameLoad body Expr Str If CompareIs NameLoad NameLoad body Assign NameStore Call NameLoad Call NameLoad Str Str Assign NameStore Call NameLoad NameLoad Assign NameStore BinOpMult Call AttributeLoad NameLoad attr TupleLoad NameLoad Num keyword AttributeLoad NameLoad attr AttributeLoad NameLoad attr For TupleStore NameStore NameStore Call NameLoad NameLoad body For TupleStore NameStore NameStore Call NameLoad NameLoad body If CompareIs NameLoad NameLoad body Continue If CompareIn NameLoad NameLoad body If CompareEq NameLoad SubscriptLoad NameLoad Index Num body Assign SubscriptStore NameLoad ExtSlice Index NameLoad Slice ListLoad NameLoad Num orelse Assign SubscriptStore NameLoad ExtSlice Index NameLoad Slice ListLoad NameLoad Num Break Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults NameLoad NameLoad body Expr Str Assign NameStore Call NameLoad NameLoad NameLoad Return Call NameLoad NameLoad NameLoad decorator_list
N/A N/A  Utilities for calculating and applying affine orientations  __future__ division print_function absolute_import N/A numpy np N/A numpy.linalg npl OrientationError N/A Exception N/A N/A N/A io_orientation N/A N/A affine tol N/A None N/A N/A  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
       Transformation affine from ``p`` inputs to ``q`` outputs.  Usually this
       will be a shape (4,4) matrix, transforming 3 inputs to 3 outputs, but
       the code also handles the more general case
    tol : {None, float}, optional
       threshold below which SVD values of the affine are considered zero. If
       `tol` is None, and ``S`` is an array with singular values for `affine`,
       and ``eps`` is the epsilon value for datatype of ``S``, then `tol` set
       to ``S.max() * max((q, p)) * eps``

    Returns
    -------
    orientations : (p, 2) ndarray
       one row per input axis, where the first value in each row is the closest
       corresponding output axis. The second value in each row is 1 if the
       input axis is in the same direction as the corresponding output axis and
       -1 if it is in the opposite direction.  If a row is [np.nan, np.nan],
       which can happen when p > q, then this row should be considered dropped.
     N/A affine N/A N/A np asarray affine N/A N/A q p N/A N/A N/A N/A affine shape N/A 0 1 N/A N/A N/A affine shape N/A 1 1 N/A RZS N/A affine N/A N/A q N/A p N/A zooms N/A N/A np sqrt N/A N/A np sum N/A RZS RZS axis 0 N/A N/A zooms N/A N/A zooms 0 1 N/A RS N/A RZS zooms N/A N/A P S Qs N/A N/A npl svd RS N/A N/A tol None N/A N/A tol N/A N/A N/A N/A S max N/A max N/A RS shape N/A N/A N/A np finfo N/A S dtype eps N/A keep N/A S tol N/A R N/A N/A np dot N/A P N/A N/A N/A keep N/A Qs N/A keep N/A ornt N/A N/A N/A np ones N/A p 2 dtype N/A np int8 N/A np nan N/A in_ax N/A range p N/A N/A col N/A R N/A N/A N/A in_ax N/A N/A N/A N/A np allclose col 0 N/A N/A out_ax N/A N/A np argmax N/A N/A np abs col N/A N/A ornt N/A N/A in_ax 0 out_ax N/A N/A N/A col N/A out_ax 0 N/A N/A N/A col N/A out_ax 0 N/A N/A N/A ornt N/A N/A in_ax 1 -1 N/A N/A N/A ornt N/A N/A in_ax 1 1 N/A N/A R N/A N/A out_ax N/A 0 N/A ornt N/A ornt_transform N/A N/A start_ornt end_ornt N/A N/A N/A Return the orientation that transforms from `start_ornt` to `end_ornt`.

    Parameters
    ----------
    start_ornt : (n,2) orientation array
        Initial orientation.

    end_ornt : (n,2) orientation array
        Final orientation.

    Returns
    -------
    orientations : (p, 2) ndarray
       The orientation that will transform the `start_ornt` to the `end_ornt`.
     N/A start_ornt N/A N/A np asarray start_ornt N/A end_ornt N/A N/A np asarray end_ornt N/A N/A N/A start_ornt shape N/A end_ornt shape N/A N/A N/A ValueError The orientations must have the same shape N/A N/A N/A N/A start_ornt shape N/A 1 2 N/A N/A N/A ValueError N/A Invalid shape for an orientation: %s N/A N/A start_ornt shape N/A result N/A N/A np empty_like start_ornt N/A N/A end_in_idx N/A end_out_idx end_flip N/A enumerate end_ornt N/A N/A N/A start_in_idx N/A start_out_idx start_flip N/A enumerate start_ornt N/A N/A N/A end_out_idx start_out_idx N/A N/A N/A start_flip end_flip N/A N/A flip 1 N/A N/A flip -1 N/A N/A result N/A N/A start_in_idx N/A N/A end_in_idx flip N/A N/A N/A N/A ValueError N/A Unable to find out axis %d in start_ornt end_out_idx N/A result N/A apply_orientation N/A N/A arr ornt N/A N/A N/A  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
       orientation transform. ``ornt[N,1]` is flip of axis N of the
       array implied by `shape`, where 1 means no flip and -1 means
       flip.  For example, if ``N==0`` and ``ornt[0,1] == -1``, and
       there's an array ``arr`` of shape `shape`, the flip would
       correspond to the effect of ``np.flipud(arr)``.  ``ornt[:,0]`` is
       the transpose that needs to be done to the implied array, as in
       ``arr.transpose(ornt[:,0])``

    Returns
    -------
    t_arr : ndarray
       data array `arr` transformed according to ornt
     N/A t_arr N/A N/A np asarray arr N/A ornt N/A N/A np asarray ornt N/A n N/A N/A ornt shape N/A 0 N/A N/A N/A t_arr ndim n N/A N/A N/A OrientationError Data array has fewer dimensions than orientation N/A N/A N/A np any N/A N/A np isnan N/A ornt N/A N/A N/A 0 N/A N/A N/A OrientationError Cannot drop coordinates when applying orientation to data N/A N/A ax flip N/A enumerate N/A ornt N/A N/A N/A 1 N/A N/A N/A flip -1 N/A N/A t_arr N/A flip_axis t_arr axis ax N/A full_transpose N/A N/A np arange N/A t_arr ndim N/A N/A full_transpose N/A n N/A N/A np argsort N/A ornt N/A N/A N/A 0 N/A t_arr N/A N/A t_arr transpose full_transpose N/A t_arr N/A inv_ornt_aff N/A N/A ornt shape N/A N/A N/A  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
       orientation transform. ``ornt[P, 1]` is flip of axis N of the array
       implied by `shape`, where 1 means no flip and -1 means flip.  For
       example, if ``P==0`` and ``ornt[0, 1] == -1``, and there's an array
       ``arr`` of shape `shape`, the flip would correspond to the effect of
       ``np.flipud(arr)``.  ``ornt[:,0]`` gives us the (reverse of the)
       transpose that has been done to ``arr``.  If there are any NaNs in
       `ornt`, we raise an ``OrientationError`` (see notes)
    shape : length p sequence
       shape of array you may transform with `ornt`

    Returns
    -------
    transform_affine : (p + 1, p + 1) ndarray
       An array ``arr`` (shape `shape`) might be transformed according to
       `ornt`, resulting in a transformed array ``tarr``.  `transformed_affine`
       is the transform that takes you from array coordinates in ``tarr`` to
       array coordinates in ``arr``.

    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
     N/A ornt N/A N/A np asarray ornt N/A N/A N/A np any N/A N/A np isnan ornt N/A N/A N/A OrientationError We cannot invert orientation transform N/A p N/A N/A ornt shape N/A 0 N/A shape N/A N/A N/A np array shape N/A p N/A axis_transpose N/A N/A int v N/A v N/A ornt N/A N/A N/A 0 N/A undo_reorder N/A N/A N/A np eye N/A p 1 N/A N/A N/A axis_transpose N/A p N/A N/A undo_flip N/A N/A np diag N/A N/A list N/A ornt N/A N/A N/A 1 N/A 1.0 N/A center_trans N/A N/A N/A shape 1 2.0 N/A N/A undo_flip N/A N/A p N/A p N/A N/A N/A ornt N/A N/A N/A 1 center_trans center_trans N/A N/A N/A np dot undo_flip undo_reorder N/A orientation_affine N/A N/A ornt shape N/A N/A N/A N/A inv_ornt_aff ornt shape N/A N/A N/A np deprecate_with_doc Please use inv_ornt_aff instead flip_axis N/A N/A arr axis N/A 0 N/A N/A  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
       axis to flip.  Default `axis` == 0

    Returns
    -------
    farr : array
       Array with axis `axis` flipped

    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]])
     N/A arr N/A N/A np asanyarray arr N/A arr N/A N/A arr swapaxes 0 axis N/A arr N/A N/A np flipud arr N/A N/A N/A arr swapaxes axis 0 N/A ornt2axcodes N/A N/A ornt labels N/A None N/A N/A  Convert orientation `ornt` to labels for axis directions

    Parameters
    ----------
    ornt : (N,2) array-like
        orientation array - see io_orientation docstring
    labels : optional, None or sequence of (2,) sequences
        (2,) sequences are labels for (beginning, end) of output axis.  That
        is, if the first row in `ornt` is ``[1, 1]``, and the second (2,)
        sequence in `labels` is ('back', 'front') then the first returned axis
        code will be ``'front'``.  If the first row in `ornt` had been
        ``[1, -1]`` then the first returned value would have been ``'back'``.
        If None, equivalent to ``(('L','R'),('P','A'),('I','S'))`` - that is -
        RAS axes.

    Returns
    -------
    axcodes : (N,) tuple
        labels for positive end of voxel axes.  Dropped axes get a label of
        None.

    Examples
    --------
    >>> ornt2axcodes([[1, 1],[0,-1],[2,1]], (('L','R'),('B','F'),('D','U')))
    ('F', 'L', 'U')
     N/A N/A labels None N/A N/A labels N/A list N/A zip LPI RAS N/A axcodes N/A N/A N/A axno direction N/A N/A np asarray ornt N/A N/A N/A N/A np isnan axno N/A N/A N/A N/A axcodes append None N/A N/A axint N/A int N/A N/A np round axno N/A N/A axint axno N/A N/A N/A ValueError N/A Non integer axis number %f axno N/A N/A N/A direction 1 N/A N/A axcode N/A N/A labels N/A axint N/A 1 N/A N/A N/A direction -1 N/A N/A axcode N/A N/A labels N/A axint N/A 0 N/A N/A N/A ValueError Direction should be -1 or 1 N/A N/A N/A axcodes append axcode N/A N/A tuple axcodes N/A axcodes2ornt N/A N/A axcodes labels N/A None N/A N/A  Convert axis codes `axcodes` to an orientation

    Parameters
    ----------
    axcodes : (N,) tuple
        axis codes - see ornt2axcodes docstring
    labels : optional, None or sequence of (2,) sequences
        (2,) sequences are labels for (beginning, end) of output axis.  That
        is, if the first element in `axcodes` is ``front``, and the second
        (2,) sequence in `labels` is ('back', 'front') then the first
        row of `ornt` will be ``[1, 1]``. If None, equivalent to
        ``(('L','R'),('P','A'),('I','S'))`` - that is - RAS axes.

    Returns
    -------
    ornt : (N,2) array-like
        orientation array - see io_orientation docstring

    Examples
    --------
    >>> axcodes2ornt(('F', 'L', 'U'), (('L','R'),('B','F'),('D','U')))
    array([[ 1.,  1.],
           [ 0., -1.],
           [ 2.,  1.]])
     N/A N/A labels None N/A N/A labels N/A list N/A zip LPI RAS N/A n_axes N/A len axcodes N/A ornt N/A N/A N/A np ones N/A n_axes 2 dtype N/A np int8 N/A np nan N/A N/A code_idx code N/A enumerate axcodes N/A N/A N/A label_idx codes N/A enumerate labels N/A N/A N/A code None N/A N/A N/A N/A code codes N/A N/A N/A code N/A codes N/A 0 N/A N/A N/A ornt N/A N/A code_idx N/A N/A label_idx -1 N/A N/A N/A ornt N/A N/A code_idx N/A N/A label_idx 1 N/A N/A ornt N/A aff2axcodes N/A N/A aff labels tol N/A None None N/A N/A  axis direction codes for affine `aff`

    Parameters
    ----------
    aff : (N,M) array-like
        affine transformation matrix
    labels : optional, None or sequence of (2,) sequences
        Labels for negative and positive ends of output axes of `aff`.  See
        docstring for ``ornt2axcodes`` for more detail
    tol : None or float
        Tolerance for SVD of affine - see ``io_orientation`` for more detail.

    Returns
    -------
    axcodes : (N,) tuple
        labels for positive end of voxel axes.  Dropped axes get a label of
        None.

    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')
     N/A ornt N/A io_orientation aff tol N/A N/A ornt2axcodes ornt labels N/A