Skip to content

MRG, FIX: Fix bug with scale_data_colormap #287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ filterwarnings =
ignore:.*ufunc size changed.*:RuntimeWarning
ignore:Using or importing the ABCs:DeprecationWarning
ignore:the imp module is deprecated in favour of importlib:DeprecationWarning
ignore:.*trait handler has been deprecated.*:DeprecationWarning
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upstream fix is in enthought/mayavi#896 waiting for merge

ignore:.*rich_compare.*metadata.*deprecated.*:DeprecationWarning
ignore:Matplotlib is building the font cache using fc-list. This may take a moment.:UserWarning
10 changes: 7 additions & 3 deletions surfer/tests/test_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,14 @@ def test_data():
def test_data_limits():
"""Test handling of data limits."""
_set_backend()
brain = Brain(*std_args)
surf_data = np.zeros(163842)
brain = Brain('fsaverage', 'both', 'inflated')
surf_data = np.linspace(0, 1, 163842)
pytest.raises(ValueError, brain.add_data, surf_data, 0, 0)
brain.add_data(surf_data, 0, 1)
brain.add_data(surf_data, 0, 1, hemi='lh')
assert brain.data_dict['lh']['fmax'] == 1.
brain.add_data(surf_data, 0, 0.5, hemi='rh')
assert brain.data_dict['lh']['fmax'] == 1. # unmodified
assert brain.data_dict['rh']['fmax'] == 0.5
brain.close()


Expand Down
20 changes: 13 additions & 7 deletions surfer/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,7 @@ def time_label(x):
self._data_dicts[hemi].append(data)

self.scale_data_colormap(min, mid, max, transparent, center, alpha,
data)
data, hemi=hemi)

if initial_time_index is not None:
self.set_data_time_index(initial_time_index)
Expand Down Expand Up @@ -1951,7 +1951,8 @@ def _brain_color(self):

@verbose
def scale_data_colormap(self, fmin, fmid, fmax, transparent,
center=None, alpha=1.0, data=None, verbose=None):
center=None, alpha=1.0, data=None,
hemi=None, verbose=None):
"""Scale the data colormap.

The colormap may be sequential or divergent. When the colormap is
Expand Down Expand Up @@ -1994,15 +1995,19 @@ def scale_data_colormap(self, fmin, fmid, fmax, transparent,
The data entry for which to scale the colormap.
If None, will use the data dict from either the left or right
hemisphere (in that order).
hemi : str | None
If None, all hemispheres will be scaled.
verbose : bool, str, int, or None
If not None, override default verbose level (see surfer.verbose).
"""
divergent = center is not None
hemis = self._check_hemis(hemi)
del hemi

# Get the original colormap
if data is None:
for h in ['lh', 'rh']:
data = self.data_dict[h]
for hemi in hemis:
data = self.data_dict[hemi]
if data is not None:
break
table = data["orig_ctable"].copy()
Expand All @@ -2015,14 +2020,15 @@ def scale_data_colormap(self, fmin, fmid, fmax, transparent,

views = self._toggle_render(False)
# Use the new colormap
for hemi in ['lh', 'rh']:
for hemi in hemis:
data = self.data_dict[hemi]
if data is not None:
for surf in data['surfaces']:
cmap = surf.module_manager.scalar_lut_manager
cmap.load_lut_from_list(lut / 255.)
if divergent:
cmap.data_range = np.array([center-fmax, center+fmax])
cmap.data_range = np.array(
[center - fmax, center + fmax])
else:
cmap.data_range = np.array([fmin, fmax])

Expand Down Expand Up @@ -2050,7 +2056,7 @@ def scale_data_colormap(self, fmin, fmid, fmax, transparent,
l_m.load_lut_from_list(lut / 255.)
if divergent:
l_m.data_range = np.array(
[center-fmax, center+fmax])
[center - fmax, center + fmax])
else:
l_m.data_range = np.array([fmin, fmax])

Expand Down