Skip to content

Commit cd2f074

Browse files
authored
MRG, FIX: Fix bug with scale_data_colormap (#287)
* FIX: Fix bug with scale_data_colormap * FIX: Fix for deprecation * FIX: One more
1 parent dd9f3b5 commit cd2f074

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ filterwarnings =
1212
ignore:.*ufunc size changed.*:RuntimeWarning
1313
ignore:Using or importing the ABCs:DeprecationWarning
1414
ignore:the imp module is deprecated in favour of importlib:DeprecationWarning
15+
ignore:.*trait handler has been deprecated.*:DeprecationWarning
16+
ignore:.*rich_compare.*metadata.*deprecated.*:DeprecationWarning
1517
ignore:Matplotlib is building the font cache using fc-list. This may take a moment.:UserWarning

surfer/tests/test_viz.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,14 @@ def test_data():
214214
def test_data_limits():
215215
"""Test handling of data limits."""
216216
_set_backend()
217-
brain = Brain(*std_args)
218-
surf_data = np.zeros(163842)
217+
brain = Brain('fsaverage', 'both', 'inflated')
218+
surf_data = np.linspace(0, 1, 163842)
219219
pytest.raises(ValueError, brain.add_data, surf_data, 0, 0)
220-
brain.add_data(surf_data, 0, 1)
220+
brain.add_data(surf_data, 0, 1, hemi='lh')
221+
assert brain.data_dict['lh']['fmax'] == 1.
222+
brain.add_data(surf_data, 0, 0.5, hemi='rh')
223+
assert brain.data_dict['lh']['fmax'] == 1. # unmodified
224+
assert brain.data_dict['rh']['fmax'] == 0.5
221225
brain.close()
222226

223227

surfer/viz.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ def time_label(x):
12001200
self._data_dicts[hemi].append(data)
12011201

12021202
self.scale_data_colormap(min, mid, max, transparent, center, alpha,
1203-
data)
1203+
data, hemi=hemi)
12041204

12051205
if initial_time_index is not None:
12061206
self.set_data_time_index(initial_time_index)
@@ -1951,7 +1951,8 @@ def _brain_color(self):
19511951

19521952
@verbose
19531953
def scale_data_colormap(self, fmin, fmid, fmax, transparent,
1954-
center=None, alpha=1.0, data=None, verbose=None):
1954+
center=None, alpha=1.0, data=None,
1955+
hemi=None, verbose=None):
19551956
"""Scale the data colormap.
19561957
19571958
The colormap may be sequential or divergent. When the colormap is
@@ -1994,15 +1995,19 @@ def scale_data_colormap(self, fmin, fmid, fmax, transparent,
19941995
The data entry for which to scale the colormap.
19951996
If None, will use the data dict from either the left or right
19961997
hemisphere (in that order).
1998+
hemi : str | None
1999+
If None, all hemispheres will be scaled.
19972000
verbose : bool, str, int, or None
19982001
If not None, override default verbose level (see surfer.verbose).
19992002
"""
20002003
divergent = center is not None
2004+
hemis = self._check_hemis(hemi)
2005+
del hemi
20012006

20022007
# Get the original colormap
20032008
if data is None:
2004-
for h in ['lh', 'rh']:
2005-
data = self.data_dict[h]
2009+
for hemi in hemis:
2010+
data = self.data_dict[hemi]
20062011
if data is not None:
20072012
break
20082013
table = data["orig_ctable"].copy()
@@ -2015,14 +2020,15 @@ def scale_data_colormap(self, fmin, fmid, fmax, transparent,
20152020

20162021
views = self._toggle_render(False)
20172022
# Use the new colormap
2018-
for hemi in ['lh', 'rh']:
2023+
for hemi in hemis:
20192024
data = self.data_dict[hemi]
20202025
if data is not None:
20212026
for surf in data['surfaces']:
20222027
cmap = surf.module_manager.scalar_lut_manager
20232028
cmap.load_lut_from_list(lut / 255.)
20242029
if divergent:
2025-
cmap.data_range = np.array([center-fmax, center+fmax])
2030+
cmap.data_range = np.array(
2031+
[center - fmax, center + fmax])
20262032
else:
20272033
cmap.data_range = np.array([fmin, fmax])
20282034

@@ -2050,7 +2056,7 @@ def scale_data_colormap(self, fmin, fmid, fmax, transparent,
20502056
l_m.load_lut_from_list(lut / 255.)
20512057
if divergent:
20522058
l_m.data_range = np.array(
2053-
[center-fmax, center+fmax])
2059+
[center - fmax, center + fmax])
20542060
else:
20552061
l_m.data_range = np.array([fmin, fmax])
20562062

0 commit comments

Comments
 (0)