def test_meas_date_convert(tmpdir): """Test conversions of meas_date to datetime objects.""" meas_date = (1346981585, 835782) meas_datetime = _stamp_to_dt(meas_date) meas_date2 = _dt_to_stamp(meas_datetime) assert (meas_date == meas_date2) assert (meas_datetime == datetime(2012, 9, 7, 1, 33, 5, 835782, tzinfo=timezone.utc)) # test old dates for BIDS anonymization meas_date = (-1533443343, 24382) meas_datetime = _stamp_to_dt(meas_date) meas_date2 = _dt_to_stamp(meas_datetime) assert (meas_date == meas_date2) assert (meas_datetime == datetime(1921, 5, 29, 19, 30, 57, 24382, tzinfo=timezone.utc))
def test_meas_date_convert(stamp, dt): """Test conversions of meas_date to datetime objects.""" meas_datetime = _stamp_to_dt(stamp) stamp2 = _dt_to_stamp(meas_datetime) assert stamp == stamp2 assert meas_datetime == datetime(*dt, tzinfo=timezone.utc) # smoke test for info __repr__ info = create_info(1, 1000., 'eeg') info['meas_date'] = meas_datetime assert str(dt[0]) in repr(info)
def test_meas_date_convert(tmpdir): """Test conversions of meas_date to datetime objects.""" meas_date = (1346981585, 835782) meas_datetime = _stamp_to_dt(meas_date) meas_date2 = _dt_to_stamp(meas_datetime) assert (meas_date == meas_date2) assert (meas_datetime == datetime(2012, 9, 7, 1, 33, 5, 835782, tzinfo=timezone.utc))
def test_anonymize(tmpdir): """Test that sensitive information can be anonymized.""" pytest.raises(TypeError, anonymize_info, 'foo') # Fake some subject data raw = read_raw_fif(raw_fname) raw.set_annotations( Annotations(onset=[0, 1], duration=[1, 1], description='dummy', orig_time=None)) first_samp = raw.first_samp expected_onset = np.arange(2) + raw._first_time assert raw.first_samp == first_samp assert_allclose(raw.annotations.onset, expected_onset) # Test instance method events = read_events(event_name) epochs = Epochs(raw, events[:1], 2, 0., 0.1, baseline=None) _test_anonymize_info(raw.info.copy()) _test_anonymize_info(epochs.info.copy()) # test that annotations are correctly zeroed raw.anonymize() assert raw.first_samp == first_samp assert_allclose(raw.annotations.onset, expected_onset) assert raw.annotations.orig_time == raw.info['meas_date'] stamp = _dt_to_stamp(raw.info['meas_date']) assert raw.annotations.orig_time == _stamp_to_dt(stamp) raw.info['meas_date'] = None with pytest.warns(RuntimeWarning, match='None'): raw.anonymize() assert raw.annotations.orig_time is None assert raw.first_samp == first_samp assert_allclose(raw.annotations.onset, expected_onset)
def test_anonymize(tmp_path): """Test that sensitive information can be anonymized.""" pytest.raises(TypeError, anonymize_info, 'foo') # Fake some subject data raw = read_raw_fif(raw_fname) raw.set_annotations( Annotations(onset=[0, 1], duration=[1, 1], description='dummy', orig_time=None)) first_samp = raw.first_samp expected_onset = np.arange(2) + raw._first_time assert raw.first_samp == first_samp assert_allclose(raw.annotations.onset, expected_onset) # test mne.anonymize_info() events = read_events(event_name) epochs = Epochs(raw, events[:1], 2, 0., 0.1, baseline=None) _test_anonymize_info(raw.info.copy()) _test_anonymize_info(epochs.info.copy()) # test instance methods & I/O roundtrip for inst, keep_his in zip((raw, epochs), (True, False)): inst = inst.copy() subject_info = dict(his_id='Volunteer', sex=2, hand=1) inst.info['subject_info'] = subject_info inst.anonymize(keep_his=keep_his) si = inst.info['subject_info'] if keep_his: assert si == subject_info else: assert si['his_id'] == '0' assert si['sex'] == 0 assert 'hand' not in si # write to disk & read back inst_type = 'raw' if isinstance(inst, BaseRaw) else 'epo' fname = 'tmp_raw.fif' if inst_type == 'raw' else 'tmp_epo.fif' out_path = tmp_path / fname inst.save(out_path, overwrite=True) if inst_type == 'raw': read_raw_fif(out_path) else: read_epochs(out_path) # test that annotations are correctly zeroed raw.anonymize() assert raw.first_samp == first_samp assert_allclose(raw.annotations.onset, expected_onset) assert raw.annotations.orig_time == raw.info['meas_date'] stamp = _dt_to_stamp(raw.info['meas_date']) assert raw.annotations.orig_time == _stamp_to_dt(stamp) with raw.info._unlock(): raw.info['meas_date'] = None raw.anonymize(daysback=None) with pytest.warns(RuntimeWarning, match='None'): raw.anonymize(daysback=123) assert raw.annotations.orig_time is None assert raw.first_samp == first_samp assert_allclose(raw.annotations.onset, expected_onset)