<jupyter_start><jupyter_text>Initial imports<jupyter_code>import stir
import stirextra
import matplotlib.pyplot as plt
import os<jupyter_output><empty_output><jupyter_text>go to directory with input files<jupyter_code># adapt this path to your situation (or start everything in the exercises directory)
os.chdir(os.getenv('STIR_exercises_PATH'))<jupyter_output><empty_output><jupyter_text>change directory to where the output files are<jupyter_code>os.chdir('working_folder/brain')<jupyter_output><empty_output><jupyter_text>initialise reconstruction object<jupyter_code># we will do this here via a .par file 
recon=stir.OSMAPOSLReconstruction3DFloat('OSEM.par')<jupyter_output><empty_output><jupyter_text>check its parameters<jupyter_code># There's quite a few! Most of these are the default values.
# You could compare to the .par file.
print(recon.parameter_info());<jupyter_output><empty_output><jupyter_text>get initial image<jupyter_code># Here we're using image size as set by the parameter file.
# You could read an image instead, and use that for initialisation.
target=recon.get_initial_data_ptr()
# we will just fill the whole array with 1 here
target.fill(1)<jupyter_output><empty_output><jupyter_text>run<jupyter_code>s=recon.set_up(target);
recon.reconstruct(target);<jupyter_output><empty_output><jupyter_text>Display<jupyter_code>plt.figure()
# extract to python for plotting
npimage=stirextra.to_numpy(target);
plt.imshow(npimage[10,:,:])
plt.show()<jupyter_output><empty_output><jupyter_text>save a copy<jupyter_code>reconstructed=target.clone();<jupyter_output><empty_output><jupyter_text>Let's continue for a few more subiterations<jupyter_code># we could just use `set_num_subiterations`, but we will make
# sure that the subiteration counter increases such that selected subsets,
# filenames etc are correct.
previous_nsubiters=recon.get_subiteration_num()
recon.set_start_subiteration_num(previous_nsubiters)
recon.set_num_subiterations(previous_nsubiters+3)
recon.reconstruct(target);
# plot slice of final image
plt.figure()
plt.imshow(npimage[10,:,:])
plt.show()
# What now?
# You could check what other parameter files are available, check their content.
# Advanced topic would be to add some filtering between iterations for regularisation<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09442993907745866, 'fraction_numerical': 0.0034812880765883376, 'mean_word_length': 9.127753303964758, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '395035', 'license': 'Apache-2.0', 'n_tokens_mistral': 794, 'n_tokens_neox': 775, 'n_words': 184, 'path': 'notebooks/reconstruction_demo.ipynb', 'repo_name': 'NikEfth/STIR-exercises', 'size': '2298'}