profit.h 10.8 KB
Newer Older
1
2
/*
*				profit.h
Emmanuel Bertin's avatar
Emmanuel Bertin committed
3
*
4
* Include file for profit.c.
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5
*
6
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Emmanuel Bertin's avatar
Emmanuel Bertin committed
7
*
8
*	This file part of:	SExtractor
Emmanuel Bertin's avatar
Emmanuel Bertin committed
9
*
10
*	Copyright:		(C) 2006-2011 Emmanuel Bertin -- IAP/CNRS/UPMC
11
12
13
14
15
16
17
18
19
20
21
22
23
24
*
*	License:		GNU General Public License
*
*	SExtractor is free software: you can redistribute it and/or modify
*	it under the terms of the GNU General Public License as published by
*	the Free Software Foundation, either version 3 of the License, or
*	(at your option) any later version.
*	SExtractor is distributed in the hope that it will be useful,
*	but WITHOUT ANY WARRANTY; without even the implied warranty of
*	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*	GNU General Public License for more details.
*	You should have received a copy of the GNU General Public License
*	along with SExtractor. If not, see <http://www.gnu.org/licenses/>.
*
25
*	Last modified:		20/05/2011
26
27
*
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
Emmanuel Bertin's avatar
Emmanuel Bertin committed
28
29
30
31

#ifndef _PROFIT_H_
#define _PROFIT_H_

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*-------------------------------- models -----------------------------------*/

#define		MODEL_NONE		0x0000
#define		MODEL_BACK		0x0001
#define		MODEL_DIRAC		0x0002
#define		MODEL_SERSIC		0x0004
#define		MODEL_DEVAUCOULEURS	0x0008
#define		MODEL_EXPONENTIAL	0x0010
#define		MODEL_ARMS		0x0020
#define		MODEL_BAR		0x0040
#define		MODEL_INRING		0x0080
#define		MODEL_OUTRING		0x0100
#define		MODEL_TABULATED		0x0200
#define		MODEL_NMAX		11

47
/*--------------------------- fitting flags ---------------------------------*/
Emmanuel Bertin's avatar
Emmanuel Bertin committed
48

49
50
51
#define		PROFLAG_MODSUB		0x0001
#define		PROFLAG_OBJSUB		0x0002
#define		PROFLAG_NOTCONST	0x0004
52
53
54
55
56
57
58
59
#define		PROFLAG_MINLIM		0x0008
#define		PROFLAG_MAXLIM		0x0010

/*------------------------- parameter type flags ----------------------------*/

#define		PROFPARAM_UNBOUNDED	1
#define		PROFPARAM_LINBOUNDED	2
#define		PROFPARAM_LOGBOUNDED	3
Emmanuel Bertin's avatar
Emmanuel Bertin committed
60
61
62
63
64
65
66
67

/*-------------------------------- macros -----------------------------------*/

#define		PROFIT_POW(x,a)		(x>0.01? exp(a*log(x)) : pow(x,a))
#define		PROFIT_POWF(x,a)	(x>0.01? expf(a*logf(x)) : powf(x,a))

/*----------------------------- Internal constants --------------------------*/

68
#define	PARAM_ALLPARAMS	(-1)	/* All parameters */
Emmanuel Bertin's avatar
Emmanuel Bertin committed
69
70
#define	PROFIT_MAXITER	1000	/* Max. nb of iterations in profile fitting */
#define	PROFIT_MAXPROF	8	/* Max. nb of profile components */
71
72
#define	PROFIT_HIDEFRES	201	/* Hi. def. model resol. (must be <MAXMODSIZE)*/
#define	PROFIT_REFFFAC	3.0	/* Factor in r_eff for measurement radius*/
73
#define	PROFIT_MAXR2MAX	1e6	/* Maximum r2_max for truncating profiles */
74
#define	PROFIT_DYNPARAM	10.0	/* Dynamic compression param. in sigma units */
75
#define	PROFIT_SMOOTHR	4.0	/* Profile smoothing radius (pixels) */
76
#define	PROFIT_MAXMODSIZE  512	/* Maximum size allowed for the model raster */
77
#define	PROFIT_MAXOBJSIZE  512	/* Maximum size allowed for the object raster */
Emmanuel Bertin's avatar
Emmanuel Bertin committed
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#define	PROFIT_BARXFADE	0.1	/* Fract. of bar length crossfaded with arms */
#define	PROFIT_MAXEXTRA	2	/* Max. nb of extra free params of profiles */
#define PROFIT_PROFRES	256	/* Pixmap size of model components */
#define PROFIT_PROFSRES	64	/* Number of model subcomponents */
#define INTERP_MAXKERNELWIDTH	8	/* Max. range of kernel (pixels) */
/* NOTES:
One must have:	PROFIT_NITER > 0
		PROFIT_MAXEXTRA > 0
*/

