Skip to content

Commit

Permalink
Merge b27b1e2 into f0f35ad
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-brett committed Jan 15, 2018
2 parents f0f35ad + b27b1e2 commit f4e4771
Show file tree
Hide file tree
Showing 20 changed files with 132 additions and 51 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Expand Up @@ -80,6 +80,7 @@ matrix:
- texlive-latex-extra
- texlive-fonts-recommended
- texlive-latex-recommended
- latexmk

before_install:
- source tools/travis_tools.sh
Expand Down Expand Up @@ -128,6 +129,9 @@ script:
- |
if [ "$DOC_BUILD" ]; then # doc build
pip install -r doc-requirements.txt
# Work round bug in Sympy atoms docstring as of 1.1.0
# https://github.com/sympy/sympy/pull/12900
pip install git+https://github.com/sympy/sympy.git
make html-stamp pdf-stamp
else
# Change into an innocuous directory and find tests from installation
Expand Down
3 changes: 3 additions & 0 deletions nipy/algorithms/registration/affine.py
Expand Up @@ -9,6 +9,9 @@
from ...externals.transforms3d.quaternions import mat2quat, quat2axangle
from .transform import Transform

# Legacy repr printing from numpy.
from nipy.testing import legacy_printing as setup_module # noqa

# Globals
RADIUS = 100
MAX_ANGLE = 1e10 * 2 * np.pi
Expand Down
3 changes: 3 additions & 0 deletions nipy/algorithms/slicetiming/timefuncs.py
Expand Up @@ -30,6 +30,9 @@

import numpy as np

# Legacy repr printing from numpy.
from nipy.testing import legacy_printing as setup_module # noqa

# Dictionary (key, value) == (name, function) for slice timing functions
SLICETIME_FUNCTIONS = {}

Expand Down
4 changes: 4 additions & 0 deletions nipy/algorithms/statistics/formula/formulae.py
Expand Up @@ -128,6 +128,10 @@

from nipy.algorithms.utils.matrices import matrix_rank, full_rank

# Legacy repr printing from numpy.
from nipy.testing import legacy_printing as setup_module # noqa


@np.deprecate(message = "Please use sympy.Dummy instead of this function")
def make_dummy(name):
""" Make dummy variable of given name
Expand Down
7 changes: 5 additions & 2 deletions nipy/algorithms/statistics/models/regression.py
Expand Up @@ -36,6 +36,9 @@

from .model import LikelihoodModel, LikelihoodModelResults

# Legacy repr printing from numpy.
from nipy.testing import legacy_printing as setup_module # noqa


class OLSModel(LikelihoodModel):
""" A simple ordinary least squares model.
Expand Down Expand Up @@ -342,9 +345,9 @@ class ARModel(OLSModel):
AR coefficients: [-0.7220361 -1.05365352]
AR coefficients: [-0.72229201 -1.05408193]
AR coefficients: [-0.722278 -1.05405838]
>>> results.theta #doctest: +FP_6DP
>>> results.theta #doctest: +NP_ALLCLOSE
array([ 1.59564228, -0.58562172])
>>> results.t() #doctest: +FP_6DP
>>> results.t() #doctest: +NP_ALLCLOSE
array([ 38.0890515 , -3.45429252])
>>> print(results.Tcontrast([0,1])) #doctest: +FP_6DP
<T contrast: effect=-0.58562172384377043, sd=0.16953449108110835,
Expand Down
22 changes: 12 additions & 10 deletions nipy/algorithms/statistics/models/utils.py
Expand Up @@ -4,11 +4,11 @@
from __future__ import print_function
from __future__ import absolute_import

__docformat__ = 'restructuredtext'

import numpy as np
import scipy.interpolate

__docformat__ = 'restructuredtext'


def mad(a, c=0.6745, axis=0):
"""
Expand All @@ -24,22 +24,24 @@ def mad(a, c=0.6745, axis=0):


class StepFunction(object):
"""
A basic step function: values at the ends are handled in the simplest
way possible: everything to the left of x[0] is set to ival; everything
to the right of x[-1] is set to y[-1].
""" A basic step function
Values at the ends are handled in the simplest way possible: everything to
the left of ``x[0]`` is set to `ival`; everything to the right of ``x[-1]``
is set to ``y[-1]``.
Examples
--------
>>> x = np.arange(20)
>>> y = np.arange(20)
>>> f = StepFunction(x, y)
>>>
>>> print(f(3.2))
>>> f(3.2)
3.0
>>> print(f([[3.2,4.5],[24,-3.1]]))
[[ 3. 4.]
[ 19. 0.]]
>>> res = f([[3.2, 4.5],[24, -3.1]])
>>> np.all(res == [[ 3, 4],
... [19, 0]])
True
"""

def __init__(self, x, y, ival=0., sorted=False):
Expand Down
6 changes: 5 additions & 1 deletion nipy/algorithms/statistics/rft.py
Expand Up @@ -17,12 +17,16 @@
from __future__ import absolute_import

import numpy as np
from numpy.linalg import pinv
from numpy.linalg import pinv

