aboutsummaryrefslogtreecommitdiff
path: root/noao/digiphot/apphot/center/apcsnratio.x
blob: 0fd0e20dd40d1ec4f5581fa28deaf83858198cc2 (plain) (blame)
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
include <mach.h>
include "../lib/center.h"
include "../lib/noise.h"

# AP_CSNRATIO -- Procedure to estimate the signal to noise ratio for centering.

real procedure ap_csnratio (ap, array, nx, ny, threshold)

pointer	ap		# apphot structure
real	array[nx,ny]	# data array
int	nx, ny		# subraster dimensions
real	threshold	# threshold value for snr computation

int	apstati()
real	apstatr(), ap_cratio(), ap_pratio()

begin
	switch (apstati (ap, NOISEFUNCTION)) {
	case AP_NCONSTANT:
	    return (ap_cratio (array, nx, ny, threshold, apstatr (ap,
	        SKYSIGMA)))
	case AP_NPOISSON:
	    return (ap_pratio (array, nx, ny, threshold, apstatr (ap,
	        SKYSIGMA), apstatr (ap, EPADU)))
	default:
	    return (MAX_REAL)
	}
end


# AP_CRATIO -- Procedure to estimate the signal to noise ratio in the
# centering aperture assuming that the noise is due to a constant sky
# sigma. These computations are approximate only.

real procedure ap_cratio (array, nx, ny, sky, noise)

real	array[nx,ny]		# centering buffer
int	nx, ny			# dimensions of the centering buffer
real	sky			# mean sky value of the data in ADU
real	noise			# estimate of sky noise in ADU

int	npts
real	signal, tnoise
real	asumr()

begin
	npts = nx * ny
	signal = asumr (array, npts) - npts * sky
	if (IS_INDEFR(noise))
	    tnoise = 0.0
	else
	    tnoise = sqrt (npts * noise ** 2)
	if (signal <= 0.0)
	    return (0.0)
	else if (tnoise <= 0.0)
	    return (MAX_REAL)
	else
	    return (signal / tnoise)
end


# AP_PRATIO -- Procedure to estimate the signal to noise ratio in the
# centering aperture assuming the noise is due to a constant sky sigma
# and poisson statistics in the image. These computations are
# approximate only.

real procedure ap_pratio (array, nx, ny, sky, noise, padu)

real	array[nx,ny]		# centering buffer
int	nx, ny			# dimensions of the centering buffer
real	sky			# mean sky value of the data in ADU
real	noise			# estimate of sky noise in ADU
real	padu			# photons per adu

int	npts
real	signal, tnoise
real	asumr()

begin
	npts = nx * ny
	signal = asumr (array, npts) - npts * sky
	if (IS_INDEFR(noise))
	    tnoise = sqrt (abs (signal / padu))
	else
	    tnoise = sqrt (abs (signal / padu) + npts * noise ** 2)
	if (signal <= 0.0)
	    return (0.0)
	else if (tnoise <= 0.0)
	    return (MAX_REAL)
	else
	    return (signal / tnoise)
end