Newer
Older
/*
profit.c
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*
* Part of: SExtractor
*
* Authors: E.BERTIN (IAP)
*
* Contents: Fit an arbitrary profile combination to a detection.
*
* Last modify: 29/01/2009
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
*
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef HAVE_MATHIMF_H
#include <mathimf.h>
#else
#define _GNU_SOURCE
#include <math.h>
#endif
#ifdef HAVE_LOGF
#define LOGF logf
#else
#define LOGF log
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "define.h"
#include "globals.h"
#include "prefs.h"
#include "fits/fitscat.h"
#include "levmar/lm.h"
#include "fft.h"
#include "fitswcs.h"
#include "check.h"
#include "pattern.h"
#include "psf.h"
#include "profit.h"
static double prof_interpolate(profstruct *prof, double *posin);
static double interpolate_pix(double *posin, double *pix, int *naxisn,
interpenum interptype);
static void make_kernel(double pos, double *kernel, interpenum interptype);
/*------------------------------- variables ---------------------------------*/
char profname[][32]={"background offset", "Sersic spheroid",
"De Vaucouleurs spheroid", "exponential disk", "spiral arms",
"bar", "inner ring", "outer ring", "tabulated model",
""};
int interp_kernwidth[5]={1,2,4,6,8};
int theniter, the_gal;
/* "Local" global variables; it seems dirty but it simplifies a lot */
/* interfacing to the LM routines */
static picstruct *the_field, *the_wfield;
profitstruct *theprofit;
/****** profit_init ***********************************************************
PROTO profitstruct profit_init(psfstruct *psf)
PURPOSE Allocate and initialize a new profile-fitting structure.
INPUT Pointer to PSF structure.
OUTPUT A pointer to an allocated profit structure.
NOTES -.
AUTHOR E. Bertin (IAP)
VERSION 26/04/2008
***/
profitstruct *profit_init(psfstruct *psf)
{
profitstruct *profit;
int p, nprof,
backflag, spheroidflag, diskflag, barflag, armsflag;
QCALLOC(profit, profitstruct, 1);
profit->psf = psf;
profit->psfdft = NULL;
profit->nparam = 0;
QMALLOC(profit->prof, profstruct *, PROF_NPROF);
backflag = spheroidflag = diskflag = barflag = armsflag = 0;
nprof = 0;
for (p=0; p<PROF_NPROF; p++)
if (!backflag && FLAG(obj2.prof_offset_flux))
{
profit->prof[p] = prof_init(profit, PROF_BACK);
backflag = 1;
nprof++;
}
else if (!spheroidflag && FLAG(obj2.prof_spheroid_flux))
{
profit->prof[p] = prof_init(profit,
FLAG(obj2.prof_spheroid_sersicn)? PROF_SERSIC : PROF_DEVAUCOULEURS);
spheroidflag = 1;
nprof++;
}
else if (!diskflag && FLAG(obj2.prof_disk_flux))
{
profit->prof[p] = prof_init(profit, PROF_EXPONENTIAL);
diskflag = 1;
nprof++;
}
else if (diskflag && !barflag && FLAG(obj2.prof_bar_flux))
{
profit->prof[p] = prof_init(profit, PROF_BAR);
barflag = 1;
nprof++;
}
else if (barflag && !armsflag && FLAG(obj2.prof_arms_flux))
{
profit->prof[p] = prof_init(profit, PROF_ARMS);
armsflag = 1;
nprof++;
}
QMALLOC(profit->covar, double, profit->nparam*profit->nparam);
profit->nprof = nprof;
return profit;
}
/****** profit_end ************************************************************
PROTO void prof_end(profstruct *prof)
PURPOSE End (deallocate) a profile-fitting structure.
INPUT Prof structure.
OUTPUT -.
NOTES -.
AUTHOR E. Bertin (IAP)
VERSION 26/04/2008
***/
void profit_end(profitstruct *profit)
{
int p;
for (p=0; p<profit->nprof; p++)
prof_end(profit->prof[p]);
free(profit->prof);
free(profit->covar);
free(profit->psfdft);
free(profit);
return;
}
/****** profit_fit ************************************************************
PROTO void profit_fit(profitstruct *profit, picstruct *field,
picstruct *wfield, objstruct *obj, obj2struct *obj2)
PURPOSE Fit profile(s) convolved with the PSF to a detected object.
INPUT Array of profile structures,
Number of profiles,
Pointer to the profile-fitting structure,
Pointer to the field,
Pointer to the field weight,
Pointer to the obj.
OUTPUT Pointer to an allocated fit structure (containing details about the
fit).
NOTES It is a modified version of the lm_minimize() of lmfit.
AUTHOR E. Bertin (IAP)
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
***/
void profit_fit(profitstruct *profit,
picstruct *field, picstruct *wfield,
objstruct *obj, obj2struct *obj2)
{
patternstruct *pattern;
psfstruct *psf;
checkstruct *check;
double *oldparaminit,
psf_fwhm, oldchi2, a , cp,sp, emx2,emy2,emxy;
int i,j,p, oldniter, nparam, ncomp;
nparam = profit->nparam;
if (profit->psfdft)
{
QFREE(profit->psfdft);
}
psf = profit->psf;
profit->pixstep = psf->pixstep;
/* Create pixmaps at image resolution */
psf_fwhm = psf->masksize[0]*psf->pixstep;
profit->objnaxisn[0] = (((int)((obj->xmax-obj->xmin+1) + psf_fwhm + 0.499)
*1.2)/2)*2 + 1;
profit->objnaxisn[1] = (((int)((obj->ymax-obj->ymin+1) + psf_fwhm + 0.499)
*1.2)/2)*2 + 1;
profit->ix = (int)(obj->mx + 0.49999);/* internal convention: 1st pix = 0 */
profit->iy = (int)(obj->my + 0.49999);/* internal convention: 1st pix = 0 */
Loading
Loading full blame…