Example #1
0
def test_event(params):
    """Test that on_process event gets fired"""
    handler = Mock()
    params.on_process = handler
    with patch('mnefun._mnefun.save_epochs') as func:
        mnefun.do_processing(params, write_epochs=True, print_status=False)
        handler.assert_called_with('Doing epoch EQ/DQ', func, func(), params)
Example #2
0
def test_exits_with_warning_if_all_epochs_autorejected(params):
    """Test that save_epochs fails gracefully if no epochs remain."""
    params.subject_indices = np.arange(1)
    params.subjects = ['x']
    params.run_names = ['%s']
    params.analyses = ['x']
    params.out_names = [[]]
    params.out_numbers = [[]]
    params.must_match = [[]]
    os.makedirs(op.join(params.work_dir, params.subjects[0], 'sss_pca_fif'))
    with patch('mnefun._epoching.read_raw_fif') as read_raw_fif, \
            patch('mnefun._scoring.concatenate_events'), \
            patch('mnefun._epoching._fix_raw_eog_cals'), \
            patch('mnefun._scoring.get_event_fnames') as get_event_fnames, \
            patch('mnefun._epoching._read_events') as _read_events, \
            patch('mnefun._epoching.Epochs') as Epochs:
        Raw = Mock()
        Raw.info = {'sfreq': 1000, 'bads': []}
        Raw._first_samps = [0]
        Raw._last_samps = [1000]
        read_raw_fif.return_value = Raw
        get_event_fnames.return_value = ['foo']
        _read_events.return_value = np.empty((0, 3), int)
        epochs = Mock()
        epochs.info = {'sfreq': 1000}
        epochs.events = np.zeros((0, 3))
        Epochs.return_value = epochs
        with pytest.raises(ValueError, match='No valid'):
            mnefun.do_processing(params, write_epochs=True, print_status=False)
Example #3
0
def test_exits_with_warning_if_all_epochs_autorejected():
    """Test that save_epochs fails gracefully if no epochs remain."""
    params = mnefun.Params()
    setdefaults(params)
    params.subject_indices = numpy.arange(1)
    params.subjects = ['x']
    params.run_names = ['%s']
    params.analyses = ['x']
    params.out_names = [[]]
    params.out_numbers = [[]]
    params.must_match = [[]]
    with patch('mnefun._mnefun.inspect'):
        with patch('mnefun._mnefun.os'):
            with patch('mnefun._mnefun.Raw'):
                with patch('mnefun._mnefun.concatenate_events'):
                    with patch('mnefun._mnefun._fix_raw_eog_cals'):
                        with patch('mnefun._mnefun.get_event_fnames'):
                            with patch('mnefun._mnefun.Epochs') as Epochs:
                                epochs = Mock()
                                epochs.info = {'sfreq': 1000}
                                epochs.events = numpy.zeros((0, 3))
                                Epochs.return_value = epochs
                                with assert_raises(ValueError) as cm:
                                        mnefun.do_processing(params,
                                                             write_epochs=True,
                                                             print_status=False)
                                assert_in('No valid epochs', str(cm.exception))
Example #4
0
def test_event():
    """Test that on_process event gets fired"""
    handler = Mock()
    params = mnefun.Params()
    setdefaults(params)
    params.on_process = handler
    with patch('mnefun._mnefun.save_epochs') as func:
        mnefun.do_processing(params,
            write_epochs=True,
        )
        handler.assert_called_with('Doing epoch EQ/DQ', func, func(), params)
Example #5
0
def test_event():
    """Test that on_process event gets fired"""
    handler = Mock()
    params = mnefun.Params()
    setdefaults(params)
    params.on_process = handler
    with patch('mnefun._mnefun.save_epochs') as func:
        mnefun.do_processing(
            params,
            write_epochs=True,
        )
        handler.assert_called_with('Doing epoch EQ/DQ', func, func(), params)
Example #6
0
)