/*--------------------------------- typedefs --------------------------------*/

typedef enum	{INTERP_NEARESTNEIGHBOUR, INTERP_BILINEAR, INTERP_LANCZOS2,
		INTERP_LANCZOS3, INTERP_LANCZOS4}       interpenum;

93
94
typedef enum	{PARAM_BACK,
		PARAM_DIRAC_FLUX, PARAM_X, PARAM_Y,
Emmanuel Bertin's avatar
Emmanuel Bertin committed
95
96
97
98
99
100
101
102
103
104
105
106
		PARAM_SPHEROID_FLUX, PARAM_SPHEROID_REFF, PARAM_SPHEROID_ASPECT,
		PARAM_SPHEROID_POSANG, PARAM_SPHEROID_SERSICN,
		PARAM_DISK_FLUX, PARAM_DISK_SCALE, PARAM_DISK_ASPECT,
		PARAM_DISK_POSANG,
		PARAM_ARMS_FLUX, PARAM_ARMS_QUADFRAC, PARAM_ARMS_SCALE,
		PARAM_ARMS_START, PARAM_ARMS_POSANG, PARAM_ARMS_PITCH,
		PARAM_ARMS_PITCHVAR, PARAM_ARMS_WIDTH,
		PARAM_BAR_FLUX, PARAM_BAR_ASPECT, PARAM_BAR_POSANG,
		PARAM_INRING_FLUX, PARAM_INRING_WIDTH, PARAM_INRING_ASPECT,
		PARAM_OUTRING_FLUX, PARAM_OUTRING_START, PARAM_OUTRING_WIDTH,
		PARAM_NPARAM}	paramenum;

107
108
109
typedef enum 	{PARFIT_FIXED, PARFIT_UNBOUND, PARFIT_LINBOUND,
		PARFIT_LOGBOUND}	parfitenum;

Emmanuel Bertin's avatar
Emmanuel Bertin committed
110
111
112
113
/*--------------------------- structure definitions -------------------------*/

typedef struct
  {
114
115
  unsigned int	code;			/* Model code */
  char		*name;			/* Model name */
116
  float		*pix;			/* Full pixmap of the model */
Emmanuel Bertin's avatar
Emmanuel Bertin committed
117
118
  int		naxis;			/* Number of pixmap dimensions */
  int		naxisn[3];		/* Pixmap size for each axis */
119
  int		npix;			/* Total number of prof pixels */
120
121
  float		typscale;		/* Typical scale in prof pixels */
  float		fluxfac;		/* Flux normalisation factor */
122
  float		lostfluxfrac;		/* Lost flux fraction */
123
  float		m0,mx2,my2,mxy;		/* 2nd order moments */
Emmanuel Bertin's avatar
Emmanuel Bertin committed
124
/* Generic presentation parameters */
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
  float		*flux;			/* Integrated flux */
  float		*x[2];			/* Coordinate vector */
  float		*scale;			/* Scaling vector */
  float		*aspect;		/* Aspect ratio */
  float		*posangle;		/* Position angle (CCW/NAXIS1)*/
  float		*featfrac;		/* Feature flux fraction */
  float		*featscale;		/* Feature relative scalelength */
  float		*featstart;		/* Feature relative starting radius */
  float		*featposang;		/* Feature position angle */
  float		*featpitch;		/* Feature pitch */
  float		*featpitchvar;		/* Feature pitch variation */
  float		*featwidth;		/* Feature width */
  float		*feataspect;		/* Feature aspect ratio */
  float		*extra[PROFIT_MAXEXTRA];/* Parameters along extra-dimension */
  float		extrazero[PROFIT_MAXEXTRA]; /* Zero-point along extra-dim. */
  float		extrascale[PROFIT_MAXEXTRA]; /* Scaling along extra-dim. */
Emmanuel Bertin's avatar
Emmanuel Bertin committed
141
142
143
  int		extracycleflag[PROFIT_MAXEXTRA]; /* !=0 for cycling dim. */
  interpenum	interptype[2+PROFIT_MAXEXTRA];	/* Interpolation type */
  int		kernelwidth[2+PROFIT_MAXEXTRA];	/* Kernel size */
144
  float		*kernelbuf;		/* Kernel buffer */
Emmanuel Bertin's avatar
Emmanuel Bertin committed
145
146
147
148
149
150
151
152
  int		kernelnlines;		/* Number of interp kernel lines */
  }	profstruct;

