Exemple #1
0
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
sino_file = 'sino'


#%% redirect STIR messages to some files
# you can check these if things go wrong
msg_red = Pet.MessageRedirector('info.txt', 'warn.txt')


#%% create template and set lm2sino converter
# template for acq_data
template_acq_data = Pet.AcquisitionData('Siemens_mMR', span=11, max_ring_diff=16, view_mash_factor=2)
template_acq_data.write('template.hs')


#%% create listmode-to-sinograms converter object
lm2sino = Pet.ListmodeToSinograms()

# set input, output and template files
lm2sino.set_input(list_file)
lm2sino.set_output_prefix(sino_file)
lm2sino.set_template('template.hs')


#%% from template sinogram, ensure that mu-map has spacing/offset
# that matches the reconstructed image
attn_image = Pet.ImageData(attn_file)
template_image = template_acq_data.create_uniform_image(1.0)

resampler = Reg.NiftyResample()
resampler.set_reference_image(template_image)
resampler.set_floating_image(attn_image)