profit.h 8.14 KB
Newer Older
Emmanuel Bertin's avatar
Emmanuel Bertin committed
1
2
3
4
5
6
7
8
9
10
11
 /*
 				profit.h

*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*
*	Part of:	SExtractor
*
*	Authors:	E.BERTIN (IAP)
*
*	Contents:	Include file for profit.c.
*
12
*	Last modify:	07/10/2009
Emmanuel Bertin's avatar
Emmanuel Bertin committed
13
14
15
16
17
18
19
20
21
*
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/

#ifndef _PROFIT_H_
#define _PROFIT_H_

/*-------------------------------- flags ------------------------------------*/

22
23
24
#define		PROFLAG_MODSUB		0x0001
#define		PROFLAG_OBJSUB		0x0002
#define		PROFLAG_NOTCONST	0x0004
Emmanuel Bertin's avatar
Emmanuel Bertin committed
25
26
27
28
29
30
31
32
33
34

/*-------------------------------- 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 --------------------------*/

#define	PROFIT_MAXITER	1000	/* Max. nb of iterations in profile fitting */
#define	PROFIT_MAXPROF	8	/* Max. nb of profile components */
Emmanuel Bertin's avatar
Emmanuel Bertin committed
35
#define	PROFIT_OVERSAMP	5	/* Max. profile oversamp. factor on each axis */
36
37
#define	PROFIT_HIDEFRES	201	/* Resolution of the high def. model raster */
#define	PROFIT_REFFFAC	6.0	/* Factor in r_eff for measurement radius*/
38
#define	PROFIT_DYNPARAM	10.0	/* Dynamic compression param. in sigma units */
39
40
#define	PROFIT_MAXMODSIZE  1024	/* Maximum size allowed for the model raster */
#define	PROFIT_MAXOBJSIZE  512	/* Maximum size allowed for the object raster */
Emmanuel Bertin's avatar
Emmanuel Bertin committed
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#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		{PROF_BACK, PROF_SERSIC, PROF_DEVAUCOULEURS,
			PROF_EXPONENTIAL, PROF_ARMS, PROF_BAR, PROF_INRING,
55
			PROF_OUTRING, PROF_SERSIC_TABEX, PROF_DIRAC, PROF_NPROF}
Emmanuel Bertin's avatar
Emmanuel Bertin committed
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
				proftypenum; /* Profile code */

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

typedef enum	{PARAM_BACK, PARAM_X, PARAM_Y,
		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;

/*--------------------------- structure definitions -------------------------*/

typedef struct
  {
  proftypenum	code;			/* Model code */
79
  float		*pix;			/* Full pixmap of the model */
Emmanuel Bertin's avatar
Emmanuel Bertin committed
80
81
  int		naxis;			/* Number of pixmap dimensions */
  int		naxisn[3];		/* Pixmap size for each axis */
82
83
  float		typscale;		/* Typical scale in prof pixels */
  float		fluxfac;		/* Flux normalisation factor */
84
  float		lostfluxfrac;		/* Lost flux fraction */
Emmanuel Bertin's avatar
Emmanuel Bertin committed
85
/* Generic presentation parameters */
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
  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
102
103
104
  int		extracycleflag[PROFIT_MAXEXTRA]; /* !=0 for cycling dim. */
  interpenum	interptype[2+PROFIT_MAXEXTRA];	/* Interpolation type */
  int		kernelwidth[2+PROFIT_MAXEXTRA];	/* Kernel size */
105
  float		*kernelbuf;		/* Kernel buffer */
Emmanuel Bertin's avatar
Emmanuel Bertin committed
106
107
108
109
110
111
112
113
  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 */
114
  float		*paramlist[PARAM_NPARAM];	/* flat parameter list */
Emmanuel Bertin's avatar
Emmanuel Bertin committed
115
  int		paramindex[PARAM_NPARAM];/* Vector of parameter indices */
116
117
118
119
120
121
  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 */
  float		*covar;		/* Covariance matrix */
  float		paramerr[PARAM_NPARAM];	/* Std deviations of parameters */
Emmanuel Bertin's avatar
Emmanuel Bertin committed
122
123
124
125
  int		niter;		/* Number of iterations */
  profstruct	**prof;		/* Array of pointers to profiles */
  int		nprof;		/* Number of profiles to consider */
  struct psf	*psf;		/* PSF */
126
  float		pixstep;	/* Model/PSF sampling step */
127
  float		fluxfac;	/* Model flux scaling factor */
128
  float		nsubsamp;	/* Subsampling factor */
129
130
131
  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 */
Emmanuel Bertin's avatar
Emmanuel Bertin committed
132
133
134
135
136
137
138
  float		*pmodpix;	/* Full res. pixmap of the partial model */
  int		modnaxisn[3];	/* Dimensions along each axis */
  PIXTYPE	*lmodpix;	/* Low resolution pixmap of the model */
  PIXTYPE	*objpix;	/* Copy of object pixmap */
  PIXTYPE	*objweight;	/* Copy of object weight-map */
  int		objnaxisn[2];	/* Dimensions along each axis */
  int		ix, iy;		/* Integer coordinates of object pixmap */
139
  float		*resi;		/* Vector of residuals */
Emmanuel Bertin's avatar
Emmanuel Bertin committed
140
  int		nresi;		/* Number of residual elements */
141
142
143
144
  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) */
Emmanuel Bertin's avatar
Emmanuel Bertin committed
145
146
147
148
149
150
151
152
153
  }	profitstruct;

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