from scipy import stats
from scipy.misc import factorial
from scipy.special import gamma, gammaln, beta, hermitenorm

# Legacy repr printing from numpy.
from nipy.testing import legacy_printing as setup_module # noqa


def binomial(n, k):
""" Binomial coefficient
Expand Down
3 changes: 3 additions & 0 deletions nipy/core/image/image.py
Expand Up @@ -27,6 +27,9 @@
input_axis_index)
from ..reference.array_coords import ArrayCoordMap

# Legacy repr printing from numpy.
from nipy.testing import legacy_printing as setup_module # noqa


class Image(object):
""" The `Image` class provides the core object type used in nipy.
Expand Down
3 changes: 3 additions & 0 deletions nipy/core/image/image_spaces.py
Expand Up @@ -80,6 +80,9 @@
from ..reference import spaces as rsp
from ..reference.coordinate_map import AffineTransform

# Legacy repr printing from numpy.
from nipy.testing import legacy_printing as setup_module # noqa


def xyz_affine(img, name2xyz=None):
""" Return xyz affine from image `img` if possible, or raise error
Expand Down
31 changes: 17 additions & 14 deletions nipy/core/reference/__init__.py
Expand Up @@ -5,12 +5,14 @@
Mathematical model
==================
The idea of a chart :lm:`\\phi` : I{U} S{sub} I{M} S{->} B{R}^k
on a "manifold" I{M}. For a chart both input (I{M}) and output coordinates
(B{R}^k) must be defined and a map relating the two coordinate systems.
The idea is of a chart $\phi : I{U} S{sub} I{M} S{->} B{R}^k$ on a "manifold"
$I{M}$. For a chart, both input ($I{M}$) and output coordinates ($B{R}^k$)
must be defined and there must be a map relating the two coordinate systems.
Description
===========
The modules in this package contains classes which define the space in which an
image exists and also functions for manipulating and traversing this space.
Expand All @@ -19,22 +21,23 @@
output CoordinateSystem, and a mapping which converts points in the
input space to points in the output space.
A `CoordinateSystem` consists of a set of ordered `Coordinate` objects. Each
A ``CoordinateSystem`` consists of a set of ordered ``Coordinate`` objects. Each
Coordinate has a name and a builtin dtype.
The typical use of a `CoordinateMap` is to define how voxels in an `Image`
(core.image.__init__.py) object's raw data map into real space.
The typical use of a ``CoordinateMap`` is to define how voxels in an ``Image``
(``core.image.__init__.py``) object's raw data map into real space.
`Image` traversal is general done in terms of the underlying coordinate_map, and a number of
iterators are provided to traverse points in the coordinate_map (iterators.py). Access to
available iterators is done through the CoordinateMap interface, rather than
accessing the iterator classes directly.
The other common image access method is to take slices through the coordinate_map. In
slices.py functions are presented which will return a `CoordinateMap` representing
a single slice through a larger coordinate_map.
``Image`` traversal is in general done in terms of the underlying
coordinate_map, and a number of iterators are provided to traverse points in
the coordinate_map (iterators.py). Access to available iterators is done
through the CoordinateMap interface, rather than accessing the iterator classes
directly.
The other common image access method is to take slices through the
coordinate_map. In slices.py functions are presented which will return a
``CoordinateMap`` representing a single slice through a larger coordinate_map.
"""

from __future__ import absolute_import
__docformat__ = 'restructuredtext'

Expand Down
5 changes: 4 additions & 1 deletion nipy/core/reference/array_coords.py
Expand Up @@ -24,6 +24,9 @@
from .coordinate_map import shifted_range_origin
from .coordinate_system import CoordinateSystem

# Legacy repr printing from numpy.
from nipy.testing import legacy_printing as setup_module # noqa


class ArrayCoordMap(object):
""" Class combining coordinate map and array shape
Expand Down Expand Up @@ -187,6 +190,7 @@ def __repr__(self):
return "ArrayCoordMap(\n coordmap=" + \
'\n '.join(repr(self.coordmap).split('\n')) + ',\n shape=%s' % repr(self.shape) + '\n)'


def _slice(coordmap, shape, *slices):
"""
Slice a 'voxel' CoordinateMap's function_domain with slices. A
Expand Down Expand Up @@ -264,7 +268,6 @@ def _slice(coordmap, shape, *slices):
A = A.astype(function_domain.coord_dtype)
slice_cmap = AffineTransform(function_domain, coordmap.function_domain, A)
return ArrayCoordMap(compose(coordmap, slice_cmap), tuple(newshape))