typedef struct
  {
  objstruct	*obj;		/* Current object */
  obj2struct	*obj2;		/* Current object */
  int		nparam;		/* Number of parameters to be fitted */
153
  float		*paramlist[PARAM_NPARAM];	/* flat parameter list */
Emmanuel Bertin's avatar
Emmanuel Bertin committed
154
  int		paramindex[PARAM_NPARAM];/* Vector of parameter indices */
155
  int		paramrevindex[PARAM_NPARAM];/* Vector of reversed indices */
156
  parfitenum	parfittype[PARAM_NPARAM];/* Parameter fitting: fixed,bounded,.*/
157
158
159
160
  float		param[PARAM_NPARAM];	/* Vector of parameters to be fitted */
  float		paraminit[PARAM_NPARAM];/* Parameter initial guesses */
  float		parammin[PARAM_NPARAM];	/* Parameter lower limits */
  float		parammax[PARAM_NPARAM];	/* Parameter upper limits */
161
162
  int		nlimmin;	/* # of parameters that hit the min limit */
  int		nlimmax;	/* # of parameters that hit the max limit */
163
  float		paramerr[PARAM_NPARAM];	/* Std deviations of parameters */
164
165
  float		*covar;		/* Covariance matrix */
  int		iter;		/* Iteration counter */
Emmanuel Bertin's avatar
Emmanuel Bertin committed
166
167
168
169
  int		niter;		/* Number of iterations */
  profstruct	**prof;		/* Array of pointers to profiles */
  int		nprof;		/* Number of profiles to consider */
  struct psf	*psf;		/* PSF */
170
  float		pixstep;	/* Model/PSF sampling step */
171
  float		fluxfac;	/* Model flux scaling factor */
172
  float		subsamp;	/* Subsampling factor */
173
174
175
  float		*psfdft;	/* Compressed Fourier Transform of the PSF */
  float		*psfpix;	/* Full res. pixmap of the PSF */
  float		*modpix;	/* Full res. pixmap of the complete model */
176
177
  float		*modpix2;	/* 2nd full res. pixmap of the complete model */
  float		*cmodpix;	/* Full res. pixmap of the convolved model */
Emmanuel Bertin's avatar
Emmanuel Bertin committed
178
  int		modnaxisn[3];	/* Dimensions along each axis */
179
  int		nmodpix;	/* Total number of model pixels */
Emmanuel Bertin's avatar
Emmanuel Bertin committed
180
  PIXTYPE	*lmodpix;	/* Low resolution pixmap of the model */
181
  PIXTYPE	*lmodpix2;	/* 2nd low resolution pixmap of the model */
Emmanuel Bertin's avatar
Emmanuel Bertin committed
182
183
184
  PIXTYPE	*objpix;	/* Copy of object pixmap */
  PIXTYPE	*objweight;	/* Copy of object weight-map */
  int		objnaxisn[2];	/* Dimensions along each axis */
185
  int		nobjpix;	/* Total number of "final" pixels */
Emmanuel Bertin's avatar
Emmanuel Bertin committed
186
  int		ix, iy;		/* Integer coordinates of object pixmap */
187
  float		*resi;		/* Vector of residuals */
Emmanuel Bertin's avatar
Emmanuel Bertin committed
188
  int		nresi;		/* Number of residual elements */
189
190
191
192
  float		chi2;		/* Std error per residual element */
  float		sigma;		/* Standard deviation of the pixel values */
  float		flux;		/* Total flux in final convolved model */
  float		spirindex;	/* Spiral index (>0 for CCW) */
193
194
195
  float		guessradius;	/* Best guess for source half-light radius */
  float		guessflux;	/* Best guess for typical source flux (>0) */
  float		guessfluxmax;	/* Best guess for source flux upper limit (>0)*/
196
197
/* Buffers */
  double	dparam[PARAM_NPARAM];
Emmanuel Bertin's avatar
Emmanuel Bertin committed
198
199
200
201
202
  }	profitstruct;

