Skip to content

Commit b6eedc7

Browse files
authored
Merge pull request #477 from tsalo/rec-to-part
ENH: Replace rec entity with part entity for complex-valued data
2 parents 1413824 + b1a3e53 commit b6eedc7

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

heudiconv/convert.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def prep_conversion(sid, dicoms, outdir, heuristic, converter, anon_sid,
238238

239239
def update_complex_name(metadata, filename, suffix):
240240
"""
241-
Insert `_rec-<magnitude|phase>` entity into filename if data are from a
241+
Insert `_part-<mag|phase>` entity into filename if data are from a
242242
sequence with magnitude/phase part.
243243
244244
Parameters
@@ -257,15 +257,18 @@ def update_complex_name(metadata, filename, suffix):
257257
Updated filename with rec entity added in appropriate position.
258258
"""
259259
# Some scans separate magnitude/phase differently
260-
unsupported_types = ['_bold', '_phase',
260+
# A small note: _phase is deprecated, but this may add part-mag to
261+
# magnitude data while leaving phase data with a separate suffix,
262+
# depending on how one sets up their heuristic.
263+
unsupported_types = ['_phase',
261264
'_magnitude', '_magnitude1', '_magnitude2',
262265
'_phasediff', '_phase1', '_phase2']
263266
if any(ut in filename for ut in unsupported_types):
264267
return filename
265268

266269
# Check to see if it is magnitude or phase part:
267270
if 'M' in metadata.get('ImageType'):
268-
mag_or_phase = 'magnitude'
271+
mag_or_phase = 'mag'
269272
elif 'P' in metadata.get('ImageType'):
270273
mag_or_phase = 'phase'
271274
else:
@@ -275,19 +278,19 @@ def update_complex_name(metadata, filename, suffix):
275278
filetype = '_' + filename.split('_')[-1]
276279

277280
# Insert rec label
278-
if not ('_rec-%s' % mag_or_phase) in filename:
279-
# If "_rec-" is specified, prepend the 'mag_or_phase' value.
280-
if '_rec-' in filename:
281+
if not ('_part-%s' % mag_or_phase) in filename:
282+
# If "_part-" is specified, prepend the 'mag_or_phase' value.
283+
if '_part-' in filename:
281284
raise BIDSError(
282-
"Reconstruction label for images will be automatically set, "
285+
"Part label for images will be automatically set, "
283286
"remove from heuristic"
284287
)
285288

286289
# Insert it **before** the following string(s), whichever appears first.
287-
for label in ['_dir', '_run', '_mod', '_echo', '_recording', '_proc', '_space', filetype]:
290+
for label in ['_recording', '_proc', '_space', filetype]:
288291
if (label == filetype) or (label in filename):
289292
filename = filename.replace(
290-
label, "_rec-%s%s" % (mag_or_phase, label)
293+
label, "_part-%s%s" % (mag_or_phase, label)
291294
)
292295
break
293296

heudiconv/tests/test_convert.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010

1111
def test_update_complex_name():
1212
"""Unit testing for heudiconv.convert.update_complex_name(), which updates
13-
filenames with the rec field if appropriate.
13+
filenames with the part field if appropriate.
1414
"""
1515
# Standard name update
1616
fn = 'sub-X_ses-Y_task-Z_run-01_sbref'
1717
metadata = {'ImageType': ['ORIGINAL', 'PRIMARY', 'P', 'MB', 'TE3', 'ND', 'MOSAIC']}
1818
suffix = 3
19-
out_fn_true = 'sub-X_ses-Y_task-Z_rec-phase_run-01_sbref'
19+
out_fn_true = 'sub-X_ses-Y_task-Z_run-01_part-phase_sbref'
2020
out_fn_test = update_complex_name(metadata, fn, suffix)
2121
assert out_fn_test == out_fn_true
2222
# Catch an unsupported type and *do not* update
@@ -26,12 +26,12 @@ def test_update_complex_name():
2626
# Data type is missing from metadata so use suffix
2727
fn = 'sub-X_ses-Y_task-Z_run-01_sbref'
2828
metadata = {'ImageType': ['ORIGINAL', 'PRIMARY', 'MB', 'TE3', 'ND', 'MOSAIC']}
29-
out_fn_true = 'sub-X_ses-Y_task-Z_rec-3_run-01_sbref'
29+
out_fn_true = 'sub-X_ses-Y_task-Z_run-01_part-3_sbref'
3030
out_fn_test = update_complex_name(metadata, fn, suffix)
3131
assert out_fn_test == out_fn_true
3232
# Catch existing field with value that *does not match* metadata
3333
# and raise Exception
34-
fn = 'sub-X_ses-Y_task-Z_rec-magnitude_run-01_sbref'
34+
fn = 'sub-X_ses-Y_task-Z_run-01_part-mag_sbref'
3535
metadata = {'ImageType': ['ORIGINAL', 'PRIMARY', 'P', 'MB', 'TE3', 'ND', 'MOSAIC']}
3636
suffix = 3
3737
with pytest.raises(BIDSError):

0 commit comments

Comments
 (0)