Skip to content

Commit df68527

Browse files
larsoneragramfort
authored andcommitted
MRG: width/height in offscreen mode (#265)
* FIX: width/height in offscreen mode * MAINT: Sisyphus * BUG: Modernize labels * FIX: Circle * FIX: Stretch * FIX: More * MAINT: Push the rock * FIX: Skip for 3
1 parent 16e5ed2 commit df68527

File tree

8 files changed

+107
-64
lines changed

8 files changed

+107
-64
lines changed

.circleci/config.yml

Lines changed: 65 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,66 @@
11
version: 2
22
jobs:
3-
build:
3+
build_docs:
44
docker:
5-
- image: circleci/python:3.6-jessie
5+
- image: circleci/python:3.7-stretch
66
steps:
7-
# Get our data and merge with upstream
87
- checkout
9-
- run: echo $(git log -1 --pretty=%B) | tee gitlog.txt
10-
- run: echo ${CI_PULL_REQUEST//*pull\//} | tee merge.txt
118
- run:
12-
command: |
13-
if [[ $(cat merge.txt) != "" ]]; then
14-
echo "Merging $(cat merge.txt)";
15-
git pull --ff-only origin "refs/pull/$(cat merge.txt)/merge";
16-
fi
9+
name: Set BASH_ENV
10+
command: |
11+
echo "set -e" >> $BASH_ENV;
12+
echo "export SUBJECTS_DIR=~/subjects" >> $BASH_ENV;
13+
echo "export DISPLAY=:99" >> $BASH_ENV;
14+
echo "export OPENBLAS_NUM_THREADS=4" >> $BASH_ENV;
15+
echo "export PATH=~/.local/bin:$PATH" >> $BASH_ENV;
16+
- run:
17+
name: Merge with upstream
18+
command: |
19+
echo $(git log -1 --pretty=%B) | tee gitlog.txt
20+
echo ${CI_PULL_REQUEST//*pull\//} | tee merge.txt
21+
if [[ $(cat merge.txt) != "" ]]; then
22+
echo "Merging $(cat merge.txt)";
23+
git remote add upstream git://github.com/nipy/PySurfer.git;
24+
git pull --ff-only upstream "refs/pull/$(cat merge.txt)/merge";
25+
git fetch upstream master;
26+
fi
1727
1828
# Load our data
1929
- restore_cache:
2030
keys:
21-
- data-cache
31+
- data-cache-0
2232
- pip-cache
2333

24-
# Fix libgcc_s.so.1 pthread_cancel bug:
34+
- run:
35+
name: Spin up Xvfb
36+
command: |
37+
/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 -noreset;
38+
2539
# https://github.com/ContinuumIO/anaconda-issues/issues/9190#issuecomment-386508136
2640
# https://github.com/golemfactory/golem/issues/1019
27-
- run: sudo apt-get install libgl1-mesa-glx libegl1-mesa libxrandr2 libxrandr2 libxss1 libxcursor1 libxcomposite1 libasound2 libxi6 libxtst6 qt5-default
28-
- run: echo "export SUBJECTS_DIR=~/subjects" >> $BASH_ENV
29-
- run: echo "export PATH=~/.local/bin:$PATH" >> $BASH_ENV
30-
- run: echo "export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4200.1" >> $BASH_ENV
31-
# Spin up Xvfb
32-
- run: echo "export DISPLAY=:99" >> $BASH_ENV
33-
- run: /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 -noreset;
34-
# Python env
35-
- run: pip install -U --user --progress-bar off numpy scipy matplotlib vtk PyQt5 sip PyQt5-sip nibabel sphinx numpydoc pillow imageio https://api.github.com/repos/sphinx-gallery/sphinx-gallery/zipball/master
36-
- run: pip install -U --user --progress-bar off mayavi
41+
- run:
42+
name: Fix libgcc_s.so.1 pthread_cancel bug
43+
command: |
44+
sudo apt-get install qt5-default
45+
46+
- run:
47+
name: Get Python running
48+
command: |
49+
pip install --user -q --upgrade pip numpy
50+
pip install --user -q --upgrade --progress-bar off scipy matplotlib vtk pyqt5 pyqt5-sip nibabel sphinx numpydoc pillow imageio imageio-ffmpeg https://api.github.com/repos/sphinx-gallery/sphinx-gallery/zipball/master mayavi
3751
- save_cache:
3852
key: pip-cache
3953
paths:
40-
- "~/.cache/pip"
41-
- run: python setup.py develop --user
42-
# Check libs
43-
- run: LIBGL_DEBUG=verbose python -c "from mayavi import mlab; import matplotlib.pyplot as plt; mlab.figure(); plt.figure()"
44-
- run: echo $SUBJECTS_DIR
54+
- ~/.cache/pip
55+
56+
# Look at what we have and fail early if there is some library conflict
57+
- run:
58+
name: Check installation
59+
command: |
60+
LIBGL_DEBUG=verbose python -c "from mayavi import mlab; import matplotlib.pyplot as plt; mlab.figure(); plt.figure()"
61+
echo $SUBJECTS_DIR
4562
- run:
63+
name: Get data
4664
command: |
4765
if [ ! -d $SUBJECTS_DIR ]; then
4866
mkdir $SUBJECTS_DIR;
@@ -51,14 +69,31 @@ jobs:
5169
unzip fsaverage_min.zip;
5270
rm fsaverage_min.zip;
5371
fi;
54-
- run: ls $SUBJECTS_DIR
55-
- run: cd doc && sphinx-build -D plot_gallery=1 -D sphinx_gallery_conf.filename_pattern=^\(\(?\!plot_fmri_activation_volume\|plot_morphometry\|plot_label\.py\|plot_probabilistic_label\|plot_resting_correlations\|plot_transparent_brain\|rotate_animation\|save_movie\|save_views\).\)*\$ -b html -d _build/doctrees . _build/html
72+
ls $SUBJECTS_DIR
73+
- run:
74+
name: Install PySurfer
75+
command: |
76+
python setup.py develop --user
77+
78+
- run:
79+
name: Build docs
80+
command: |
81+
cd doc
82+
sphinx-build -D plot_gallery=1 -D sphinx_gallery_conf.filename_pattern=^\(\(?\!plot_fmri_activation_volume\|plot_morphometry\|plot_label\.py\|plot_probabilistic_label\|plot_resting_correlations\|plot_transparent_brain\|rotate_animation\|save_movie\|save_views\).\)*\$ -b html -d _build/doctrees . _build/html
5683
5784
- store_artifacts:
5885
path: doc/_build/html/
5986
destination: html
6087

6188
- save_cache:
62-
key: data-cache
89+
key: data-cache-0
6390
paths:
6491
- "~/subjects"
92+
93+
workflows:
94+
version: 2
95+
96+
default:
97+
jobs:
98+
- build_docs
99+

.travis.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ language: c
22
sudo: false
33

44
env:
5-
global: PYTHON_VERSION=3.6
5+
global: PYTHON_VERSION=3.7
66
CONDA_DEPENDENCIES="numpy scipy matplotlib pyqt>=5.9 coverage pytest pytest-cov flake8 pygments traits traitsui pyface"
7-
PIP_DEPENDENCIES="codecov pytest-sugar pytest-faulthandler nibabel imageio"
7+
PIP_DEPENDENCIES="codecov pytest-sugar pytest-faulthandler nibabel imageio imageio-ffmpeg"
88
DISPLAY=:99.0
99

1010
matrix:
@@ -57,9 +57,6 @@ before_script:
5757
- unzip ../fsaverage_min.zip
5858
- cd ..
5959
- export SUBJECTS_DIR="${PWD}/subjects"
60-
- if [[ $PIP_DEPENDENCIES == *"imageio"* ]] || [ ! -z "$CONDA_ENVIRONMENT" ]; then
61-
python -c "import imageio; imageio.plugins.ffmpeg.download()";
62-
fi
6360

6461
script:
6562
- cd ${SRC_DIR}

appveyor.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ environment:
66
install:
77
- "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"
88
- "python --version"
9-
- "pip install numpy scipy matplotlib nose pillow pytest pytest-cov pytest-faulthandler coverage imageio codecov pyqt5==5.9"
9+
- "pip install numpy scipy matplotlib nose pillow pytest pytest-cov pytest-faulthandler coverage imageio imageio-ffmpeg codecov pyqt5==5.9"
1010
- "pip install traits traitsui pyface vtk mayavi nibabel"
11-
- "python -c \"import imageio; imageio.plugins.ffmpeg.download()\""
1211
- "powershell make/get_fsaverage.ps1"
1312
- "python setup.py develop"
1413
- "SET SUBJECTS_DIR=%CD%\\subjects"

setup.cfg

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ filterwarnings =
88
ignore:can't resolve package from __spec__ or __package__, falling back on __name__ and __path__:ImportWarning
99
ignore:The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead:DeprecationWarning
1010
ignore:elementwise == comparison failed:DeprecationWarning
11-
ignore:Matplotlib is building the font cache using fc-list. This may take a moment.:UserWarning
11+
ignore:Importing from numpy:DeprecationWarning
12+
ignore:.*ufunc size changed.*:RuntimeWarning
13+
ignore:Using or importing the ABCs:DeprecationWarning
14+
ignore:Matplotlib is building the font cache using fc-list. This may take a moment.:UserWarning

surfer/tests/test_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ def _slow_compute_normals(rr, tris):
3232
@utils.requires_fsaverage()
3333
def test_surface():
3434
"""Test IO for Surface class"""
35-
subj_dir = utils._get_subjects_dir()
35+
extra, subj_dir = utils._get_extra()
3636
for subjects_dir in [None, subj_dir]:
3737
surface = utils.Surface('fsaverage', 'lh', 'inflated',
3838
subjects_dir=subjects_dir)
3939
surface.load_geometry()
40-
surface.load_label('BA1')
40+
surface.load_label('BA1' + extra)
4141
surface.load_curvature()
4242
xfm = np.eye(4)
4343
xfm[:3, -1] += 2 # translation

surfer/tests/test_viz.py

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
from unittest import SkipTest
1414

1515
from surfer import Brain, io, utils
16-
from surfer.utils import requires_fsaverage, requires_imageio, requires_fs
16+
from surfer.utils import (requires_fsaverage, requires_imageio, requires_fs,
17+
_get_extra)
1718

1819
warnings.simplefilter('always')
1920

@@ -247,30 +248,30 @@ def test_label():
247248
brain = Brain(subject_id, hemi, surf)
248249
view = get_view(brain)
249250

250-
brain.add_label("BA1")
251+
extra, subj_dir = _get_extra()
252+
brain.add_label("BA1" + extra)
251253
check_view(brain, view)
252-
brain.add_label("BA1", color="blue", scalar_thresh=.5)
253-
subj_dir = utils._get_subjects_dir()
254+
brain.add_label("BA1" + extra, color="blue", scalar_thresh=.5)
254255
label_file = pjoin(subj_dir, subject_id,
255-
"label", "%s.MT.label" % hemi)
256+
"label", "%s.MT%s.label" % (hemi, extra))
256257
brain.add_label(label_file)
257-
brain.add_label("BA44", borders=True)
258-
brain.add_label("BA6", alpha=.7)
258+
brain.add_label("BA44" + extra, borders=True)
259+
brain.add_label("BA6" + extra, alpha=.7)
259260
brain.show_view("medial")
260-
brain.add_label("V1", color="steelblue", alpha=.6)
261-
brain.add_label("V2", color="#FF6347", alpha=.6)
262-
brain.add_label("entorhinal", color=(.2, 1, .5), alpha=.6)
261+
brain.add_label("V1" + extra, color="steelblue", alpha=.6)
262+
brain.add_label("V2" + extra, color="#FF6347", alpha=.6)
263+
brain.add_label("entorhinal" + extra, color=(.2, 1, .5), alpha=.6)
263264
brain.set_surf('white')
264265
brain.show_view(dict(elevation=40, distance=430), distance=430)
265266
with pytest.raises(ValueError, match='!='):
266267
brain.show_view(dict(elevation=40, distance=430), distance=431)
267268

268269
# remove labels
269-
brain.remove_labels('V1')
270-
assert 'V2' in brain.labels_dict
271-
assert 'V1' not in brain.labels_dict
270+
brain.remove_labels('V1' + extra)
271+
assert 'V2' + extra in brain.labels_dict
272+
assert 'V1' + extra not in brain.labels_dict
272273
brain.remove_labels()
273-
assert 'V2' not in brain.labels_dict
274+
assert 'V2' + extra not in brain.labels_dict
274275

275276
brain.close()
276277

@@ -354,7 +355,8 @@ def test_morphometry():
354355
def test_movie(tmpdir):
355356
"""Test saving a movie of an MEG inverse solution."""
356357
import imageio
357-
358+
if sys.version_info < (3,):
359+
raise SkipTest('imageio ffmpeg requires Python 3')
358360
# create and setup the Brain instance
359361
_set_backend()
360362
brain = Brain(*std_args)
@@ -432,15 +434,15 @@ def test_probabilistic_labels():
432434
brain = Brain("fsaverage", "lh", "inflated",
433435
cortex="low_contrast")
434436

435-
brain.add_label("BA1", color="darkblue")
436-
437-
brain.add_label("BA1", color="dodgerblue", scalar_thresh=.5)
437+
extra, subj_dir = _get_extra()
438+
brain.add_label("BA1" + extra, color="darkblue")
439+
brain.add_label("BA1" + extra, color="dodgerblue", scalar_thresh=.5)
440+
brain.add_label("BA45" + extra, color="firebrick", borders=True)
441+
brain.add_label("BA45" + extra, color="salmon", borders=True,
442+
scalar_thresh=.5)
438443

439-
brain.add_label("BA45", color="firebrick", borders=True)
440-
brain.add_label("BA45", color="salmon", borders=True, scalar_thresh=.5)
441-
442-
subj_dir = utils._get_subjects_dir()
443-
label_file = pjoin(subj_dir, "fsaverage", "label", "lh.BA6.label")
444+
label_file = pjoin(subj_dir, "fsaverage", "label",
445+
"lh.BA6%s.label" % (extra,))
444446
prob_field = np.zeros_like(brain.geo['lh'].x)
445447
ids, probs = nib.freesurfer.read_label(label_file, read_scalars=True)
446448
prob_field[ids] = probs

surfer/utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,3 +745,10 @@ def requires_fs():
745745
has = ('FREESURFER_HOME' in os.environ)
746746
return pytest.mark.skipif(
747747
not has, reason='Requires FreeSurfer command line tools')
748+
749+
750+
def _get_extra():
751+
# Get extra label for newer freesurfer
752+
subj_dir = _get_subjects_dir()
753+
fname = op.join(subj_dir, 'fsaverage', 'label', 'lh.BA1.label')
754+
return '_exvivo' if not op.isfile(fname) else '', subj_dir

surfer/viz.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def _make_viewer(figure, n_row, n_col, title, scene_size, offscreen,
208208
try:
209209
mlab.options.offscreen = True
210210
with warnings.catch_warnings(record=True): # traits
211-
figures = [[mlab.figure(size=(h / n_row, w / n_col))
211+
figures = [[mlab.figure(size=(w / n_col, h / n_row))
212212
for _ in range(n_col)] for __ in range(n_row)]
213213
finally:
214214
mlab.options.offscreen = orig_val

0 commit comments

Comments
 (0)