Skip to content

Commit c19507c

Browse files
authored
Merge pull request #163 from Eric89GXL/empty
MRG: Fix for empty case
2 parents c47a1c8 + 6047c91 commit c19507c

File tree

2 files changed

+20
-34
lines changed

2 files changed

+20
-34
lines changed

surfer/tests/test_viz.py

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ def has_freesurfer():
3333

3434
@requires_fsaverage
3535
def test_offscreen():
36-
"""Test offscreen rendering
37-
"""
36+
"""Test offscreen rendering."""
3837
mlab.options.backend = 'auto'
3938
brain = Brain(*std_args, offscreen=True)
4039
# Sometimes the first screenshot is rendered with a different
@@ -47,8 +46,7 @@ def test_offscreen():
4746

4847
@requires_fsaverage
4948
def test_image():
50-
"""Test image saving
51-
"""
49+
"""Test image saving."""
5250
tmp_name = mktemp() + '.png'
5351

5452
mlab.options.backend = 'auto'
@@ -68,8 +66,7 @@ def test_image():
6866

6967
@requires_fsaverage
7068
def test_brains():
71-
"""Test plotting of Brain with different arguments
72-
"""
69+
"""Test plotting of Brain with different arguments."""
7370
# testing backend breaks when passing in a figure, so we use 'auto' here
7471
# (shouldn't affect usability, but it makes testing more annoying)
7572
mlab.options.backend = 'auto'
@@ -102,8 +99,7 @@ def test_brains():
10299

103100
@requires_fsaverage
104101
def test_annot():
105-
"""Test plotting of annot
106-
"""
102+
"""Test plotting of annot."""
107103
mlab.options.backend = 'test'
108104
annots = ['aparc', 'aparc.a2005s']
109105
borders = [True, False, 2]
@@ -117,8 +113,7 @@ def test_annot():
117113

118114
@requires_fsaverage
119115
def test_contour():
120-
"""Test plotting of contour overlay
121-
"""
116+
"""Test plotting of contour overlay."""
122117
mlab.options.backend = 'test'
123118
brain = Brain(*std_args)
124119
overlay_file = pjoin(data_dir, "lh.sig.nii.gz")
@@ -133,21 +128,20 @@ def test_contour():
133128
@requires_fsaverage
134129
@requires_fs
135130
def test_data():
136-
"""Test plotting of data
137-
"""
131+
"""Test plotting of data."""
138132
mlab.options.backend = 'test'
139133
brain = Brain(*std_args)
140134
mri_file = pjoin(data_dir, 'resting_corr.nii.gz')
141135
reg_file = pjoin(data_dir, 'register.dat')
142136
surf_data = io.project_volume_data(mri_file, "lh", reg_file)
143137
brain.add_data(surf_data, -.7, .7, colormap="jet", alpha=.7)
138+
brain.add_data([], vertices=np.array([], int))
144139
brain.close()
145140

146141

147142
@requires_fsaverage
148143
def test_foci():
149-
"""Test plotting of foci
150-
"""
144+
"""Test plotting of foci."""
151145
mlab.options.backend = 'test'
152146
brain = Brain(*std_args)
153147
coords = [[-36, 18, -3],
@@ -167,8 +161,7 @@ def test_foci():
167161

168162
@requires_fsaverage
169163
def test_label():
170-
"""Test plotting of label
171-
"""
164+
"""Test plotting of label."""
172165
mlab.options.backend = 'test'
173166
subject_id = "fsaverage"
174167
hemi = "lh"
@@ -190,8 +183,7 @@ def test_label():
190183

191184
@requires_fsaverage
192185
def test_meg_inverse():
193-
"""Test plotting of MEG inverse solution
194-
"""
186+
"""Test plotting of MEG inverse solution."""
195187
mlab.options.backend = 'test'
196188
brain = Brain(*std_args)
197189
stc_fname = os.path.join(data_dir, 'meg_source_estimate-lh.stc')
@@ -223,8 +215,7 @@ def time_label(t):
223215

224216
@requires_fsaverage
225217
def test_morphometry():
226-
"""Test plotting of morphometry
227-
"""
218+
"""Test plotting of morphometry."""
228219
mlab.options.backend = 'test'
229220
brain = Brain(*std_args)
230221
brain.add_morphometry("curv")
@@ -236,8 +227,7 @@ def test_morphometry():
236227
@requires_imageio
237228
@requires_fsaverage
238229
def test_movie():
239-
"""Test saving a movie of an MEG inverse solution
240-
"""
230+
"""Test saving a movie of an MEG inverse solution."""
241231
import imageio
242232

243233
# create and setup the Brain instance
@@ -273,8 +263,7 @@ def test_movie():
273263

274264
@requires_fsaverage
275265
def test_overlay():
276-
"""Test plotting of overlay
277-
"""
266+
"""Test plotting of overlay."""
278267
mlab.options.backend = 'test'
279268
# basic overlay support
280269
overlay_file = pjoin(data_dir, "lh.sig.nii.gz")
@@ -306,8 +295,7 @@ def test_overlay():
306295

307296
@requires_fsaverage
308297
def test_probabilistic_labels():
309-
"""Test plotting of probabilistic labels
310-
"""
298+
"""Test plotting of probabilistic labels."""
311299
mlab.options.backend = 'test'
312300
brain = Brain("fsaverage", "lh", "inflated",
313301
cortex="low_contrast")
@@ -332,8 +320,7 @@ def test_probabilistic_labels():
332320

333321
@requires_fsaverage
334322
def test_text():
335-
"""Test plotting of text
336-
"""
323+
"""Test plotting of text."""
337324
mlab.options.backend = 'test'
338325
brain = Brain(*std_args)
339326
brain.add_text(0.1, 0.1, 'Hello', 'blah')
@@ -342,8 +329,7 @@ def test_text():
342329

343330
@requires_fsaverage
344331
def test_animate():
345-
"""Test animation
346-
"""
332+
"""Test animation."""
347333
mlab.options.backend = 'auto'
348334
brain = Brain(*std_args, size=100)
349335
brain.add_morphometry('curv')
@@ -357,8 +343,7 @@ def test_animate():
357343

358344
@requires_fsaverage
359345
def test_views():
360-
"""Test showing different views
361-
"""
346+
"""Test showing different views."""
362347
mlab.options.backend = 'test'
363348
brain = Brain(*std_args)
364349
brain.show_view('lateral')

surfer/viz.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -987,11 +987,12 @@ def add_data(self, array, min=None, max=None, thresh=None,
987987
sample (default).
988988
"""
989989
hemi = self._check_hemi(hemi)
990+
array = np.asarray(array)
990991

991992
if min is None:
992-
min = array.min()
993+
min = array.min() if array.size > 0 else 0
993994
if max is None:
994-
max = array.max()
995+
max = array.max() if array.size > 0 else 0
995996

996997
# Create smoothing matrix if necessary
997998
if len(array) < self.geo[hemi].x.shape[0]:

0 commit comments

Comments
 (0)