| 1 |
233 |
bertin |
/*
|
| 2 |
|
|
* profit.h
|
| 3 |
42 |
bertin |
*
|
| 4 |
233 |
bertin |
* Include file for profit.c.
|
| 5 |
42 |
bertin |
*
|
| 6 |
233 |
bertin |
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
| 7 |
42 |
bertin |
*
|
| 8 |
233 |
bertin |
* This file part of: SExtractor
|
| 9 |
42 |
bertin |
*
|
| 10 |
235 |
bertin |
* Copyright: (C) 2006-2010 Emmanuel Bertin -- IAP/CNRS/UPMC
|
| 11 |
42 |
bertin |
*
|
| 12 |
233 |
bertin |
* License: GNU General Public License
|
| 13 |
|
|
*
|
| 14 |
|
|
* SExtractor is free software: you can redistribute it and/or modify
|
| 15 |
|
|
* it under the terms of the GNU General Public License as published by
|
| 16 |
|
|
* the Free Software Foundation, either version 3 of the License, or
|
| 17 |
|
|
* (at your option) any later version.
|
| 18 |
|
|
* SExtractor is distributed in the hope that it will be useful,
|
| 19 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 20 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 21 |
|
|
* GNU General Public License for more details.
|
| 22 |
|
|
* You should have received a copy of the GNU General Public License
|
| 23 |
|
|
* along with SExtractor. If not, see <http://www.gnu.org/licenses/>.
|
| 24 |
|
|
*
|
| 25 |
241 |
bertin |
* Last modified: 24/01/2011
|
| 26 |
233 |
bertin |
*
|
| 27 |
|
|
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
| 28 |
42 |
bertin |
|
| 29 |
79 |
bertin |
#ifndef _PROFIT_H_
|
| 30 |
|
|
#define _PROFIT_H_
|
| 31 |
|
|
|
| 32 |
82 |
bertin |
/*-------------------------------- flags ------------------------------------*/
|
| 33 |
|
|
|
| 34 |
211 |
bertin |
#define PROFLAG_MODSUB 0x0001
|
| 35 |
|
|
#define PROFLAG_OBJSUB 0x0002
|
| 36 |
|
|
#define PROFLAG_NOTCONST 0x0004
|
| 37 |
82 |
bertin |
|
| 38 |
86 |
bertin |
/*-------------------------------- macros -----------------------------------*/
|
| 39 |
|
|
|
| 40 |
|
|
#define PROFIT_POW(x,a) (x>0.01? exp(a*log(x)) : pow(x,a))
|
| 41 |
|
|
#define PROFIT_POWF(x,a) (x>0.01? expf(a*logf(x)) : powf(x,a))
|
| 42 |
|
|
|
| 43 |
42 |
bertin |
/*----------------------------- Internal constants --------------------------*/
|
| 44 |
|
|
|
| 45 |
221 |
bertin |
#define PARAM_ALLPARAMS (-1) /* All parameters */
|
| 46 |
117 |
bertin |
#define PROFIT_MAXITER 1000 /* Max. nb of iterations in profile fitting */
|
| 47 |
50 |
bertin |
#define PROFIT_MAXPROF 8 /* Max. nb of profile components */
|
| 48 |
221 |
bertin |
#define PROFIT_HIDEFRES 201 /* Hi. def. model resol. (must be <MAXMODSIZE)*/
|
| 49 |
|
|
#define PROFIT_REFFFAC 3.0 /* Factor in r_eff for measurement radius*/
|
| 50 |
233 |
bertin |
#define PROFIT_MAXR2MAX 1e6 /* Maximum r2_max for truncating profiles */
|
| 51 |
180 |
bertin |
#define PROFIT_DYNPARAM 10.0 /* Dynamic compression param. in sigma units */
|
| 52 |
241 |
bertin |
#define PROFIT_SMOOTHR 4.0 /* Profile smoothing radius (pixels) */
|
| 53 |
212 |
bertin |
#define PROFIT_MAXMODSIZE 512 /* Maximum size allowed for the model raster */
|
| 54 |
211 |
bertin |
#define PROFIT_MAXOBJSIZE 512 /* Maximum size allowed for the object raster */
|
| 55 |
81 |
bertin |
#define PROFIT_BARXFADE 0.1 /* Fract. of bar length crossfaded with arms */
|
| 56 |
49 |
bertin |
#define PROFIT_MAXEXTRA 2 /* Max. nb of extra free params of profiles */
|
| 57 |
60 |
bertin |
#define PROFIT_PROFRES 256 /* Pixmap size of model components */
|
| 58 |
52 |
bertin |
#define PROFIT_PROFSRES 64 /* Number of model subcomponents */
|
| 59 |
50 |
bertin |
#define INTERP_MAXKERNELWIDTH 8 /* Max. range of kernel (pixels) */
|
| 60 |
42 |
bertin |
/* NOTES:
|
| 61 |
|
|
One must have: PROFIT_NITER > 0
|
| 62 |
49 |
bertin |
PROFIT_MAXEXTRA > 0
|
| 63 |
42 |
bertin |
*/
|
| 64 |
|
|
|
| 65 |
|
|
/*--------------------------------- typedefs --------------------------------*/
|
| 66 |
|
|
|
| 67 |
233 |
bertin |
typedef enum {PROF_BACK, PROF_DIRAC, PROF_SERSIC, PROF_DEVAUCOULEURS,
|
| 68 |
85 |
bertin |
PROF_EXPONENTIAL, PROF_ARMS, PROF_BAR, PROF_INRING,
|
| 69 |
233 |
bertin |
PROF_OUTRING, PROF_SERSIC_TABEX, PROF_NPROF}
|
| 70 |
60 |
bertin |
proftypenum; /* Profile code */
|
| 71 |
118 |
bertin |
|
| 72 |
46 |
bertin |
typedef enum {INTERP_NEARESTNEIGHBOUR, INTERP_BILINEAR, INTERP_LANCZOS2,
|
| 73 |
|
|
INTERP_LANCZOS3, INTERP_LANCZOS4} interpenum;
|
| 74 |
42 |
bertin |
|
| 75 |
233 |
bertin |
typedef enum {PARAM_BACK,
|
| 76 |
|
|
PARAM_DIRAC_FLUX, PARAM_X, PARAM_Y,
|
| 77 |
115 |
bertin |
PARAM_SPHEROID_FLUX, PARAM_SPHEROID_REFF, PARAM_SPHEROID_ASPECT,
|
| 78 |
|
|
PARAM_SPHEROID_POSANG, PARAM_SPHEROID_SERSICN,
|
| 79 |
|
|
PARAM_DISK_FLUX, PARAM_DISK_SCALE, PARAM_DISK_ASPECT,
|
| 80 |
|
|
PARAM_DISK_POSANG,
|
| 81 |
84 |
bertin |
PARAM_ARMS_FLUX, PARAM_ARMS_QUADFRAC, PARAM_ARMS_SCALE,
|
| 82 |
66 |
bertin |
PARAM_ARMS_START, PARAM_ARMS_POSANG, PARAM_ARMS_PITCH,
|
| 83 |
115 |
bertin |
PARAM_ARMS_PITCHVAR, PARAM_ARMS_WIDTH,
|
| 84 |
84 |
bertin |
PARAM_BAR_FLUX, PARAM_BAR_ASPECT, PARAM_BAR_POSANG,
|
| 85 |
88 |
bertin |
PARAM_INRING_FLUX, PARAM_INRING_WIDTH, PARAM_INRING_ASPECT,
|
| 86 |
87 |
bertin |
PARAM_OUTRING_FLUX, PARAM_OUTRING_START, PARAM_OUTRING_WIDTH,
|
| 87 |
58 |
bertin |
PARAM_NPARAM} paramenum;
|
| 88 |
|
|
|
| 89 |
115 |
bertin |
/*--------------------------- structure definitions -------------------------*/
|
| 90 |
42 |
bertin |
|
| 91 |
|
|
typedef struct
|
| 92 |
|
|
{
|
| 93 |
50 |
bertin |
proftypenum code; /* Model code */
|
| 94 |
201 |
bertin |
float *pix; /* Full pixmap of the model */
|
| 95 |
42 |
bertin |
int naxis; /* Number of pixmap dimensions */
|
| 96 |
141 |
bertin |
int naxisn[3]; /* Pixmap size for each axis */
|
| 97 |
221 |
bertin |
int npix; /* Total number of prof pixels */
|
| 98 |
201 |
bertin |
float typscale; /* Typical scale in prof pixels */
|
| 99 |
|
|
float fluxfac; /* Flux normalisation factor */
|
| 100 |
207 |
bertin |
float lostfluxfrac; /* Lost flux fraction */
|
| 101 |
221 |
bertin |
float m0,mx2,my2,mxy; /* 2nd order moments */
|
| 102 |
42 |
bertin |
/* Generic presentation parameters */
|
| 103 |
201 |
bertin |
float *flux; /* Integrated flux */
|
| 104 |
|
|
float *x[2]; /* Coordinate vector */
|
| 105 |
|
|
float *scale; /* Scaling vector */
|
| 106 |
|
|
float *aspect; /* Aspect ratio */
|
| 107 |
|
|
float *posangle; /* Position angle (CCW/NAXIS1)*/
|
| 108 |
|
|
float *featfrac; /* Feature flux fraction */
|
| 109 |
|
|
float *featscale; /* Feature relative scalelength */
|
| 110 |
|
|
float *featstart; /* Feature relative starting radius */
|
| 111 |
|
|
float *featposang; /* Feature position angle */
|
| 112 |
|
|
float *featpitch; /* Feature pitch */
|
| 113 |
|
|
float *featpitchvar; /* Feature pitch variation */
|
| 114 |
|
|
float *featwidth; /* Feature width */
|
| 115 |
|
|
float *feataspect; /* Feature aspect ratio */
|
| 116 |
|
|
float *extra[PROFIT_MAXEXTRA];/* Parameters along extra-dimension */
|
| 117 |
|
|
float extrazero[PROFIT_MAXEXTRA]; /* Zero-point along extra-dim. */
|
| 118 |
|
|
float extrascale[PROFIT_MAXEXTRA]; /* Scaling along extra-dim. */
|
| 119 |
50 |
bertin |
int extracycleflag[PROFIT_MAXEXTRA]; /* !=0 for cycling dim. */
|
| 120 |
52 |
bertin |
interpenum interptype[2+PROFIT_MAXEXTRA]; /* Interpolation type */
|
| 121 |
|
|
int kernelwidth[2+PROFIT_MAXEXTRA]; /* Kernel size */
|
| 122 |
201 |
bertin |
float *kernelbuf; /* Kernel buffer */
|
| 123 |
52 |
bertin |
int kernelnlines; /* Number of interp kernel lines */
|
| 124 |
42 |
bertin |
} profstruct;
|
| 125 |
|
|
|
| 126 |
|
|
typedef struct
|
| 127 |
|
|
{
|
| 128 |
146 |
bertin |
objstruct *obj; /* Current object */
|
| 129 |
|
|
obj2struct *obj2; /* Current object */
|
| 130 |
42 |
bertin |
int nparam; /* Number of parameters to be fitted */
|
| 131 |
201 |
bertin |
float *paramlist[PARAM_NPARAM]; /* flat parameter list */
|
| 132 |
128 |
bertin |
int paramindex[PARAM_NPARAM];/* Vector of parameter indices */
|
| 133 |
221 |
bertin |
int paramrevindex[PARAM_NPARAM];/* Vector of reversed indices */
|
| 134 |
|
|
int freeparam_flag[PARAM_NPARAM]; /* Free parameter flag */
|
| 135 |
|
|
int nfreeparam; /* Number of free parameters */
|
| 136 |
201 |
bertin |
float param[PARAM_NPARAM]; /* Vector of parameters to be fitted */
|
| 137 |
|
|
float paraminit[PARAM_NPARAM];/* Parameter initial guesses */
|
| 138 |
|
|
float parammin[PARAM_NPARAM]; /* Parameter lower limits */
|
| 139 |
|
|
float parammax[PARAM_NPARAM]; /* Parameter upper limits */
|
| 140 |
221 |
bertin |
float paramerr[PARAM_NPARAM]; /* Std deviations of parameters */
|
| 141 |
201 |
bertin |
float *covar; /* Covariance matrix */
|
| 142 |
221 |
bertin |
int iter; /* Iteration counter */
|
| 143 |
42 |
bertin |
int niter; /* Number of iterations */
|
| 144 |
|
|
profstruct **prof; /* Array of pointers to profiles */
|
| 145 |
|
|
int nprof; /* Number of profiles to consider */
|
| 146 |
79 |
bertin |
struct psf *psf; /* PSF */
|
| 147 |
201 |
bertin |
float pixstep; /* Model/PSF sampling step */
|
| 148 |
207 |
bertin |
float fluxfac; /* Model flux scaling factor */
|
| 149 |
212 |
bertin |
float subsamp; /* Subsampling factor */
|
| 150 |
201 |
bertin |
float *psfdft; /* Compressed Fourier Transform of the PSF */
|
| 151 |
|
|
float *psfpix; /* Full res. pixmap of the PSF */
|
| 152 |
|
|
float *modpix; /* Full res. pixmap of the complete model */
|
| 153 |
221 |
bertin |
float *modpix2; /* 2nd full res. pixmap of the complete model */
|
| 154 |
|
|
float *cmodpix; /* Full res. pixmap of the convolved model */
|
| 155 |
141 |
bertin |
int modnaxisn[3]; /* Dimensions along each axis */
|
| 156 |
221 |
bertin |
int nmodpix; /* Total number of model pixels */
|
| 157 |
50 |
bertin |
PIXTYPE *lmodpix; /* Low resolution pixmap of the model */
|
| 158 |
221 |
bertin |
PIXTYPE *lmodpix2; /* 2nd low resolution pixmap of the model */
|
| 159 |
50 |
bertin |
PIXTYPE *objpix; /* Copy of object pixmap */
|
| 160 |
|
|
PIXTYPE *objweight; /* Copy of object weight-map */
|
| 161 |
47 |
bertin |
int objnaxisn[2]; /* Dimensions along each axis */
|
| 162 |
221 |
bertin |
int nobjpix; /* Total number of "final" pixels */
|
| 163 |
145 |
bertin |
int ix, iy; /* Integer coordinates of object pixmap */
|
| 164 |
201 |
bertin |
float *resi; /* Vector of residuals */
|
| 165 |
43 |
bertin |
int nresi; /* Number of residual elements */
|
| 166 |
201 |
bertin |
float chi2; /* Std error per residual element */
|
| 167 |
|
|
float sigma; /* Standard deviation of the pixel values */
|
| 168 |
|
|
float flux; /* Total flux in final convolved model */
|
| 169 |
|
|
float spirindex; /* Spiral index (>0 for CCW) */
|
| 170 |
221 |
bertin |
/* Buffers */
|
| 171 |
|
|
double dparam[PARAM_NPARAM];
|
| 172 |
42 |
bertin |
} profitstruct;
|
| 173 |
|
|
|
| 174 |
|
|
/*----------------------------- Global variables ----------------------------*/
|
| 175 |
|
|
/*-------------------------------- functions --------------------------------*/
|
| 176 |
50 |
bertin |
|
| 177 |
115 |
bertin |
profitstruct *profit_init(struct psf *psf);
|
| 178 |
50 |
bertin |
|
| 179 |
|
|
profstruct *prof_init(profitstruct *profit, proftypenum profcode);
|
| 180 |
|
|
|
| 181 |
201 |
bertin |
float *profit_compresi(profitstruct *profit, float dynparam,
|
| 182 |
|
|
float *resi),
|
| 183 |
50 |
bertin |
*profit_residuals(profitstruct *profit, picstruct *field,
|
| 184 |
201 |
bertin |
picstruct *wfield, float dynparam,
|
| 185 |
|
|
float *param, float *resi),
|
| 186 |
221 |
bertin |
prof_add(profitstruct *profit, profstruct *prof,
|
| 187 |
|
|
int extfluxfac_flag),
|
| 188 |
207 |
bertin |
profit_minradius(profitstruct *profit, float refffac),
|
| 189 |
146 |
bertin |
profit_spiralindex(profitstruct *profit);
|
| 190 |
50 |
bertin |
|
| 191 |
|
|
int profit_copyobjpix(profitstruct *profit, picstruct *field,
|
| 192 |
146 |
bertin |
picstruct *wfield),
|
| 193 |
79 |
bertin |
profit_minimize(profitstruct *profit, int niter),
|
| 194 |
225 |
bertin |
prof_moments(profitstruct *profit, profstruct *prof,
|
| 195 |
|
|
double *jac),
|
| 196 |
221 |
bertin |
profit_resample(profitstruct *profit, float *inpix,
|
| 197 |
|
|
PIXTYPE *outpix, float factor),
|
| 198 |
115 |
bertin |
profit_setparam(profitstruct *profit, paramenum paramtype,
|
| 199 |
201 |
bertin |
float param, float parammin, float parammax);
|
| 200 |
50 |
bertin |
|
| 201 |
207 |
bertin |
void prof_end(profstruct *prof),
|
| 202 |
58 |
bertin |
profit_addparam(profitstruct *profit, paramenum paramindex,
|
| 203 |
201 |
bertin |
float **param),
|
| 204 |
221 |
bertin |
profit_boundtounbound(profitstruct *profit,
|
| 205 |
|
|
float *param, double *dparam, int index),
|
| 206 |
65 |
bertin |
profit_fit(profitstruct *profit,
|
| 207 |
52 |
bertin |
picstruct *field, picstruct *wfield,
|
| 208 |
50 |
bertin |
objstruct *obj, obj2struct *obj2),
|
| 209 |
201 |
bertin |
profit_convolve(profitstruct *profit, float *modpix),
|
| 210 |
221 |
bertin |
profit_covarunboundtobound(profitstruct *profit,
|
| 211 |
|
|
double *dparam, float *param),
|
| 212 |
50 |
bertin |
profit_end(profitstruct *profit),
|
| 213 |
221 |
bertin |
profit_evaluate(double *par, double *fvec, int m, int n,
|
| 214 |
57 |
bertin |
void *adata),
|
| 215 |
235 |
bertin |
profit_fluxcor(profitstruct *profit, objstruct *obj,
|
| 216 |
|
|
obj2struct *obj2),
|
| 217 |
52 |
bertin |
profit_makedft(profitstruct *profit),
|
| 218 |
207 |
bertin |
profit_moments(profitstruct *profit, obj2struct *obj2),
|
| 219 |
201 |
bertin |
profit_printout(int n_par, float* par, int m_dat, float* fvec,
|
| 220 |
58 |
bertin |
void *data, int iflag, int iter, int nfev ),
|
| 221 |
122 |
bertin |
profit_psf(profitstruct *profit),
|
| 222 |
146 |
bertin |
profit_resetparam(profitstruct *profit, paramenum paramtype),
|
| 223 |
|
|
profit_resetparams(profitstruct *profit),
|
| 224 |
221 |
bertin |
profit_surface(profitstruct *profit, obj2struct *obj2),
|
| 225 |
|
|
profit_unboundtobound(profitstruct *profit,
|
| 226 |
|
|
double *dparam, float *param, int index);
|
| 227 |
65 |
bertin |
|
| 228 |
79 |
bertin |
#endif
|