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
|
include <math.h>
include <mach.h>
# CGAUSS1D - Compute the value of a 1-D Gaussian function on a constant
# background.
procedure cgauss1d (x, nvars, p, np, z)
real x[ARB] # variables, x[1] = position coordinate
int nvars # the number of variables, not used
real p[ARB] # p[1]=amplitude p[2]=center p[3]=variance p[4]=sky
int np # number of parameters np = 4
real z # function return
real r2
begin
if (p[3] == 0.)
r2 = 36.0
else
r2 = (x[1] - p[2]) ** 2 / (2. * p[3])
if (abs (r2) > 25.0)
z = p[4]
else
z = p[1] * exp (-r2) + p[4]
end
# CDGAUSS1D -- Compute the value a 1-D Gaussian profile on a constant
# background and its derivatives.
procedure cdgauss1d (x, nvars p, dp, np, z, der)
real x[ARB] # variables, x[1] = position coordinate
int nvars # the number of variables, not used
real p[ARB] # p[1]=amplitude, p[2]=center, p[3]=sky p[4]=variance
real dp[ARB] # parameter derivatives
int np # number of parameters np=4
real z # function value
real der[ARB] # derivatives
real dx, r2
begin
dx = x[1] - p[2]
if (p[3] == 0.)
r2 = 36.0
else
r2 = dx * dx / (2.0 * p[3])
if (abs (r2) > 25.0) {
z = p[4]
der[1] = 0.0
der[2] = 0.0
der[3] = 0.0
der[4] = 1.0
} else {
der[1] = exp (-r2)
z = p[1] * der[1]
der[2] = z * dx / p[3]
der[3] = z * r2 / p[3]
der[4] = 1.0
z = z + p[4]
}
end
# GAUSSR -- Compute the value of a 2-D radially symmetric Gaussian profile
# which is assumed to be sitting on a constant background.
# Parameter Allocation:
# 1 Amplitude
# 2 X-center
# 3 Y-center
# 4 Variance
# 5 Sky
procedure gaussr (x, nvars, p, np, z)
real x[ARB] # the input variables
int nvars # the number of variables
real p[np] # parameter vector
int np # number of parameters
real z # function return
real dx, dy, r2
begin
dx = x[1] - p[2]
dy = x[2] - p[3]
if (p[4] == 0.)
r2 = 36.0
else
r2 = (dx * dx + dy * dy) / (2.0 * p[4])
if (abs (r2) > 25.0)
z = p[5]
else
z = p[1] * exp (- r2) + p[5]
end
# DGAUSSR -- Compute the value of a 2-D Gaussian profile and its derivatives
# which assumed to be sitting on top of a constant background.
procedure dgaussr (x, nvars, p, dp, np, z, der)
real x[ARB] # the input variables
int nvars # the number of variables
real p[np] # parameter vector
real dp[np] # dummy array of parameter increments
int np # number of parameters
real z # function return
real der[np] # derivatives
real dx, dy, r2
begin
dx = x[1] - p[2]
dy = x[2] - p[3]
if (p[4] == 0.)
r2 = 36.0
else
r2 = (dx * dx + dy * dy) / (2.0 * p[4])
if (abs (r2) > 25.0) {
z = p[5]
der[1] = 0.0
der[2] = 0.0
der[3] = 0.0
der[4] = 0.0
der[5] = 1.0
} else {
der[1] = exp (-r2)
z = p[1] * der[1]
der[2] = z * dx / p[4]
der[3] = z * dy / p[4]
der[4] = z * r2 / p[4]
z = z + p[5]
der[5] = 1.0
}
end
# ELGAUSS -- Compute the value of a 2-D elliptical Gaussian function which
# is assumed to be sitting on top of a constant background.
# Parameter Allocation:
# 1 Amplitude
# 2 X-center
# 3 Y-center
# 4 Variance-x
# 5 Variance-y
# 6 Theta-rotation
# 7 Sky
procedure elgauss (x, nvars, p, np, z)
real x[ARB] # input variables, x[1] = x, x[2] = y
int nvars # number of variables, not used
real p[np] # parameter vector
int np # number of parameters
real z # function return
real dx, dy, crot, srot, xt, yt, r2
begin
dx = x[1] - p[2]
dy = x[2] - p[3]
crot = cos (p[6])
srot = sin (p[6])
xt = (dx * crot + dy * srot)
yt = (-dx * srot + dy * crot)
if (p[4] == 0. || p[5] == 0.)
r2 = 36.0
else
r2 = (xt ** 2 / p[4] + yt ** 2 / p[5]) / 2.0
if (abs (r2) > 25.0)
z = p[7]
else
z = p[1] * exp (-r2) + p[7]
end
# DELGAUSS -- Compute the value of a 2-D elliptical Gaussian assumed to
# sitting on top of a constant background and its derivatives.
procedure delgauss (x, nvars, p, dp, np, z, der)
real x[ARB] # input variables, x[1] = x, x[2] = y
int nvars # number of variables, not used
real p[np] # parameter vector
real dp[np] # delta of parameters
int np # number of parameters
real z # function value
real der[np] # function return
real crot, srot, crot2, srot2, sigx2, sigy2, a, b, c
real dx, dy, dx2, dy2, r2
begin
crot = cos (p[6])
srot = sin (p[6])
crot2 = crot ** 2
srot2 = srot ** 2
sigx2 = p[4]
sigy2 = p[5]
if (sigx2 == 0. || sigy2 == 0.)
r2 = 36.0
else {
a = (crot2 / sigx2 + srot2 / sigy2)
b = 2.0 * crot * srot * (1.0 / sigx2 - 1.0 /sigy2)
c = (srot2 / sigx2 + crot2 / sigy2)
dx = x[1] - p[2]
dy = x[2] - p[3]
dx2 = dx ** 2
dy2 = dy ** 2
r2 = 0.5 * (a * dx2 + b * dx * dy + c * dy2)
}
if (abs (r2) > 25.0) {
z = p[7]
der[1] = 0.0
der[2] = 0.0
der[3] = 0.0
der[4] = 0.0
der[5] = 0.0
der[6] = 0.0
der[7] = 1.0
} else {
der[1] = exp (-r2)
z = p[1] * der[1]
der[2] = z * (2.0 * a * dx + b * dy)
der[3] = z * (b * dx + 2.0 * c * dy)
der[4] = z * (crot2 * dx2 + 2.0 * crot * srot * dx * dy +
srot2 * dy2) / (2.0 * sigx2 * sigx2)
der[5] = z * (srot2 * dx2 - 2.0 * crot * srot * dx * dy +
crot2 * dy2) / (2.0 * sigy2 * sigy2)
der[6] = z * (b * dx2 + 2.0 * (c - a) * dx * dy - b * dy2)
z = z + p[7]
der[7] = 1.0
}
end
# GAUSS1D -- Compute the profile of a 1d Gaussian with a background value
# of zero.
procedure gauss1d (x, nvars, p, np, z)
real x[ARB] # list of variables, x[1] = position coordinate
int nvars # number of variables
real p[ARB] # p[1]=amplitude p[2]=center p[3]=sigma
int np # number of parameters == 3
real z # function return
real r
begin
if (p[3] == 0.)
r = 6.0
else
r = (x[1] - p[2]) / (p[3] * SQRTOF2)
if (abs (r) > 5.0)
z = 0.0
else
z = p[1] * exp (- r ** 2)
end
# DGAUSS1D -- Compute the function value and derivatives of a 1-D Gaussian
# function with a background value of zero.
procedure dgauss1d (x, nvars, p, dp, np, z, der)
real x[ARB] # list of variables, x[1] = position coordinate
int nvars # number of variables
real p[ARB] # p[1]=amplitude, p[2]=center, p[3]=sigma
real dp[ARB] # parameter derivatives
int np # number of parameters
real z # function value
real der[ARB] # derivatives
real r
begin
if (p[3] == 0.)
r = 6.0
else
r = (x[1] - p[2]) / (SQRTOF2 * p[3])
if (abs (r) > 5.0) {
z = 0.0
der[1] = 0.0
der[2] = 0.0
der[3] = 0.0
} else {
der[1] = exp (- r ** 2)
z = der[1] * p[1]
der[2] = z * r * SQRTOF2 / p[3]
der[3] = der[2] * SQRTOF2 * r
}
end
# GAUSSKEW - Compute the value of a 1-D skewed Gaussian profile.
# The background value is assumed to be zero.
procedure gausskew (x, nvars, p, np, z)
real x[ARB] # list of variables, x[1] = position coordinate
int nvars # number of variables, not used
real p[ARB] # p[1]=amplitude p[2]=center p[3]=variance p[4]=skew
int np # number of parameters == 3
real z # function return
real dx, r2, r3
begin
dx = (x[1] - p[2])
if (p[3] == 0.)
r2 = 36.0
else {
r2 = dx ** 2 / (2.0 * p[3])
r3 = r2 * dx / sqrt (2.0 * abs (p[3]))
}
if (abs (r2) > 25.0)
z = 0.0
else
z = (1.0 + p[4] * r3) * p[1] * exp (-r2)
end
# DGAUSSKEW -- Compute the value of a 1-D skewed Gaussian and its derivatives.
# The background value is assumed to be zero.
procedure dgausskew (x, nvars, p, dp, np, z, der)
real x[ARB] # list of variables, x[1] = position coordinate
int nvars # number of variables, not used
real p[ARB] # p[1]=amplitude, p[2]=center, p[3]=variance, p[4]=skew
real dp[ARB] # parameter derivatives
int np # number of parameters
real z # function value
real der[ARB] # derivatives
real dx, d1, d2, d3, r, r2, r3, rint
begin
dx = x[1] - p[2]
if (p[3] == 0.)
r2 = 36.0
else
r2 = dx ** 2 / (2.0 * p[3])
if (abs (r2) > 25.0) {
z = 0.0
der[1] = 0.0
der[2] = 0.0
der[3] = 0.0
der[4] = 0.0
} else {
r = dx / sqrt (2.0 * abs (p[3]))
r3 = r2 * r
d1 = exp (-r2)
z = d1 * p[1]
d2 = z * dx / p[3]
d3 = z * r2 / p[3]
rint = 1.0 + p[4] * r3
der[1] = d1 * rint
der[2] = d2 * (rint - 1.5 * p[4] * r)
der[3] = d3 * (rint - 1.5 * p[4] * r)
der[4] = z * r3
z = z * rint
}
end
|