Skip to content

Commit 74550b8

Browse files
committed
ENH: anonymize_sid - do sanity check that anonymization script produced output
So it will be for the script to just return original sid if it decides to not anonymize it, which is to some degree change in behavior. But I think it would be beneficial in the long run due to more straight-forward and robust operation. Docstring for anon_cmd does not mention that empty output implies no change in subject id
1 parent 5015185 commit 74550b8

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

heudiconv/utils.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,13 @@ def dec(obj):
110110

111111

112112
def anonymize_sid(sid, anon_sid_cmd):
113-
113+
"""
114+
Raises
115+
------
116+
ValueError
117+
if script returned an empty string (after whitespace stripping),
118+
or output with multiple words/lines.
119+
"""
114120
cmd = [anon_sid_cmd, sid]
115121
shell_return = check_output(cmd)
116122

@@ -119,7 +125,14 @@ def anonymize_sid(sid, anon_sid_cmd):
119125
else:
120126
anon_sid = shell_return
121127

122-
return anon_sid.strip()
128+
anon_sid = anon_sid.strip()
129+
if not anon_sid:
130+
raise ValueError(f"{anon_sid_cmd!r} {sid!r} returned empty sid")
131+
# rudimentary check for sanity: no multiple lines or words (in general
132+
# ok, but not ok for BIDS) in the output
133+
if len(anon_sid.split()) > 1:
134+
raise ValueError(f"{anon_sid_cmd!r} {sid!r} returned multiline output")
135+
return anon_sid
123136

124137

125138
def create_file_if_missing(filename, content):

0 commit comments

Comments
 (0)