# Set what processing steps will execute
default = False
mnefun.do_processing(
    params,
    fetch_raw=default,     # Fetch raw recording files from acquisition machine
    do_score=default,      # Do scoring to slice data into trials

    # Before running SSS, make SUBJ/raw_fif/SUBJ_prebad.txt file with
    # space-separated list of bad MEG channel numbers
    push_raw=default,      # Push raw files and SSS script to SSS workstation
    do_sss=default,        # Run SSS remotely (on sws) or locally with MNE
    fetch_sss=default,     # Fetch SSSed files from SSS workstation
    do_ch_fix=default,     # Fix channel ordering

    # Before running SSP, examine SSS'ed files and make
    # SUBJ/bads/bad_ch_SUBJ_post-sss.txt; usually, this should only contain EEG
    # channels.
    gen_ssp=default,       # Generate SSP vectors
    apply_ssp=default,     # Apply SSP vectors and filtering
    write_epochs=default,  # Write epochs to disk
    gen_covs=default,      # Generate covariances

    # Make SUBJ/trans/SUBJ-trans.fif using mne_analyze; needed for fwd calc.
    gen_fwd=default,       # Generate forward solutions (and source space)
    gen_inv=default,       # Generate inverses
    gen_report=default,    # Write mne report html of results to disk
    print_status=default,  # Print completeness status update
)
Example #7
0
    ],
    snr=[
        dict(analysis='English',
             name='EngGram',
             inv='%s-80-sss-meg-free-inv.fif'),
        dict(analysis='English',
             name='EngUngram',
             inv='%s-80-sss-meg-free-inv.fif'),
        dict(analysis='Jab', name='JabGram', inv='%s-80-sss-meg-free-inv.fif'),
        dict(analysis='Jab',
             name='JabUngram',
             inv='%s-80-sss-meg-free-inv.fif')
    ],
    psd=False,
)

mnefun.do_processing(params,
                     fetch_raw=False,
                     push_raw=False,
                     do_sss=False,
                     fetch_sss=False,
                     do_ch_fix=False,
                     gen_ssp=False,
                     apply_ssp=False,
                     write_epochs=False,
                     gen_covs=False,
                     gen_fwd=False,
                     gen_inv=False,
                     gen_report=True,
                     print_status=True)
    mnefun.do_processing(
        params,
        fetch_raw=False,  # Fetch raw recording files from acquisition machine
        do_score=False,  # Do scoring to slice data into trials

        # Before running SSS, make SUBJ/raw_fif/SUBJ_prebad.txt file with
        # space-separated list of bad MEG channel numbers
        push_raw=False,  # Push raw files and SSS script to SSS workstation
        do_sss=False,  # Run SSS remotely (on sws) or locally with mne-python
        fetch_sss=False,  # Fetch SSSed files from SSS workstation
        do_ch_fix=False,  # Fix channel ordering

        # Before running SSP, examine SSS'ed files and make
        # SUBJ/bads/bad_ch_SUBJ_post-sss.txt; usually, this should only contain EEG
        # channels.
        gen_ssp=False,  # Generate SSP vectors
        apply_ssp=False,  # Apply SSP vectors and filtering
        plot_psd=False,  # Plot raw data power spectra
        write_epochs=True,  # Write epochs to disk
        gen_covs=True,  # Generate covariances

        # Make SUBJ/trans/SUBJ-trans.fif using mne_analyze; needed for fwd calc.
        gen_fwd=False,  # Generate forward solutions (and src space if needed)
        gen_inv=False,  # Generate inverses
        gen_report=True,  # Write mne report html of results to disk
        print_status=False,  # Print completeness status update

        #        params,
        #        fetch_raw=False,
        #        do_score=True, # True
        #        push_raw=False,
        #        do_sss=True, # True
        #        fetch_sss=False,
        #        do_ch_fix=True, # True
        #        gen_ssp=True, # True
        #        apply_ssp=True, # True
        #        write_epochs=True, # True
        #        plot_psd=False,
        #        gen_covs=False,
        #        gen_fwd=False,
        #        gen_inv=False,
        #        print_status=False,
        #        gen_report=True # true
    )
Example #9
0
# use_subjects = ['bad_302a']  # Expected 2 ERM projectors for channel type grad based on proj_nums but got 0 in /mnt/bakraid/larsoner/kam/badbaby/badbaby/data/bad_302a/sss_pca_fif/preproc_cont-proj.fif
# use_subjects = ['bad_310b']  # RuntimeError: Only 7/1527 good ECG epochs found
# use_subjects = ['bad_925b']  # ValueError: extended_proj[0] channel names (length 299) do not match the good MEG channel names (length 297)
# Re-run epoching/cov/report for all to make sure no events are missing.

