-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdo_mcmc_tests
executable file
·290 lines (242 loc) · 11.2 KB
/
do_mcmc_tests
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#!/bin/bash
#
# Regression tests for imfit-mcmc
#
# Predefine some ANSI color escape codes
RED='\033[0;31m'
GREEN='\033[0;0;32m'
NC='\033[0m' # No Color
# create an integer variable for status (& counting number of failed tests)
declare -i STATUS=0
FAILED_TEXT=" ** Test failed. **"
# create output directory for test_dump*, etc. files (will do nothing if
# directory already exists)
mkdir -p temptest
echo ""
echo "Running tests for imfit-mcmc..."
# simple tests using small images; seed=7 to ensure repeatable pseudo-random numbers
echo -n " (now running MCMC chain (test 1)...)"
./imfit-mcmc tests/faintstar.fits -c tests/imfit-mcmc_reference/config_imfit_faintstar.dat --no-subsampling --seed=7 -o temptest/mcmc_test &> temptest/test_dump_mcmc1
echo ""
if [ "$1" == "--all" ]
then
# same, but now checking that we correct for image offset when we specify subsection
# of data image
echo -n " (now running MCMC chain (test 2)...)"
./imfit-mcmc tests/faintstar.fits[3:10,3:10] -c tests/imfit-mcmc_reference/config_imfit_faintstar.dat --no-subsampling --seed=7 -o temptest/mcmc_test2 &> /dev/null
echo ""
else
echo " (-- skipping test 2 --)"
fi
if [ "$1" == "--all" ]
then
# 2c: testing that we can restart from previous iterations
echo -n " (now running MCMC chain (test 3: restarting from previous chains)...)"
cp tests/mcmc_data/mcmc_test_short*.txt temptest/
# note that there's no point in specifying seed=7, bcs we wouldn't be starting at the same RNG
# state as the original imfit-mcmc run left off at
./imfit-mcmc tests/faintstar.fits -c tests/imfit-mcmc_reference/config_imfit_faintstar.dat --no-subsampling --seed=1 -o temptest/mcmc_test_short --append &> temptest/test_dump_mcmc1c
echo ""
else
echo " (-- skipping test 3 --)"
fi
if [ "$1" == "--all" ]
then
# 4: testing that we handle image sections OK
echo -n " (now running MCMC chain (test 4: using image section)...)"
# note that we only do 2000 steps, since we just want to see if things trend
# in the right direction
./imfit-mcmc examples/ic3478rss_256.fits[60:195,70:185] -c examples/config_sersic_ic3478_256.dat --gain=4.725 --readnoise=4.3 --sky=130.14 --output=temptest/mcmc_test4 --max-chain-length=2000 --seed=1001 &> temptest/test_dump_mcmc1d
echo ""
else
echo " (-- skipping test 4 --)"
fi
# Testing to see if we catch input-image problems: all pixels masked, mismatched image sizes,
# 2a: testing that we catch error: case of all pixels masked:
./imfit-mcmc tests/ic3478rss_64x64.fits -c tests/imfit_reference/imfit_config_ic3478_64x64b.dat --mask tests/totalmask_64x64.fits &> temptest/test_dump2a
# 2b: testing that we catch error: case of mismatched image sizes:
./imfit-mcmc tests/ic3478rss_64x64.fits -c tests/imfit_reference/imfit_config_ic3478_64x64b.dat --mask tests/n3073rss_small_mask.fits &> temptest/test_dump2b
# 2a: testing that we catch bad model-config file: missing parameter limit
./imfit-mcmc tests/faintstar.fits -c tests/imfit-mcmc_reference/config_imfit_faintstar_nolims.dat --no-subsampling --seed=7 &> temptest/test_dump_bad0
./imfit-mcmc -c tests/makeimage_reference/config_makeimage_sersictest512_bad1.dat tests/ic3478rss_64x64.fits &> temptest/test_dump_bad1
./imfit-mcmc -c tests/makeimage_reference/config_makeimage_sersictest512_bad2.dat tests/ic3478rss_64x64.fits &> temptest/test_dump_bad2
./imfit-mcmc -c tests/makeimage_reference/config_makeimage_sersictest512_bad3.dat tests/ic3478rss_64x64.fits &> temptest/test_dump_bad3
./imfit-mcmc -c tests/makeimage_reference/config_makeimage_sersictest512_bad4.dat tests/ic3478rss_64x64.fits &> temptest/test_dump_bad4
./imfit-mcmc -c tests/imfit_reference/config_imfit_sersictest512_badlimits1.dat tests/ic3478rss_64x64.fits &> temptest/test_dump_bad5
./imfit-mcmc -c tests/imfit_reference/config_imfit_sersictest512_badlimits2.dat tests/ic3478rss_64x64.fits &> temptest/test_dump_bad6
./imfit-mcmc -c tests/imfit_reference/config_imfit_sersictest512_badlimits3.dat tests/ic3478rss_64x64.fits &> temptest/test_dump_bad7
./imfit-mcmc -c tests/imfit_reference/config_imfit_sersictest512_badlimits3.dat tests/ic3478rss_64x64.fits &> temptest/test_dump_bad7
./imfit-mcmc -c tests/imfit_reference/config_imfit_badparamline.dat tests/ic3478rss_64x64.fits &> temptest/test_dump_bad8
# Other input testing:
# specifying oversampling PSF image but failing to specify one or more oversampling regions
./imfit-mcmc -c tests/imfit_reference/config_imfit_2gauss_small.dat tests/twogaussian_psf+2osamp_noisy.fits --psf=tests/psf_moffat_35.fits --overpsf tests/psf_moffat_35_oversamp3.fits --overpsf_scale 3 &> temptest/test_dump_nooverpsfregions
echo ""
# Note that we diff only the first n lines to avoid irrelevant variations in the
# elapsed-time output (reported at the end of the file).
printf "*** Diff comparison with archives: first test... "
# skip last 4 lines to avoid trying to compare elapsed times
./python/diff_printouts.py temptest/test_dump_mcmc1 tests/imfit-mcmc_reference/mcmc_textout1 --skip-last=4
STATUS+=$?
printf " Comparing first output chain file from test 1... "
# skip first three lines of output file to avoid comparing timestamps
tail -n +3 temptest/mcmc_test.1.txt > temptest/mcmc_test.1.txt_skip3
if (diff --brief temptest/mcmc_test.1.txt_skip3 tests/imfit-mcmc_reference/mcmc_ref1.1.txt_skip3)
then
printf " OK\n"
else
echo -e " ${RED}Failed:${NC} Output MCMC chain file temptest/mcmc_test.1.txt differs from reference file tests/imfit-mcmc_reference/imfit-mcmc_reference/mcmc_ref1.1.txt_skip3"
STATUS+=1
fi
if [ "$1" == "--all" ]
then
printf " Comparing first output chain file from test 2 (fitting faintstar.fits[3:10,3:10])... "
# skip first two lines of output file to avoid comparing timestamps
tail -n +3 temptest/mcmc_test2.1.txt > temptest/mcmc_test2.1.txt_skip3
if (diff --brief temptest/mcmc_test2.1.txt_skip3 tests/imfit-mcmc_reference/mcmc_ref2.1.txt_skip3)
then
printf " OK\n"
else
echo -e " ${RED}Failed:${NC} Output MCMC chain file temptest/mcmc_test2.1.txt differs from reference file tests/imfit-mcmc_reference/mcmc_ref2.1.txt_skip3"
STATUS+=1
fi
fi
if [ "$1" == "--all" ]
then
printf " Comparing first output chain file from test 3 (restart + append)... "
# skip first two lines of output file to avoid comparing timestamps
tail -n 100 temptest/mcmc_test_short.1.txt > temptest/mcmc_test_short.1.txt_last100
if (diff --brief temptest/mcmc_test_short.1.txt_last100 tests/imfit-mcmc_reference/mcmc_test_short_ref.1.txt_last100)
then
printf " OK\n"
else
echo -e " ${RED}Failed:${NC} Output MCMC chain file temptest/mcmc_test2.1.txt differs from reference file tests/imfit-mcmc_reference/mcmc_test_short_ref.1.txt_last100"
STATUS+=1
fi
fi
if [ "$1" == "--all" ]
then
printf " Comparing first output chain file from test 4 (fitting ic3478rss_256.fits[60:195,70:185])... "
# skip first two lines of output file to avoid comparing timestamps
# note that reference file was generated using imfit-mcmc and a cutout of the
# data image (corresponding to the specified image section)
tail -n +3 temptest/mcmc_test4.1.txt > temptest/mcmc_test4.1.txt_skip3
if (diff --brief temptest/mcmc_test4.1.txt_skip3 tests/imfit-mcmc_reference/mcmc_ref4.1.txt_skip3)
then
printf " OK\n"
else
echo -e " ${RED}Failed:${NC} Output MCMC chain file temptest/mcmc_test4.1.txt differs from reference file tests/imfit-mcmc_reference/mcmc_ref4.1.txt_skip3"
STATUS+=1
fi
fi
echo -n "*** Diff comparison with archives: catching the case of all data pixels masked... "
./python/diff_printouts.py tests/test_dump_mcmc2a temptest/test_dump2a
STATUS+=$?
echo -n "*** Diff comparison with archives: catching the case of mismatch in data and mask sizes... "
./python/diff_printouts.py tests/test_dump_mcmc2b temptest/test_dump2b
STATUS+=$?
# Note that for the following, we can compare with the imfit reference files,
# because the output should be the same
echo -n "*** Diff comparison with archives: bad config file 0 (missing parameter limits)... "
if (diff --brief temptest/test_dump_bad0 tests/imfit_reference/imfit_textout_bad0)
then
echo " OK"
else
echo -e " ${RED}Failed:${NC} Diff output:"
diff temptest/test_dump_bad0 tests/imfit_reference/imfit_textout_bad0
STATUS+=1
fi
echo -n "*** Diff comparison with archives: bad config file 1... "
if (diff --brief temptest/test_dump_bad1 tests/imfit_reference/imfit_textout_bad1)
then
echo " OK"
else
echo -e " ${RED}Failed:${NC} Diff output:"
diff temptest/test_dump_bad1 tests/imfit_reference/imfit_textout_bad1
STATUS+=1
fi
echo -n "*** Diff comparison with archives: bad config file 2... "
if (diff --brief temptest/test_dump_bad2 tests/imfit_reference/imfit_textout_bad2)
then
echo " OK"
else
echo -e " ${RED}Failed:${NC} Diff output:"
diff temptest/test_dump_bad2 tests/imfit_reference/imfit_textout_bad2
STATUS+=1
fi
echo -n "*** Diff comparison with archives: bad config file 3... "
if (diff --brief temptest/test_dump_bad3 tests/imfit_reference/imfit_textout_bad3)
then
echo " OK"
else
echo -e " ${RED}Failed:${NC} Diff output:"
diff temptest/test_dump_bad3 tests/imfit_reference/imfit_textout_bad3
STATUS+=1
fi
echo -n "*** Diff comparison with archives: bad config file 4... "
if (diff --brief temptest/test_dump_bad4 tests/imfit_reference/imfit_textout_bad4)
then
echo " OK"
else
echo -e " ${RED}Failed:${NC} Diff output:"
diff temptest/test_dump_bad4 tests/imfit_reference/imfit_textout_bad4
STATUS+=1
fi
echo -n "*** Diff comparison with archives: bad config file 5... "
if (diff --brief temptest/test_dump_bad5 tests/imfit_reference/imfit_textout_bad5)
then
echo " OK"
else
echo -e " ${RED}Failed:${NC} Diff output:"
diff temptest/test_dump_bad5 tests/imfit_reference/imfit_textout_bad5
STATUS+=1
fi
echo -n "*** Diff comparison with archives: bad config file 6... "
if (diff --brief temptest/test_dump_bad6 tests/imfit_reference/imfit_textout_bad6)
then
echo " OK"
else
echo -e " ${RED}Failed:${NC} Diff output:"
diff temptest/test_dump_bad6 tests/imfit_reference/imfit_textout_bad6
STATUS+=1
fi
echo -n "*** Diff comparison with archives: bad config file 7... "
if (diff --brief temptest/test_dump_bad7 tests/imfit_reference/imfit_textout_bad7)
then
echo " OK"
else
echo -e " ${RED}Failed:${NC} Diff output:"
diff temptest/test_dump_bad7 tests/imfit_reference/imfit_textout_bad7
STATUS+=1
fi
echo -n "*** Diff comparison with archives: bad parameter specification... "
if (diff --brief temptest/test_dump_bad8 tests/imfit_reference/imfit_textout_bad8)
then
echo " OK"
else
echo -e " ${RED}Failed:${NC} Diff output:"
diff temptest/test_dump_bad8 tests/imfit_reference/imfit_textout_bad8
STATUS+=1
fi
echo -n "*** Diff comparison with archives: oversampled PSF supplied, but no oversampling regions... "
if (diff --brief temptest/test_dump_nooverpsfregions tests/imfit_reference/imfit_textout_nooverpsfregions)
then
echo " OK"
else
echo -e " ${RED}Failed:${NC}Diff output:"
diff temptest/test_dump_nooverpsfregions tests/imfit_reference/imfit_textout_nooverpsfregions
STATUS+=1
fi
echo ""
if [ $STATUS -eq 1 ]
then
echo -e "${RED}One test failed!${NC}"
elif [ $STATUS -gt 1 ]
then
echo -e "${RED}${STATUS} tests failed!${NC}"
else
echo -e "${GREEN}All tests passed.${NC}"
fi
echo ""
echo "Done."
echo ""
exit $STATUS