-
Notifications
You must be signed in to change notification settings - Fork 3
/
deconvolve_gauss.pro
158 lines (130 loc) · 4.74 KB
/
deconvolve_gauss.pro
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
pro deconvolve_gauss $
, meas_maj = meas_maj $ ; measured major axis
, meas_min = meas_min $ ; measured minor axis
, meas_pa = meas_pa $ ; measured position angle
, beam_maj = beam_maj $ ; beam major axis
, beam_min = beam_min $ ; beam minor axis
, beam_pa = beam_pa $ ; beam position angle
, src_maj = src_maj $ ; source major axis
, src_min = src_min $ ; source minor axis
, src_pa = src_pa $ ; source position angle
, worked = worked $ ; returns 0 if not possible to convolve
, point = point $ ; returns 1 if close to a point source
, verbose = verbose ; set output level
; WARNING!!! Currently this appears to have issues returning a full
; range of position angle values. This needs more investigation.
; ADAPTED FROM gaupar.for in MIRIAD via K. Sandstrom
;
; Determine the parameters of a gaussian deconvolved with another
; gaussian.
;
; Input:
; bmaj1,bmin1 Major and minor FWHM of the source..
; bpa1 Position angle of 1st gaussian, in degrees.
; bmaj2,bmin2 Major and minor FWHM of gaussian to deconvolve with.
; bpa2 Position angle of 2nd gaussian, in degrees.
; Output:
; bmaj,bmin Major and minor axes of resultant gaussian.
; bpa Position angle of the result, in radians.
; fac Always 1 (for future use ...).
; ifail Success status: 0 All OK.
; 1 Result is pretty close to a
; point source.
; 2 Illegal result.
; %&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&
; DEFAULTS AND DEFINITIONS
; %&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&
; FAIL IF MAJOR AXIS OF MEASUREMENT LACKING
if n_elements(meas_maj) eq 0 then begin
if keyword_set(verbose) then $
message, "No measurement supplied. Failing.", /info
worked = 0B
return
endif
; FAIL IF MAJOR AXIS OF BEAM LACKING
if n_elements(beam_maj) eq 0 then begin
if keyword_set(verbose) then $
message, "No beam supplied. Failing.", /info
worked = 0B
return
endif
; NO MINOR AXIS MEASURED FOR MEASUREMENT
if n_elements(meas_min) eq 0 then begin
if keyword_set(verbose) then $
message, "Minor axis not supplied. Assuming round measurement.", /info
meas_min = meas_maj
endif
; NO MINOR AXIS BEAM FOR BEAM
if n_elements(beam_min) eq 0 then begin
if keyword_set(verbose) then $
message, "Minor axis not supplied. Assuming round beam.", /info
beam_min = beam_maj
endif
; NO POSITION ANGLE - DEFAULT TO 0
if n_elements(meas_pa) eq 0 then begin
if keyword_set(verbose) then $
message, "Position not supplied. Assuming measurement PA = 0.", /info
meas_pa = 0.0
endif
; NO POSITION ANGLE - DEFAULT TO 0
if n_elements(beam_pa) eq 0 then begin
if keyword_set(verbose) then $
message, "Position not supplied. Assuming beam PA = 0.", /info
beam_pa = 0.0
endif
; %&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&
; CALCULATIONS
; %&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&
; CONVERT TO RADIANS
meas_theta = meas_pa*!dtor
beam_theta = beam_pa*!dtor
; MATH (FROM MIRIAD VIA K. SANDSTROM)
alpha = $
(meas_maj*cos(meas_theta))^2d + (meas_min*sin(meas_theta))^2d - $
(beam_maj*cos(beam_theta))^2d - (beam_min*sin(beam_theta))^2d
beta = $
(meas_maj*sin(meas_theta))^2d + (meas_min*cos(meas_theta))^2d - $
(beam_maj*sin(beam_theta))^2d - (beam_min*cos(beam_theta))^2d
gamma = $
2d*((meas_min^2-meas_maj^2)*sin(meas_theta)*cos(meas_theta) - $
(beam_min^2-beam_maj^2)*sin(beam_theta)*cos(beam_theta))
s = alpha + beta
t = sqrt((alpha-beta)^2d + gamma^2d)
; FIND THE SMALLEST RESOLUTION
limit = meas_min < meas_maj < beam_maj < beam_min
limit = 0.1*limit*limit
; TWO CASES:
if (alpha lt 0 or beta lt 0 or s lt t) then BEGIN
; ... FAILURE
src_maj = 0
src_min = 0
src_pa = 0
; ... NOTE THAT IT DIDN'T WORK
worked = 0B
if keyword_set(verbose) then $
message, "Illegal alpha, beta, or s value.", /info
; ... CLOSE TO A POINT SOURCE
if (0.5*(s-t) lt limit and $
alpha gt -1*limit and $
beta gt -1*limit) then begin
point = 1B
endif else begin
; ... FAILURE BUT NOT A POINT SOURCE
point = 0B
endelse
endif else begin
; ... SUCCESS
src_maj = sqrt(0.5*(s+t))
src_min = sqrt(0.5*(s-t))
if (abs(gamma)+abs(alpha-beta) eq 0) then BEGIN
src_pa = 0
endif else BEGIN
src_pa = (1.0d/!dtor)*0.5*atan(-1*gamma,alpha-beta)
endelse
; ... NOTE THAT IT WORKED AND IT'S NOT A POINT SOURCE
worked = 1B
point = 0B
endelse
; RETURN!
return
end