示例#1
0
def test_annotate_nan(meas_date):
    """Tests automatic NaN annotation generation."""
    # Load data
    raw = mne.io.read_raw_fif(raw_fname)
    sfreq = 100
    raw.resample(sfreq)
    if meas_date is None:
        raw.set_meas_date(None)

    # No Nans, annotate returns empty annots
    assert not np.isnan(raw._data).any()
    annot_nan = annotate_nan(raw)
    assert len(annot_nan) == 0

    # but orig_time should be meas_date
    assert annot_nan.orig_time == raw.info["meas_date"]

    # insert block of NaN from 1s to 3s for one channel
    nan_ch_idx = 0
    raw._data[nan_ch_idx, 1 * sfreq:3 * sfreq] = np.nan

    # annotate_nan accurately finds this
    annot_nan = annotate_nan(raw)
    onset = np.array([1.])
    if raw.info["meas_date"]:
        onset += raw.first_time
    assert_array_equal(annot_nan.onset, onset)
    assert_array_equal(annot_nan.duration, np.array([2]))
    assert_array_equal(annot_nan.description, np.array(['BAD_NAN']))
    assert len(annot_nan.ch_names) == 1
    assert annot_nan.ch_names[0] == (raw.ch_names[nan_ch_idx], )

    # Set the NaN annotations to the raw object
    raw.set_annotations(annot_nan)
示例#2
0
def test_nirsport_v1_w_bad_sat(preload, meas_date):
    """Test NIRSport1 file with NaNs."""
    fname = nirsport1_w_fullsat
    raw = read_raw_nirx(fname, preload=preload)
    data = raw.get_data()
    assert not np.isnan(data).any()
    assert len(raw.annotations) == 5
    # annotated version and ignore should have same data but different annot
    raw_ignore = read_raw_nirx(fname, saturated='ignore', preload=preload)
    assert_allclose(raw_ignore.get_data(), data)
    assert len(raw_ignore.annotations) == 2
    assert not any('NAN' in d for d in raw_ignore.annotations.description)
    # nan version should not have same data, but we can give it the same annot
    raw_nan = read_raw_nirx(fname, saturated='nan', preload=preload)
    data_nan = raw_nan.get_data()
    assert np.isnan(data_nan).any()
    assert not np.allclose(raw_nan.get_data(), data)
    raw_nan_annot = raw_ignore.copy()
    if meas_date is None:
        raw.set_meas_date(None)
        raw_nan.set_meas_date(None)
        raw_nan_annot.set_meas_date(None)
    nan_annots = annotate_nan(raw_nan)
    assert nan_annots.orig_time == raw_nan.info["meas_date"]
    raw_nan_annot.set_annotations(nan_annots)
    use_mask = np.where(raw.annotations.description == 'BAD_SATURATED')
    for key in ('onset', 'duration'):
        a = getattr(raw_nan_annot.annotations, key)[::2]  # one ch in each
        b = getattr(raw.annotations, key)[use_mask]  # two chs in each
        assert_allclose(a, b)