Skip to content

Commit 939ccfd

Browse files
committed
Rename suffix to suffix_counter in update_complex_name.
The variable name "suffix" is confusing.
1 parent bb5ffdf commit 939ccfd

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

heudiconv/convert.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def prep_conversion(sid, dicoms, outdir, heuristic, converter, anon_sid,
239239
getattr(heuristic, 'DEFAULT_FIELDS', {}))
240240

241241

242-
def update_complex_name(metadata, filename, suffix):
242+
def update_complex_name(metadata, filename, suffix_counter):
243243
"""
244244
Insert `_part-<mag|phase>` entity into filename if data are from a
245245
sequence with magnitude/phase part.
@@ -250,7 +250,7 @@ def update_complex_name(metadata, filename, suffix):
250250
Scan metadata dictionary from BIDS sidecar file.
251251
filename : str
252252
Incoming filename
253-
suffix : str
253+
suffix_counter : str
254254
An index used for cases where a single scan produces multiple files,
255255
but the differences between those files are unknown.
256256
@@ -275,7 +275,7 @@ def update_complex_name(metadata, filename, suffix):
275275
elif 'P' in metadata.get('ImageType'):
276276
mag_or_phase = 'phase'
277277
else:
278-
mag_or_phase = suffix
278+
mag_or_phase = suffix_counter
279279

280280
# Determine scan suffix
281281
filetype = '_' + filename.split('_')[-1]

heudiconv/tests/test_convert.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,38 @@ def test_update_complex_name():
2323
# Standard name update
2424
fn = 'sub-X_ses-Y_task-Z_run-01_sbref'
2525
metadata = {'ImageType': ['ORIGINAL', 'PRIMARY', 'P', 'MB', 'TE3', 'ND', 'MOSAIC']}
26-
suffix = 3
26+
file_counter = 3 # This is the third file with the same name
2727
out_fn_true = 'sub-X_ses-Y_task-Z_run-01_part-phase_sbref'
28-
out_fn_test = update_complex_name(metadata, fn, suffix)
28+
out_fn_test = update_complex_name(metadata, fn, file_counter)
2929
assert out_fn_test == out_fn_true
3030

3131
# Catch an unsupported type and *do not* update
3232
fn = 'sub-X_ses-Y_task-Z_run-01_phase'
33-
out_fn_test = update_complex_name(metadata, fn, suffix)
33+
out_fn_test = update_complex_name(metadata, fn, file_counter)
3434
assert out_fn_test == fn
3535

3636
# Data type is missing from metadata so use suffix
3737
fn = 'sub-X_ses-Y_task-Z_run-01_sbref'
3838
metadata = {'ImageType': ['ORIGINAL', 'PRIMARY', 'MB', 'TE3', 'ND', 'MOSAIC']}
3939
out_fn_true = 'sub-X_ses-Y_task-Z_run-01_part-3_sbref'
40-
out_fn_test = update_complex_name(metadata, fn, suffix)
40+
out_fn_test = update_complex_name(metadata, fn, file_counter)
4141
assert out_fn_test == out_fn_true
4242

43-
# Catch existing field with value that *does not match* metadata
44-
# and raise Exception
43+
# Catch existing field with value (part is already in the filename)
44+
# that *does not match* metadata and raise Exception
4545
fn = 'sub-X_ses-Y_task-Z_run-01_part-mag_sbref'
4646
metadata = {'ImageType': ['ORIGINAL', 'PRIMARY', 'P', 'MB', 'TE3', 'ND', 'MOSAIC']}
47-
suffix = 3
47+
file_counter = 3
4848
with pytest.raises(BIDSError):
49-
assert update_complex_name(metadata, fn, suffix)
49+
update_complex_name(metadata, fn, file_counter)
50+
51+
# Catch existing field with value (part is already in the filename)
52+
# that *does match* metadata and do not update
53+
fn = 'sub-X_ses-Y_task-Z_run-01_part-phase_sbref'
54+
metadata = {'ImageType': ['ORIGINAL', 'PRIMARY', 'P', 'MB', 'TE3', 'ND', 'MOSAIC']}
55+
file_counter = 3
56+
out_fn_test = update_complex_name(metadata, fn, file_counter)
57+
assert out_fn_test == fn
5058

5159

5260
def test_update_multiecho_name():

0 commit comments

Comments
 (0)