-
Notifications
You must be signed in to change notification settings - Fork 7
/
testing_imfit_with_oversampling.txt
431 lines (345 loc) · 13.8 KB
/
testing_imfit_with_oversampling.txt
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
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
# Commands to test oversampled-PSF convolution with imfit (and output from running them)
All should be executed in oversample_testing/ subdirectory
# [X]0. Make some initial PSF images, etc.
# Non-oversampled Gaussian PSF:
../makeimage config_makeimage_gauss-psf_for_test.dat -o psf_standard.fits
# 3x3-oversampled PSF:
../makeimage config_makeimage_gauss-psf_for_test_oversamp.dat -o psf_oversamp.fits
# test image: convolved with non-oversampled PSF *and* with inner 10x10 pixels around
# function center convolved with 3x3-oversampled PSF:
../makeimage config_makeimage_target_200.dat -o oversamp_test1.fits --psf psf_standard.fits --overpsf psf_oversamp.fits --overpsf_scale 3 --overpsf_region 100:110,100:110
# [X]1. Test: fit oversampled Gaussian image using *standard* PSF (no oversampling)
../imfit -c config_imfit_gauss-oversample-test.dat --gain=100 --mlr --nm oversamp_test1.fits --psf psf_standard.fits
POISSON-MLR STATISTIC = 0.000105
Reduced Chi^2 = 0.000000
AIC = 8.001106, BIC = 42.386644
X0 105.0000
Y0 105.0000
FUNCTION Gaussian
PA 0
ell 0
I_0 0.999964
sigma 10.0001
# Test: fit same image using oversampling
../imfit -c config_imfit_gauss-oversample-test.dat --gain=100 --mlr --nm oversamp_test1.fits --psf psf_standard.fits --overpsf psf_oversamp.fits --overpsf_scale 3 --overpsf_region 100:110,100:110
POISSON-MLR STATISTIC = 0.000000
Reduced Chi^2 = 0.000000
AIC = 8.001000, BIC = 42.386539
X0 105.0000
Y0 105.0000
FUNCTION Gaussian
PA 0
ell 0
I_0 1
sigma 10
Marginally better fit and better agreement with original model when using PSF oversampling!
# [x]2. Test: fit oversampled *narrow* Gaussian (sigma = 1.2 pix, centered in x,y = 105,105)
# A. Generate model image using oversampling
$ ../makeimage config_makeimage_target_200_narrow.dat -o oversamp_test2.fits --psf psf_standard.fits --overpsf psf_oversamp.fits --overpsf_scale 3 --overpsf_region 100:110,100:110
# A. fit oversampled Gaussian image using *standard* PSF (no oversampling)
../imfit -c config_imfit_gauss-oversample-test2.dat --gain=100 --mlr --nm oversamp_test2.fits --psf psf_standard.fits
POISSON-MLR STATISTIC = 0.000968
Reduced Chi^2 = 0.000000
AIC = 8.001968, BIC = 42.387507
X0 105.0000
Y0 105.0000
FUNCTION Gaussian
PA 0
ell 0
I_0 99.8532
sigma 1.2007
# B. fit same image using oversampling
../imfit -c config_imfit_gauss-oversample-test2.dat --gain=100 --mlr --nm oversamp_test2.fits --psf psf_standard.fits --overpsf psf_oversamp.fits --overpsf_scale 3 --overpsf_region 100:110,100:110
POISSON-MLR STATISTIC = 0.000057
Reduced Chi^2 = 0.000000
AIC = 8.001058, BIC = 42.386596
X0 105.0000
Y0 105.0000
FUNCTION Gaussian
PA 0
ell 0
I_0 99.9857
sigma 1.20009
Again, marginally better fit and better agreement with original model!
# [x]3. Same, but now using 10x10 oversampled PSF
# A. Make 10x10 oversampled PSF (sigma = 30 oversampled pix = 3 standard pix)
../makeimage config_makeimage_gauss-psf_for_test_scale10.dat -o psf_oversamp10.fits
# B. Generate model image with using 10x10 oversampling
../makeimage config_makeimage_target_200_narrow.dat -o oversamp_test3.fits --psf psf_standard.fits --overpsf psf_oversamp10.fits --overpsf_scale 10 --overpsf_region 100:110,100:110
# C. Fit with standard (non-oversampled) PSF
../imfit -c config_imfit_gauss-oversample-test2.dat --gain=100 --mlr --nm oversamp_test3.fits --psf psf_standard.fits
POISSON-MLR STATISTIC = 0.003459
Reduced Chi^2 = 0.000000
AIC = 8.004460, BIC = 42.389998
X0 105.0000
Y0 105.0000
FUNCTION Gaussian
PA 0
ell 0
I_0 99.7358
sigma 1.2013
[time ~ 2s]
# D. Fit with 3x3 oversampling
../imfit -c config_imfit_gauss-oversample-test2.dat --gain=100 --mlr --nm oversamp_test3.fits --psf psf_standard.fits --overpsf psf_oversamp.fits --overpsf_scale 3 --overpsf_region 100:110,100:110
POISSON-MLR STATISTIC = 0.001706
Reduced Chi^2 = 0.000000
AIC = 8.002706, BIC = 42.388245
X0 105.0000
Y0 105.0000
FUNCTION Gaussian
PA 0
ell 0
I_0 99.8686
sigma 1.20069
[time ~ 8s]
# E. Fit with 10x10 oversampling
../imfit -c config_imfit_gauss-oversample-test2.dat --gain=100 --mlr --nm oversamp_test3.fits --psf psf_standard.fits --overpsf psf_oversamp10.fits --overpsf_scale 10 --overpsf_region 100:110,100:110
POISSON-MLR STATISTIC = 0.000060
Reduced Chi^2 = 0.000000
AIC = 8.001061, BIC = 42.386599
X0 105.0000
Y0 105.0000
FUNCTION Gaussian
PA 0
ell 0
I_0 99.9849
sigma 1.2001
[time ~ 58s]
# [x]4. Same, but now model with center not in center of pixel: (105.2377, 105.4582)
# A. Generate non-pixel-centered model image using 10x10 oversampling
../makeimage config_makeimage_target_200_narrow_off-center.dat -o oversamp_test4.fits --psf psf_standard.fits --overpsf psf_oversamp10.fits --overpsf_scale 10 --overpsf_region 100:110,100:110
# B. Fit with standard (non-oversampled) PSF
../imfit -c config_imfit_gauss-oversample-test2.dat --gain=100 --mlr --nm oversamp_test4.fits --psf psf_standard.fits
POISSON-MLR STATISTIC = 0.003884
Reduced Chi^2 equivalent = 0.000000
AIC = 8.004884, BIC = 42.390423
X0 105.2377 [agrees perfectly with input]
Y0 105.4582 [agrees perfectly with input]
FUNCTION Gaussian
PA 0
ell 0
I_0 99.7433
sigma 1.20124
# C. Fit with 3x3 oversampling
../imfit -c config_imfit_gauss-oversample-test2.dat --gain=100 --mlr --nm oversamp_test4.fits --psf psf_standard.fits --overpsf psf_oversamp.fits --overpsf_scale 3 --overpsf_region 100:110,100:110
POISSON-MLR STATISTIC = 0.001855
Reduced Chi^2 equivalent = 0.000000
AIC = 8.002855, BIC = 42.388394
X0 105.2377
Y0 105.4582
FUNCTION Gaussian
PA 0
ell 0
I_0 99.8787
sigma 1.20062
# D. Fit with 10x10 oversampling
../imfit -c config_imfit_gauss-oversample-test2.dat --gain=100 --mlr --nm oversamp_test4.fits --psf psf_standard.fits --overpsf psf_oversamp10.fits --overpsf_scale 10 --overpsf_region 100:110,100:110
POISSON-MLR STATISTIC = 0.000000
Reduced Chi^2 equivalent = 0.000000
AIC = 8.001000, BIC = 42.386539
X0 105.2377
Y0 105.4582
FUNCTION Gaussian
PA 0
ell 0
I_0 100
sigma 1.2
# [x]5. Same, but using narrow PSF (sigma = 0.64 pix)
# A. Make standard-sampled PSF with sigma = 0.64 (fwhm ~ 1.5)
../makeimage config_makeimage_narrow-gauss-psf_for_test.dat -o psf_standard_sigma0.64.fits
# Make oversampled 3x3 PSF with sigma = 0.64 (sigma = 1.92 oversampled pix = 0.64 standard pix)
../makeimage config_makeimage_narrow-gauss-psf_for_test_scale3.dat -o psf_sigma_0.64_oversamp3.fits
# Make oversampled 10x10 PSF with sigma = 0.64 (sigma = 6.4 oversampled pix = 0.64 standard pix)
../makeimage config_makeimage_narrow-gauss-psf_for_test_scale10.dat -o psf_sigma_0.64_oversamp10.fits
# B. Generate non-pixel-centered model image with using 10x10 oversampling
../makeimage config_makeimage_target_200_narrow_off-center.dat -o oversamp_test5.fits --psf psf_standard_sigma0.64.fits --overpsf psf_sigma_0.64_oversamp10.fits --overpsf_scale 10 --overpsf_region 100:110,100:110
# C. Fit with standard (non-oversampled) PSF
../imfit -c config_imfit_gauss-oversample-test2.dat --gain=100 --mlr --nm oversamp_test5.fits --psf psf_standard_sigma0.64.fits
POISSON-MLR STATISTIC = 0.085738
Reduced Chi^2 equivalent = 0.000002
AIC = 8.086738, BIC = 42.472277
X0 105.2377
Y0 105.4582
FUNCTION Gaussian
PA 0
ell 0
I_0 99.9942
sigma 1.20004
[time ~ 1.6s]
# D. Fit with 3x3 oversampled PSF
../imfit -c config_imfit_gauss-oversample-test2.dat --gain=100 --mlr --nm oversamp_test5.fits --psf psf_standard_sigma0.64.fits --overpsf psf_sigma_0.64_oversamp3.fits --overpsf_scale 3 --overpsf_region 100:110,100:110
POISSON-MLR STATISTIC = 0.000179
Reduced Chi^2 equivalent = 0.000000
AIC = 8.001179, BIC = 42.386718
X0 105.2377
Y0 105.4582
FUNCTION Gaussian
PA 0
ell 0
I_0 99.9931
sigma 1.20004
[time ~ 6.0s]
# E. Fit with 10x10 oversampled PSF
../imfit -c config_imfit_gauss-oversample-test2.dat --gain=100 --mlr --nm oversamp_test5.fits --psf psf_standard_sigma0.64.fits --overpsf psf_sigma_0.64_oversamp10.fits --overpsf_scale 10 --overpsf_region 100:110,100:110
POISSON-MLR STATISTIC = 0.000000
Reduced Chi^2 equivalent = 0.000000
AIC = 8.001000, BIC = 42.386539
X0 105.2377
Y0 105.4582
FUNCTION Gaussian
PA 0
ell 0
I_0 100
sigma 1.2
[time ~ 50s]
# [ ]6. Same as 4, but now testing whether we correctly account for offsets when
# image region is specified
# [x]A. Generate 150x150 cutout of original 200x200 oversamp_test4.fits
cl> imcopy oversamp_test4.fits[51:200,41:190] oversamp_test4_150x150cutout.fits
# [x]B.1. Fit cutout image with standard (non-oversampled) PSF
../imfit -c config_imfit_gauss-oversample-test2_150x150cutout.dat --gain=100 --mlr --nm oversamp_test4_150x150cutout.fits --psf psf_standard.fits
POISSON-MLR STATISTIC = 0.003884
Reduced Chi^2 equivalent = 0.000000
AIC = 8.005662, BIC = 40.088966
X0 55.2377
Y0 65.4582
FUNCTION Gaussian
PA 0
ell 0
I_0 99.7433
sigma 1.20124
# [x]B.2. Fit cutout image with 3x3 oversampling
../imfit -c config_imfit_gauss-oversample-test2_150x150cutout.dat --gain=100 --mlr --nm oversamp_test4_150x150cutout.fits --psf psf_standard.fits --overpsf psf_oversamp.fits --overpsf_scale 3 --overpsf_region 50:60,60:70
POISSON-MLR STATISTIC = 0.001855
Reduced Chi^2 equivalent = 0.000000
AIC = 8.003633, BIC = 40.086937
X0 55.2377
Y0 65.4582
FUNCTION Gaussian
PA 0
ell 0
I_0 99.8789
sigma 1.20062
# [ ]C. Fit full image with 3x3 oversampling, specifying image section matching cutout image
../imfit -c config_imfit_gauss-oversample-test2.dat --gain=100 --mlr --nm oversamp_test4.fits[51:200,41:190] --psf psf_standard.fits --overpsf psf_oversamp.fits --overpsf_scale 3 --overpsf_region 100:110,100:110
>> INITIAL, INCORRECT RESULT (prior to fixing code):
POISSON-MLR STATISTIC = 0.003884
Reduced Chi^2 equivalent = 0.000000
AIC = 8.005662, BIC = 40.088966
X0 105.2377
Y0 105.4582
FUNCTION Gaussian
PA 0
ell 0
I_0 99.7433
sigma 1.20124
(i.e., effectively same as no-PSF-oversampling version, because the oversampled region is
too far away from Gaussian center to matter for the fit)
>> REVISED RESULT (after fixing code):
POISSON-MLR STATISTIC = 0.001855
Reduced Chi^2 equivalent = 0.000000
AIC = 8.003633, BIC = 40.086937
X0 105.2377
Y0 105.4582
FUNCTION Gaussian
PA 0
ell 0
I_0 99.8787
sigma 1.20062
(Same as when fitting cutout image; also same as fitting full image in 3C -- presumably
because the outermost pixels excluded by the cutout have too little signal to really
affect the fit)
*** Testing with multiple oversampling regions
Original makeimage config file:
config_makeimage_2gauss_small.dat
Generate image with two Gaussians, each convolved with 3x3-oversampled PSF:
$ ./makeimage config_makeimage_2gauss_small.dat -o modelimage_psf+2osamp.fits --psf tests/psf_moffat_35.fits --overpsf tests/psf_moffat_35_oversamp3.fits --overpsf_scale 3 --overpsf_region 35:45,35:45 --overpsf_region 10:20,5:15
$ ~/python/add_noise_to_image.py modelimage_psf+2osamp.fits modelimage_psf+2osamp_noisy.fits --gain=1000 --seed=10
[ cp modelimage_psf+2osamp_noisy.fits tests/twogaussian_psf+2osamp_noisy.fits ]
Makeimage parameters:
X0 40.5
Y0 40.25
FUNCTION Gaussian
PA 0
ell 0
I_0 110
sigma 1.0
X0 15.1
Y0 10.6
FUNCTION Gaussian
PA 0
ell 0
I_0 90
sigma 1.0
FUNCTION FlatSky
I_0 100.0
Fit to noisy image using just main PSF:
$ ./imfit -c config_imfit_2gauss_small.dat modelimage_psf+2osamp_noisy.fits --psf=tests/psf_moffat_35.fits
Reduced Chi^2 = 0.999850
AIC = 2507.685240, BIC = 2554.219800
X0 40.1703 # +/- 0.0064
Y0 39.9137 # +/- 0.0064
FUNCTION Gaussian
PA 0 # +/- 0
ell 0 # +/- 0
I_0 109.668 # +/- 1.27346
sigma 1.00101 # +/- 0.00687169
X0 14.7626 # +/- 0.0078
Y0 10.2573 # +/- 0.0078
FUNCTION Gaussian
PA 0 # +/- 0
ell 0 # +/- 0
I_0 88.6079 # +/- 1.22085
sigma 1.01015 # +/- 0.00827045
Fit to noisy image using oversampled PSF as well:
$ ./imfit -c config_imfit_2gauss_small.dat modelimage_psf+2osamp_noisy.fits --psf=tests/psf_moffat_35.fits --overpsf tests/psf_moffat_35_oversamp3.fits --overpsf_scale 3 --overpsf_region 35:45,35:45 --overpsf_region 10:20,5:15
Reduced Chi^2 = 0.999991
AIC = 2508.035300, BIC = 2554.569860
X0 40.5036 # +/- 0.0064
Y0 40.2470 # +/- 0.0064
FUNCTION Gaussian
PA 0 # +/- 0
ell 0 # +/- 0
I_0 109.583 # +/- 1.27144
sigma 1.00132 # +/- 0.00686879
X0 15.0959 # +/- 0.0078
Y0 10.5906 # +/- 0.0078
FUNCTION Gaussian
PA 0 # +/- 0
ell 0 # +/- 0
I_0 88.5157 # +/- 1.21834
sigma 1.01064 # +/- 0.00826686
BETTER! (Not dramatically so -- delta-AIC is ~ 1 -- but X0,Y0 values are definitely
closer)
Fit to clean image using main PSF:
$ ./imfit -c config_imfit_2gauss_small.dat modelimage_psf+2osamp.fits --psf=tests/psf_moffat_35.fits
X0 40.1667 # +/- 0.0064
Y0 39.9167 # +/- 0.0064
FUNCTION Gaussian
PA 0 # +/- 0
ell 0 # +/- 0
I_0 110.104 # +/- 1.27929
sigma 0.999584 # +/- 0.00686315
X0 14.7667 # +/- 0.0077
Y0 10.2667 # +/- 0.0077
FUNCTION Gaussian
PA 0 # +/- 0
ell 0 # +/- 0
I_0 90.09 # +/- 1.25894
sigma 0.99954 # +/- 0.00828357
Fit to clean image using oversampled PSF as well:
$ ./imfit -c config_imfit_2gauss_small.dat modelimage_psf+2osamp.fits --psf=tests/psf_moffat_35.fits --overpsf tests/psf_moffat_35_oversamp3.fits --overpsf_scale 3 --overpsf_region 35:45,35:45 --overpsf_region 10:20,5:15
X0 40.5000 # +/- 0.0064
Y0 40.2500 # +/- 0.0064
FUNCTION Gaussian
PA 0 # +/- 0
ell 0 # +/- 0
I_0 109.99 # +/- 1.27658
sigma 1.00003 # +/- 0.00685993
X0 15.1000 # +/- 0.0077
Y0 10.6000 # +/- 0.0077
FUNCTION Gaussian
PA 0 # +/- 0
ell 0 # +/- 0
I_0 89.9915 # +/- 1.25616
sigma 1.00003 # +/- 0.00828014