Skip to content

Commit

Permalink
MAINT: Reduce execution time for examples (#10071) [circle deploy]
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner authored Dec 2, 2021
1 parent 4128974 commit 3aad5b1
Show file tree
Hide file tree
Showing 32 changed files with 206 additions and 397 deletions.
1 change: 0 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ jobs:
default: "false"
machine:
image: ubuntu-2004:202111-01
resource_class: large
steps:
- restore_cache:
keys:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/circle_artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ jobs:
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
artifact-path: 0/dev/index.html
circleci-jobs: build_docs
circleci-jobs: build_docs,build_docs-1
job-title: Check the rendered docs here!
8 changes: 4 additions & 4 deletions examples/decoding/decoding_csp_timefreq.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@
# Assemble the classifier using scikit-learn pipeline
clf = make_pipeline(CSP(n_components=4, reg=None, log=True, norm_trace=False),
LinearDiscriminantAnalysis())
n_splits = 5 # how many folds to use for cross-validation
n_splits = 3 # for cross-validation, 5 is better, here we use 3 for speed
cv = StratifiedKFold(n_splits=n_splits, shuffle=True, random_state=42)

# Classification & time-frequency parameters
tmin, tmax = -.200, 2.000
n_cycles = 10. # how many complete cycles: used to define window size
min_freq = 5.
max_freq = 25.
n_freqs = 8 # how many frequency bins to use
min_freq = 8.
max_freq = 20.
n_freqs = 6 # how many frequency bins to use

# Assemble list of frequency range tuples
freqs = np.linspace(min_freq, max_freq, n_freqs) # assemble frequencies
Expand Down
14 changes: 7 additions & 7 deletions examples/decoding/decoding_spoc_CMC.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,23 @@
# Define parameters
fname = data_path() + '/SubjectCMC.ds'
raw = mne.io.read_raw_ctf(fname)
raw.crop(50., 250.) # crop for memory purposes
raw.crop(50., 200.) # crop for memory purposes

# Filter muscular activity to only keep high frequencies
emg = raw.copy().pick_channels(['EMGlft']).load_data()
emg.filter(20., None, fir_design='firwin')
emg.filter(20., None)

# Filter MEG data to focus on beta band
raw.pick_types(meg=True, ref_meg=True, eeg=False, eog=False).load_data()
raw.filter(15., 30., fir_design='firwin')
raw.filter(15., 30.)

# Build epochs as sliding windows over the continuous raw file
events = mne.make_fixed_length_events(raw, id=1, duration=.250)
events = mne.make_fixed_length_events(raw, id=1, duration=0.75)

# Epoch length is 1.5 second
meg_epochs = Epochs(raw, events, tmin=0., tmax=1.500, baseline=None,
detrend=1, decim=8)
emg_epochs = Epochs(emg, events, tmin=0., tmax=1.500, baseline=None)
meg_epochs = Epochs(raw, events, tmin=0., tmax=1.5, baseline=None,
detrend=1, decim=12)
emg_epochs = Epochs(emg, events, tmin=0., tmax=1.5, baseline=None)

# Prepare classification
X = meg_epochs.get_data()
Expand Down
188 changes: 0 additions & 188 deletions examples/inverse/covariance_whitening_dspm.py

This file was deleted.

6 changes: 5 additions & 1 deletion examples/inverse/mixed_norm_inverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@
evoked, forward, cov, alpha, loose=loose, depth=depth, maxit=3000,
tol=1e-4, active_set_size=10, debias=False, weights=stc_dspm,
weights_min=8., n_mxne_iter=n_mxne_iter, return_residual=True,
return_as_dipoles=True, verbose=True, random_state=0)
return_as_dipoles=True, verbose=True, random_state=0,
# for this dataset we know we should use a high alpha, so avoid some
# of the slower (lower) alpha values
sure_alpha_grid=np.linspace(100, 40, 10),
)

t = 0.083
tidx = evoked.time_as_index(t)
Expand Down
4 changes: 2 additions & 2 deletions examples/inverse/mixed_source_space_inverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@
brain = stc_vec.plot(
hemi='both', src=inverse_operator['src'], views='coronal',
initial_time=initial_time, subjects_dir=subjects_dir,
brain_kwargs=dict(silhouette=True))
brain_kwargs=dict(silhouette=True), smoothing_steps=7)

