From 2b619194197801dbec6645f44343d3ecbcb469ee Mon Sep 17 00:00:00 2001 From: Alex Rockhill Date: Wed, 21 Jul 2021 12:08:22 -0700 Subject: [PATCH] [BUG, MRG] Fix tutorial + example show_view to use correct keyword args (#9599) * fix tutorial + example show_view * clean up paths to touch examples * seg fault --- .../connectivity/mne_inverse_coherence_epochs.py | 12 +++++++----- examples/inverse/covariance_whitening_dspm.py | 16 ++++++++++------ .../time_frequency/source_power_spectrum_opm.py | 2 +- mne/viz/_brain/_brain.py | 3 ++- tutorials/clinical/20_seeg.py | 2 +- tutorials/inverse/60_visualize_stc.py | 2 +- tutorials/simulation/80_dics.py | 6 ++---- 7 files changed, 24 insertions(+), 19 deletions(-) diff --git a/examples/connectivity/mne_inverse_coherence_epochs.py b/examples/connectivity/mne_inverse_coherence_epochs.py index 190db3d3f37..773e83cb578 100644 --- a/examples/connectivity/mne_inverse_coherence_epochs.py +++ b/examples/connectivity/mne_inverse_coherence_epochs.py @@ -13,6 +13,7 @@ # %% +import os.path as op import numpy as np import mne @@ -32,12 +33,13 @@ # compute the event-related coherence. data_path = sample.data_path() -subjects_dir = data_path + '/subjects' -fname_inv = data_path + '/MEG/sample/sample_audvis-meg-oct-6-meg-inv.fif' -fname_raw = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw.fif' -fname_event = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw-eve.fif' +subjects_dir = op.join(data_path, 'subjects') +sample_dir = op.join(data_path, 'MEG', 'sample') +fname_inv = op.join(sample_dir, 'sample_audvis-meg-oct-6-meg-inv.fif') +fname_raw = op.join(sample_dir, 'sample_audvis_filt-0-40_raw.fif') +fname_event = op.join(sample_dir, 'sample_audvis_filt-0-40_raw-eve.fif') label_name_lh = 'Aud-lh' -fname_label_lh = data_path + '/MEG/sample/labels/%s.label' % label_name_lh +fname_label_lh = op.join(sample_dir, 'labels', f'{label_name_lh}.label') event_id, tmin, tmax = 1, -0.2, 0.5 method = "dSPM" # use dSPM method (could also be MNE or sLORETA) diff --git a/examples/inverse/covariance_whitening_dspm.py b/examples/inverse/covariance_whitening_dspm.py index d9f88f11109..678268a5c1e 100644 --- a/examples/inverse/covariance_whitening_dspm.py +++ b/examples/inverse/covariance_whitening_dspm.py @@ -28,6 +28,7 @@ # %% +import os.path as op import numpy as np import matplotlib.pyplot as plt @@ -43,11 +44,12 @@ # Get data data_path = spm_face.data_path() -subjects_dir = data_path + '/subjects' +subjects_dir = op.join(data_path, 'subjects') -raw_fname = data_path + '/MEG/spm/SPM_CTF_MEG_example_faces%d_3D.ds' +raw_fname = op.join(data_path, 'MEG', 'spm', + 'SPM_CTF_MEG_example_faces{run}_3D.ds') -raw = io.read_raw_ctf(raw_fname % 1) # Take first run +raw = io.read_raw_ctf(raw_fname.format(run=1)) # Take first run # To save time and memory for this demo, we'll just use the first # 2.5 minutes (all we need to get 30 total events) and heavily # resample 480->60 Hz (usually you wouldn't do either of these!) @@ -103,12 +105,14 @@ del epochs # Make forward -trans = data_path + '/MEG/spm/SPM_CTF_MEG_example_faces1_3D_raw-trans.fif' +trans = op.join(data_path, 'MEG', 'spm', + 'SPM_CTF_MEG_example_faces1_3D_raw-trans.fif') # oct5 and add_dist are just for speed, not recommended in general! src = mne.setup_source_space( - 'spm', spacing='oct5', subjects_dir=data_path + '/subjects', + 'spm', spacing='oct5', subjects_dir=subjects_dir, add_dist=False) -bem = data_path + '/subjects/spm/bem/spm-5120-5120-5120-bem-sol.fif' +bem = op.join(data_path, 'subjects', 'spm', 'bem', + 'spm-5120-5120-5120-bem-sol.fif') forward = mne.make_forward_solution(evokeds[0][0].info, trans, src, bem) del src for noise_covs_, evokeds_ in zip(noise_covs, evokeds): diff --git a/examples/time_frequency/source_power_spectrum_opm.py b/examples/time_frequency/source_power_spectrum_opm.py index eda4cbbb05e..564fdc61c75 100644 --- a/examples/time_frequency/source_power_spectrum_opm.py +++ b/examples/time_frequency/source_power_spectrum_opm.py @@ -197,7 +197,7 @@ def plot_band(kind, band): time_label=title, title=title, colormap='inferno', time_viewer=False, show_traces=False, clim=dict(kind='percent', lims=(70, 85, 99)), smoothing_steps=10) - brain.show_view(dict(azimuth=0, elevation=0), roll=0) + brain.show_view(azimuth=0, elevation=0, roll=0) return fig, brain diff --git a/mne/viz/_brain/_brain.py b/mne/viz/_brain/_brain.py index 9c41bc4f696..3938ac63f29 100644 --- a/mne/viz/_brain/_brain.py +++ b/mne/viz/_brain/_brain.py @@ -2699,7 +2699,8 @@ def show_view(self, view=None, roll=None, distance=None, elevation = view['elevation'] view = None if (row == 'deprecated' or col == 'deprecated') and \ - len([_ for h in self._hemis for _ in self._iter_views(h)]) > 1: + len(set([_ for h in self._hemis + for _ in self._iter_views(h)])) > 1: warn('`row` and `col` default behavior is changing, in version ' '0.25 the default behavior will be to apply `show_view` to ' 'all views', DeprecationWarning) diff --git a/tutorials/clinical/20_seeg.py b/tutorials/clinical/20_seeg.py index f4205204e2a..e9782ad8f37 100644 --- a/tutorials/clinical/20_seeg.py +++ b/tutorials/clinical/20_seeg.py @@ -174,7 +174,7 @@ brain = mne.viz.Brain('fsaverage', alpha=0.1, cortex='low_contrast', subjects_dir=subjects_dir, units='m', figure=fig) brain.add_volume_labels(aseg='aparc+aseg', labels=labels) -brain.show_view(dict(azimuth=120, elevation=90, distance=0.25)) +brain.show_view(azimuth=120, elevation=90, distance=0.25) brain.enable_depth_peeling() # %% diff --git a/tutorials/inverse/60_visualize_stc.py b/tutorials/inverse/60_visualize_stc.py index c2f4e8a703a..cea7be72227 100644 --- a/tutorials/inverse/60_visualize_stc.py +++ b/tutorials/inverse/60_visualize_stc.py @@ -161,7 +161,7 @@ brain = mne.viz.Brain('sample', hemi='both', surf='pial', alpha=0.5, cortex='low_contrast', subjects_dir=subjects_dir) brain.add_volume_labels(aseg='aparc.a2009s+aseg', labels=labels) -brain.show_view(dict(azimuth=250, elevation=40, distance=400)) +brain.show_view(azimuth=250, elevation=40, distance=400) brain.enable_depth_peeling() # %% diff --git a/tutorials/simulation/80_dics.py b/tutorials/simulation/80_dics.py index 0472f356ebc..ab92dadacc3 100644 --- a/tutorials/simulation/80_dics.py +++ b/tutorials/simulation/80_dics.py @@ -223,8 +223,7 @@ def coh_signal_gen(): brain.add_foci(vertices[1][0], coords_as_verts=True, hemi='rh') # Rotate the view and add a title. -brain.show_view(view={'azimuth': 0, 'elevation': 0, 'distance': 550, - 'focalpoint': [0, 0, 0]}) +brain.show_view(azimuth=0, elevation=0, distance=550, focalpoint=(0, 0, 0)) # %% # We will now compute the cortical power map at 10 Hz. using a DICS beamformer. @@ -280,8 +279,7 @@ def plot_approach(power, n): brain.add_foci(vertices[0][0], coords_as_verts=True, hemi='lh', color='b') brain.add_foci(vertices[1][0], coords_as_verts=True, hemi='rh', color='b') # Rotate the view and add a title. - brain.show_view(view={'azimuth': 0, 'elevation': 0, 'distance': 550, - 'focalpoint': [0, 0, 0]}) + brain.show_view(azimuth=0, elevation=0, distance=550, focalpoint=(0, 0, 0)) return brain