@@ -413,12 +413,13 @@ def infotodict(seqinfo):
413
413
skipped , skipped_unknown = [], []
414
414
current_run = 0
415
415
run_label = None # run-
416
- image_data_type = None
416
+ dcm_image_iod_spec = None
417
+ skip_derived = False
417
418
for s in seqinfo :
418
419
# XXX: skip derived sequences, we don't store them to avoid polluting
419
420
# the directory, unless it is the motion corrected ones
420
421
# (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 :
422
423
skipped .append (s .series_id )
423
424
lgr .debug ("Ignoring derived data %s" , s .series_id )
424
425
continue
@@ -433,18 +434,25 @@ def infotodict(seqinfo):
433
434
434
435
# figure out type of image from s.image_info -- just for checking ATM
435
436
# 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
448
456
449
457
protocol_name_tuned = s .protocol_name
450
458
# Few common replacements
@@ -453,8 +461,8 @@ def infotodict(seqinfo):
453
461
454
462
regd = parse_dbic_protocol_name (protocol_name_tuned )
455
463
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 )
458
466
459
467
if not regd :
460
468
skipped_unknown .append (s .series_id )
@@ -490,11 +498,13 @@ def infotodict(seqinfo):
490
498
seqtype_label = 'bold'
491
499
492
500
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" )
493
503
seqtype_label = {
494
504
'M' : 'magnitude' , # might want explicit {file_index} ?
495
505
'P' : 'phasediff' ,
496
506
'DIFFUSION' : 'epi' , # according to KODI those DWI are the EPIs we need
497
- }[image_data_type ]
507
+ }[dcm_image_iod_spec ]
498
508
499
509
# label for dwi as well
500
510
if seqtype == 'dwi' and not seqtype_label :
@@ -507,8 +517,8 @@ def infotodict(seqinfo):
507
517
# some sequences, e.g. fmap, would generate two (or more?)
508
518
# sequences -- e.g. one for magnitude(s) and other ones for
509
519
# 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' :
512
522
# XXX if we have a known earlier study, we need to always
513
523
# increase the run counter for phasediff because magnitudes
514
524
# were not acquired
@@ -517,7 +527,7 @@ def infotodict(seqinfo):
517
527
else :
518
528
raise RuntimeError (
519
529
"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 )
521
531
# else we do nothing special
522
532
else : # and otherwise we go to the next run
523
533
current_run += 1
0 commit comments