Skip to content

Commit

Permalink
BUG: Fix bug with anonymization (#12967)
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner authored Nov 14, 2024
1 parent 060b600 commit d810cc5
Show file tree
Hide file tree
Showing 8 changed files with 207 additions and 87 deletions.
8 changes: 4 additions & 4 deletions mne/_fiff/meas_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,9 @@ class HeliumInfo(ValidatedDict):
_check_types, name='helium_info["orig_file_guid"]', types=str
),
"meas_date": partial(
_check_types, name='helium_info["meas_date"]', types=datetime.datetime
_check_types,
name='helium_info["meas_date"]',
types=(datetime.datetime, None),
),
}

Expand Down Expand Up @@ -3525,9 +3527,7 @@ def anonymize_info(info, daysback=None, keep_his=False, verbose=None):
if none_meas_date and hi.get("meas_date") is not None:
hi["meas_date"] = _ensure_meas_date_none_or_dt(DATE_NONE)
elif hi.get("meas_date") is not None:
hi["meas_date"] = _ensure_meas_date_none_or_dt(
_add_timedelta_to_stamp(hi["meas_date"], -delta_t)
)
hi["meas_date"] = hi["meas_date"] - delta_t

di = info.get("device_info")
if di is not None:
Expand Down
54 changes: 34 additions & 20 deletions mne/_fiff/proc_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,38 @@
write_string,
)

_proc_keys = [
"parent_file_id",
"block_id",
"parent_block_id",
"date",
"experimenter",
"creator",
]
_proc_ids = [
FIFF.FIFF_PARENT_FILE_ID,
FIFF.FIFF_BLOCK_ID,
FIFF.FIFF_PARENT_BLOCK_ID,
FIFF.FIFF_MEAS_DATE,
FIFF.FIFF_EXPERIMENTER,
FIFF.FIFF_CREATOR,
]
_proc_writers = [write_id, write_id, write_id, write_int, write_string, write_string]
_proc_casters = [dict, dict, dict, np.array, str, str]
_proc_map = dict( # ID, caster, writer
parent_file_id=(
FIFF.FIFF_PARENT_FILE_ID,
dict,
write_id,
),
block_id=(
FIFF.FIFF_BLOCK_ID,
dict,
write_id,
),
parent_block_id=(
FIFF.FIFF_PARENT_BLOCK_ID,
dict,
write_id,
),
date=(
FIFF.FIFF_MEAS_DATE,
lambda d: tuple(int(dd) for dd in d),
write_int,
),
experimenter=(
FIFF.FIFF_EXPERIMENTER,
str,
write_string,
),
creator=(
FIFF.FIFF_CREATOR,
str,
write_string,
),
)


def _read_proc_history(fid, tree):
Expand Down Expand Up @@ -98,7 +112,7 @@ def _read_proc_history(fid, tree):
for i_ent in range(proc_record["nent"]):
kind = proc_record["directory"][i_ent].kind
pos = proc_record["directory"][i_ent].pos
for key, id_, cast in zip(_proc_keys, _proc_ids, _proc_casters):
for key, (id_, cast, _) in _proc_map.items():
if kind == id_:
tag = read_tag(fid, pos)
record[key] = cast(tag.data)
Expand All @@ -122,7 +136,7 @@ def _write_proc_history(fid, info):
start_block(fid, FIFF.FIFFB_PROCESSING_HISTORY)
for record in info["proc_history"]:
start_block(fid, FIFF.FIFFB_PROCESSING_RECORD)
for key, id_, writer in zip(_proc_keys, _proc_ids, _proc_writers):
for key, (id_, _, writer) in _proc_map.items():
if key in record:
writer(fid, id_, record[key])
_write_maxfilter_record(fid, record["max_info"])
Expand Down
Loading

0 comments on commit d810cc5

Please sign in to comment.