-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
MRG: Link brains with _LinkViewer and plot_linked_brains #7227
MRG: Link brains with _LinkViewer and plot_linked_brains #7227
Conversation
This is just one amazing unit of work you’re doing here!! ❤️❤️❤️ |
Codecov Report
@@ Coverage Diff @@
## master #7227 +/- ##
==========================================
+ Coverage 89.78% 89.79% +<.01%
==========================================
Files 445 445
Lines 80241 80350 +109
Branches 12842 12857 +15
==========================================
+ Hits 72043 72148 +105
- Misses 5379 5381 +2
- Partials 2819 2821 +2 |
What can I use in the docstring of
Or is it okay not to specify a return at all? |
only certain types of types are valid. Public functions should only link to
public types. One solution is too keep _plot_linked_brain function private
… |
Could you just not return anything? |
(If there is a return you must describe it, but if you don't return anything then you don't need a returns section at all) |
I'll try returning nothing then if it does not work I'll make it private. Thank you. |
Now the import os
import mne
from mne.datasets import sample
from mne.viz import plot_linked_brains
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')
stc1 = mne.read_source_estimate(fname_stc, subject='sample')
stc2 = mne.read_source_estimate(fname_stc, subject='sample')
initial_time = 0.1
with mne.viz.use_3d_backend('pyvista'):
brain1 = stc1.plot(subjects_dir=subjects_dir, initial_time=initial_time,
clim=dict(kind='value', pos_lims=[3, 6, 9]),
hemi='split', views=['lat', 'med'])
brain2 = stc2.plot(subjects_dir=subjects_dir, initial_time=initial_time,
clim=dict(kind='value', pos_lims=[4, 6, 7]))
plot_linked_brains([brain1, brain2]) What else could be linked between the windows? |
This is caused by the outdated slider representation: It turns out that it is built at every update of the slider so it does not makes sense to store it. I thought it could help improve performance. I will revert. |
Not related at all to the representation:
Sure, my pleasure |
mne/viz/_brain/_timeviewer.py
Outdated
value=default_playback_speed, | ||
rng=[0.01, 1], title="playback speed", | ||
rng=[0.01, 1], title="play speed", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should just use speed
, it's short but still descriptive. Let's do it in another PR unless you're planning to push more commits
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's do it here. it's a very short change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM +1 for merge after:
latest.inc
update- update to the capability table in the code, if relevant
* Add support for both in _TimeViewer * Port slider position patch from #7227
I implemented @larsoner feedbacks and fix the conflicts with This is ready to go on my end @agramfort |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also I still get the bug with the colormap change when pressing y. It switches to all red.
@GuillaumeFavelier @larsoner you want to do this in a follow up PR?
mne/viz/_3d.py
Outdated
brains : list, tuple or np.ndarray | ||
The collection of brains to plot. | ||
""" | ||
import collections |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not nest this import
The collection of brains to plot. | ||
""" | ||
import collections | ||
from ._brain import _Brain, _TimeViewer, _LinkViewer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to do a check that this function requires pyvista backend?
mne/viz/_3d.py
Outdated
if not hasattr(brain, 'time_viewer') or brain.time_viewer is None: | ||
brain = _TimeViewer(brain) | ||
else: | ||
raise TypeError("Expected type is _Brain but" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not refer to a private type.
raise TypeError("Expected type is _Brain but" | |
raise TypeError("Expected type is Brain but" |
this is now a bit wrong but I prefer this.
mne/viz/_brain/_timeviewer.py
Outdated
|
||
|
||
class SmartSlider(object): | ||
"""Class to manage smart slider.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you be more explicit. smart in what sense? What does it allow you to do?
+1 to do this in another PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok merge if CIs are green. Thx
Yes I still need to do the refactoring of |
CircleCI is unrelated, thanks @GuillaumeFavelier ! |
* Add support for both in _TimeViewer * Port slider position patch from mne-tools#7227
) * Build first prototype * Fix docstring * Synchronize the slider handle * Add representation memory to IntSlider and ShowView * Introduce SmartSlider * Update time callback * Update orientation callback * Change default name of the time slider * Update smoothing call * Update fmin/fmid/fmax callbacks * Update fscale callback * Improve performance for auto_scaling * Use local _update_slider_callback * Improve plot_linked_brains docstring * Add plot_linked_brains to reference * Link play and playback speed * Update docstring * Add plot_linked_brains to tests * Add _LinkViewer to tests * Rename plot_linked_brains into link_brains * Remove local patch for normalized coordinate system * Fix double _TimeViewer wrapping * Fix issue with slider placement * Fix UI inconsistency * Change playback speed title to short version * Update latest and overview table * Fix name spelling * Implement reviews
* Add support for both in _TimeViewer * Port slider position patch from mne-tools#7227
) * Build first prototype * Fix docstring * Synchronize the slider handle * Add representation memory to IntSlider and ShowView * Introduce SmartSlider * Update time callback * Update orientation callback * Change default name of the time slider * Update smoothing call * Update fmin/fmid/fmax callbacks * Update fscale callback * Improve performance for auto_scaling * Use local _update_slider_callback * Improve plot_linked_brains docstring * Add plot_linked_brains to reference * Link play and playback speed * Update docstring * Add plot_linked_brains to tests * Add _LinkViewer to tests * Rename plot_linked_brains into link_brains * Remove local patch for normalized coordinate system * Fix double _TimeViewer wrapping * Fix issue with slider placement * Fix UI inconsistency * Change playback speed title to short version * Update latest and overview table * Fix name spelling * Implement reviews
This PR adds the
plot_linked_brains()
function which contains a collection of_TimeViewer
and share their properties. This is still a work in progress and only thetime_slider
is shared for now (we assume the same time array between the brains). This design provides independant apps and focus on what should be 'linked' with very little change. Please note that it can totally change depending on user needs/experience or performance.Here is an example:
ToDo
playback_speed
andplay
plot_linked_brains
tomne/viz/tests/test_3d.py
_LinkViewer
tomne/viz/_brain/tests/test_brain.py
toggle_interface
Known issue
It's an item of #7162