Skip to content

Fix Brain slider ranges - #12612

Merged
wmvanvliet merged 3 commits into
mne-tools:mainfrom
wmvanvliet:slider-range
May 16, 2024
Merged

wmvanvliet merged 3 commits into
mne-tools:mainfrom
wmvanvliet:slider-range

Conversation

@wmvanvliet

@wmvanvliet wmvanvliet commented May 16, 2024

Copy link
Copy Markdown
Contributor

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:

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
image

fixes #12606

@wmvanvliet
wmvanvliet requested a review from larsoner as a code owner May 16, 2024 13:24
@wmvanvliet
wmvanvliet requested a review from drammock May 16, 2024 13:25

@drammock drammock left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

behavior does seem better, thanks! Please add a changelog entry.

@wmvanvliet
wmvanvliet enabled auto-merge (squash) May 16, 2024 19:39
@drammock

Copy link
Copy Markdown
Member

once #12615 lands we can merge main and that should get CIs green here

@wmvanvliet
wmvanvliet merged commit 5a20b82 into mne-tools:main May 16, 2024
@wmvanvliet
wmvanvliet deleted the slider-range branch May 17, 2024 06:03
@hoechenberger

hoechenberger commented May 17, 2024

Copy link
Copy Markdown
Member

image

i love it 😍

@larsoner

Copy link
Copy Markdown
Member

@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)))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

@wmvanvliet

Copy link
Copy Markdown
Contributor Author

Oh no! That looks like a platform issue. Was np.finfo("float32").min a poor choice?

@wmvanvliet

Copy link
Copy Markdown
Contributor Author

Yes, I really think it was a poor choice. I meant to do this: #12619

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OverFlowError when calling : SourceEstimate.plot(...)

5 participants