@@ -118,7 +118,7 @@ def init_bold_fit_wf(
118
118
Parameters
119
119
----------
120
120
bold_series
121
- List of paths to NIfTI files.
121
+ List of paths to NIfTI files, sorted by echo time .
122
122
precomputed
123
123
Dictionary containing precomputed derivatives to reuse, if possible.
124
124
fieldmap_id
@@ -204,27 +204,26 @@ def init_bold_fit_wf(
204
204
205
205
layout = config .execution .layout
206
206
207
- # Collect bold and sbref files, sorted by EchoTime
208
- bold_files = sorted (bold_series , key = lambda fname : layout .get_metadata (fname ).get ("EchoTime" ))
207
+ # Collect sbref files, sorted by EchoTime
209
208
sbref_files = get_sbrefs (
210
- bold_files ,
209
+ bold_series ,
211
210
entity_overrides = config .execution .get ().get ('bids_filters' , {}).get ('sbref' , {}),
212
211
layout = layout ,
213
212
)
214
213
215
214
# Fitting operates on the shortest echo
216
215
# This could become more complicated in the future
217
- bold_file = bold_files [0 ]
216
+ bold_file = bold_series [0 ]
218
217
219
218
# Get metadata from BOLD file(s)
220
- entities = extract_entities (bold_files )
219
+ entities = extract_entities (bold_series )
221
220
metadata = layout .get_metadata (bold_file )
222
221
orientation = "" .join (nb .aff2axcodes (nb .load (bold_file ).affine ))
223
222
224
223
bold_tlen , mem_gb = estimate_bold_mem_usage (bold_file )
225
224
226
225
# Boolean used to update workflow self-descriptions
227
- multiecho = len (bold_files ) > 1
226
+ multiecho = len (bold_series ) > 1
228
227
229
228
have_hmcref = "hmc_boldref" in precomputed
230
229
have_coregref = "coreg_boldref" in precomputed
@@ -699,27 +698,20 @@ def init_bold_native_wf(
699
698
layout = config .execution .layout
700
699
701
700
# Shortest echo first
702
- all_metadata , bold_files , echo_times = zip (
703
- * sorted (
704
- (
705
- (md := layout .get_metadata (bold_file ), bold_file , md .get ("EchoTime" ))
706
- for bold_file in listify (bold_series )
707
- ),
708
- key = lambda x : x [2 ],
709
- )
710
- )
711
- multiecho = len (bold_files ) > 1
701
+ all_metadata = [layout .get_metadata (bold_file ) for bold_file in bold_series ]
702
+ echo_times = [md .get ("EchoTime" ) for md in all_metadata ]
703
+ multiecho = len (bold_series ) > 1
712
704
713
- bold_file = bold_files [0 ]
705
+ bold_file = bold_series [0 ]
714
706
metadata = all_metadata [0 ]
715
707
716
708
bold_tlen , mem_gb = estimate_bold_mem_usage (bold_file )
717
709
718
710
if multiecho :
719
- shapes = [nb .load (echo ).shape for echo in bold_files ]
711
+ shapes = [nb .load (echo ).shape for echo in bold_series ]
720
712
if len (set (shapes )) != 1 :
721
713
diagnostic = "\n " .join (
722
- f"{ os .path .basename (echo )} : { shape } " for echo , shape in zip (bold_files , shapes )
714
+ f"{ os .path .basename (echo )} : { shape } " for echo , shape in zip (bold_series , shapes )
723
715
)
724
716
raise RuntimeError (f"Multi-echo images found with mismatching shapes\n { diagnostic } " )
725
717
if len (shapes ) == 2 :
@@ -774,12 +766,12 @@ def init_bold_native_wf(
774
766
# almost identically
775
767
echo_index = pe .Node (niu .IdentityInterface (fields = ["echoidx" ]), name = "echo_index" )
776
768
if multiecho :
777
- echo_index .iterables = [("echoidx" , range (len (bold_files )))]
769
+ echo_index .iterables = [("echoidx" , range (len (bold_series )))]
778
770
else :
779
771
echo_index .inputs .echoidx = 0
780
772
781
773
# BOLD source: track original BOLD file(s)
782
- bold_source = pe .Node (niu .Select (inlist = bold_files ), name = "bold_source" )
774
+ bold_source = pe .Node (niu .Select (inlist = bold_series ), name = "bold_source" )
783
775
validate_bold = pe .Node (ValidateImage (), name = "validate_bold" )
784
776
workflow .connect ([
785
777
(echo_index , bold_source , [("echoidx" , "index" )]),
0 commit comments