Skip to content

Commit 14a5a33

Browse files
committed
RF: reproin - make possible to convert derived, make IOD fields in image type optional
1 parent e1dd902 commit 14a5a33

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed

heudiconv/heuristics/reproin.py

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -413,12 +413,13 @@ def infotodict(seqinfo):
413413
skipped, skipped_unknown = [], []
414414
current_run = 0
415415
run_label = None # run-
416-
image_data_type = None
416+
dcm_image_iod_spec = None
417+
skip_derived = False
417418
for s in seqinfo:
418419
# XXX: skip derived sequences, we don't store them to avoid polluting
419420
# the directory, unless it is the motion corrected ones
420421
# (will get _rec-moco suffix)
421-
if s.is_derived and not s.is_motion_corrected:
422+
if skip_derived and s.is_derived and not s.is_motion_corrected:
422423
skipped.append(s.series_id)
423424
lgr.debug("Ignoring derived data %s", s.series_id)
424425
continue
@@ -433,18 +434,25 @@ def infotodict(seqinfo):
433434

434435
# figure out type of image from s.image_info -- just for checking ATM
435436
# since we primarily rely on encoded in the protocol name information
436-
prev_image_data_type = image_data_type
437-
image_data_type = s.image_type[2]
438-
image_type_seqtype = {
439-
'P': 'fmap', # phase
440-
'FMRI': 'func',
441-
'MPR': 'anat',
442-
# 'M': 'func', "magnitude" -- can be for scout, anat, bold, fmap
443-
'DIFFUSION': 'dwi',
444-
'MIP_SAG': 'anat', # angiography
445-
'MIP_COR': 'anat', # angiography
446-
'MIP_TRA': 'anat', # angiography
447-
}.get(image_data_type, None)
437+
prev_dcm_image_iod_spec = dcm_image_iod_spec
438+
if len(s.image_type) > 2:
439+
# https://dicom.innolitics.com/ciods/cr-image/general-image/00080008
440+
# 0 - ORIGINAL/DERIVED
441+
# 1 - PRIMARY/SECONDARY
442+
# 3 - Image IOD specific specialization (optional)
443+
dcm_image_iod_spec = s.image_type[2]
444+
image_type_seqtype = {
445+
'P': 'fmap', # phase
446+
'FMRI': 'func',
447+
'MPR': 'anat',
448+
# 'M': 'func', "magnitude" -- can be for scout, anat, bold, fmap
449+
'DIFFUSION': 'dwi',
450+
'MIP_SAG': 'anat', # angiography
451+
'MIP_COR': 'anat', # angiography
452+
'MIP_TRA': 'anat', # angiography
453+
}.get(dcm_image_iod_spec, None)
454+
else:
455+
dcm_image_iod_spec = image_type_seqtype = None
448456

449457
protocol_name_tuned = s.protocol_name
450458
# Few common replacements
@@ -453,8 +461,8 @@ def infotodict(seqinfo):
453461

454462
regd = parse_dbic_protocol_name(protocol_name_tuned)
455463

456-
if image_data_type.startswith('MIP'):
457-
regd['acq'] = regd.get('acq', '') + sanitize_str(image_data_type)
464+
if dcm_image_iod_spec and dcm_image_iod_spec.startswith('MIP'):
465+
regd['acq'] = regd.get('acq', '') + sanitize_str(dcm_image_iod_spec)
458466

459467
if not regd:
460468
skipped_unknown.append(s.series_id)
@@ -490,11 +498,13 @@ def infotodict(seqinfo):
490498
seqtype_label = 'bold'
491499

492500
if seqtype == 'fmap' and not seqtype_label:
501+
if not dcm_image_iod_spec:
502+
raise ValueError("Do not know image data type yet to make decision")
493503
seqtype_label = {
494504
'M': 'magnitude', # might want explicit {file_index} ?
495505
'P': 'phasediff',
496506
'DIFFUSION': 'epi', # according to KODI those DWI are the EPIs we need
497-
}[image_data_type]
507+
}[dcm_image_iod_spec]
498508

499509
# label for dwi as well
500510
if seqtype == 'dwi' and not seqtype_label:
@@ -507,8 +517,8 @@ def infotodict(seqinfo):
507517
# some sequences, e.g. fmap, would generate two (or more?)
508518
# sequences -- e.g. one for magnitude(s) and other ones for
509519
# phases. In those we must not increment run!
510-
if image_data_type == 'P':
511-
if prev_image_data_type != 'M':
520+
if dcm_image_iod_spec and dcm_image_iod_spec == 'P':
521+
if prev_dcm_image_iod_spec != 'M':
512522
# XXX if we have a known earlier study, we need to always
513523
# increase the run counter for phasediff because magnitudes
514524
# were not acquired
@@ -517,7 +527,7 @@ def infotodict(seqinfo):
517527
else:
518528
raise RuntimeError(
519529
"Was expecting phase image to follow magnitude "
520-
"image, but previous one was %r", prev_image_data_type)
530+
"image, but previous one was %r", prev_dcm_image_iod_spec)
521531
# else we do nothing special
522532
else: # and otherwise we go to the next run
523533
current_run += 1

0 commit comments

Comments
 (0)