Repository: mne-tools/mne-python

Issue:
Fix Brain slider ranges
This updates the logic that determines the ranges for the three sliders (fmin, fmid, fmax) on the left of a `Brain` figure. There was an overflow when the data is all zeros (`np.log10(fmax)`) which this PR fixes by using `np.log10(max(fmax, 1e-30))` instead. While I was there, I noticed that the minimum and maximum values for the sliders were set based on the `fmin` and `fmax` of the current timepoint instead of the entire data. Finally, on second thought, the minimum value for the sliders should always be `0`, that makes a lot more sense to me than capping it to `fmin`.

To check out the new behavior:

```python
import mne
path = mne.datasets.sample.data_path()
stc = mne.read_source_estimate(path / "MEG/sample/fsaverage_audvis-meg")
brain = stc.plot("fsaverage", hemi="both", subjects_dir=path / "subjects")
```
![image](https://github.com/mne-tools/mne-python/assets/428273/b0c43a96-b907-4315-9c3f-6a31226598bf)
![image](https://github.com/mne-tools/mne-python/assets/428273/2c375434-b018-4479-b24b-f952cbd1eeb4)

fixes #12606


Discussion:
once #12615 lands we can merge main and that should get CIs green here
![image](https://github.com/mne-tools/mne-python/assets/2046265/60f883b8-a4c3-4e44-9388-f9d58a773b3f)


i love it 😍 
@wmvanvliet looks like this broke an example:

https://app.circleci.com/pipelines/github/mne-tools/mne-python/24096/workflows/69ebaf39-fe26-4774-83e0-238a1fd85918/jobs/66162

```
Unexpected failing examples:

    ../examples/inverse/source_space_snr.py failed leaving traceback:

    Traceback (most recent call last):
      File "/home/circleci/project/examples/inverse/source_space_snr.py", line 74, in <module>
        brain = snr_stc.plot(**kwargs)
      ...
      File "/home/circleci/project/mne/viz/_brain/_brain.py", line 4164, in _get_range
        fscale_power = int(np.log10(max(fmax, np.finfo("float32").min)))
    RuntimeWarning: invalid value encountered in log10
```
And locally just running the example I get the warning then an error:
```
/home/larsoner/python/mne-python/mne/viz/_brain/_brain.py:4164: RuntimeWarning: invalid value encountered in log10
  fscale_power = int(np.log10(max(fmax, np.finfo("float32").min)))
Traceback (most recent call last):
  File "/home/larsoner/python/mne-python/examples/inverse/source_space_snr.py", line 74, in <module>
    brain = snr_stc.plot(**kwargs)
            ^^^^^^^^^^^^^^^^^^^^^^
  ...
  File "/home/larsoner/python/mne-python/mne/viz/_brain/_brain.py", line 4164, in _get_range
    fscale_power = int(np.log10(max(fmax, np.finfo("float32").min)))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
Oh no! That looks like a platform issue. Was `np.finfo("float32").min` a poor choice?

Resolving patch:
diff --git a/examples/inverse/source_space_snr.py b/examples/inverse/source_space_snr.py
--- a/examples/inverse/source_space_snr.py
+++ b/examples/inverse/source_space_snr.py
@@ -8,6 +8,7 @@
 This example shows how to compute and plot source space SNR as in
 :footcite:`GoldenholzEtAl2009`.
 """
+
 # Author: Padma Sundaram <tottochan@gmail.com>
 #         Kaisu Lankinen <klankinen@mgh.harvard.edu>
 #
diff --git a/mne/viz/_brain/_brain.py b/mne/viz/_brain/_brain.py
--- a/mne/viz/_brain/_brain.py
+++ b/mne/viz/_brain/_brain.py
@@ -4157,11 +4157,11 @@ def _get_range(brain):
     multiplied by the scaling factor and when getting a value, this value
     should be divided by the scaling factor.
     """
-    fmax = brain._data["fmax"]
+    fmax = abs(brain._data["fmax"])
     if 1e-02 <= fmax <= 1e02:
         fscale_power = 0
     else:
-        fscale_power = int(np.log10(max(fmax, np.finfo("float32").min)))
+        fscale_power = int(np.log10(max(fmax, np.finfo("float32").smallest_normal)))
         if fscale_power < 0:
             fscale_power -= 1
     fscale = 10**-fscale_power


Test patch: