6464
6565
6666def process_files (prompts_header_filename ,
67+ file_prefix = '' ,
6768 mu_map_header = 'umap_00.h33' , # the *.h33 header
6869 randoms_data_filename = 'smoothed_rand_00.s' ,
6970 scatter_2D_header_filename = 'scat_00_00.s.hdr' ,
@@ -98,31 +99,31 @@ def process_files(prompts_header_filename,
9899 # header-name for prompts as we don't want to overwrite the Siemens header
99100 prompts_header_to_read_withSTIR = prompts_header_filename [:- 6 ] + '_readwSTIR.s.hdr'
100101 # STIR writes the (DOI-adapted) prompts out to a STIR-file:
101- prompts_filename_STIR_corr_DOI = 'prompts.hs'
102+ prompts_filename_STIR_corr_DOI = file_prefix + 'prompts.hs'
102103 # STIR writes a non-TOF sinogram, name:
103104 nonTOF_template_sinogram_name = 'template_nonTOF.hs'
104105 # header-name for attenuation correction factors as we don't want to overwrite the Siemens header
105106 attenuation_corr_factor_header_to_read_withSTIR = attenuation_corr_factor_data_filename [:- 2 ] + '_readwSTIR.s.hdr'
106107 # header-name for randoms as we don't want to overwrite the Siemens header
107108 norm_sino_to_read_withSTIR = norm_sino_data_filename [:- 2 ] + '_readwSTIR.s.hdr'
108109 # STIR writes the DOI-adapted, negative corrected norm-sino to
109- norm_filename_fSTIR = 'norm_sino_fSTIR.hs'
110+ norm_filename_fSTIR = file_prefix + 'norm_sino_fSTIR.hs'
110111 # STIR writes the DOI-adapted detection efficiencies to
111- det_effs_filename_fSIRF = 'detection_efficiencies_forSIRF.hs'
112+ det_effs_filename_fSIRF = file_prefix + 'detection_efficiencies_forSIRF.hs'
112113 # header-name for randoms as we don't want to overwrite the Siemens header
113114 randoms_header_to_read_withSTIR = randoms_data_filename [:- 2 ] + '_readwSTIR.s.hdr'
114115 # header-name for randoms as we don't want to overwrite the Siemens header
115116 scatter_2D_header_to_read_withSTIR = scatter_2D_header_filename [:- 6 ] + '_readwSTIR.s.hdr'
116117 # STIR writes the (DOI-adapted) randoms to
117- randoms_adapted_DOI_filename = randoms_data_filename [:- 2 ] + '_fSTIR.hs'
118+ randoms_adapted_DOI_filename = file_prefix + randoms_data_filename [:- 2 ] + '_fSTIR.hs'
118119 # STIR writes the (DOI-adapted), iSSRBd, unnormalized scatter to
119- scatter_3D_unnorm_filename = 'scatter_3D_unnormalized.hs'
120+ scatter_3D_unnorm_filename = file_prefix + 'scatter_3D_unnormalized.hs'
120121 # STIR writes the additive term (that's normalized scatter + normalized randoms, attenuation corrected) to:
121- additive_term_filename_fSTIR = 'additive_term.hs'
122+ additive_term_filename_fSTIR = file_prefix + 'additive_term.hs'
122123 # STIR writes the multiplicative term (that's norm_sino * attenuation_CORRECTION_factors) to:
123- multi_term_filename_fSTIR = 'mult_factors_forSTIR.hs'
124+ multi_term_filename_fSTIR = file_prefix + 'mult_factors_forSTIR.hs'
124125 # STIR writes the multiplicative term for SIRF (that's detection_efficiency_sino * attenuation_factors) to:
125- multi_term_filename_fSIRF = 'mult_factors_forSIRF.hs'
126+ multi_term_filename_fSIRF = file_prefix + 'mult_factors_forSIRF.hs'
126127
127128 #%%
128129 try :
@@ -148,6 +149,10 @@ def process_files(prompts_header_filename,
148149 ## the crystal depth of interaction (DOI) from 7mm to 10mm to minimize the differences.
149150 if apply_DOI_adaption : DOI_adaption (prompts_from_e7 , 10 )
150151
152+ ###################### View Offset ADAPTION ############################
153+
154+ view_offset_adaption (prompts_from_e7 , 0.0324 )
155+
151156 ## write to file so you can use it later
152157 prompts_from_e7 .write_to_file (os .path .join (STIR_output_folder , prompts_filename_STIR_corr_DOI ))
153158
@@ -182,13 +187,24 @@ def process_files(prompts_header_filename,
182187
183188 #### now let's read it from file and plot to see if it worked
184189 mu_map = stir .FloatVoxelsOnCartesianGrid .read_from_file (mu_map_header [:- 3 ]+ 'hv' )
190+ mu_map .write_to_file (os .path .join (STIR_output_folder , file_prefix + 'mu_map.hv' ))
185191 mu_map_arr = stirextra .to_numpy (mu_map )
186192
187193 plt .figure ()
188- plot_2d_image ([1 ,1 ,1 ],mu_map_arr [mu_map_arr .shape [0 ]// 2 ,:,:],'mu-map' )
189- plt .savefig (os .path .join (STIR_output_folder ,'mu_map.png' ), transparent = False , facecolor = 'w' )
194+ plot_2d_image ([1 ,2 ,1 ],mu_map_arr [mu_map_arr .shape [0 ]// 2 ,:,:],'mu-map' , cmap = 'Greys_r' )
195+ plot_2d_image ([1 ,2 ,2 ],mu_map_arr [:,mu_map_arr .shape [1 ]// 2 ,:],'mu-map' , cmap = 'Greys_r' )
196+ plt .savefig (os .path .join (STIR_output_folder , file_prefix + 'mu_map.png' ), transparent = False , facecolor = 'w' )
190197 plt .close ()
191198
199+ #%%
200+ ###################### UNI 1 image ############################
201+ ## to get a uniform 1 image for initialising, use mu-map
202+ ## This is important to match Siemens Image dimensions!!
203+
204+ uni1 = mu_map .get_empty_copy ()
205+ uni1 .fill (1 )
206+ uni1 .write_to_file (os .path .join (STIR_output_folder , file_prefix + 'uni1_img.hv' ))
207+
192208
193209 # %%
194210 ###################### NORMALIZATION ############################
@@ -472,6 +488,15 @@ def DOI_adaption(projdata, DOI_new):
472488 DOI = proj_info .get_scanner ().get_average_depth_of_interaction ()
473489 print ('New Depth of interaction:' , DOI )
474490
491+ def view_offset_adaption (projdata , view_offset ):
492+ proj_info = projdata .get_proj_data_info ()
493+
494+ VO = proj_info .get_scanner ().get_intrinsic_azimuthal_tilt ()
495+ print ('Current view offset (rad):' , VO )
496+ proj_info .get_scanner ().set_intrinsic_azimuthal_tilt (view_offset )
497+ VO = proj_info .get_scanner ().get_average_depth_of_interaction ()
498+ print ('New Depth of interaction(rad):' , VO )
499+
475500def check_if_compressed (header_filename ):
476501 with open (header_filename ) as f :
477502 data = f .read ()
@@ -609,6 +634,7 @@ def remove_tof_dimension(header_name_new, header_name):
609634 prog = 'Vision_files_preprocess.py' ,
610635 description = 'Converts e7tools sinogram files for the Vision into sinogram files that can be read by STIR' )
611636 parser .add_argument ('--prompts_filename_inclPath' , required = True , help = "The filename of the prompts file, including path" )
637+ parser .add_argument ('--file_prefix' , default = '' , help = "A prefix added to all output files" )
612638 parser .add_argument ('--mu_map_header' , default = 'umap_00.h33' , help = "The filename of the mu-map header" )
613639 parser .add_argument ('--randoms_data_filename' , default = 'smoothed_rand_00.s' , help = "The filename of the randoms data" )
614640 parser .add_argument ('--scatter_2D_header_filename' , default = 'scat_00_00.s.hdr' , help = "The filename of the 2D scatter header" )
@@ -619,9 +645,10 @@ def remove_tof_dimension(header_name_new, header_name):
619645 args = parser .parse_args ()
620646
621647 process_files (args .prompts_filename_inclPath ,
648+ file_prefix = args .file_prefix ,
622649 mu_map_header = args .mu_map_header ,
623650 randoms_data_filename = args .randoms_data_filename ,
624651 scatter_2D_header_filename = args .scatter_2D_header_filename ,
625652 norm_sino_data_filename = args .norm_sino_data_filename ,
626653 attenuation_corr_factor_data_filename = args .attenuation_corr_factor_data_filename ,
627- STIR_output_folder = args .STIR_output_folder )
654+ STIR_output_folder = args .STIR_output_folder )
0 commit comments