Skip to content

BUG: raw.anonymize() not fully anonymizing #11966

@paulroujansky

Description

@paulroujansky

Description of the problem

When anonymizing a raw object with func anonymize(), the subject info and meas_date are still accessible through raw._raw_extras attribute as shown in the below example.

Regarding subject info, it would be easier in my opinion to remove field "subject_info" from both raw.info and *raw._raw_extras (or simply empty unecessary fields, keeping "his_id" only for instance) as it is not expected to be able to retrieve the information afterwards by definition.

Steps to reproduce

import mne

data_path = mne.datasets.testing.data_path(download=False)
fpath = data_path / "EDF" / "test_edf_stim_resamp.edf"

raw = mne.io.read_raw_edf(fpath, verbose=False)

print("Subject info before anonymization")
print("\t", raw.info["subject_info"])
print("\t", raw.info["meas_date"])
print("\t", raw._raw_extras[0]["subject_info"])
print("\t", raw._raw_extras[0]["meas_date"])

raw.anonymize()

print("\t", "\nSubject info after anonymization")
print("\t", raw.info["subject_info"])
print("\t", raw.info["meas_date"])
print("\t", raw._raw_extras[0]["subject_info"])
print("\t", raw._raw_extras[0]["meas_date"])
print(raw._raw_extras[0]["subject_info"])

Expected results

Subject info before anonymization
         {'his_id': 'X', 'sex': 1, 'last_name': 'X', 'birthday': (1967, 10, 9)}
         2016-02-14 10:33:35+00:00
         {'id': 'X', 'sex': 'M', 'birthday': datetime.datetime(1967, 10, 9, 0, 0), 'name': 'X'}
         2016-02-14 10:33:35+00:00

Subject info after anonymization
         {'his_id': '0', 'sex': 0, 'last_name': 'mne_anonymize', 'birthday': (1951, 8, 25)}
         2000-01-01 00:00:00+00:00
         {'id': '0', 'sex': 'unknown', 'birthday': datetime.datetime(1951, 8, 25, 0, 0), 'name': 'mne_anonymize'}
         2000-01-01 00:00:00+00:00

or alternatively

Subject info before anonymization
         {'his_id': 'X', 'sex': 1, 'last_name': 'X', 'birthday': (1967, 10, 9)}
         2016-02-14 10:33:35+00:00
         {'id': 'X', 'sex': 'M', 'birthday': datetime.datetime(1967, 10, 9, 0, 0), 'name': 'X'}
         2016-02-14 10:33:35+00:00

Subject info after anonymization
         {'his_id': 'X'}
         2000-01-01 00:00:00+00:00
         {}
         2000-01-01 00:00:00+00:00

Actual results

Subject info before anonymization
         {'his_id': 'X', 'sex': 1, 'last_name': 'X', 'birthday': (1967, 10, 9)}
         2016-02-14 10:33:35+00:00
         {'id': 'X', 'sex': 'M', 'birthday': datetime.datetime(1967, 10, 9, 0, 0), 'name': 'X'}
         2016-02-14 10:33:35+00:00

Subject info after anonymization
         {'his_id': '0', 'sex': 0, 'last_name': 'mne_anonymize', 'birthday': (1951, 8, 25)}
         2000-01-01 00:00:00+00:00
         {'id': 'X', 'sex': 'M', 'birthday': datetime.datetime(1967, 10, 9, 0, 0), 'name': 'X'}
         2016-02-14 10:33:35+00:00

Additional information

The above code uses the latest release (mne==1.5.1).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions