-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
FIX: anonymize annotations #7016
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d159849
BUG: anonymize annotations
bloyl 817516d
shift all secs/usecs in block,meas,file _ids\nImprove testing
bloyl 7e2db16
Fix Pep
bloyl 117287b
Test for int32 limits
bloyl 9bfc2cd
fix spelling
bloyl 65fad80
Response to Review
bloyl 46256b6
roll back check
bloyl a69c8d5
remove all date/time info (no timeshifting) if info['meas_date'] is None
bloyl 57367b5
flake
bloyl 124144b
use delta_t instead of dt
bloyl 3bda9bb
Apply suggestions from code review
bloyl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,11 +19,12 @@ | |
| from mne.io import (read_fiducials, write_fiducials, _coil_trans_to_loc, | ||
| _loc_to_coil_trans, read_raw_fif, read_info, write_info) | ||
| from mne.io.constants import FIFF | ||
| from mne.io.write import _generate_meas_id | ||
| from mne.io.write import _generate_meas_id, DATE_NONE | ||
| from mne.io.meas_info import (Info, create_info, _merge_info, | ||
| _force_update_info, RAW_INFO_FIELDS, | ||
| _bad_chans_comp, _get_valid_units, | ||
| anonymize_info, _stamp_to_dt, _dt_to_stamp) | ||
| anonymize_info, _stamp_to_dt, _dt_to_stamp, | ||
| _add_timedelta_to_meas_date) | ||
| from mne.io._digitization import (_write_dig_points, _read_dig_points, | ||
| _make_dig_points,) | ||
| from mne.io import read_raw_ctf | ||
|
|
@@ -457,7 +458,7 @@ def _test_anonymize_info(base_info): | |
| exp_info['description'] = default_desc | ||
| exp_info['experimenter'] = default_str | ||
| exp_info['proj_name'] = default_str | ||
| exp_info['proj_id'][:] = 0 | ||
| exp_info['proj_id'] = np.array([0]) | ||
| exp_info['subject_info']['first_name'] = default_str | ||
| exp_info['subject_info']['last_name'] = default_str | ||
| exp_info['subject_info']['id'] = default_subject_id | ||
|
|
@@ -467,38 +468,69 @@ def _test_anonymize_info(base_info): | |
| # 2010 and 2000. | ||
| exp_info['subject_info']['birthday'] = (1977, 4, 7) | ||
| exp_info['meas_date'] = _dt_to_stamp(default_anon_dos) | ||
|
|
||
| # make copies | ||
| exp_info_3 = exp_info.copy() | ||
|
|
||
| # adjust each expected outcome | ||
| delta_t = timedelta(days=3653) | ||
| for key in ('file_id', 'meas_id'): | ||
| value = exp_info.get(key) | ||
| if value is not None: | ||
| assert 'msecs' not in value | ||
| value['secs'] = exp_info['meas_date'][0] | ||
| value['usecs'] = exp_info['meas_date'][1] | ||
| tmp = _add_timedelta_to_meas_date((value['secs'], value['usecs']), | ||
| -delta_t) | ||
| value['secs'] = tmp[0] | ||
| value['usecs'] = tmp[1] | ||
| value['machid'][:] = 0 | ||
|
|
||
| # exp 2 tests the keep_his option | ||
| exp_info_2 = exp_info.copy() | ||
| exp_info_2['subject_info']['his_id'] = 'foobar' | ||
|
|
||
| # exp 3 tests is a supplied daysback | ||
| dt = timedelta(days=43) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't use dt for a timedelta
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| exp_info_3 = exp_info.copy() | ||
| delta_t_2 = timedelta(days=43) | ||
| exp_info_3['subject_info']['birthday'] = (1987, 2, 24) | ||
| exp_info_3['meas_date'] = _dt_to_stamp(meas_date - dt) | ||
| exp_info_3['meas_date'] = _dt_to_stamp(meas_date - delta_t_2) | ||
| for key in ('file_id', 'meas_id'): | ||
| value = exp_info_3.get(key) | ||
| if value is not None: | ||
| assert 'msecs' not in value | ||
| value['secs'] = exp_info_3['meas_date'][0] | ||
| value['usecs'] = exp_info_3['meas_date'][1] | ||
| tmp = _add_timedelta_to_meas_date((value['secs'], value['usecs']), | ||
| -delta_t_2) | ||
| value['secs'] = tmp[0] | ||
| value['usecs'] = tmp[1] | ||
| value['machid'][:] = 0 | ||
|
|
||
| # exp 4 tests is a supplied daysback | ||
| delta_t_3 = timedelta(days=223 + 364 * 500) | ||
|
|
||
| new_info = anonymize_info(base_info.copy()) | ||
| assert_object_equal(new_info, exp_info) | ||
|
|
||
| new_info = anonymize_info(base_info.copy(), keep_his=True) | ||
| assert_object_equal(new_info, exp_info_2) | ||
|
|
||
| new_info = anonymize_info(base_info.copy(), daysback=dt.days) | ||
| new_info = anonymize_info(base_info.copy(), daysback=delta_t_2.days) | ||
| assert_object_equal(new_info, exp_info_3) | ||
|
|
||
| with pytest.raises(RuntimeError, match='anonymize_info generated'): | ||
| anonymize_info(base_info.copy(), daysback=delta_t_3.days) | ||
| # assert_object_equal(new_info, exp_info_4) | ||
|
|
||
| # test with meas_date = None | ||
| base_info['meas_date'] = None | ||
| exp_info_3['meas_date'] = None | ||
| exp_info_3['file_id']['secs'] = DATE_NONE[0] | ||
| exp_info_3['file_id']['usecs'] = DATE_NONE[1] | ||
| exp_info_3['meas_id']['secs'] = DATE_NONE[0] | ||
| exp_info_3['meas_id']['usecs'] = DATE_NONE[1] | ||
| exp_info_3['subject_info'].pop('birthday', None) | ||
|
|
||
| new_info = anonymize_info(base_info.copy(), daysback=delta_t_2.days) | ||
| assert_object_equal(new_info, exp_info_3) | ||
|
|
||
| new_info = anonymize_info(base_info.copy()) | ||
| assert_object_equal(new_info, exp_info_3) | ||
|
|
||
|
|
||
|
|
@@ -539,7 +571,11 @@ def test_anonymize(tmpdir): | |
|
|
||
| # test that annotations are correctly zeroed | ||
| raw.anonymize() | ||
| assert(raw.annotations.orig_time is raw.info['meas_date']) | ||
| assert(raw.annotations.orig_time == (raw.info['meas_date'][0] + | ||
| raw.info['meas_date'][1] / 1000000.)) | ||
| raw.info['meas_date'] = None | ||
| raw.anonymize() | ||
| assert(raw.annotations.orig_time == 0) | ||
|
|
||
|
|
||
| @testing.requires_testing_data | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.