continue_on_error = False
for subject in use_subjects:
    params.subject_indices = [params.subjects.index(subject)]
    default = False
    try:
        mnefun.do_processing(
            params,
            do_score=default,
            do_sss=default,
            do_ch_fix=default,
            gen_ssp=default,
            apply_ssp=default,
            write_epochs=default,
            gen_covs=True,
            gen_report=True,
            print_status=True,
        )
    except Exception:
        if not continue_on_error:
            raise
        traceback.print_exc()
        bad.append(subject)
    else:
        good.append(subject)
print(f"Successfully processed {len(good)}/{len(good) + len(bad)}, bad:\n{bad}")
Example #10
0
    [1] * len(params.in_numbers),
    [101, 102, 103, 104, 105, 106, 107, 108,
     201, 202, 203, 204, 205, 206, 207, 208]
    ]

params.must_match = [
    [],
    [],
    ]
# Set what will run
mnefun.do_processing(
    params,
    fetch_raw=False,
    do_score=False, # True
    push_raw=False,
    do_sss=False, # True
    fetch_sss=False,
    do_ch_fix=False, # True
    gen_ssp=False, # True
    apply_ssp=False, # True
    write_epochs=True,
    plot_psd=False,
    gen_covs=False,
    gen_fwd=False,
    gen_inv=False,
    print_status=False,
    gen_report=True
)


Example #11
0
    [1, -1, -1],    # Combine all standards
    [-1, 1, 2],    # take deviants seperate
    [1, 2, -1],   # Combine each oddball stimulus separately
    [1, -1, 2]
]
params.must_match = [
    [],
    [],
    [1, 2],
    [],
    []
]
# Set what will run
mnefun.do_processing(
    params,
    fetch_raw=True,  # Fetch raw recording files from acq machine
    do_score=False,  # do scoring
    push_raw=False,  # Push raw files and SSS script to SSS workstation
    do_sss=False,  # Run SSS remotely
    fetch_sss=False,  # Fetch SSSed files
    do_ch_fix=False,  # Fix channel ordering
    gen_ssp=False,  # Generate SSP vectors
    apply_ssp=False,  # Apply SSP vectors and filtering
    write_epochs=False,  # Write epochs to disk
    gen_covs=False,  # Generate covariances
    gen_fwd=False,  # Generate forward solutions (and source space if needed)
    gen_inv=False,  # Generate inverses
    gen_report=False,
    print_status=True
)
Example #12
0
             inv='%s-80-sss-meg-free-inv.fif',
             views=['lat', 'med'],
             size=(800, 800)),
        dict(analysis='Conditions',
             name='speech',
             times=times,
             inv='%s-80-sss-meg-free-inv.fif',
             views=['lat', 'med'],
             size=(800, 800)),
    ],
    psd=False,
)
default = False
mnefun.do_processing(
    params,
    fetch_raw=default,
    do_score=default,
    push_raw=default,
    do_sss=default,
    fetch_sss=default,
    do_ch_fix=default,
    gen_ssp=default,
    apply_ssp=default,
    write_epochs=default,
    gen_covs=default,
    gen_fwd=default,
    gen_inv=default,
    gen_report=True,
    print_status=False,
)
Example #13
0
    params.in_numbers,  # Leave events split the same way they were scored
]
params.must_match = [
    [],
    [0, 1],  # only make the standard event counts match
]

# Set what will run
mnefun.do_processing(
    params,
    fetch_raw=True,  # Fetch raw recording files from acq machine
    do_score=True,  # do scoring
    # Make SUBJ/raw_fif/SUBJ_prebad.txt file with space-separated
    # list of bad MEG channel numbers, needed for running SSS.
    push_raw=True,  # Push raw files and SSS script to SSS workstation
    do_sss=True,  # Run SSS remotely
    fetch_sss=True,  # Fetch SSSed files
    do_ch_fix=True,  # Fix channel ordering
    # Examine SSS'ed files and make SUBJ/bads/bad_ch_SUBJ_post-sss.txt,
    # usually only contains EEG channels, needed for preprocessing.
    gen_ssp=True,  # Generate SSP vectors
    apply_ssp=True,  # Apply SSP vectors and filtering
    write_epochs=True,  # Write epochs to disk
    gen_covs=True,  # Generate covariances
    # Make SUBJ/trans/SUBJ-trans.fif file in mne_analyze, needed for fwd calc.
    gen_fwd=True,  # Generate forward solutions (and source space if needed)
    gen_inv=True,  # Generate inverses
    gen_report=True,  # Write mne report html of results to disk
    print_status=True,  # Print completeness status update
)
Example #14
0
params.report_params['pre_fun'] = pre_fun
params.report_params['post_fun'] = post_fun
params.subject_indices = [0, 1]

