Changeset 28781
- Timestamp:
- Jul 29, 2010, 2:35:46 PM (16 years ago)
- Location:
- branches/eam_branches/ipp-20100621/psModules/src/objects
- Files:
-
- 6 edited
-
models/pmModel_SERSIC.c (modified) (6 diffs)
-
pmPCMdata.c (modified) (1 diff)
-
pmPCMdata.h (modified) (1 diff)
-
pmSource.c (modified) (4 diffs)
-
pmSource.h (modified) (1 diff)
-
pmSourceFitPCM.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20100621/psModules/src/objects/models/pmModel_SERSIC.c
r28656 r28781 126 126 dPAR[PM_PAR_SKY] = +1.0; 127 127 dPAR[PM_PAR_I0] = +f1; 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); 128 dPAR[PM_PAR_7] = (z < 0.01) ? -z0*pow(0.01,PAR[PM_PAR_7])*log(0.01) : -z0*f2*log(z); 129 dPAR[PM_PAR_7] *= 3.0; 129 130 130 131 assert (isfinite(z1)); … … 133 134 dPAR[PM_PAR_XPOS] = +1.0*z1*(2.0*px/PAR[PM_PAR_SXX] + Y*PAR[PM_PAR_SXY]); 134 135 dPAR[PM_PAR_YPOS] = +1.0*z1*(2.0*py/PAR[PM_PAR_SYY] + X*PAR[PM_PAR_SXY]); 135 dPAR[PM_PAR_SXX] = +2.0*z1*px*px/PAR[PM_PAR_SXX]; 136 dPAR[PM_PAR_SXX] = +2.0*z1*px*px/PAR[PM_PAR_SXX]; // XXX : increase drag? 136 137 dPAR[PM_PAR_SYY] = +2.0*z1*py*py/PAR[PM_PAR_SYY]; 137 138 dPAR[PM_PAR_SXY] = -1.0*z1*X*Y; … … 224 225 psF32 *PAR = model->params->data.F32; 225 226 227 // the other parameters depend on the guess for PAR_7 228 if (!isfinite(PAR[PM_PAR_7])) { 229 PAR[PM_PAR_7] = 0.25; 230 } 231 float index = 0.5 / PAR[PM_PAR_7]; 232 233 // the scale-length is a function of the moments and the index: 234 // Rmajor_guess = Rmajor_moments * Scale * Zero 235 float Scale = 0.70 + 0.053 * PAR[PM_PAR_7]; 236 float Zero = 1.16 - 0.615 * PAR[PM_PAR_7]; 237 226 238 psEllipseMoments emoments; 227 239 emoments.x2 = moments->Mxx; … … 236 248 if (!isfinite(axes.theta)) return false; 237 249 250 // set a lower limit to avoid absurd solutions.. 251 float Rmajor = PS_MAX(1.0, Scale * axes.major + Zero); 252 float Rminor = Rmajor * (axes.minor / axes.major); 253 254 fprintf (stderr, "guess index: %f : %f, %f -> %f, %f\n", index, axes.major, axes.minor, Rmajor, Rminor); 255 256 axes.major = Rmajor; 257 axes.minor = Rminor; 238 258 psEllipseShape shape = psEllipseAxesToShape (axes); 239 259 … … 242 262 if (!isfinite(shape.sxy)) return false; 243 263 244 // the other parameters depend on the guess for PAR_7245 if (!isfinite(PAR[PM_PAR_7])) {246 PAR[PM_PAR_7] = 0.25;247 // PAR[PM_PAR_7] = 0.125;248 // PAR[PM_PAR_7] = 0.5;249 }250 251 float index = 0.5 / PAR[PM_PAR_7];252 264 float bn = 1.9992*index - 0.3271; 253 265 // float fR = 1.0 / (sqrt(2.0) * pow (bn, index)); 254 266 float Io = exp(0.5*bn); 267 268 // XXX do we need this factor of sqrt(2)? 269 // float Sxx = PS_MAX(0.5, M_SQRT2*shape.sx); 270 // float Syy = PS_MAX(0.5, M_SQRT2*shape.sy); 255 271 256 272 float Sxx = PS_MAX(0.5, shape.sx); … … 329 345 psF64 zn = log(PAR[PM_PAR_I0] / flux); 330 346 psF64 radius = axes.major * sqrt (2.0) * pow(zn, 0.5 / PAR[PM_PAR_7]); 347 348 fprintf (stderr, "sersic model %f %f, n %f, radius: %f, zn: %f, f/Io: %f, major: %f\n", PAR[PM_PAR_XPOS], PAR[PM_PAR_YPOS], PAR[PM_PAR_7], radius, zn, flux/PAR[PM_PAR_I0], axes.major); 331 349 332 350 psAssert (isfinite(radius), "fix this code: z should not be nan for %f", PAR[PM_PAR_7]); -
branches/eam_branches/ipp-20100621/psModules/src/objects/pmPCMdata.c
r28702 r28781 256 256 return pcm; 257 257 } 258 259 // has the set of fitted terms changed? has the fitting radius changed? 260 bool pmPCMupdate(pmPCMdata *pcm, pmSource *source, pmSourceFitOptions *fitOptions, pmModel *model) { 261 262 bool newWindow = (source->pixels->numRows != pcm->modelFlux->numRows) || (source->pixels->numCols != pcm->modelFlux->numCols); 263 264 // re-count the number of unmasked pixels: 265 if (newWindow) { 266 for (psS32 i = 0; i < source->pixels->numRows; i++) { 267 for (psS32 j = 0; j < source->pixels->numCols; j++) { 268 // XXX are we doing the right thing with the mask? 269 // skip masked points 270 if (source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[i][j]) { 271 continue; 272 } 273 // skip zero-variance points 274 if (source->variance->data.F32[i][j] == 0) { 275 continue; 276 } 277 // skip nan value points 278 if (!isfinite(source->pixels->data.F32[i][j])) { 279 continue; 280 } 281 pcm->nPix ++; 282 } 283 } 284 } 285 286 // if we changed the fit mode, we need to update nDOF 287 int nParams = 0; 288 // set parameter mask based on fitting mode 289 switch (fitOptions->mode) { 290 case PM_SOURCE_FIT_NORM: 291 // NORM-only model fits only source normalization (Io) 292 nParams = 1; 293 psVectorInit (pcm->constraint->paramMask, 1); 294 pcm->constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_I0] = 0; 295 break; 296 case PM_SOURCE_FIT_PSF: 297 // PSF model only fits x,y,Io 298 nParams = 3; 299 psVectorInit (pcm->constraint->paramMask, 1); 300 pcm->constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_I0] = 0; 301 pcm->constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_XPOS] = 0; 302 pcm->constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_YPOS] = 0; 303 break; 304 case PM_SOURCE_FIT_EXT: 305 // EXT model fits all params (except sky) 306 nParams = model->params->n - 1; 307 psVectorInit (pcm->constraint->paramMask, 0); 308 pcm->constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_SKY] = 1; 309 break; 310 case PM_SOURCE_FIT_INDEX: 311 // PSF model only fits Io, index (PAR7) -- only Io for models with < 8 params 312 psVectorInit (pcm->constraint->paramMask, 1); 313 pcm->constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_I0] = 0; 314 if (model->params->n == 7) { 315 nParams = 1; 316 } else { 317 nParams = 2; 318 pcm->constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_7] = 0; 319 } 320 break; 321 case PM_SOURCE_FIT_NO_INDEX: 322 // PSF model only fits Io, index (PAR7) -- only Io for models with < 8 params 323 psVectorInit (pcm->constraint->paramMask, 0); 324 pcm->constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_SKY] = 1; 325 if (model->params->n == 7) { 326 nParams = model->params->n - 1; 327 } else { 328 nParams = model->params->n - 2; 329 pcm->constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_7] = 1; 330 } 331 break; 332 default: 333 psAbort("invalid fitting mode"); 334 } 335 336 if (pcm->nPix < nParams + 1) { 337 psTrace ("psModules.objects", 4, "insufficient valid pixels\n"); 338 model->flags |= PM_MODEL_STATUS_BADARGS; 339 return false; 340 } 341 pcm->nDOF = pcm->nPix - nParams - 1; 342 343 // has the source pixel window changed? 344 if (newWindow) { 345 346 // adjust all supporting images: 347 pcm->modelFlux = psImageCopy (pcm->modelFlux, source->pixels, PS_TYPE_F32); 348 for (psS32 n = 0; n < pcm->dmodelsFlux->n; n++) { 349 if ((pcm->constraint->paramMask != NULL) && (pcm->constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[n])) { continue; } 350 pcm->dmodelsFlux->data[n] = psImageCopy (pcm->dmodelsFlux->data[n], source->pixels, PS_TYPE_F32); 351 } 352 353 // adjust images for convolved model and derivative images 354 pcm->modelConvFlux = psImageCopy (pcm->modelConvFlux, source->pixels, PS_TYPE_F32); 355 for (psS32 n = 0; n < pcm->dmodelsConvFlux->n; n++) { 356 if ((pcm->constraint->paramMask != NULL) && (pcm->constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[n])) { continue; } 357 pcm->dmodelsConvFlux->data[n] = psImageCopy (pcm->dmodelsConvFlux->data[n], source->pixels, PS_TYPE_F32); 358 } 359 } 360 361 return true; 362 } -
branches/eam_branches/ipp-20100621/psModules/src/objects/pmPCMdata.h
r28702 r28781 62 62 63 63 pmPCMdata *pmPCMinit(pmSource *source, pmSourceFitOptions *fitOptions, pmModel *model, psImageMaskType maskVal, float psfSize); 64 bool pmPCMupdate(pmPCMdata *pcm, pmSource *source, pmSourceFitOptions *fitOptions, pmModel *model); 64 65 65 66 psImage *pmPCMdataSaveImage (pmPCMdata *pcm); -
branches/eam_branches/ipp-20100621/psModules/src/objects/pmSource.c
r28676 r28781 966 966 bool addNoise = mode & PM_MODEL_OP_NOISE; 967 967 968 if (source->modelFlux) { 968 // require the use of pmModelAddWithOffset if we are adding noise (because the model size and norm are rescaled) 969 if (!addNoise && source->modelFlux) { 969 970 // add in the pixels from the modelFlux image 970 971 int dX = source->modelFlux->col0 - source->pixels->col0; … … 987 988 988 989 psF32 **target = source->pixels->data.F32; 989 if (addNoise) {990 // when adding noise, we assume the shape and Io have been modified991 target = source->variance->data.F32;992 }993 990 994 991 for (int iy = 0; iy < source->modelFlux->numRows; iy++) { … … 1005 1002 } 1006 1003 } 1007 if (!addNoise) { 1008 if (add) { 1009 source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED; 1010 } else { 1011 source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED; 1012 } 1004 if (add) { 1005 source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED; 1006 } else { 1007 source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED; 1013 1008 } 1014 1009 return true; … … 1029 1024 } 1030 1025 } 1026 1027 return true; 1028 } 1029 1030 // should we call pmSourceCacheModel if it does not exist? 1031 bool pmSourceNoiseOp (pmSource *source, pmModelOpMode mode, float FACTOR, float SIZE, bool add, psImageMaskType maskVal, int dx, int dy) 1032 { 1033 assert (mode & PM_MODEL_OP_NOISE); 1034 PS_ASSERT_PTR_NON_NULL(source, false); 1035 PS_ASSERT_PTR_NON_NULL(source->peak, false); 1036 1037 if (add) { 1038 psTrace ("psphot", 3, "adding noise to object at %f,%f\n", source->peak->xf, source->peak->yf); 1039 } else { 1040 psTrace ("psphot", 3, "removing noise from object at %f,%f\n", source->peak->xf, source->peak->yf); 1041 } 1042 1043 pmSourceNoiseOpModel (source->modelPSF, source, mode, FACTOR, SIZE, add, maskVal, dx, dy); 1044 1045 if (source->modelEXT) { 1046 pmSourceNoiseOpModel (source->modelEXT, source, mode, FACTOR, SIZE, add, maskVal, dx, dy); 1047 } 1048 1049 return true; 1050 } 1051 1052 bool pmSourceNoiseOpModel (pmModel *model, pmSource *source, pmModelOpMode mode, float FACTOR, float SIZE, bool add, psImageMaskType maskVal, int dx, int dy) 1053 { 1054 bool status; 1055 psEllipseShape oldshape; 1056 psEllipseShape newshape; 1057 psEllipseAxes axes; 1058 1059 if (add) { 1060 psTrace ("psphot", 4, "adding noise for object at %f,%f\n", model->params->data.F32[PM_PAR_XPOS], model->params->data.F32[PM_PAR_YPOS]); 1061 } else { 1062 psTrace ("psphot", 4, "remove noise for object at %f,%f\n", model->params->data.F32[PM_PAR_XPOS], model->params->data.F32[PM_PAR_YPOS]); 1063 } 1064 1065 psF32 *PAR = model->params->data.F32; 1066 1067 // save original values 1068 float oldI0 = PAR[PM_PAR_I0]; 1069 oldshape.sx = PAR[PM_PAR_SXX]; 1070 oldshape.sy = PAR[PM_PAR_SYY]; 1071 oldshape.sxy = PAR[PM_PAR_SXY]; 1072 1073 // XXX can this be done more intelligently? 1074 if (oldI0 == 0.0) return false; 1075 if (!isfinite(oldI0)) return false; 1076 1077 // increase size and height of source 1078 axes = psEllipseShapeToAxes (oldshape, 20.0); 1079 axes.major *= SIZE; 1080 axes.minor *= SIZE; 1081 newshape = psEllipseAxesToShape (axes); 1082 PAR[PM_PAR_I0] = FACTOR*oldI0; 1083 PAR[PM_PAR_SXX] = newshape.sx; 1084 PAR[PM_PAR_SYY] = newshape.sy; 1085 PAR[PM_PAR_SXY] = newshape.sxy; 1086 1087 psImage *target = source->variance; 1088 1089 if (add) { 1090 status = pmModelAddWithOffset (target, source->maskObj, model, mode, maskVal, dx, dy); 1091 } else { 1092 status = pmModelSubWithOffset (target, source->maskObj, model, mode, maskVal, dx, dy); 1093 } 1094 1095 // restore original values 1096 PAR[PM_PAR_I0] = oldI0; 1097 PAR[PM_PAR_SXX] = oldshape.sx; 1098 PAR[PM_PAR_SYY] = oldshape.sy; 1099 PAR[PM_PAR_SXY] = oldshape.sxy; 1031 1100 1032 1101 return true; -
branches/eam_branches/ipp-20100621/psModules/src/objects/pmSource.h
r28676 r28781 236 236 bool pmSourceSubWithOffset (pmSource *source, pmModelOpMode mode, psImageMaskType maskVal, int dx, int dy); 237 237 238 bool pmSourceNoiseOpModel (pmModel *model, pmSource *source, pmModelOpMode mode, float FACTOR, float SIZE, bool add, psImageMaskType maskVal, int dx, int dy); 239 bool pmSourceNoiseOp (pmSource *source, pmModelOpMode mode, float FACTOR, float SIZE, bool add, psImageMaskType maskVal, int dx, int dy); 240 238 241 bool pmSourceOp (pmSource *source, pmModelOpMode mode, bool add, psImageMaskType maskVal, int dx, int dy); 239 242 bool pmSourceCacheModel (pmSource *source, psImageMaskType maskVal); -
branches/eam_branches/ipp-20100621/psModules/src/objects/pmSourceFitPCM.c
r28692 r28781 107 107 bool pmSourceModelGuessPCM (pmPCMdata *pcm, pmSource *source, psImageMaskType maskVal, psImageMaskType markVal) { 108 108 109 pcm->modelConv->modelGuess(pcm->modelConv, source); 109 if (!pcm->modelConv->modelGuess(pcm->modelConv, source)) { 110 return false; 111 } 112 return true; 110 113 111 114 // generate copy of the model … … 114 117 115 118 // XXX test : modify the Io, SXX, SYY terms based on the psf SXX, SYY terms: 119 // SXX,SYY in model parameters are sqrt(2) * shape.Sxx,Syy 116 120 psEllipseShape psfShape; 117 121 psfShape.sx = source->modelPSF->params->data.F32[PM_PAR_SXX] / M_SQRT2; 118 122 psfShape.sxy = source->modelPSF->params->data.F32[PM_PAR_SXY]; 119 123 psfShape.sy = source->modelPSF->params->data.F32[PM_PAR_SYY] / M_SQRT2; 124 120 125 psEllipseAxes psfAxes = psEllipseShapeToAxes (psfShape, 20.0); 126 if (!isfinite(psfAxes.major)) return false; 127 if (!isfinite(psfAxes.minor)) return false; 128 if (!isfinite(psfAxes.theta)) return false; 121 129 122 130 // XXX test : modify the Io, SXX, SYY terms based on the psf SXX, SYY terms: … … 125 133 extShape.sxy = pcm->modelConv->params->data.F32[PM_PAR_SXY]; 126 134 extShape.sy = pcm->modelConv->params->data.F32[PM_PAR_SYY] / M_SQRT2; 135 127 136 psEllipseAxes extAxes = psEllipseShapeToAxes (extShape, 20.0); 137 if (!isfinite(extAxes.major)) return false; 138 if (!isfinite(extAxes.minor)) return false; 139 if (!isfinite(extAxes.theta)) return false; 128 140 129 141 // decrease the initial guess ellipse by psf_minor axis: 130 142 psEllipseAxes extAxesMod; 131 extAxesMod.major = sqrt (PS_MAX ( 1.0, PS_SQR(extAxes.major) - PS_SQR(psfAxes.minor)));132 extAxesMod.minor = sqrt (PS_MAX ( 1.0, PS_SQR(extAxes.minor) - PS_SQR(psfAxes.minor)));143 extAxesMod.major = sqrt (PS_MAX (0.25, PS_SQR(extAxes.major) - PS_SQR(psfAxes.minor))); 144 extAxesMod.minor = sqrt (PS_MAX (0.25, PS_SQR(extAxes.minor) - PS_SQR(psfAxes.minor))); 133 145 extAxesMod.theta = extAxes.theta; 134 146 135 147 psEllipseShape extShapeMod = psEllipseAxesToShape (extAxesMod); 148 if (!isfinite(extShapeMod.sx)) return false; 149 if (!isfinite(extShapeMod.sy)) return false; 150 if (!isfinite(extShapeMod.sxy)) return false; 151 136 152 pcm->modelConv->params->data.F32[PM_PAR_SXX] = extShapeMod.sx * M_SQRT2; 137 153 pcm->modelConv->params->data.F32[PM_PAR_SXY] = extShapeMod.sxy;
Note:
See TracChangeset
for help on using the changeset viewer.