/*----------------------------- Global variables ----------------------------*/
/*-------------------------------- functions --------------------------------*/

203
profitstruct	*profit_init(struct psf *psf, unsigned int modeltype);
Emmanuel Bertin's avatar
Emmanuel Bertin committed
204

205
profstruct	*prof_init(profitstruct *profit, unsigned int modeltype);
Emmanuel Bertin's avatar
Emmanuel Bertin committed
206

207
208
float		*profit_compresi(profitstruct *profit, float dynparam,
				float *resi),
Emmanuel Bertin's avatar
Emmanuel Bertin committed
209
		*profit_residuals(profitstruct *profit, picstruct *field,
210
211
			picstruct *wfield, float dynparam,
			float *param, float *resi),
212
213
		prof_add(profitstruct *profit, profstruct *prof,
			int extfluxfac_flag),
214
		profit_minradius(profitstruct *profit, float refffac),
215
		profit_noisearea(profitstruct *profit),
Emmanuel Bertin's avatar
Emmanuel Bertin committed
216
217
		profit_spiralindex(profitstruct *profit);

218
219
220
int		profit_boundtounbound(profitstruct *profit,
			float *param, double *dparam, int index),
		profit_copyobjpix(profitstruct *profit, picstruct *field,
Emmanuel Bertin's avatar
Emmanuel Bertin committed
221
			picstruct *wfield),
222
223
		profit_covarunboundtobound(profitstruct *profit,
			double *dparam, float *param),
Emmanuel Bertin's avatar
Emmanuel Bertin committed
224
		profit_minimize(profitstruct *profit, int niter),
225
226
		prof_moments(profitstruct *profit, profstruct *prof,
				double *jac),
227
228
		profit_resample(profitstruct *profit, float *inpix,
			PIXTYPE *outpix, float factor),
Emmanuel Bertin's avatar
Emmanuel Bertin committed
229
		profit_setparam(profitstruct *profit, paramenum paramtype,
230
231
232
233
			float param, float parammin, float parammax,
			parfitenum parfittype),
		profit_unboundtobound(profitstruct *profit,
			double *dparam, float *param, int index);
Emmanuel Bertin's avatar
Emmanuel Bertin committed
234

235
void		prof_end(profstruct *prof),
Emmanuel Bertin's avatar
Emmanuel Bertin committed
236
		profit_addparam(profitstruct *profit, paramenum paramindex,
237
			float **param),
Emmanuel Bertin's avatar
Emmanuel Bertin committed
238
239
240
		profit_fit(profitstruct *profit,
			picstruct *field, picstruct *wfield,
			objstruct *obj, obj2struct *obj2),
241
		profit_convmoments(profitstruct *profit, obj2struct *obj2),
242
		profit_convolve(profitstruct *profit, float *modpix),
Emmanuel Bertin's avatar
Emmanuel Bertin committed
243
		profit_end(profitstruct *profit),
244
		profit_evaluate(double *par, double *fvec, int m, int n,
Emmanuel Bertin's avatar
Emmanuel Bertin committed
245
			void *adata),
Emmanuel Bertin's avatar
Emmanuel Bertin committed
246
247
		profit_fluxcor(profitstruct *profit, objstruct *obj,
				obj2struct *obj2),
Emmanuel Bertin's avatar
Emmanuel Bertin committed
248
		profit_makedft(profitstruct *profit),
249
		profit_moments(profitstruct *profit, obj2struct *obj2),
250
		profit_printout(int n_par, float* par, int m_dat, float* fvec,
Emmanuel Bertin's avatar
Emmanuel Bertin committed
251
252
253
254
			void *data, int iflag, int iter, int nfev ),
		profit_psf(profitstruct *profit),
		profit_resetparam(profitstruct *profit, paramenum paramtype),
		profit_resetparams(profitstruct *profit),
255
		profit_surface(profitstruct *profit, obj2struct *obj2);
Emmanuel Bertin's avatar
Emmanuel Bertin committed
256
257

#endif