Skip to content

ENH: block parameter for viz plots - #10222

Merged
larsoner merged 14 commits into
mne-tools:mainfrom
GuillaumeFavelier:enh/block
Jan 20, 2022
Merged

larsoner merged 14 commits into
mne-tools:mainfrom
GuillaumeFavelier:enh/block

Conversation

@GuillaumeFavelier

@GuillaumeFavelier GuillaumeFavelier commented Jan 19, 2022 •

Copy link
Copy Markdown
Contributor

This PR introduces the block parameter to start the Qt event loop and effectively hold the context.

This PR is what I had in mind @hoechenberger

Related to #10221

@GuillaumeFavelier GuillaumeFavelier self-assigned this Jan 19, 2022
@hoechenberger

Copy link
Copy Markdown
Member

Beautiful!!!!! 😍😍😍

@GuillaumeFavelier

Copy link
Copy Markdown
Contributor Author

Did you try it @hoechenberger ? Does it work for you?

@GuillaumeFavelier

Copy link
Copy Markdown
Contributor Author

We have to use brain_kwargs to set the block parameter with stc or we can use get_brain_class() and it will block at the call to show().

Details
import os
import mne
from mne.datasets import sample


data_path = sample.data_path()
sample_dir = os.path.join(data_path, 'MEG', 'sample')
subjects_dir = os.path.join(data_path, 'subjects')
fname_stc = os.path.join(sample_dir, 'sample_audvis-meg')
stc = mne.read_source_estimate(fname_stc, subject='sample')
initial_time = 0.096
mne.viz.set_3d_backend('pyvista')

brain = stc.plot(subjects_dir=subjects_dir, initial_time=initial_time,
                 clim=dict(kind='value', lims=[3, 6, 9]),
                 size=600,
                 hemi='rh',
                 views=['lat', 'med'],
                 brain_kwargs=dict(block=True),
                 )

@hoechenberger

Copy link
Copy Markdown
Member

Yes, works!

@GuillaumeFavelier

Copy link
Copy Markdown
Contributor Author

Any opinion @larsoner ?

@larsoner larsoner 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.

Other than my deprecation complaint and needing latest.inc entries, looks reasonable to me.

Has anyone tested if multiple block=True calls can be made (e.g., sequential stc.plot(brain_kwargs=dict(block=True)) calls)?

Comment thread mne/gui/_coreg.py Resolved
Co-authored-by: Eric Larson <[email protected]>
@GuillaumeFavelier

Copy link
Copy Markdown
Contributor Author

Has anyone tested if multiple block=True calls can be made

I think the first call should block so anything after should be executed when the window is closed.

@larsoner

Copy link
Copy Markdown
Member

Agreed that should happen in theory, can you test that it works as expected?

@GuillaumeFavelier

GuillaumeFavelier commented Jan 19, 2022 •

Copy link
Copy Markdown
Contributor Author

I tested the following real quick:

import os
import mne
from mne.datasets import sample


data_path = sample.data_path()
sample_dir = os.path.join(data_path, 'MEG', 'sample')
subjects_dir = os.path.join(data_path, 'subjects')
fname_stc = os.path.join(sample_dir, 'sample_audvis-meg')
stc = mne.read_source_estimate(fname_stc, subject='sample')
initial_time = 0.096
mne.viz.set_3d_backend('pyvista')

brain = stc.plot(subjects_dir=subjects_dir, initial_time=initial_time,
                 clim=dict(kind='value', lims=[3, 6, 9]),
                 size=600,
                 hemi='rh',
                 views=['lat', 'med'],
                 brain_kwargs=dict(block=True),
                 )
brain = stc.plot(subjects_dir=subjects_dir, initial_time=initial_time,
                 clim=dict(kind='value', lims=[3, 6, 9]),
                 size=600,
                 hemi='rh',
                 views=['lat', 'med'],
                 brain_kwargs=dict(block=True),
                 )

and this is what I got:

output.mp4

I realize now that it is NOT obvious. I actually close the windows with my shortcut 😅 they do not close by themselves

@larsoner larsoner 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.

Deprecation not fully implemented or documented yet

Comment thread doc/changes/latest.inc Resolved
GuillaumeFavelier and others added 2 commits January 20, 2022 12:10
Co-authored-by: Richard Höchenberger <[email protected]>
This reverts commit e3b8420.
@GuillaumeFavelier GuillaumeFavelier changed the title ENH: block parameter for viz plots WIP,ENH: block parameter for viz plots Jan 20, 2022

@larsoner larsoner 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.

LGTM +1 for merge. Good to go from your end @GuillaumeFavelier ?

@GuillaumeFavelier

GuillaumeFavelier commented Jan 20, 2022 •

Copy link
Copy Markdown
Contributor Author

It is ready for me @larsoner

@GuillaumeFavelier GuillaumeFavelier changed the title WIP,ENH: block parameter for viz plots ENH: block parameter for viz plots Jan 20, 2022
@larsoner
larsoner merged commit e05151a into mne-tools:main Jan 20, 2022
@larsoner

Copy link
Copy Markdown
Member

Thanks @GuillaumeFavelier @hoechenberger !

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.

3 participants