Skip to content

Commit

Permalink
Fix Brain slider ranges (#12612)
Browse files Browse the repository at this point in the history
  • Loading branch information
wmvanvliet committed May 16, 2024
1 parent 823e25d commit 5a20b82
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
1 change: 1 addition & 0 deletions doc/changes/devel/12612.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix overflow when plotting source estimates where data is all zero (or close to zero), and fix the range of allowed values for the colorbar sliders, by `Marijn van Vliet`_.
11 changes: 5 additions & 6 deletions mne/viz/_brain/_brain.py
Original file line number Diff line number Diff line change
Expand Up @@ -869,8 +869,8 @@ def set_orientation(value, orientation_data=orientation_data):
)

def _configure_dock_colormap_widget(self, name):
fmin, fmax, fscale, fscale_power = _get_range(self)
rng = [fmin * fscale, fmax * fscale]
fmax, fscale, fscale_power = _get_range(self)
rng = [0, fmax * fscale]
self._data["fscale"] = fscale

layout = self._renderer._dock_add_group_box(name)
Expand Down Expand Up @@ -4157,16 +4157,15 @@ def _get_range(brain):
multiplied by the scaling factor and when getting a value, this value
should be divided by the scaling factor.
"""
val = np.abs(np.concatenate(list(brain._current_act_data.values())))
fmin, fmax = np.min(val), np.max(val)
fmax = brain._data["fmax"]
if 1e-02 <= fmax <= 1e02:
fscale_power = 0
else:
fscale_power = int(np.log10(fmax))
fscale_power = int(np.log10(max(fmax, np.finfo("float32").min)))
if fscale_power < 0:
fscale_power -= 1
fscale = 10**-fscale_power
return fmin, fmax, fscale, fscale_power
return fmax, fscale, fscale_power


class _FakeIren:
Expand Down

0 comments on commit 5a20b82

Please sign in to comment.