def test_main(rec=False, verb=False, throw=True): pet.MessageRedirector() for scheme in ("file", "memory"): pet.AcquisitionData.set_storage_scheme(scheme) original_verb = pet.get_verbosity() pet.set_verbosity(False) # create an acq_model that is explicitly a RayTracingMatrix am = pet.AcquisitionModelUsingRayTracingMatrix() # load sample data data_path = pet.examples_data_path('PET') raw_data_file = pet.existing_filepath(data_path, 'Utahscat600k_ca_seg4.hs') ad = pet.AcquisitionData(raw_data_file) # create sample image image = pet.ImageData() image.initialise(dim=(31, 111, 111), vsize=(2.25, 2.25, 2.25)) # set up Acquisition Model am.set_up(ad, image) # test for adjointnesss if not is_operator_adjoint(am, verbose=verb): raise AssertionError( 'AcquisitionModelUsingRayTracingMatrix is not adjoint') # Reset original verbose-ness pet.set_verbosity(original_verb) return 0, 1
def test_main(rec=False, verb=False, throw=True): msg_red = pet.MessageRedirector() data_path = pet.examples_data_path('PET') raw_data_file = pet.existing_filepath(data_path, 'mMR/list.l.hdr') lm2sino = pet.ListmodeToSinograms() lm2sino.set_input(raw_data_file) num_prompts_threshold = 73036. known_time = 22. time_at_which_num_prompts_exceeds_threshold = \ lm2sino.get_time_at_which_num_prompts_exceeds_threshold(num_prompts_threshold) if abs(time_at_which_num_prompts_exceeds_threshold - known_time) > 1.e-4: raise AssertionError( "ListmodeToSinograms::get_time_at_which_num_prompts_exceeds_threshold failed" ) return 0, 1
args = docopt(__doc__, version=__version__) # import engine module import sirf.STIR as PET import os from sirf.Utilities import show_2D_array # process command-line options data_file = args['--file'] data_path = args['--path'] print("FILE", __file__) if data_path is None: data_path = os.path.join(os.path.dirname(__file__), '..', '..', 'parameter_files') print(data_path) acq_template_filename = PET.existing_filepath(data_path, data_file) output_file = args['--output'] def main(): ## PET.AcquisitionData.set_storage_scheme('memory') # no info printing from the engine, warnings and errors sent to stdout msg_red = PET.MessageRedirector() # Create a template Acquisition Model #acq_template = AcquisitionData('Siemens mMR', 1, 0, 1) acq_template = PET.AcquisitionData( acq_template_filename) #q.get_uniform_copy() # create the attenuation image
def test_main(rec=False, verb=False, throw=True): # Set STIR verbosity to off original_verb = pet.get_verbosity() pet.set_verbosity(0) time.sleep(0.5) sys.stderr.write("Testing NiftyPET projector...") time.sleep(0.5) data_path = pet.examples_data_path('PET') raw_data_file = pet.existing_filepath(data_path, 'mMR/mMR_template_span11.hs') template_acq_data = pet.AcquisitionData(raw_data_file) # Get image image = get_image() # Get AM try: acq_model = pet.AcquisitionModelUsingNiftyPET() except: return 1, 1 acq_model.set_cuda_verbosity(verb) acq_model.set_up(template_acq_data, image) # Test operator adjointness if verb: print('testing adjointness') if not is_operator_adjoint(acq_model, num_tests=1, verbose=True): raise AssertionError('NiftyPet AcquisitionModel is not adjoint') # Generate test data simulated_acq_data = acq_model.forward(image) simulated_acq_data_w_noise = add_noise(simulated_acq_data, 10) obj_fun = pet.make_Poisson_loglikelihood(template_acq_data) obj_fun.set_acquisition_model(acq_model) recon = pet.OSMAPOSLReconstructor() recon.set_objective_function(obj_fun) recon.set_num_subsets(1) recon.set_num_subiterations(1) recon.set_input(simulated_acq_data_w_noise) if verb: print('setting up, please wait...') initial_estimate = image.get_uniform_copy() recon.set_up(initial_estimate) if verb: print('reconstructing...') recon.set_current_estimate(initial_estimate) recon.process() reconstructed_im = recon.get_output() if not reconstructed_im: raise AssertionError() # Reset original verbose-ness pet.set_verbosity(original_verb) return 0, 1
# import engine module import sirf.STIR as PET from sirf.Utilities import show_2D_array import PET_plot_functions #import os # process command-line options raw_data_file = args['--file'] randoms_data_file = args['--randoms'] acf_file = args['--attenuation_correction_factors'] data_path = args['--path'] if data_path is None: data_path = PET.examples_data_path('PET') + '/mMR' norm_file = PET.existing_filepath(data_path, args['--norm']) mu_map_file = PET.existing_filepath(data_path, args['--attenuation_image']) output_prefix = args['--output'] def main(): # direct all engine's messages to files msg_red = PET.MessageRedirector('info.txt', 'warn.txt', 'errr.txt') PET.AcquisitionData.set_storage_scheme('memory') # Create the Scatter Estimator # We can use a STIR parameter file like this # par_file_path = os.path.join(os.path.dirname(__file__), '..', '..', 'parameter_files') # se = PET.ScatterEstimator(PET.existing_filepath(par_file_path, 'scatter_estimation.par'))
args = docopt(__doc__, version=__version__) # import engine module import sirf.STIR as PET from sirf.Utilities import show_2D_array import PET_plot_functions #import os # process command-line options data_file = args['--file'] data_path = args['--path'] if data_path is None: data_path = '.' raw_data_file = PET.existing_filepath(data_path, data_file) randoms_data_file = args['--randoms'] if not (randoms_data_file is None): randoms_data_file = PET.existing_filepath(data_path, randoms_data_file) norm_file = args['--norm'] if not (norm_file is None): norm_file = PET.existing_filepath(data_path, norm_file) acf_file = args['--attenuation_correction_factors'] if not (acf_file is None): acf_file = PET.existing_filepath(data_path, acf_file) mu_map_file = args['--attenuation_image'] if not (mu_map_file is None): mu_map_file = PET.existing_filepath(data_path, mu_map_file) output_prefix = args['--output']