-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathsimulate_PET_data_for_tests.sh
executable file
·132 lines (114 loc) · 3.53 KB
/
simulate_PET_data_for_tests.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#! /bin/sh
# A script to simulate some data used by other tests.
# Careful: run_scatter_tests.sh compares with previously generated data
# so you cannot simply modify this one with adjusting that as well.
#
# This script is not intended to be run on its own!
#
# Copyright (C) 2011 - 2011-01-14, Hammersmith Imanet Ltd
# Copyright (C) 2011-07-01 - 2011, Kris Thielemans
# Copyright (C) 2014, 2020, 2022 University College London
# This file is part of STIR.
#
# SPDX-License-Identifier: Apache-2.0
#
# See STIR/LICENSE.txt for details
#
# Author Kris Thielemans
#
echo This script should work with STIR version 6.x. If you have
echo a later version, you might have to update your test pack.
echo Please check the web site.
echo
command -v generate_image >/dev/null 2>&1 || { echo "generate_image not found or not executable. Aborting." >&2; exit 1; }
echo "Using `command -v generate_image`"
force_zero_view_offset=0
TOF=0
suffix=""
#
# Parse option arguments (--)
# Note that the -- is required to suppress interpretation of $1 as options
# to expr
#
while test `expr -- "$1" : "--.*"` -gt 0
do
if test "$1" = "--force_zero_view_offset"
then
force_zero_view_offset=1
elif test "$1" = "--TOF"
then
TOF=1
elif test "$1" = "--suffix"
then
suffix="$2"
shift 1
elif test "$1" = "--help"
then
echo "Usage: `basename $0` [--force_zero_view_offset] [--suffix sometext] [install_dir]"
echo "(where [] means that an argument is optional)"
exit 1
else
echo Warning: Unknown option "$1"
echo rerun with --help for more info.
exit 1
fi
shift 1
done
if [ $# -eq 1 ]; then
echo "Prepending $1 to your PATH for the duration of this script."
PATH=$1:$PATH
fi
# first need to set this to the C locale, as this is what the STIR utilities use
# otherwise, awk might interpret floating point numbers incorrectly
LC_ALL=C
export LC_ALL
echo "=== make emission image"
generate_image generate_uniform_cylinder.par
echo "=== make attenuation image"
generate_image generate_atten_cylinder.par
if [ "$TOF" -eq 0 ]; then
echo "=== create template sinogram (DSTE in 3D with max ring diff 2 to save time)"
template_sino=my_DSTE_3D_rd3_template.hs
cat > my_input.txt <<EOF
Discovery STE
1
n
0
2
EOF
else
echo "=== create template sinogram (D690 in 3D with view-mash =2, TOF-mash=11, max ring diff 3 to save time)"
template_sino=my_D690_3D_rd2_template.hs
cat > my_input.txt <<EOF
Discovery 690
2
11
N
2
3
EOF
fi
create_projdata_template ${template_sino} < my_input.txt > my_create_${template_sino}.log 2>&1
if [ $? -ne 0 ]; then
echo "ERROR running create_projdata_template. Check my_create_${template_sino}.log"; exit 1;
fi
# fix-up header by insert energy info just before the end
# trick for awk comes from the www.theunixschool.com
awk '/END OF INTERFILE/ { print "number of energy windows := 1\nenergy window lower level[1] := 350\nenergy window upper level[1] := 650\nEnergy resolution := 0.22\nReference energy (in keV) := 511" }1 ' \
${template_sino} > tmp_header.hs
mv tmp_header.hs ${template_sino}
if [ $force_zero_view_offset -eq 1 ]; then
if [ "$TOF" -eq 1 ]; then
echo "$0 would need work to be used with both TOF and zero-offset. Exiting"
exit 1
fi
new_template_sino=my_DSTE_3D_rd2_template$suffix.hs
force_view_offset_to_zero.sh ${new_template_sino} ${template_sino}
template_sino=${new_template_sino}
fi
# create sinograms
./simulate_data.sh my_uniform_cylinder.hv my_atten_image.hv ${template_sino} 10 ${suffix}
if [ $? -ne 0 ]; then
echo "Error running simulation"
exit 1
fi