Skip to content

Commit 0ab42c9

Browse files
Make imageio dependency optional
1 parent 08d538a commit 0ab42c9

File tree

6 files changed

+40
-7
lines changed

6 files changed

+40
-7
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ install:
2929
travis_retry sudo apt-get install mencoder;
3030
fi;
3131
- pip install -q coverage coveralls nose-timer nibabel flake8
32-
- python setup.py build
33-
- python setup.py install
32+
- pip install .[save_movie]
3433
- SRC_DIR=$(pwd)
3534

3635
before_script:

doc/install.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ If you already have PySurfer installed, you can also use pip to update it::
1111

1212
pip install -U pysurfer
1313

14+
If you would like to save movies of time course data, also include the
15+
optional dependency `imageio` with::
16+
17+
pip install -U pysurfer[save_movie]
18+
1419
If you'd like to install the development version, you have two options. You can
1520
use pip::
1621

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,6 @@ def check_dependencies():
9292
platforms='any',
9393
packages=['surfer', 'surfer.tests'],
9494
scripts=['bin/pysurfer'],
95-
install_requires=['nibabel >= 1.2',
96-
'imageio >= 1.5'],
95+
install_requires=['nibabel >= 1.2'],
96+
extras_require={'save_movie': ['imageio >= 1.5']},
9797
)

surfer/tests/test_viz.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
import shutil
55
from tempfile import mkdtemp, mktemp
66

7-
import imageio
87
from nose.tools import assert_equal
98
from mayavi import mlab
109
import nibabel as nib
1110
import numpy as np
1211
from numpy.testing import assert_raises, assert_array_equal
1312

1413
from surfer import Brain, io, utils
15-
from surfer.utils import requires_fsaverage
14+
from surfer.utils import requires_fsaverage, requires_imageio
1615

1716
subj_dir = utils._get_subjects_dir()
1817
subject_id = 'fsaverage'
@@ -214,10 +213,13 @@ def test_morphometry():
214213
brain.close()
215214

216215

216+
@requires_imageio
217217
@requires_fsaverage
218218
def test_movie():
219219
"""Test saving a movie of an MEG inverse solution
220220
"""
221+
import imageio
222+
221223
# create and setup the Brain instance
222224
mlab.options.backend = 'auto'
223225
brain = Brain(*std_args)

surfer/utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,5 +623,18 @@ def has_fsaverage(subjects_dir=None):
623623
return False
624624
return True
625625

626+
627+
def has_imageio():
628+
try:
629+
import imageio
630+
except ImportError:
631+
return False
632+
else:
633+
return True
634+
635+
626636
requires_fsaverage = np.testing.dec.skipif(not has_fsaverage(),
627637
'Requires fsaverage subject data')
638+
639+
requires_imageio = np.testing.dec.skipif(not has_imageio(),
640+
"Requires imageio package")

surfer/viz.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from os.path import join as pjoin
44
from warnings import warn
55

6-
import imageio
76
import numpy as np
87
from scipy import stats, ndimage, misc
98
from scipy.interpolate import interp1d
@@ -2194,7 +2193,22 @@ def save_movie(self, fname, time_dilation=4., tmin=None, tmax=None,
21942193
bitrate : str | float
21952194
Bitrate to use to encode movie. Can be specified as number (e.g.
21962195
64000) or string (e.g. '64k'). Default value is 1M
2196+
2197+
Notes
2198+
-----
2199+
Requires imageio package, which can be installed together with
2200+
PySurfer with::
2201+
2202+
$ pip install -U pysurfer[save_movie]
21972203
"""
2204+
try:
2205+
import imageio
2206+
except ImportError:
2207+
raise ImportError("Saving movies from PySurfer requires the "
2208+
"imageio library. To install imageio with "
2209+
"PySurfer, run\n\n $ pip install -U "
2210+
"pysurfer[save_movie]\n")
2211+
21982212
if tmin is None:
21992213
tmin = self._times[0]
22002214
elif tmin < self._times[0]:

0 commit comments

Comments
 (0)