Changeset 28643 for branches/eam_branches/ipp-20100621/psModules/src/objects/models/pmModel_SERSIC.c
- Timestamp:
- Jul 9, 2010, 10:56:32 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20100621/psModules/src/objects/models/pmModel_SERSIC.c
r26916 r28643 18 18 * PM_PAR_7 7 - normalized sersic parameter 19 19 20 note that a standard sersic model uses exp(-K*(z^(1/ n) - 1). the additional elements (K,20 note that a standard sersic model uses exp(-K*(z^(1/2n) - 1). the additional elements (K, 21 21 the -1 offset) are absorbed in this model by the normalization, the exponent, and the 22 22 radial scale. We fit the elements in this form, then re-normalize them on output. … … 25 25 #include <stdio.h> 26 26 #include <pslib.h> 27 27 #include "pmHDU.h" 28 #include "pmFPA.h" 29 30 #include "pmTrend2D.h" 31 #include "pmResiduals.h" 32 #include "pmGrowthCurve.h" 33 #include "pmSpan.h" 34 #include "pmFootprintSpans.h" 35 #include "pmFootprint.h" 36 #include "pmPeaks.h" 28 37 #include "pmMoments.h" 29 #include "pmPeaks.h" 38 #include "pmModelFuncs.h" 39 #include "pmModel.h" 40 #include "pmModelUtils.h" 41 #include "pmModelClass.h" 42 #include "pmSourceMasks.h" 43 #include "pmSourceExtendedPars.h" 44 #include "pmSourceDiffStats.h" 30 45 #include "pmSource.h" 31 #include "pmModel.h" 46 #include "pmSourceFitModel.h" 47 #include "pmPSF.h" 48 #include "pmPSFtry.h" 49 #include "pmDetections.h" 50 32 51 #include "pmModel_SERSIC.h" 33 52 53 # define PM_MODEL_NPARAM 8 34 54 # define PM_MODEL_FUNC pmModelFunc_SERSIC 35 55 # define PM_MODEL_FLUX pmModelFlux_SERSIC … … 47 67 48 68 // Lax parameter limits 49 static float paramsMinLax[] = { -1.0e3, 1.0e-2, -100, -100, 0.0 5, 0.05, -1.0, 0.05 };69 static float paramsMinLax[] = { -1.0e3, 1.0e-2, -100, -100, 0.001, 0.001, -1.0, 0.05 }; 50 70 static float paramsMaxLax[] = { 1.0e5, 1.0e8, 1.0e4, 1.0e4, 100, 100, 1.0, 4.0 }; 51 71 … … 84 104 assert (z >= 0); 85 105 86 psF32 f2 = pow(z,PAR[PM_PAR_7]); 87 psF32 f1 = exp(-f2); 106 float index = 0.5 / PAR[PM_PAR_7]; 107 float bn = 1.9992*index - 0.3271; 108 float Io = exp(bn); 109 110 psF32 f2 = bn*pow(z,PAR[PM_PAR_7]); 111 psF32 f1 = Io*exp(-f2); 88 112 psF32 z0 = PAR[PM_PAR_I0]*f1; 89 113 psF32 f0 = PAR[PM_PAR_SKY] + z0; … … 98 122 99 123 // gradient is infinite for z = 0; saturate at z = 0.01 100 psF32 z1 = (z < 0.01) ? z0* PAR[PM_PAR_7]*pow(0.01,PAR[PM_PAR_7] - 1.0) : z0*PAR[PM_PAR_7]*pow(z,PAR[PM_PAR_7] - 1.0);124 psF32 z1 = (z < 0.01) ? z0*bn*PAR[PM_PAR_7]*pow(0.01,PAR[PM_PAR_7] - 1.0) : z0*bn*PAR[PM_PAR_7]*pow(z,PAR[PM_PAR_7] - 1.0); 101 125 102 126 dPAR[PM_PAR_SKY] = +1.0; 103 127 dPAR[PM_PAR_I0] = +f1; 104 dPAR[PM_PAR_7] = (z == 0.0) ? 0.0 : -z0*f2*log(z);128 dPAR[PM_PAR_7] = (z < 0.01) ? -1.5*z0*pow(0.01,PAR[PM_PAR_7])*log(0.01) : -1.5*z0*f2*log(z); 105 129 106 130 assert (isfinite(z1)); … … 111 135 dPAR[PM_PAR_SXX] = +2.0*z1*px*px/PAR[PM_PAR_SXX]; 112 136 dPAR[PM_PAR_SYY] = +2.0*z1*py*py/PAR[PM_PAR_SYY]; 113 dPAR[PM_PAR_SXY] = -1.0*z1*X*Y;114 137 dPAR[PM_PAR_SXY] = -1.0*z1*X*Y; 115 138 } … … 127 150 return true; 128 151 } 129 psAssert(nParam >= 0 && nParam < = PM_PAR_7, "Parameter index is out of bounds");152 psAssert(nParam >= 0 && nParam < PM_MODEL_NPARAM, "Parameter index is out of bounds"); 130 153 131 154 // we need to calculate the limits for SXY specially … … 219 242 if (!isfinite(shape.sxy)) return false; 220 243 244 // the other parameters depend on the guess for PAR_7 245 if (0) { 246 } else { 247 PAR[PM_PAR_7] = 0.25; 248 // PAR[PM_PAR_7] = 0.125; 249 // PAR[PM_PAR_7] = 0.5; 250 } 251 252 float index = 0.5 / PAR[PM_PAR_7]; 253 float bn = 1.9992*index - 0.3271; 254 // float fR = 1.0 / (sqrt(2.0) * pow (bn, index)); 255 float Io = exp(0.5*bn); 256 257 float Sxx = PS_MAX(0.5, shape.sx); 258 float Syy = PS_MAX(0.5, shape.sy); 259 221 260 PAR[PM_PAR_SKY] = 0.0; 222 PAR[PM_PAR_I0] = peak->flux ;261 PAR[PM_PAR_I0] = peak->flux / Io; 223 262 PAR[PM_PAR_XPOS] = peak->xf; 224 263 PAR[PM_PAR_YPOS] = peak->yf; 225 PAR[PM_PAR_SXX] = PS_MAX(0.5, M_SQRT2*shape.sx);226 PAR[PM_PAR_SYY] = PS_MAX(0.5, M_SQRT2*shape.sy);264 PAR[PM_PAR_SXX] = Sxx; 265 PAR[PM_PAR_SYY] = Syy; 227 266 PAR[PM_PAR_SXY] = shape.sxy; 228 PAR[PM_PAR_7] = 0.5;229 267 230 268 return(true); … … 254 292 float f1, f2; 255 293 for (z = DZ; z < 50; z += DZ) { 256 f1 = 1.0 / (1 + PAR[PM_PAR_7]*z + pow(z, 2.25)); 294 // f1 = 1.0 / (1 + PAR[PM_PAR_7]*z + pow(z, 2.25)); 295 f1 = exp(-pow(z,PAR[PM_PAR_7])); 257 296 z += DZ; 258 f2 = 1.0 / (1 + PAR[PM_PAR_7]*z + pow(z, 2.25));297 f2 = exp(-pow(z,PAR[PM_PAR_7])); 259 298 norm += f0 + 4*f1 + f2; 260 299 f0 = f2; … … 287 326 288 327 psEllipseAxes axes = psEllipseShapeToAxes (shape, 20.0); 289 psF64 sigma = axes.major; 290 291 psF64 limit = flux / PAR[PM_PAR_I0]; 292 293 psF64 z = pow (-log(limit), (1.0 / PAR[PM_PAR_7])); 294 psAssert (isfinite(z), "fix this code: z should not be nan for %f", PAR[PM_PAR_7]); 295 296 psF64 radius = sigma * sqrt (2.0 * z); 297 psAssert (isfinite(radius), "fix this code: radius should not be nan for %f, %f", PAR[PM_PAR_7], sigma); 298 299 if (isnan(radius)) 300 psAbort("error in code: radius is NaN"); 301 328 329 // f = Io exp(-z^n) -> z^n = ln(Io/f) 330 psF64 zn = log(PAR[PM_PAR_I0] / flux); 331 psF64 radius = axes.major * sqrt (2.0) * pow(zn, 0.5 / PAR[PM_PAR_7]); 332 333 psAssert (isfinite(radius), "fix this code: z should not be nan for %f", PAR[PM_PAR_7]); 302 334 return (radius); 303 335 } … … 448 480 return; 449 481 } 450 451 # undef PM_MODEL_FUNC452 # undef PM_MODEL_FLUX453 # undef PM_MODEL_GUESS454 # undef PM_MODEL_LIMITS455 # undef PM_MODEL_RADIUS456 # undef PM_MODEL_FROM_PSF457 # undef PM_MODEL_PARAMS_FROM_PSF458 # undef PM_MODEL_FIT_STATUS459 # undef PM_MODEL_SET_LIMITS
Note:
See TracChangeset
for help on using the changeset viewer.
