@@ -523,6 +523,34 @@ def update_uncombined_name(
523
523
return filename
524
524
525
525
526
+ def update_multiorient_name (
527
+ metadata : dict [str , Any ],
528
+ filename : str ,
529
+ ) -> str :
530
+ if "acq-" in filename :
531
+ lgr .warning (
532
+ "Not embedding multi-orientation information as prefix already uses acq- parameter."
533
+ )
534
+ return filename
535
+ iop = metadata .get ("ImageOrientationPatientDICOM" )
536
+ iop = [round (x ) for x in iop ]
537
+ cross_prod = [
538
+ iop [1 ] * iop [5 ] - iop [2 ] * iop [4 ],
539
+ iop [2 ] * iop [3 ] - iop [0 ] * iop [5 ],
540
+ iop [0 ] * iop [4 ] - iop [1 ] * iop [3 ],
541
+ ]
542
+ cross_prod = [abs (x ) for x in cross_prod ]
543
+ slice_orient = ["sagittal" , "coronal" , "axial" ][cross_prod .index (1 )]
544
+ bids_pairs = filename .split ("_" )
545
+ # acq needs to be inserted right after sub- or ses-
546
+ ses_or_sub_idx = sum (
547
+ [bids_pair .split ("-" )[0 ] in ["sub" , "ses" ] for bids_pair in bids_pairs ]
548
+ )
549
+ bids_pairs .insert (ses_or_sub_idx , "acq-%s" % slice_orient )
550
+ filename = "_" .join (bids_pairs )
551
+ return filename
552
+
553
+
526
554
def convert (
527
555
items : list [tuple [str , tuple [str , ...], list [str ]]],
528
556
converter : str ,
@@ -953,6 +981,7 @@ def save_converted_files(
953
981
echo_times : set [float ] = set ()
954
982
channel_names : set [str ] = set ()
955
983
image_types : set [str ] = set ()
984
+ iops : set [str ] = set ()
956
985
for metadata in bids_metas :
957
986
if not metadata :
958
987
continue
@@ -968,6 +997,10 @@ def save_converted_files(
968
997
image_types .update (metadata ["ImageType" ])
969
998
except KeyError :
970
999
pass
1000
+ try :
1001
+ iops .update (str (metadata ["ImageOrientationPatientDICOM" ]))
1002
+ except KeyError :
1003
+ pass
971
1004
972
1005
is_multiecho = (
973
1006
len (set (filter (bool , echo_times ))) > 1
@@ -978,6 +1011,7 @@ def save_converted_files(
978
1011
is_complex = (
979
1012
"M" in image_types and "P" in image_types
980
1013
) # Determine if data are complex (magnitude + phase)
1014
+ is_multiorient = len (iops ) > 1
981
1015
echo_times_lst = sorted (echo_times ) # also converts to list
982
1016
channel_names_lst = sorted (channel_names ) # also converts to list
983
1017
@@ -1008,6 +1042,11 @@ def save_converted_files(
1008
1042
bids_meta , this_prefix_basename , channel_names_lst
1009
1043
)
1010
1044
1045
+ if is_multiorient :
1046
+ this_prefix_basename = update_multiorient_name (
1047
+ bids_meta , this_prefix_basename
1048
+ )
1049
+
1011
1050
# Fallback option:
1012
1051
# If we have failed to modify this_prefix_basename, because it didn't fall
1013
1052
# into any of the options above, just add the suffix at the end:
0 commit comments