# Set what processing steps will execute
default = False
mnefun.do_processing(
    params,
    fetch_raw=default,     # Fetch raw recording files from acquisition machine
    do_score=default,      # Do scoring to slice data into trials

    # Before running SSS, make SUBJ/raw_fif/SUBJ_prebad.txt file with
    # space-separated list of bad MEG channel numbers
    do_sss=default,        # Run SSS locally with MNE
    do_ch_fix=default,     # Fix channel ordering

    # Before running SSP, examine SSS'ed files and make
    # SUBJ/bads/bad_ch_SUBJ_post-sss.txt; usually, this should only contain EEG
    # channels.
    gen_ssp=default,       # Generate SSP vectors
    apply_ssp=default,     # Apply SSP vectors and filtering
    write_epochs=default,  # Write epochs to disk
    gen_covs=default,      # Generate covariances

    # Make SUBJ/trans/SUBJ-trans.fif using mne_analyze; needed for fwd calc.
    gen_fwd=default,       # Generate forward solutions (and source space)
    gen_inv=default,       # Generate inverses
    gen_report=default,    # Write mne report html of results to disk
    print_status=default,  # Print completeness status update
)
Example #15
0
    ]  # Continuous (from ERM)

    # Maxwell filter with mne-python
    params.sss_type = 'python'
    params.sss_regularize = 'svd'  # mc-svd SSS
    params.tsss_dur = 4.
    params.int_order = 6
    params.st_correlation = .9
    params.trans_to = (0, 0, 0.03)

    # Set what will execute
    mnefun.do_processing(
        params,
        fetch_raw=False,  # Fetch raw recording files from acq machine
        do_score=False,  # do scoring
        push_raw=False,  # Push raw files and SSS script to SSS workstation
        do_sss=False,  # Run SSS remotely
        fetch_sss=False,  # Fetch SSSed files
        do_ch_fix=False,  # Fix channel ordering
        gen_ssp=False,  # Generate SSP vectors
        apply_ssp=False,  # Apply SSP vectors and filtering
        plot_psd=False,  # Plot raw data power spectra
        write_epochs=False,  # Write epochs to disk
        gen_covs=False,  # Generate covariances
        gen_fwd=False,
        # Generate forward solutions (and source space if needed)
        gen_inv=False,  # Generate inverses
        gen_report=False,  # Write mne report html of results to disk
        print_status=True  # Print completeness status update
    )
Example #16
0
]
params.must_match = [
    [],
    [0, 1],  # only make the standard event counts match
]

# Set what will run
mnefun.do_processing(
    params,
    fetch_raw=True,  # Fetch raw recording files from acq machine
    do_score=True,  # do scoring
    # Make SUBJ/raw_fif/SUBJ_prebad.txt file with space-separated
    # list of bad MEG channel numbers, needed for running SSS.
    push_raw=True,  # Push raw files and SSS script to SSS workstation
    do_sss=True,  # Run SSS remote using Maxfilter or local with mne-python
    fetch_sss=True,  # Fetch SSSed files from SSS workstation
    do_ch_fix=True,  # Fix channel ordering
    # Examine SSS'ed files and make SUBJ/bads/bad_ch_SUBJ_post-sss.txt,
    # usually only contains EEG channels, needed for preprocessing.
    gen_ssp=True,  # Generate SSP vectors
    apply_ssp=True,  # Apply SSP vectors and filtering
    plot_psd=True,  # Plot raw data power spectra
    write_epochs=True,  # Write epochs to disk
    gen_covs=True,  # Generate covariances
    # Make SUBJ/trans/SUBJ-trans.fif file in mne_analyze, needed for fwd calc.
    gen_fwd=True,  # Generate forward solutions (and source space if needed)
    gen_inv=True,  # Generate inverses
    gen_report=True,  # Write mne report html of results to disk
    print_status=True,  # Print completeness status update
)