# %%
# Plot the surface
# ----------------
brain = stc.surface().plot(initial_time=initial_time,
subjects_dir=subjects_dir)
subjects_dir=subjects_dir, smoothing_steps=7)
# %%
# Plot the volume
# ---------------
Expand Down
22 changes: 10 additions & 12 deletions examples/inverse/mne_cov_power.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,26 @@
raw_empty_room_fname = op.join(
data_path, 'MEG', 'sample', 'ernoise_raw.fif')
raw_empty_room = mne.io.read_raw_fif(raw_empty_room_fname)
raw_empty_room.crop(0, 60)
raw_empty_room.crop(0, 30) # cropped just for speed
raw_empty_room.info['bads'] = ['MEG 2443']
raw_empty_room.add_proj(raw.info['projs'])
noise_cov = mne.compute_raw_covariance(
raw_empty_room, method=['empirical', 'shrunk'])
noise_cov = mne.compute_raw_covariance(raw_empty_room, method='shrunk')
del raw_empty_room

# %%
# Epoch the data
# --------------

raw.info['bads'] = ['MEG 2443', 'EEG 053']
raw.load_data().filter(4, 12)
raw.pick(['meg', 'stim', 'eog']).load_data().filter(4, 12)
raw.info['bads'] = ['MEG 2443']
events = mne.find_events(raw, stim_channel='STI 014')
event_id = dict(aud_l=1, aud_r=2, vis_l=3, vis_r=4)
tmin, tmax = -0.2, 0.5
baseline = (None, 0) # means from the first instant to t = 0
reject = dict(grad=4000e-13, mag=4e-12, eog=150e-6)
epochs = mne.Epochs(raw.copy().filter(4, 12), events, event_id, tmin, tmax,
epochs = mne.Epochs(raw, events, event_id, tmin, tmax,
proj=True, picks=('meg', 'eog'), baseline=None,
reject=reject, preload=True)
reject=reject, preload=True, decim=5, verbose='error')
del raw

# %%
Expand All @@ -78,11 +77,9 @@
# to noise sources).

base_cov = mne.compute_covariance(
epochs, tmin=-0.2, tmax=0, method=['shrunk', 'empirical'], rank=None,
verbose=True)
epochs, tmin=-0.2, tmax=0, method='shrunk', verbose=True)
data_cov = mne.compute_covariance(
epochs, tmin=0., tmax=0.2, method=['shrunk', 'empirical'], rank=None,
verbose=True)
epochs, tmin=0., tmax=0.2, method='shrunk', verbose=True)

fig_noise_cov = mne.viz.plot_cov(noise_cov, epochs.info, show_svd=False)
fig_base_cov = mne.viz.plot_cov(base_cov, epochs.info, show_svd=False)
Expand Down Expand Up @@ -131,4 +128,5 @@

stc_data /= stc_base
brain = stc_data.plot(subject='sample', subjects_dir=subjects_dir,
clim=dict(kind='percent', lims=(50, 90, 98)))
clim=dict(kind='percent', lims=(50, 90, 98)),
smoothing_steps=7)
11 changes: 7 additions & 4 deletions examples/inverse/vector_mne_solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

data_path = sample.data_path()
subjects_dir = data_path + '/subjects'
smoothing_steps = 7

# Read evoked data
fname_evoked = data_path + '/MEG/sample/sample_audvis-ave.fif'
Expand All @@ -58,7 +59,8 @@

# sphinx_gallery_thumbnail_number = 2
brain = stc.plot(
initial_time=peak_time, hemi='lh', subjects_dir=subjects_dir)
initial_time=peak_time, hemi='lh', subjects_dir=subjects_dir,
smoothing_steps=smoothing_steps)

# You can save a brain movie with:
# brain.save_movie(time_dilation=20, tmin=0.05, tmax=0.16, framerate=10,
Expand All @@ -74,14 +76,14 @@
f'{np.abs(np.sum(directions * inv["source_nn"][2::3], axis=-1)).mean()}')
brain_max = stc_max.plot(
initial_time=peak_time, hemi='lh', subjects_dir=subjects_dir,
time_label='Max power')
time_label='Max power', smoothing_steps=smoothing_steps)

# %%
# The normal is very similar:

brain_normal = stc.project('normal', inv['src'])[0].plot(
initial_time=peak_time, hemi='lh', subjects_dir=subjects_dir,
time_label='Normal')
time_label='Normal', smoothing_steps=smoothing_steps)

# %%
# You can also do this with a fixed-orientation inverse. It looks a lot like
Expand All @@ -94,4 +96,5 @@
stc_fixed = apply_inverse(
evoked, inv_fixed, lambda2, 'dSPM', pick_ori='vector')
brain_fixed = stc_fixed.plot(
initial_time=peak_time, hemi='lh', subjects_dir=subjects_dir)
initial_time=peak_time, hemi='lh', subjects_dir=subjects_dir,
smoothing_steps=smoothing_steps)
Loading

0 comments on commit 3aad5b1

Please sign in to comment.