MCPcopy
hub / github.com/mne-tools/mne-python / test_average_movements

Function test_average_movements

mne/tests/test_epochs.py:366–476  ·  view source on GitHub ↗

Test movement averaging algorithm.

()

Source from the content-addressed store, hash-verified

364@pytest.mark.slowtest
365@testing.requires_testing_data
366def test_average_movements():
367 """Test movement averaging algorithm."""
368 # usable data
369 crop = 0.0, 10.0
370 origin = (0.0, 0.0, 0.04)
371 raw = read_raw_fif(fname_raw_move, allow_maxshield="yes")
372 raw.info["bads"] += ["MEG2443"] # mark some bad MEG channel
373 raw.crop(*crop).load_data()
374 raw.filter(None, 20, fir_design="firwin")
375 events = make_fixed_length_events(raw, event_id)
376 picks = pick_types(
377 raw.info, meg=True, eeg=True, stim=True, ecg=True, eog=True, exclude=()
378 )
379 epochs = Epochs(
380 raw, events, event_id, tmin, tmax, picks=picks, proj=False, preload=True
381 )
382 with pytest.warns(RuntimeWarning, match="were dropped"):
383 epochs_proj = Epochs(
384 raw, events[:1], event_id, tmin, tmax, picks=picks, proj=True, preload=True
385 )
386 raw_sss_stat = maxwell_filter(
387 raw, origin=origin, regularize=None, bad_condition="ignore"
388 )
389 del raw
390 epochs_sss_stat = Epochs(
391 raw_sss_stat, events, event_id, tmin, tmax, picks=picks, proj=False
392 )
393 evoked_sss_stat = epochs_sss_stat.average()
394 del raw_sss_stat, epochs_sss_stat
395 head_pos = read_head_pos(fname_raw_move_pos)
396 trans = epochs.info["dev_head_t"]["trans"]
397 head_pos_stat = (
398 np.array([trans[:3, 3]]),
399 np.array([trans[:3, :3]]),
400 np.array([0.0]),
401 )
402
403 # SSS-based
404 pytest.raises(TypeError, average_movements, epochs, None)
405 evoked_move_non = average_movements(
406 epochs, head_pos=head_pos, weight_all=False, origin=origin
407 )
408 evoked_move_all = average_movements(
409 epochs, head_pos=head_pos, weight_all=True, origin=origin
410 )
411 evoked_stat_all = average_movements(
412 epochs, head_pos=head_pos_stat, weight_all=True, origin=origin
413 )
414 evoked_std = epochs.average()
415 for ev in (evoked_move_non, evoked_move_all, evoked_stat_all):
416 assert_equal(ev.nave, evoked_std.nave)
417 assert_equal(len(ev.info["bads"]), 0)
418 # substantial changes to MEG data
419 for ev in (evoked_move_non, evoked_stat_all):
420 assert_meg_snr(ev, evoked_std, 0.0, 0.1)
421 pytest.raises(AssertionError, assert_meg_snr, ev, evoked_std, 1.0, 1.0)
422 meg_picks = pick_types(evoked_std.info, meg=True, exclude=())
423 assert_allclose(

Callers

nothing calls this directly

Calls 13

read_raw_fifFunction · 0.90
make_fixed_length_eventsFunction · 0.90
pick_typesFunction · 0.90
EpochsClass · 0.90
maxwell_filterFunction · 0.90
read_head_posFunction · 0.90
average_movementsFunction · 0.90
assert_meg_snrFunction · 0.90
head_pos_to_trans_rot_tFunction · 0.90
load_dataMethod · 0.45
cropMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected