Skip to content

Commit ebd61cf

Browse files
Georg SchrammGeorg Schramm
authored andcommitted
update README
1 parent 0a506c3 commit ebd61cf

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

README.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ cd python
1414
python 01_analytic_petsird_lm_simulator.py
1515
```
1616

17+
The simulation script creates a binary petsird LM file, but also many other
18+
files (e.g. a reference sensitivity image) that are all stored in the output
19+
directory
20+
```
21+
tree --charset=ascii my_lm_sim
22+
23+
my_lm_sim
24+
|-- reference_histogram_mlem_50_epochs.npy
25+
|-- reference_sensitivity_image.npy
26+
|-- scanner_geometry.png
27+
|-- sim_parameters.json
28+
|-- simulated_lm_file.bin
29+
`-- tof_profile_and_sensitivity_image.png
30+
```
31+
1732
The simulation can be customized in many ways (number of counts to simulate,
1833
uniform or non-uniform efficiencies ...) via command line options.
1934

@@ -22,14 +37,18 @@ These option can be listed via
2237
python 01_analytic_petsird_lm_simulator.py
2338
```
2439

40+
**Note:** The "reference" MLEM using histogrammed data is only run if a
41+
value > 0 is given via `--num_epochs_mlem`. Otherwise it is skipped to save
42+
time.
43+
2544
## Run a listmode OSEM recon on the simulated
2645

2746
```
28-
python 02_recon_block_scanner_listmode_data.py
47+
python 02_lm_osem_recon_simulated_data.py
2948
```
3049

3150
Thes command line optione for the LM OSEM recon script can be listed via
3251
```
33-
python 02_recon_block_scanner_listmode_data.py -h
52+
python 02_lm_osem_recon_simulated_data.py -h
3453
```
3554

python/01_analytic_petsird_lm_simulator.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,9 @@ def parse_float_tuple(arg):
305305
else:
306306
emission_data = img_fwd_tof
307307

308+
# save the ground truth image
309+
xp.save(output_dir / "ground_truth_image.npy", img)
310+
308311
# %%
309312
if num_epochs_mlem > 0:
310313
recon = xp.ones(img_shape, dtype=xp.float32, device=dev)

python/02_recon_block_scanner_listmode_data.py renamed to python/02_lm_osem_recon_simulated_data.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
from pathlib import Path
1919
import argparse
2020

21-
# %%
22-
2321

2422
def transform_to_mat44(
2523
transform: petsird.RigidTransformation,
@@ -87,34 +85,40 @@ def parse_float_tuple(arg):
8785
# %%
8886

8987
parser = argparse.ArgumentParser()
90-
parser.add_argument("--fname", type=str, default="my_lm_sim/simulated_lm_file.bin")
88+
parser.add_argument("--lm_fname", type=str, default="my_lm_sim/simulated_lm_file.bin")
9189
parser.add_argument("--num_epochs", type=int, default=5)
9290
parser.add_argument("--num_subsets", type=int, default=20)
9391
parser.add_argument("--img_shape", type=parse_int_tuple, default=(100, 100, 11))
9492
parser.add_argument("--voxel_size", type=parse_float_tuple, default=(1.0, 1.0, 1.0))
9593
parser.add_argument("--fwhm_mm", type=float, default=1.5)
94+
parser.add_argument("--output_dir", type=str, default="my_lm_sim")
9695

9796
args = parser.parse_args()
9897

99-
fname = args.fname
98+
lm_fname = args.lm_fname
10099
num_epochs = args.num_epochs
101100
num_subsets = args.num_subsets
102101
img_shape = args.img_shape
103102
voxel_size = args.voxel_size
104103
fwhm_mm = args.fwhm_mm
104+
output_dir = Path(args.output_dir)
105105

106106
dev = "cpu"
107+
108+
if not output_dir.exists():
109+
output_dir.mkdir(parents=True)
110+
107111
# %%
108-
if not Path(fname).exists():
112+
if not Path(lm_fname).exists():
109113
raise FileNotFoundError(
110-
f"{args.fname} not found. Create it first using the generator."
114+
f"{args.lm_fname} not found. Create it first using the generator."
111115
)
112116

113117
# %%
114118
# read the scanner geometry
115119

116120

117-
reader = petsird.BinaryPETSIRDReader(fname)
121+
reader = petsird.BinaryPETSIRDReader(lm_fname)
118122
header = reader.read_header()
119123

120124
# %%
@@ -317,3 +321,7 @@ def parse_float_tuple(arg):
317321
recon *= tmp / sens_img
318322

319323
print("")
324+
325+
opath = output_dir / f"lm_osem_{num_epochs}_{num_subsets}.npy"
326+
xp.save(opath, recon)
327+
print(f"LM OSEM recon saved to {opath}")

0 commit comments

Comments
 (0)