Commit c690e756 authored by Eric Larson's avatar Eric Larson

ENH: Add Travis

parent 9db84140
[run]
branch = True
source = surfer
include = */surfer/*
omit =
*/setup.py
......@@ -22,4 +22,3 @@ doc/samples
pysurfer.egg-info
*.avi
.tmp/*.png
examples/example_data/coord-lh.label
language: python
env:
# Enable python 2 and python 3 builds
# DEPS=full: build optional dependencies: pandas, nitime, statsmodels,
# scikit-learn, patsy, nibabel; in the case of Python 2, also
# nitime
# DEPS=minimal: don't build optional dependencies; tests that require those
# dependencies are supposed to be skipped
- PYTHON=2.7 DEPS=full
# PYTHON=3.3 DEPS=full # Mayavi doesn't support Py3 :(
- PYTHON=2.7 DEPS=minimal # mencoder is an optional dependency
# Setup anaconda
before_install:
- wget http://repo.continuum.io/miniconda/Miniconda-2.2.2-Linux-x86_64.sh -O miniconda.sh
- chmod +x miniconda.sh
- ./miniconda.sh -b
- export PATH=/home/travis/anaconda/bin:$PATH
- conda update --yes conda
install:
- conda create -n testenv --yes pip python=$PYTHON
- source activate testenv
# Pillow (or PIL/imaging) is necessary for scipy.misc.imsave to exist
- conda install --yes --quiet ipython==1.1.0 numpy scipy mayavi matplotlib nose imaging
- if [ "${DEPS}" == "full" ]; then
travis_retry sudo apt-get install mencoder;
fi;
- pip install -q coverage coveralls nose-timer nibabel flake8
- python setup.py build
- python setup.py install
- SRC_DIR=$(pwd)
before_script:
# Let's create a (fake) display on Travis, and let's use a funny resolution
- export DISPLAY=:99.0
- /sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -screen 0 1400x900x24 -ac +extension GLX +render
- cd ~
- wget --quiet http://faculty.washington.edu/larsoner/fsaverage_min.tar.gz
- mkdir subjects
- tar --directory subjects -xzf fsaverage_min.tar.gz
- export SUBJECTS_DIR="${PWD}/subjects"
- SURFER_DIR=$(python -c 'import surfer;print(surfer.__path__[0])')
# Link coverage to src dir, coveralls should be run from there (needs git calls)
- ln -s ${SURFER_DIR}/../.coverage ${SRC_DIR}/.coverage
- cd ${SURFER_DIR}/../
- ln -s ${SRC_DIR}/.coveragerc .coveragerc
- ln -s ${SRC_DIR}/Makefile Makefile
- ln -s ${SRC_DIR}/setup.cfg setup.cfg
- ln -s ${SRC_DIR}/examples examples
script:
- # Nose-timer has bugs on 3+ as of Jan 2014
- if [ "{PYTHON}" == "2.7" ]; then
nosetests --with-timer --timer-top-n 20;
else
nosetests;
fi
- cd ${SRC_DIR}
- make flake
after_success:
# Need to run from source dir to exectue "git" commands
- coveralls
# simple makefile to simplify repetetive build env management tasks under posix
# caution: testing won't work on windows, see README
PYTHON ?= python
NOSETESTS ?= nosetests
CTAGS ?= ctags
all: clean inplace test
clean-pyc:
find . -name "*.pyc" | xargs rm -f
clean-so:
find . -name "*.so" | xargs rm -f
find . -name "*.pyd" | xargs rm -f
clean-build:
rm -rf build
clean-ctags:
rm -f tags
clean: clean-build clean-pyc clean-so clean-ctags
flake:
if command -v flake8 > /dev/null; then \
flake8 --count surfer examples; \
fi
in: inplace # just a shortcut
inplace:
$(PYTHON) setup.py build_ext -i
nosetests:
rm -f .coverage
$(NOSETESTS) surfer
test: clean nosetests flake
......@@ -52,8 +52,8 @@ Alternatively, if your data are already in register with the Freesurfer
anatomy, you can provide project_volume_data with the subject ID, avoiding the
need to specify a registration file.
By default, 3mm of smoothing is applied on the surface to clean up the overlay a
bit, although the extent of smoothing can be controlled.
By default, 3mm of smoothing is applied on the surface to clean up the overlay
a bit, although the extent of smoothing can be controlled.
"""
zstat = project_volume_data(volume_file, "lh",
subject_id="fsaverage", smooth_fwhm=0.5)
......@@ -68,8 +68,8 @@ brain.add_overlay(zstat, min=2, max=12)
It can also be a good idea to plot the inverse of the mask that was used in the
analysis, so you can be clear about areas that were not included.
It's good to change some parameters of the sampling to account for the fact that
you are projecting binary (0, 1) data.
It's good to change some parameters of the sampling to account for the fact
that you are projecting binary (0, 1) data.
"""
mask_file = "example_data/mask.nii.gz"
mask = project_volume_data(mask_file, "lh", subject_id="fsaverage",
......
......@@ -28,9 +28,8 @@ brain = Brain("fsaverage", "lh", "inflated",
Read both of the activation maps in using
surfer's io functions.
"""
data_dir = op.join("example_data")
sig1 = io.read_scalar_data(op.join(data_dir, "lh.sig.nii.gz"))
sig2 = io.read_scalar_data(op.join(data_dir, "lh.alt_sig.nii.gz"))
sig1 = io.read_scalar_data(op.join('example_data', "lh.sig.nii.gz"))
sig2 = io.read_scalar_data(op.join('example_data', "lh.alt_sig.nii.gz"))
"""
Zero out the vertices that do not meet a threshold.
......
......@@ -57,7 +57,7 @@ surface by finding the vertex on the "white" mesh that is closest to the
coordinate of the point we want to display.
"""
brain.add_foci([coord], map_surface="white", coords_as_verts=True,
color="mediumblue")
color="mediumblue")
"""
Set the camera position to show the extent of the labels.
......
......@@ -10,7 +10,7 @@ print __doc__
import os
import numpy as np
from surfer import Brain, TimeViewer
from surfer import Brain
from surfer.io import read_stc
"""
......@@ -29,8 +29,8 @@ brain = Brain(subject_id, hemi, surface,
read MNE dSPM inverse solution
"""
for hemi in ['lh', 'rh']:
stc_fname = os.path.join('example_data',
'meg_source_estimate-' + hemi + '.stc')
stc_fname = os.path.join('example_data/meg_source_estimate-'
+ hemi + '.stc')
stc = read_stc(stc_fname)
"""
......@@ -66,6 +66,7 @@ brain.set_data_time_index(2)
brain.scale_data_colormap(fmin=13, fmid=18, fmax=22, transparent=True)
"""
uncomment this line to use the interactive TimeViewer GUI
uncomment these lines to use the interactive TimeViewer GUI
"""
#from surfer import TimeViewer
#viewer = TimeViewer(brain)
......@@ -47,11 +47,13 @@ We want to use an appropriate color map for these data: a divergent map that
is centered on 0, which is a meaningful transition-point as it marks the change
from negative correlations to positive correlations.
We'll also plot the map with some transparency so that we can see through to the
underlying anatomy.
We'll also plot the map with some transparency so that we can see through to
the underlying anatomy.
"""
brain.add_data(surf_data_lh, -.7, .7, colormap="coolwarm", alpha=.75, hemi='lh')
brain.add_data(surf_data_rh, -.7, .7, colormap="coolwarm", alpha=.75, hemi='rh')
brain.add_data(surf_data_lh, -.7, .7, colormap="coolwarm", alpha=.75,
hemi='lh')
brain.add_data(surf_data_rh, -.7, .7, colormap="coolwarm", alpha=.75,
hemi='rh')
"""
This overlay represents resting-state correlations with a
......
......@@ -7,6 +7,7 @@
descr = """PySurfer: Python / FreeSurfer / Mayavi2 for brain imaging"""
import os
from os import path as op
# deal with MPL sandbox violations during easy_install
os.environ['MPLCONFIGDIR'] = '.'
......@@ -37,28 +38,28 @@ if __name__ == "__main__":
os.remove('MANIFEST')
setup(name=DISTNAME,
maintainer=MAINTAINER,
include_package_data=True,
maintainer_email=MAINTAINER_EMAIL,
description=DESCRIPTION,
license=LICENSE,
url=URL,
version=VERSION,
download_url=DOWNLOAD_URL,
long_description=LONG_DESCRIPTION,
zip_safe=False, # the package can run out of an .egg file
classifiers=['Intended Audience :: Science/Research',
'Intended Audience :: Developers',
'License :: OSI Approved',
'Programming Language :: Python',
'Topic :: Software Development',
'Topic :: Scientific/Engineering',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX',
'Operating System :: Unix',
'Operating System :: MacOS'
],
platforms='any',
packages=['surfer', 'surfer.tests'],
scripts=['bin/pysurfer'],
)
maintainer=MAINTAINER,
include_package_data=True,
maintainer_email=MAINTAINER_EMAIL,
description=DESCRIPTION,
license=LICENSE,
url=URL,
version=VERSION,
download_url=DOWNLOAD_URL,
long_description=LONG_DESCRIPTION,
zip_safe=False, # the package can run out of an .egg file
classifiers=['Intended Audience :: Science/Research',
'Intended Audience :: Developers',
'License :: OSI Approved',
'Programming Language :: Python',
'Topic :: Software Development',
'Topic :: Scientific/Engineering',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX',
'Operating System :: Unix',
'Operating System :: MacOS'
],
platforms='any',
packages=['surfer', 'surfer.tests'],
scripts=['bin/pysurfer'],
)
from viz import Brain, TimeViewer
from utils import Surface, verbose, set_log_level, set_log_file
from io import project_volume_data
from .viz import Brain, TimeViewer # noqa
from .utils import Surface, verbose, set_log_level, set_log_file # noqa
from .io import project_volume_data # noqa
__version__ = "0.5.dev"
set_log_level()
set_log_file() # initialize handlers
set_log_level() # initialize logging level
......@@ -7,7 +7,7 @@ There should be no reason to import this module in an
interpreter session.
"""
import argparse
from argparse import ArgumentParser, RawDescriptionHelpFormatter
help_text = """
PySurfer is a package for visualization and interaction with cortical
......@@ -26,10 +26,11 @@ about how to interact with the Brain object.
"""
parser = argparse.ArgumentParser(prog='pysurfer',
usage='%(prog)s subject_id hemisphere surface [options]',
formatter_class=argparse.RawDescriptionHelpFormatter,
description=help_text)
parser = ArgumentParser(prog='pysurfer',
usage='%(prog)s subject_id hemisphere surface '
'[options]',
formatter_class=RawDescriptionHelpFormatter,
description=help_text)
parser.add_argument("subject_id",
help="subject id as in subjects dir")
parser.add_argument("hemi", metavar="hemi", choices=["lh", "rh",
......
......@@ -5,8 +5,7 @@ from numpy.testing import assert_raises, assert_array_equal
from tempfile import mktemp
import nibabel as nib
from surfer import Brain
from surfer import io, utils
from surfer import Brain, io, utils
from surfer.utils import requires_fsaverage
from mayavi import mlab
......@@ -36,6 +35,7 @@ def test_offscreen():
brain = Brain(*std_args, offscreen=True)
shot = brain.screenshot()
assert_array_equal(shot.shape, (800, 800, 3))
brain.close()
@requires_fsaverage
......@@ -61,7 +61,7 @@ def test_brains():
# testing backend breaks when passing in a figure, so we use 'auto' here
# (shouldn't affect usability, but it makes testing more annoying)
mlab.options.backend = 'auto'
surfs = ['inflated', 'sphere']
surfs = ['inflated', 'white']
hemis = ['lh', 'rh']
curvs = [True, False]
titles = [None, 'Hello']
......@@ -126,8 +126,8 @@ def test_foci():
mlab.options.backend = 'test'
brain = Brain(*std_args)
coords = [[-36, 18, -3],
[-43, 25, 24],
[-48, 26, -2]]
[-43, 25, 24],
[-48, 26, -2]]
brain.add_foci(coords, map_surface="white", color="gold")
annot_path = pjoin(subj_dir, subject_id, 'label', 'lh.aparc.a2009s.annot')
......@@ -147,7 +147,7 @@ def test_label():
mlab.options.backend = 'test'
subject_id = "fsaverage"
hemi = "lh"
surf = "smoothwm"
surf = "inflated"
brain = Brain(subject_id, hemi, surf)
brain.add_label("BA1")
brain.add_label("BA1", color="blue", scalar_thresh=.5)
......
......@@ -77,7 +77,7 @@ class Surface(object):
def load_geometry(self):
surf_path = op.join(self.data_path, "surf",
"%s.%s" % (self.hemi, self.surf))
"%s.%s" % (self.hemi, self.surf))
self.coords, self.faces = nib.freesurfer.read_geometry(surf_path)
if self.offset is not None:
if self.hemi == 'lh':
......@@ -88,7 +88,7 @@ class Surface(object):
def save_geometry(self):
surf_path = op.join(self.data_path, "surf",
"%s.%s" % (self.hemi, self.surf))
"%s.%s" % (self.hemi, self.surf))
nib.freesurfer.write_geometry(surf_path, self.coords, self.faces)
@property
......@@ -130,7 +130,7 @@ class Surface(object):
def apply_xfm(self, mtx):
"""Apply an affine transformation matrix to the x,y,z vectors."""
self.coords = np.dot(np.c_[self.coords, np.ones(len(self.coords))],
mtx.T)[:, :3]
mtx.T)[:, :3]
def _fast_cross_3d(x, y):
......@@ -521,8 +521,8 @@ def smoothing_matrix(vertices, adj_mat, smoothing_steps=20, verbose=None):
# and is in COO format
smooth_mat = smooth_mat.tocoo()
smooth_mat = sparse.coo_matrix((smooth_mat.data,
(idx_use[smooth_mat.row],
smooth_mat.col)),
(idx_use[smooth_mat.row],
smooth_mat.col)),
shape=(n_vertices,
len(vertices)))
......
......@@ -19,7 +19,6 @@ from .utils import Surface, verbose, create_color_lut, _get_subjects_dir
import logging
logging.basicConfig() # suppress "No handlers found for logger" error
logger = logging.getLogger('surfer')
from traits.api import (HasTraits, Range, Int, Float,
......@@ -1675,7 +1674,6 @@ class Brain(object):
self._v.dispose()
self._v = None
###########################################################################
# SAVING OUTPUT
def save_single_image(self, filename, row=-1, col=-1):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment