@@ -140,11 +140,9 @@ def gradient_distortion_correction(wf, inp_image, name):
140140 return (wf , out_warpmask , out_applywarp )
141141
142142
143- def phase_encode (unwarp_dir , phase_one , phase_two , dwell_time_one ,
144- dwell_time_two ):
145- """
146-
147- Calculate readout time and populate parameter file
143+ def phase_encode (unwarp_dir , phase_one , phase_two , dwell_time_one = None ,
144+ dwell_time_two = None , ro_time_one = None , ro_time_two = None ):
145+ """Calculate readout time and populate parameter file
148146
149147 Parameters
150148 __________
@@ -159,8 +157,10 @@ def phase_encode(unwarp_dir, phase_one, phase_two, dwell_time_one,
159157 echo spacing of phase one
160158 dwell_time_two
161159 echo spacing of phase two
162- fsl_dir
163- FSL directory
160+ ro_time_one
161+ total readout time of phase one
162+ ro_time_two
163+ total readout time of phase two
164164
165165 Returns
166166 _______
@@ -177,22 +177,30 @@ def phase_encode(unwarp_dir, phase_one, phase_two, dwell_time_one,
177177 unwarp_dir = unwarp_dir .decode ()
178178
179179 if unwarp_dir in ["x" , "x-" , "-x" ,"i" ,"-i" ,"i-" ]:
180- dim = nibabel .load (phase_one ).shape [0 ]
181- n_PE_steps = dim - 1
182- ro_time_one = np .round (dwell_time_one * n_PE_steps , 6 )
183- ro_time_two = np .round (dwell_time_two * n_PE_steps , 6 )
180+ if not ro_time_one or not ro_time_two :
181+ if dwell_time_one and dwell_time_two :
182+ dim = nibabel .load (phase_one ).shape [0 ]
183+ n_PE_steps = dim - 1
184+ ro_time_one = np .round (dwell_time_one * n_PE_steps , 6 )
185+ ro_time_two = np .round (dwell_time_two * n_PE_steps , 6 )
186+ else :
187+ raise Exception ("[!] No dwell time or total readout time "
188+ "present for the acq-fMRI EPI field maps." )
184189 ro_times = [f"-1 0 0 { ro_time_one } " , f"1 0 0 { ro_time_two } " ]
185190 elif unwarp_dir in ["y" , "y-" , "-y" ,"j" ,"-j" ,"j-" ]:
186- dim = nibabel .load (phase_one ).shape [1 ]
187- n_PE_steps = dim - 1
188- ro_time_one = np .round (dwell_time_one * n_PE_steps , 6 )
189- ro_time_two = np .round (dwell_time_two * n_PE_steps , 6 )
191+ if not ro_time_one or not ro_time_two :
192+ if dwell_time_one and dwell_time_two :
193+ dim = nibabel .load (phase_one ).shape [1 ]
194+ n_PE_steps = dim - 1
195+ ro_time_one = np .round (dwell_time_one * n_PE_steps , 6 )
196+ ro_time_two = np .round (dwell_time_two * n_PE_steps , 6 )
197+ else :
198+ raise Exception ("[!] No dwell time or total readout time "
199+ "present for the acq-fMRI EPI field maps." )
190200 ro_times = [f"0 -1 0 { ro_time_one } " , f"0 1 0 { ro_time_two } " ]
191201 else :
192202 raise Exception (f"unwarp_dir={ unwarp_dir } is unsupported." )
193203
194-
195-
196204 # get number of volumes
197205 dims = [
198206 int (subprocess .check_output ([f"fslval" , phase_one , "dim4" ]).decode (sys .stdout .encoding )),
0 commit comments