profitstruct	*profit_init(struct psf *psf);

profstruct	*prof_init(profitstruct *profit, proftypenum profcode);

154
155
float		*profit_compresi(profitstruct *profit, float dynparam,
				float *resi),
Emmanuel Bertin's avatar
Emmanuel Bertin committed
156
		*profit_residuals(profitstruct *profit, picstruct *field,
157
158
			picstruct *wfield, float dynparam,
			float *param, float *resi),
159
160
		prof_add(profstruct *prof, profitstruct *profit),
		profit_minradius(profitstruct *profit, float refffac),
Emmanuel Bertin's avatar
Emmanuel Bertin committed
161
162
163
164
165
166
		profit_spiralindex(profitstruct *profit);

int		profit_copyobjpix(profitstruct *profit, picstruct *field,
			picstruct *wfield),
		profit_minimize(profitstruct *profit, int niter),
		profit_setparam(profitstruct *profit, paramenum paramtype,
167
			float param, float parammin, float parammax);
Emmanuel Bertin's avatar
Emmanuel Bertin committed
168

169
void		prof_end(profstruct *prof),
Emmanuel Bertin's avatar
Emmanuel Bertin committed
170
		profit_addparam(profitstruct *profit, paramenum paramindex,
171
172
			float **param),
		profit_boundtounbound(profitstruct *profit, float *param),
Emmanuel Bertin's avatar
Emmanuel Bertin committed
173
174
175
		profit_fit(profitstruct *profit,
			picstruct *field, picstruct *wfield,
			objstruct *obj, obj2struct *obj2),
176
		profit_convolve(profitstruct *profit, float *modpix),
Emmanuel Bertin's avatar
Emmanuel Bertin committed
177
178
		profit_covarunboundtobound(profitstruct *profit),
		profit_end(profitstruct *profit),
179
		profit_evaluate(float *par, float *fvec, int m, int n,
Emmanuel Bertin's avatar
Emmanuel Bertin committed
180
181
			void *adata),
		profit_makedft(profitstruct *profit),
182
		profit_moments(profitstruct *profit, obj2struct *obj2),
183
		profit_printout(int n_par, float* par, int m_dat, float* fvec,
Emmanuel Bertin's avatar
Emmanuel Bertin committed
184
185
			void *data, int iflag, int iter, int nfev ),
		profit_psf(profitstruct *profit),
186
187
		profit_resample(profitstruct *profit, float *inpix,
			PIXTYPE *outpix, float factor),
Emmanuel Bertin's avatar
Emmanuel Bertin committed
188
189
		profit_resetparam(profitstruct *profit, paramenum paramtype),
		profit_resetparams(profitstruct *profit),
190
191
		profit_surface(profitstruct *profit, obj2struct *obj2,
			double lostfluxfrac),
192
		profit_unboundtobound(profitstruct *profit, float *param);
Emmanuel Bertin's avatar
Emmanuel Bertin committed
193
194

#endif