@@ -280,8 +280,8 @@ def fix_canceled_runs(seqinfo: list[SeqInfo]) -> list[SeqInfo]:
280280 """Function that adds cancelme_ to known bad runs which were forgotten"""
281281 if not fix_accession2run :
282282 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
285285 if accession_number and accession_number in fix_accession2run :
286286 lgr .info (
287287 "Considering some runs possibly marked to be "
@@ -292,12 +292,12 @@ def fix_canceled_runs(seqinfo: list[SeqInfo]) -> list[SeqInfo]:
292292 # a single accession, but left as is for now
293293 badruns = fix_accession2run [accession_number ]
294294 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 ))
297297 fixedkwargs = dict ()
298298 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 )
301301 return seqinfo
302302
303303
@@ -341,19 +341,19 @@ def _apply_substitutions(
341341 seqinfo : list [SeqInfo ], substitutions : list [tuple [str , str ]], subs_scope : str
342342) -> None :
343343 lgr .info ("Considering %s substitutions" , subs_scope )
344- for i , s in enumerate (seqinfo ):
344+ for i , curr_seqinfo in enumerate (seqinfo ):
345345 fixed_kwargs = dict ()
346346 # need to replace both protocol_name series_description
347347 for key in series_spec_fields :
348- oldvalue = value = getattr (s , key )
348+ oldvalue = value = getattr (curr_seqinfo , key )
349349 # replace all I need to replace
350350 for substring , replacement in substitutions :
351351 value = re .sub (substring , replacement , value )
352352 if oldvalue != value :
353353 lgr .info (" %s: %r -> %r" , key , oldvalue , value )
354354 fixed_kwargs [key ] = value
355355 # namedtuples are immutable
356- seqinfo [i ] = s ._replace (** fixed_kwargs )
356+ seqinfo [i ] = curr_seqinfo ._replace (** fixed_kwargs )
357357
358358
359359def fix_seqinfo (seqinfo : list [SeqInfo ]) -> list [SeqInfo ]:
@@ -402,32 +402,34 @@ def infotodict(
402402 run_label : Optional [str ] = None # run-
403403 dcm_image_iod_spec : Optional [str ] = None
404404 skip_derived = False
405- for s in seqinfo :
405+ for curr_seqinfo in seqinfo :
406406 # XXX: skip derived sequences, we don't store them to avoid polluting
407407 # the directory, unless it is the motion corrected ones
408408 # (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 )
412412 continue
413413
414414 # possibly apply present formatting in the series_description or protocol name
415415 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+ )
417419
418420 template = None
419421 suffix = ""
420422 # seq = []
421423
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
423425 # since we primarily rely on encoded in the protocol name information
424426 prev_dcm_image_iod_spec = dcm_image_iod_spec
425- if len (s .image_type ) > 2 :
427+ if len (curr_seqinfo .image_type ) > 2 :
426428 # https://dicom.innolitics.com/ciods/cr-image/general-image/00080008
427429 # 0 - ORIGINAL/DERIVED
428430 # 1 - PRIMARY/SECONDARY
429431 # 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 ]
431433 image_type_datatype = {
432434 # Note: P and M are too generic to make a decision here, could be
433435 # for different datatypes (bold, fmap, etc)
@@ -443,7 +445,7 @@ def infotodict(
443445
444446 series_info = {} # For please lintian and its friends
445447 for sfield in series_spec_fields :
446- svalue = getattr (s , sfield )
448+ svalue = getattr (curr_seqinfo , sfield )
447449 series_info = parse_series_spec (svalue )
448450 if series_info : # looks like a valid spec - we are done
449451 series_spec = svalue
@@ -454,10 +456,10 @@ def infotodict(
454456 if not series_info :
455457 series_spec = None # we cannot know better
456458 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" ,
458460 ", " .join (series_spec_fields ),
459461 )
460- skipped_unknown .append (s .series_id )
462+ skipped_unknown .append (curr_seqinfo .series_id )
461463 continue
462464
463465 if dcm_image_iod_spec and dcm_image_iod_spec .startswith ("MIP" ):
@@ -476,14 +478,14 @@ def infotodict(
476478 series_spec ,
477479 )
478480
479- # if s .is_derived:
481+ # if curr_seqinfo .is_derived:
480482 # # Let's for now stash those close to original images
481483 # # TODO: we might want a separate tree for all of this!?
482484 # # so more of a parameter to the create_key
483485 # #datatype += '/derivative'
484486 # # just keep it lower case and without special characters
485487 # # XXXX what for???
486- # #seq.append(s .series_description.lower())
488+ # #seq.append(curr_seqinfo .series_description.lower())
487489 # prefix = os.path.join('derivatives', 'scanner')
488490 # else:
489491 # prefix = ''
@@ -493,14 +495,14 @@ def infotodict(
493495 # Figure out the datatype_suffix (BIDS _suffix)
494496 #
495497 # 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
497499 if not datatype_suffix :
498500 if datatype == "func" :
499501 if "_pace_" in series_spec :
500502 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 :
502504 datatype_suffix = "phase"
503- elif "M" in s .image_type :
505+ elif "M" in curr_seqinfo .image_type :
504506 datatype_suffix = "bold"
505507 else :
506508 # assume bold by default
@@ -526,7 +528,7 @@ def infotodict(
526528 # since they are complementary files produced along-side with original
527529 # ones.
528530 #
529- if s .series_description .endswith ("_SBRef" ):
531+ if curr_seqinfo .series_description .endswith ("_SBRef" ):
530532 datatype_suffix = "sbref"
531533
532534 if not datatype_suffix :
@@ -550,7 +552,7 @@ def infotodict(
550552 # XXX if we have a known earlier study, we need to always
551553 # increase the run counter for phasediff because magnitudes
552554 # were not acquired
553- if get_study_hash ([s ]) == "9d148e2a05f782273f6343507733309d" :
555+ if get_study_hash ([curr_seqinfo ]) == "9d148e2a05f782273f6343507733309d" :
554556 current_run += 1
555557 else :
556558 raise RuntimeError (
@@ -583,10 +585,10 @@ def infotodict(
583585 run_label = None
584586
585587 # 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'"
588590
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" , "" ):
590592 raise NotImplementedError (
591593 "want to add _rec-moco but there is _rec- already"
592594 )
@@ -611,7 +613,7 @@ def from_series_info(name: str) -> Optional[str]:
611613 from_series_info ("acq" ),
612614 # But we want to add an indicator in case it was motion corrected
613615 # 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" ,
615617 from_series_info ("dir" ),
616618 series_info .get ("bids" ),
617619 run_label ,
@@ -621,7 +623,7 @@ def from_series_info(name: str) -> Optional[str]:
621623 suffix = "_" .join (filter (bool , filename_suffix_parts )) # type: ignore[arg-type]
622624
623625 # # .series_description in case of
624- # sdesc = s .study_description
626+ # sdesc = curr_seqinfo .study_description
625627 # # temporary aliases for those phantoms which we already collected
626628 # # so we rename them into this
627629 # #MAPPING
@@ -638,13 +640,16 @@ def from_series_info(name: str) -> Optional[str]:
638640 # https://github.com/nipy/heudiconv/issues/145
639641 outtype : tuple [str , ...]
640642 if (
641- "_Scout" in s .series_description
643+ "_Scout" in curr_seqinfo .series_description
642644 or (
643645 datatype == "anat"
644646 and datatype_suffix
645647 and datatype_suffix .startswith ("scout" )
646648 )
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+ )
648653 ):
649654 outtype = ("dicom" ,)
650655 else :
@@ -654,7 +659,7 @@ def from_series_info(name: str) -> Optional[str]:
654659 # we wanted ordered dict for consistent demarcation of dups
655660 if template not in info :
656661 info [template ] = []
657- info [template ].append (s .series_id )
662+ info [template ].append (curr_seqinfo .series_id )
658663
659664 if skipped :
660665 lgr .info ("Skipped %d sequences: %s" % (len (skipped ), skipped ))
@@ -762,7 +767,7 @@ def infotoids(seqinfos: Iterable[SeqInfo], outdir: str) -> dict[str, Optional[st
762767
763768 # So -- use `outdir` and locator etc to see if for a given locator/subject
764769 # 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)
766771 # to figure out presence of sessions.
767772 ses_markers : list [str ] = []
768773
0 commit comments