class Grid(object):
Expand Down
47 changes: 25 additions & 22 deletions nipy/core/reference/coordinate_map.py
Expand Up @@ -4,15 +4,13 @@
This module describes two types of *mappings*:
* CoordinateMap: a general function from a domain to a range, with a possible
inverse function.
inverse function;
* AffineTransform: an affine function from a domain to a range, not
necessarily of the same dimension, hence not always invertible.
necessarily of the same dimension, hence not always invertible.
Each of these objects is meant to encapsulate a tuple of
(domain, range, function).
Each of the mapping objects contain all the details about their domain
CoordinateSystem, their range CoordinateSystem and the mapping between
Each of these objects is meant to encapsulate a tuple of (domain, range,
function). Each of the mapping objects contain all the details about their
domain CoordinateSystem, their range CoordinateSystem and the mapping between
them.
Common API
Expand All @@ -21,13 +19,16 @@
They are separate classes, neither one inheriting from the other.
They do, however, share some parts of an API, each having methods:
* renamed_domain : rename on the coordinates of the domain (returns a new mapping)
* renamed_domain : rename on the coordinates of the domain (returns a new
mapping)
* renamed_range : rename the coordinates of the range (returns a new mapping)
* reordered_domain : reorder the coordinates of the domain (returns a new mapping)
* reordered_domain : reorder the coordinates of the domain (returns a new
mapping)
* reordered_range : reorder the coordinates of the range (returns a new mapping)
* reordered_range : reorder the coordinates of the range (returns a new
mapping)
* inverse : when appropriate, return the inverse *mapping*
Expand All @@ -45,20 +46,19 @@
-----------------------------------------------
* compose : Take a sequence of mappings (either CoordinateMaps or
AffineTransforms) and return their composition. If they are all
AffineTransforms, an AffineTransform is returned. This checks to
ensure that domains and ranges of the various mappings agree.
AffineTransforms) and return their composition. If they are all
AffineTransforms, an AffineTransform is returned. This checks to ensure that
domains and ranges of the various mappings agree.
* product : Take a sequence of mappings (either CoordinateMaps or
AffineTransforms) and return a new mapping that has domain and range
given by the concatenation of their domains and ranges, and the
mapping simply concatenates the output of each of the individual
mappings. If they are all AffineTransforms, an AffineTransform is
returned. If they are all AffineTransforms that are in fact linear
(i.e. origin=0) then can is represented as a block matrix with the
size of the blocks determined by
AffineTransforms) and return a new mapping that has domain and range given by
the concatenation of their domains and ranges, and the mapping simply
concatenates the output of each of the individual mappings. If they are all
AffineTransforms, an AffineTransform is returned. If they are all
AffineTransforms that are in fact linear (i.e. origin=0) then can is
represented as a block matrix with the size of the blocks determined by
* concat : Take a mapping and prepend a coordinate to its domain and
range. For mapping `m`, this is the same as
product(AffineTransform.identity('concat'), `m`)
range. For mapping ``m``, this is the same as
``product(AffineTransform.identity('concat'), m)``
"""
from __future__ import absolute_import

Expand All @@ -76,6 +76,9 @@
product as coordsys_product
)

# Legacy repr printing from numpy.
from nipy.testing import legacy_printing as setup_module # noqa

# shorthand
CS = CoordinateSystem

Expand Down
4 changes: 4 additions & 0 deletions nipy/core/reference/spaces.py
Expand Up @@ -13,6 +13,10 @@

from ...externals.six import string_types

# Legacy repr printing from numpy.
from nipy.testing import legacy_printing as setup_module # noqa


class XYZSpace(object):
""" Class contains logic for spaces with XYZ coordinate systems
Expand Down
3 changes: 3 additions & 0 deletions nipy/core/reference/tests/test_coordinate_map.py
Expand Up @@ -24,6 +24,8 @@

from numpy.testing import (assert_array_equal, assert_almost_equal, dec)

# Legacy repr printing from numpy.
from nipy.testing import legacy_printing

# Dtypes for testing coordinate map creation / processing
_SYMPY_SAFE_DTYPES = (np.sctypes['int'] + np.sctypes['uint'] +
Expand Down Expand Up @@ -61,6 +63,7 @@ def g(x):
[ 8, 9, 10, 11],
[ 8, 9, 10, 11],
[ 0, 0, 0, 1]]))
legacy_printing()


def test_shift_origin():
Expand Down
3 changes: 3 additions & 0 deletions nipy/core/utils/generators.py
Expand Up @@ -23,6 +23,9 @@

from nipy.utils import seq_prod

# Legacy repr printing from numpy.
from nipy.testing import legacy_printing as setup_module # noqa


def parcels(data, labels=None, exclude=()):
""" Return a generator for ``[data == label for label in labels]``
Expand Down
4 changes: 4 additions & 0 deletions nipy/externals/transforms3d/quaternions.py
Expand Up @@ -18,8 +18,12 @@
from __future__ import absolute_import

import math

import numpy as np

# Legacy repr printing from numpy.
from nipy.testing import legacy_printing as setup_module # noqa

_MAX_FLOAT = np.maximum_sctype(np.float)
_FLOAT_EPS = np.finfo(np.float).eps

Expand Down
3 changes: 3 additions & 0 deletions nipy/modalities/fmri/utils.py
Expand Up @@ -31,6 +31,9 @@

from nipy.algorithms.statistics.formula.formulae import Term, Formula

# Legacy repr printing from numpy.
from nipy.testing import legacy_printing as setup_module # noqa

T = Term('t')


Expand Down

0 comments on commit f4e4771

Please sign in to comment.