@@ -521,6 +521,34 @@ def update_uncombined_name(
521521 return filename
522522
523523
524+ def update_multiorient_name (
525+ metadata : dict [str , Any ],
526+ filename : str ,
527+ ) -> str :
528+ if "acq-" in filename :
529+ lgr .warning (
530+ "Not embedding multi-orientation information as prefix already uses acq- parameter."
531+ )
532+ return filename
533+ iop = metadata .get ("ImageOrientationPatientDICOM" )
534+ iop = [round (x ) for x in iop ]
535+ cross_prod = [
536+ iop [1 ] * iop [5 ] - iop [2 ] * iop [4 ],
537+ iop [2 ] * iop [3 ] - iop [0 ] * iop [5 ],
538+ iop [0 ] * iop [4 ] - iop [1 ] * iop [3 ],
539+ ]
540+ cross_prod = [abs (x ) for x in cross_prod ]
541+ slice_orient = ["sagittal" , "coronal" , "axial" ][cross_prod .index (1 )]
542+ bids_pairs = filename .split ("_" )
543+ # acq needs to be inserted right after sub- or ses-
544+ ses_or_sub_idx = sum (
545+ [bids_pair .split ("-" )[0 ] in ["sub" , "ses" ] for bids_pair in bids_pairs ]
546+ )
547+ bids_pairs .insert (ses_or_sub_idx , "acq-%s" % slice_orient )
548+ filename = "_" .join (bids_pairs )
549+ return filename
550+
551+
524552def convert (
525553 items : list [tuple [str , tuple [str , ...], list [str ]]],
526554 converter : str ,
@@ -1029,6 +1057,7 @@ def rename_files() -> None:
10291057 echo_times : set [float ] = set ()
10301058 channel_names : set [str ] = set ()
10311059 image_types : set [str ] = set ()
1060+ iops : set [str ] = set ()
10321061 for metadata in bids_metas :
10331062 if not metadata :
10341063 continue
@@ -1044,6 +1073,12 @@ def rename_files() -> None:
10441073 image_types .update (metadata ["ImageType" ])
10451074 except KeyError :
10461075 pass
1076+ try :
1077+ iops .add (str (metadata ["ImageOrientationPatientDICOM" ]))
1078+ except KeyError :
1079+ pass
1080+
1081+ print (iops )
10471082
10481083 is_multiecho = (
10491084 len (set (filter (bool , echo_times ))) > 1
@@ -1054,6 +1089,7 @@ def rename_files() -> None:
10541089 is_complex = (
10551090 "M" in image_types and "P" in image_types
10561091 ) # Determine if data are complex (magnitude + phase)
1092+ is_multiorient = len (iops ) > 1
10571093 echo_times_lst = sorted (echo_times ) # also converts to list
10581094 channel_names_lst = sorted (channel_names ) # also converts to list
10591095
@@ -1084,6 +1120,11 @@ def rename_files() -> None:
10841120 bids_meta , this_prefix_basename , channel_names_lst
10851121 )
10861122
1123+ if is_multiorient :
1124+ this_prefix_basename = update_multiorient_name (
1125+ bids_meta , this_prefix_basename
1126+ )
1127+
10871128 # Fallback option:
10881129 # If we have failed to modify this_prefix_basename, because it didn't fall
10891130 # into any of the options above, just add the suffix at the end:
0 commit comments