-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdo_makeimage_tests
executable file
·413 lines (359 loc) · 16 KB
/
do_makeimage_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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
#!/bin/bash
#
# Regression tests for makeimage
# 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. **"
do_fits_tests=$(./python/py_startup_test.py)
if [[ $do_fits_tests == "0" ]]
then
echo -n "Unable to load numpy and/or pyfits Python modules"
echo
echo -n "Tests will skip comparison of FITS files"
fi
if [ ! -f ./makeimage ]
then
echo "*** Unable to find local copy of makeimage! ***"
echo
exit 2
fi
# case "$OSTYPE" in
# darwin*) osname="osx" ;;
# linux*) osname="linux" ;;
# *) echo "unknown: $OSTYPE" ;;
# esac
# create output directory for test_dump*, etc. files (will do nothing if
# directory already exists)
mkdir -p temptest
echo ""
echo "Running tests for makeimage..."
# do we correctly print list of available functions?
./makeimage --list-functions > temptest/test_dump0
# simple tests using small images
./makeimage tests/makeimage_reference/config_biggertest_4c.dat -o temptest/biggertest.fits --ncols 64 --nrows 64 > temptest/test_dump1
./makeimage tests/makeimage_reference/config_makeimage_gensersic512.dat -o temptest/gensersictest.fits > temptest/test_dump2
# test two functions and also --output-functions mode
./makeimage tests/makeimage_reference/config_makeimage_sersic+exp512.dat -o temptest/sersic+exp.fits --output-functions temptest/singleImage > temptest/test_dump3
# same, but now testing --refimage [we assume that tests/gensersictest_orig.fits is 512x512]
./makeimage tests/makeimage_reference/config_makeimage_sersic+exp512_nosize.dat -o temptest/sersic+exp_b.fits --refimage tests/gensersictest_orig.fits > temptest/test_dump3b
# test using PSF convolution:
./makeimage tests/makeimage_reference/config_makeimage_gensersic512.dat -o temptest/gensersictest_conv.fits --psf tests/psf_moffat_35_n4699z.fits > temptest/test_dump4
# test doing --print-fluxes:
./makeimage tests/makeimage_reference/config_makeimage_sersic+exp512.dat --print-fluxes --nosave > temptest/test_dump5
# test doing --print-fluxes with a FlatSky component:
./makeimage tests/makeimage_reference/config_makeimage_sersic+exp512b.dat --print-fluxes --nosave > temptest/test_dump5b
# test doing --save-fluxes:
./makeimage tests/makeimage_reference/config_makeimage_sersic+exp512b.dat --save-fluxes=temptest/savefluxes_out.dat --nosave > temptest/test_dump_null
# tests of --output-functions with PSF convolution:
./makeimage tests/makeimage_reference/config_makeimage_sersic+exp512.dat -o temptest/sersic+exp_conv.fits --output-functions temptest/singleImage_conv --psf tests/psf_moffat_35_n4699z.fits > temptest/test_dump_null
# tests of PSF oversampling: one region (including single-function image output)
./makeimage tests/makeimage_reference/config_makeimage_gauss-oversample.dat -o temptest/oversampled.fits --psf tests/psf_standard.fits --overpsf tests/psf_oversamp.fits --overpsf_scale 3 --overpsf_region 100:110,100:110 --output-functions=temptest/oversampled_single > temptest/test_dump_null
# tests of PSF oversampling: two regions, same PSF
./makeimage tests/makeimage_reference/config_makeimage_gauss-oversample2.dat -o temptest/oversampled2both.fits --psf tests/psf_standard.fits --overpsf tests/psf_oversamp.fits --overpsf_scale 3 --overpsf_region 100:110,100:110 --overpsf_region 20:30,20:30 --output-functions=temptest/oversampled_double > temptest/test_dump_null
# tests of PSF oversampling: two regions, two PSFs
./makeimage tests/makeimage_reference/config_makeimage_gauss-oversample2.dat -o temptest/oversampled2both_2psf.fits --psf tests/psf_standard.fits --overpsf tests/psf_oversamp.fits --overpsf_scale 3 --overpsf_region 100:110,100:110 --overpsf tests/psf_oversamp.fits --overpsf_scale 3 --overpsf_region 20:30,20:30 > temptest/test_dump_null
# tests of PSF oversampling with PointSource model
./makeimage tests/makeimage_reference/config_makeimage_pointsource-oversample.dat -o temptest/oversampled_pointsource.fits --psf tests/psf_standard.fits --overpsf tests/psf_oversamp.fits --overpsf_scale 3 --overpsf_region 80:120,80:120 > temptest/test_dump_null
# Tests that we catch bad input
# testing that bad config files are caught (redirect stderr to temptest/test_dump* files):
./makeimage tests/makeimage_reference/config_makeimage_sersictest512_bad1.dat &> temptest/test_dump6
./makeimage tests/makeimage_reference/config_makeimage_sersictest512_bad2.dat &> temptest/test_dump7
./makeimage tests/makeimage_reference/config_makeimage_sersictest512_bad3.dat &> temptest/test_dump8
./makeimage tests/makeimage_reference/config_makeimage_sersictest512_bad4.dat &> temptest/test_dump9
./makeimage tests/makeimage_reference/config_makeimage_sersictest512_bad5.dat &> temptest/test_dump10
./makeimage tests/makeimage_reference/config_makeimage_sersic+exp512_nosize.dat &> temptest/test_dump11
# testing that bad reference files are caught (redirect stderr to temptest/test_dump* files):
./makeimage tests/makeimage_reference/config_makeimage_sersic+exp512_nosize.dat --refimage=tests/makeimage_reference/config_makeimage_gensersic512.dat &> temptest/test_dump12
# testing that bad PSF files (non-FITS, FITS w/ NaN, nonexistent) are caught
# (redirect stderr to temptest/test_dump* files):
./makeimage tests/makeimage_reference/config_makeimage_sersic+exp512.dat --psf=tests/makeimage_reference/config_makeimage_gensersic512.dat &> temptest/test_dump13
./makeimage tests/makeimage_reference/config_makeimage_sersic+exp512.dat --psf=tests/testimage_3x3_nan.fits &> temptest/test_dump13b
./makeimage tests/makeimage_reference/config_makeimage_sersic+exp512.dat --psf=tests/testimage_3x3_allzeros.fits &> temptest/test_dump13c
./makeimage tests/makeimage_reference/config_makeimage_sersic+exp512.dat --psf=_nofilewiththisname_wehope.fits &> temptest/test_dump14
# more bad config file tests
./makeimage tests/imfit_reference/config_imfit_badparamline.dat &> temptest/test_dump15
# specifying oversampling PSF image but failing to specify one or more oversampling regions
./makeimage tests/makeimage_reference/config_makeimage_gauss-oversample.dat -o temptest/oversampled.fits --psf tests/psf_standard.fits --overpsf tests/psf_oversamp.fits --overpsf_scale 3 &> temptest/test_dump16
echo ""
echo -n "*** Diff comparison with archives: printing function list... "
if (diff --brief temptest/test_dump0 tests/makeimage_reference/makeimage_textout0)
then
echo " OK"
else
echo -e " ${RED}Failed:${NC}Diff output:"
diff temptest/test_dump0 tests/makeimage_reference/makeimage_textout0
STATUS+=1
fi
echo -n "*** Diff comparison with archives: biggertest... "
if (diff --brief temptest/test_dump1 tests/makeimage_reference/makeimage_textout1)
then
echo " OK"
else
echo -e " ${RED}Failed:${NC}Diff output:"
diff temptest/test_dump1 tests/makeimage_reference/makeimage_textout1
STATUS+=1
fi
if [[ $do_fits_tests == "1" ]]
then
./python/compare_fits_files.py temptest/biggertest.fits tests/biggertest_orig.fits
STATUS+=$?
fi
echo -n "*** Diff comparison with archives: gensersictest... "
if (diff --brief temptest/test_dump2 tests/makeimage_reference/makeimage_textout2)
then
echo " OK"
else
echo -e " ${RED}Failed:${NC}Diff output:"
diff temptest/test_dump2 tests/makeimage_reference/makeimage_textout2
STATUS+=1
fi
if [[ $do_fits_tests == "1" ]]
then
./python/compare_fits_files.py temptest/gensersictest.fits tests/gensersictest_orig.fits
STATUS+=$?
fi
echo -n "*** Diff comparison with archives: sersic + exponential... "
if (diff --brief temptest/test_dump3 tests/makeimage_reference/makeimage_textout3)
then
echo " OK"
else
echo -e " ${RED}Failed:${NC}Diff output:"
diff temptest/test_dump3 tests/makeimage_reference/makeimage_textout3
STATUS+=1
fi
if [[ $do_fits_tests == "1" ]]
then
./python/compare_fits_files.py temptest/sersic+exp.fits tests/sersic+exp_orig.fits
STATUS+=$?
fi
if [[ $do_fits_tests == "1" ]]
then
./python/compare_fits_files.py temptest/sersic+exp_b.fits tests/sersic+exp_orig.fits
STATUS+=$?
fi
echo -n "*** Diff comparison with archives: gensersictest + PSF convolution... "
# note that here we are comparing a 512x512 output image with the 512x512 cutout of
# a larger original image (to test that PSF convolution properly handles edges)
if (diff --brief temptest/test_dump4 tests/makeimage_reference/makeimage_textout4)
then
echo " OK"
else
echo -e " ${RED}Failed:${NC}Diff output:"
diff temptest/test_dump4 tests/makeimage_reference/makeimage_textout4
STATUS+=1
fi
if [[ $do_fits_tests == "1" ]]
then
./python/compare_fits_files.py temptest/gensersictest_conv.fits tests/gensersictest612_conv_cutout512.fits
STATUS+=$?
fi
if [[ $do_fits_tests == "1" ]]
echo -n "*** Testing that single-function images add up to combined-function image... "
echo ""
then
./python/compare_fits_files.py --compare-sum temptest/singleImage_conv1_Sersic.fits temptest/singleImage_conv2_Exponential.fits temptest/sersic+exp_conv.fits
STATUS+=$?
fi
# Note that we chose an OS-specific path for the reference file (image output is
# marginally different for Linux vs OS X).
# Also, we only test pixels with values > 1.0e-7, since ~ zero-valued pixels in FFT
# output tend to vary depending on SSE, etc., and we're really only interested in how
# well the PSF convolution of the source reproduces.
if [[ $do_fits_tests == "1" ]]
echo -n "*** Testing that convolution with oversampled PSF works (single region)... "
echo ""
then
./python/compare_fits_files.py --min-value=1.0e-7 temptest/oversampled.fits tests/oversampled_orig.fits
STATUS+=$?
fi
if [[ $do_fits_tests == "1" ]]
echo -n "*** Testing that convolution with oversampled PSF works for single-function output (single region)... "
echo ""
then
./python/compare_fits_files.py --min-value=1.0e-7 temptest/oversampled_single1_Gaussian.fits tests/oversampled_orig.fits
STATUS+=$?
fi
if [[ $do_fits_tests == "1" ]]
echo -n "*** Testing that convolution with oversampled PSF works (two regions, same PSF)... "
echo ""
then
./python/compare_fits_files.py --min-value=1.0e-7 temptest/oversampled2both.fits tests/oversampled2both_orig.fits
STATUS+=$?
fi
if [[ $do_fits_tests == "1" ]]
echo -n "*** Testing that single-function images add up to combined-function image for convolution with oversampled PSF works... "
echo ""
then
./python/compare_fits_files.py --compare-sum --min-value=1.0e-7 temptest/oversampled_double1_Gaussian.fits temptest/oversampled_double2_Gaussian.fits temptest/oversampled2both.fits
STATUS+=$?
fi
if [[ $do_fits_tests == "1" ]]
echo -n "*** Testing that convolution with oversampled PSF works (two regions, 2 PSFs)... "
echo ""
then
./python/compare_fits_files.py --min-value=1.0e-7 temptest/oversampled2both_2psf.fits tests/oversampled2both_orig.fits
STATUS+=$?
fi
if [[ $do_fits_tests == "1" ]]
echo -n "*** Testing that using PointSource function in oversampled region works... "
echo ""
then
./python/compare_fits_files.py --min-value=1.0e-7 temptest/oversampled_pointsource.fits tests/oversampled_pointsource.fits
STATUS+=$?
fi
echo -n "*** Diff comparison with archives: print-fluxes mode... "
if (diff --brief temptest/test_dump5 tests/makeimage_reference/makeimage_textout5)
then
echo " OK"
else
echo -e " ${RED}Failed:${NC}Diff output:"
diff temptest/test_dump5 tests/makeimage_reference/makeimage_textout5
STATUS+=1
fi
echo -n "*** Diff comparison with archives: print-fluxes mode w/ FlatSky component... "
if (diff --brief temptest/test_dump5b tests/makeimage_reference/makeimage_textout5b)
then
echo " OK"
else
echo -e " ${RED}Failed:${NC}Diff output:"
diff temptest/test_dump5b tests/makeimage_reference/makeimage_textout5b
STATUS+=1
fi
echo -n "*** Diff comparison with archives: save-fluxes mode w/ FlatSky component... "
./python/diff_printouts.py tests/makeimage_reference/savefluxes_out.dat temptest/savefluxes_out.dat --skip-first=1
STATUS+=$?
echo -n "*** Diff comparison with archives: bad config file 1... "
if (diff --brief temptest/test_dump6 tests/makeimage_reference/makeimage_textout6)
then
echo " OK"
else
echo -e " ${RED}Failed:${NC}Diff output:"
diff temptest/test_dump6 tests/makeimage_reference/makeimage_textout6
STATUS+=1
fi
echo -n "*** Diff comparison with archives: bad config file 2... "
if (diff --brief temptest/test_dump7 tests/makeimage_reference/makeimage_textout7)
then
echo " OK"
else
echo -e " ${RED}Failed:${NC}Diff output:"
diff temptest/test_dump7 tests/makeimage_reference/makeimage_textout7
STATUS+=1
fi
echo -n "*** Diff comparison with archives: bad config file 3... "
if (diff --brief temptest/test_dump8 tests/makeimage_reference/makeimage_textout8)
then
echo " OK"
else
echo -e " ${RED}Failed:${NC}Diff output:"
diff temptest/test_dump8 tests/makeimage_reference/makeimage_textout8
STATUS+=1
fi
echo -n "*** Diff comparison with archives: bad config file 4... "
if (diff --brief temptest/test_dump9 tests/makeimage_reference/makeimage_textout9)
then
echo " OK"
else
echo -e " ${RED}Failed:${NC}Diff output:"
diff temptest/test_dump9 tests/makeimage_reference/makeimage_textout9
STATUS+=1
fi
echo -n "*** Diff comparison with archives: bad config file 5... "
if (diff --brief temptest/test_dump10 tests/makeimage_reference/makeimage_textout10)
then
echo " OK"
else
echo -e " ${RED}Failed:${NC}Diff output:"
diff temptest/test_dump10 tests/makeimage_reference/makeimage_textout10
STATUS+=1
fi
echo -n "*** Diff comparison with archives: bad config file 6... "
if (diff --brief temptest/test_dump11 tests/makeimage_reference/makeimage_textout11)
then
echo " OK"
else
echo -e " ${RED}Failed:${NC}Diff output:"
diff temptest/test_dump11 tests/makeimage_reference/makeimage_textout11
STATUS+=1
fi
echo -n "*** Diff comparison with archives: bad reference file... "
if (diff --brief temptest/test_dump12 tests/makeimage_reference/makeimage_textout12)
then
echo " OK"
else
echo -e " ${RED}Failed:${NC}Diff output:"
diff temptest/test_dump12 tests/makeimage_reference/makeimage_textout12
STATUS+=1
fi
echo -n "*** Diff comparison with archives: bad PSF-image file... "
if (diff --brief temptest/test_dump13 tests/makeimage_reference/makeimage_textout13)
then
echo " OK"
else
echo -e " ${RED}Failed:${NC}Diff output:"
diff temptest/test_dump13 tests/makeimage_reference/makeimage_textout13
STATUS+=1
fi
echo -n "*** Diff comparison with archives: PSF-image file with NaN values... "
if (diff --brief temptest/test_dump13b tests/makeimage_reference/makeimage_textout13b)
then
echo " OK"
else
echo -e " ${RED}Failed:${NC}Diff output:"
diff temptest/test_dump13b tests/makeimage_reference/makeimage_textout13b
STATUS+=1
fi
echo -n "*** Diff comparison with archives: PSF-image file with all-zero values... "
if (diff --brief temptest/test_dump13c tests/makeimage_reference/makeimage_textout13c)
then
echo " OK"
else
echo -e " ${RED}Failed:${NC}Diff output:"
diff temptest/test_dump13c tests/makeimage_reference/makeimage_textout13c
STATUS+=1
fi
echo -n "*** Diff comparison with archives: non-existent PSF-image file... "
if (diff --brief temptest/test_dump14 tests/makeimage_reference/makeimage_textout14)
then
echo " OK"
else
echo -e " ${RED}Failed:${NC}Diff output:"
diff temptest/test_dump14 tests/makeimage_reference/makeimage_textout14
STATUS+=1
fi
echo -n "*** Diff comparison with archives: bad parameter specification... "
if (diff --brief temptest/test_dump15 tests/makeimage_reference/makeimage_textout15)
then
echo " OK"
else
echo -e " ${RED}Failed:${NC}Diff output:"
diff temptest/test_dump15 tests/makeimage_reference/makeimage_textout15
STATUS+=1
fi
echo -n "*** Diff comparison with archives: oversampled PSF supplied, but no oversampling regions... "
if (diff --brief temptest/test_dump16 tests/makeimage_reference/makeimage_textout16)
then
echo " OK"
else
echo -e " ${RED}Failed:${NC}Diff output:"
diff temptest/test_dump16 tests/makeimage_reference/makeimage_textout16
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