@@ -280,8 +280,8 @@ def fix_canceled_runs(seqinfo: list[SeqInfo]) -> list[SeqInfo]:
280
280
"""Function that adds cancelme_ to known bad runs which were forgotten"""
281
281
if not fix_accession2run :
282
282
return seqinfo # nothing to do
283
- for i , s in enumerate (seqinfo ):
284
- accession_number = s .accession_number
283
+ for i , curr_seqinfo in enumerate (seqinfo ):
284
+ accession_number = curr_seqinfo .accession_number
285
285
if accession_number and accession_number in fix_accession2run :
286
286
lgr .info (
287
287
"Considering some runs possibly marked to be "
@@ -292,12 +292,12 @@ def fix_canceled_runs(seqinfo: list[SeqInfo]) -> list[SeqInfo]:
292
292
# a single accession, but left as is for now
293
293
badruns = fix_accession2run [accession_number ]
294
294
badruns_pattern = "|" .join (badruns )
295
- if re .match (badruns_pattern , s .series_id ):
296
- lgr .info ("Fixing bad run {0}" .format (s .series_id ))
295
+ if re .match (badruns_pattern , curr_seqinfo .series_id ):
296
+ lgr .info ("Fixing bad run {0}" .format (curr_seqinfo .series_id ))
297
297
fixedkwargs = dict ()
298
298
for key in series_spec_fields :
299
- fixedkwargs [key ] = "cancelme_" + getattr (s , key )
300
- seqinfo [i ] = s ._replace (** fixedkwargs )
299
+ fixedkwargs [key ] = "cancelme_" + getattr (curr_seqinfo , key )
300
+ seqinfo [i ] = curr_seqinfo ._replace (** fixedkwargs )
301
301
return seqinfo
302
302
303
303
@@ -341,19 +341,19 @@ def _apply_substitutions(
341
341
seqinfo : list [SeqInfo ], substitutions : list [tuple [str , str ]], subs_scope : str
342
342
) -> None :
343
343
lgr .info ("Considering %s substitutions" , subs_scope )
344
- for i , s in enumerate (seqinfo ):
344
+ for i , curr_seqinfo in enumerate (seqinfo ):
345
345
fixed_kwargs = dict ()
346
346
# need to replace both protocol_name series_description
347
347
for key in series_spec_fields :
348
- oldvalue = value = getattr (s , key )
348
+ oldvalue = value = getattr (curr_seqinfo , key )
349
349
# replace all I need to replace
350
350
for substring , replacement in substitutions :
351
351
value = re .sub (substring , replacement , value )
352
352
if oldvalue != value :
353
353
lgr .info (" %s: %r -> %r" , key , oldvalue , value )
354
354
fixed_kwargs [key ] = value
355
355
# namedtuples are immutable
356
- seqinfo [i ] = s ._replace (** fixed_kwargs )
356
+ seqinfo [i ] = curr_seqinfo ._replace (** fixed_kwargs )
357
357
358
358
359
359
def fix_seqinfo (seqinfo : list [SeqInfo ]) -> list [SeqInfo ]:
@@ -402,32 +402,34 @@ def infotodict(
402
402
run_label : Optional [str ] = None # run-
403
403
dcm_image_iod_spec : Optional [str ] = None
404
404
skip_derived = False
405
- for s in seqinfo :
405
+ for curr_seqinfo in seqinfo :
406
406
# XXX: skip derived sequences, we don't store them to avoid polluting
407
407
# the directory, unless it is the motion corrected ones
408
408
# (will get _rec-moco suffix)
409
- if skip_derived and s .is_derived and not s .is_motion_corrected :
410
- skipped .append (s .series_id )
411
- lgr .debug ("Ignoring derived data %s" , s .series_id )
409
+ if skip_derived and curr_seqinfo .is_derived and not curr_seqinfo .is_motion_corrected :
410
+ skipped .append (curr_seqinfo .series_id )
411
+ lgr .debug ("Ignoring derived data %s" , curr_seqinfo .series_id )
412
412
continue
413
413
414
414
# possibly apply present formatting in the series_description or protocol name
415
415
for f in "series_description" , "protocol_name" :
416
- s = s ._replace (** {f : getattr (s , f ).format (** s ._asdict ())})
416
+ curr_seqinfo = curr_seqinfo ._replace (
417
+ ** {f : getattr (curr_seqinfo , f ).format (** curr_seqinfo ._asdict ())}
418
+ )
417
419
418
420
template = None
419
421
suffix = ""
420
422
# seq = []
421
423
422
- # figure out type of image from s .image_info -- just for checking ATM
424
+ # figure out type of image from curr_seqinfo .image_info -- just for checking ATM
423
425
# since we primarily rely on encoded in the protocol name information
424
426
prev_dcm_image_iod_spec = dcm_image_iod_spec
425
- if len (s .image_type ) > 2 :
427
+ if len (curr_seqinfo .image_type ) > 2 :
426
428
# https://dicom.innolitics.com/ciods/cr-image/general-image/00080008
427
429
# 0 - ORIGINAL/DERIVED
428
430
# 1 - PRIMARY/SECONDARY
429
431
# 3 - Image IOD specific specialization (optional)
430
- dcm_image_iod_spec = s .image_type [2 ]
432
+ dcm_image_iod_spec = curr_seqinfo .image_type [2 ]
431
433
image_type_datatype = {
432
434
# Note: P and M are too generic to make a decision here, could be
433
435
# for different datatypes (bold, fmap, etc)
@@ -443,7 +445,7 @@ def infotodict(
443
445
444
446
series_info = {} # For please lintian and its friends
445
447
for sfield in series_spec_fields :
446
- svalue = getattr (s , sfield )
448
+ svalue = getattr (curr_seqinfo , sfield )
447
449
series_info = parse_series_spec (svalue )
448
450
if series_info : # looks like a valid spec - we are done
449
451
series_spec = svalue
@@ -454,10 +456,10 @@ def infotodict(
454
456
if not series_info :
455
457
series_spec = None # we cannot know better
456
458
lgr .warning (
457
- "Could not determine the series name by looking at " " %s fields" ,
459
+ "Could not determine the series name by looking at %s fields" ,
458
460
", " .join (series_spec_fields ),
459
461
)
460
- skipped_unknown .append (s .series_id )
462
+ skipped_unknown .append (curr_seqinfo .series_id )
461
463
continue
462
464
463
465
if dcm_image_iod_spec and dcm_image_iod_spec .startswith ("MIP" ):
@@ -476,14 +478,14 @@ def infotodict(
476
478
series_spec ,
477
479
)
478
480
479
- # if s .is_derived:
481
+ # if curr_seqinfo .is_derived:
480
482
# # Let's for now stash those close to original images
481
483
# # TODO: we might want a separate tree for all of this!?
482
484
# # so more of a parameter to the create_key
483
485
# #datatype += '/derivative'
484
486
# # just keep it lower case and without special characters
485
487
# # XXXX what for???
486
- # #seq.append(s .series_description.lower())
488
+ # #seq.append(curr_seqinfo .series_description.lower())
487
489
# prefix = os.path.join('derivatives', 'scanner')
488
490
# else:
489
491
# prefix = ''
@@ -493,14 +495,14 @@ def infotodict(
493
495
# Figure out the datatype_suffix (BIDS _suffix)
494
496
#
495
497
# If none was provided -- let's deduce it from the information we find:
496
- # analyze s .protocol_name (series_id is based on it) for full name mapping etc
498
+ # analyze curr_seqinfo .protocol_name (series_id is based on it) for full name mapping etc
497
499
if not datatype_suffix :
498
500
if datatype == "func" :
499
501
if "_pace_" in series_spec :
500
502
datatype_suffix = "pace" # or should it be part of seq-
501
- elif "P" in s .image_type :
503
+ elif "P" in curr_seqinfo .image_type :
502
504
datatype_suffix = "phase"
503
- elif "M" in s .image_type :
505
+ elif "M" in curr_seqinfo .image_type :
504
506
datatype_suffix = "bold"
505
507
else :
506
508
# assume bold by default
@@ -526,7 +528,7 @@ def infotodict(
526
528
# since they are complementary files produced along-side with original
527
529
# ones.
528
530
#
529
- if s .series_description .endswith ("_SBRef" ):
531
+ if curr_seqinfo .series_description .endswith ("_SBRef" ):
530
532
datatype_suffix = "sbref"
531
533
532
534
if not datatype_suffix :
@@ -550,7 +552,7 @@ def infotodict(
550
552
# XXX if we have a known earlier study, we need to always
551
553
# increase the run counter for phasediff because magnitudes
552
554
# were not acquired
553
- if get_study_hash ([s ]) == "9d148e2a05f782273f6343507733309d" :
555
+ if get_study_hash ([curr_seqinfo ]) == "9d148e2a05f782273f6343507733309d" :
554
556
current_run += 1
555
557
else :
556
558
raise RuntimeError (
@@ -583,10 +585,10 @@ def infotodict(
583
585
run_label = None
584
586
585
587
# yoh: had a wrong assumption
586
- # if s .is_motion_corrected:
587
- # assert s .is_derived, "Motion corrected images must be 'derived'"
588
+ # if curr_seqinfo .is_motion_corrected:
589
+ # assert curr_seqinfo .is_derived, "Motion corrected images must be 'derived'"
588
590
589
- if s .is_motion_corrected and "rec-" in series_info .get ("bids" , "" ):
591
+ if curr_seqinfo .is_motion_corrected and "rec-" in series_info .get ("bids" , "" ):
590
592
raise NotImplementedError (
591
593
"want to add _rec-moco but there is _rec- already"
592
594
)
@@ -611,7 +613,7 @@ def from_series_info(name: str) -> Optional[str]:
611
613
from_series_info ("acq" ),
612
614
# But we want to add an indicator in case it was motion corrected
613
615
# in the magnet. ref sample /2017/01/03/qa
614
- None if not s .is_motion_corrected else "rec-moco" ,
616
+ None if not curr_seqinfo .is_motion_corrected else "rec-moco" ,
615
617
from_series_info ("dir" ),
616
618
series_info .get ("bids" ),
617
619
run_label ,
@@ -621,7 +623,7 @@ def from_series_info(name: str) -> Optional[str]:
621
623
suffix = "_" .join (filter (bool , filename_suffix_parts )) # type: ignore[arg-type]
622
624
623
625
# # .series_description in case of
624
- # sdesc = s .study_description
626
+ # sdesc = curr_seqinfo .study_description
625
627
# # temporary aliases for those phantoms which we already collected
626
628
# # so we rename them into this
627
629
# #MAPPING
@@ -638,13 +640,16 @@ def from_series_info(name: str) -> Optional[str]:
638
640
# https://github.com/nipy/heudiconv/issues/145
639
641
outtype : tuple [str , ...]
640
642
if (
641
- "_Scout" in s .series_description
643
+ "_Scout" in curr_seqinfo .series_description
642
644
or (
643
645
datatype == "anat"
644
646
and datatype_suffix
645
647
and datatype_suffix .startswith ("scout" )
646
648
)
647
- or (s .series_description .lower () == s .protocol_name .lower () + "_setter" )
649
+ or (
650
+ curr_seqinfo .series_description .lower ()
651
+ == curr_seqinfo .protocol_name .lower () + "_setter"
652
+ )
648
653
):
649
654
outtype = ("dicom" ,)
650
655
else :
@@ -654,7 +659,7 @@ def from_series_info(name: str) -> Optional[str]:
654
659
# we wanted ordered dict for consistent demarcation of dups
655
660
if template not in info :
656
661
info [template ] = []
657
- info [template ].append (s .series_id )
662
+ info [template ].append (curr_seqinfo .series_id )
658
663
659
664
if skipped :
660
665
lgr .info ("Skipped %d sequences: %s" % (len (skipped ), skipped ))
@@ -762,7 +767,7 @@ def infotoids(seqinfos: Iterable[SeqInfo], outdir: str) -> dict[str, Optional[st
762
767
763
768
# So -- use `outdir` and locator etc to see if for a given locator/subject
764
769
# and possible ses+ in the sequence names, so we would provide a sequence
765
- # So might need to go through parse_series_spec(s .protocol_name)
770
+ # So might need to go through parse_series_spec(curr_seqinfo .protocol_name)
766
771
# to figure out presence of sessions.
767
772
ses_markers : list [str ] = []
768
773
0 commit comments