Changeset 27531
- Timestamp:
- Mar 30, 2010, 1:29:50 PM (16 years ago)
- Location:
- trunk/psModules/src
- Files:
-
- 15 edited
- 3 copied
-
objects/Makefile.am (modified) (3 diffs)
-
objects/models/pmModel_PGAUSS.c (modified) (2 diffs)
-
objects/models/pmModel_PS1_V1.c (modified) (5 diffs)
-
objects/models/pmModel_QGAUSS.c (modified) (9 diffs)
-
objects/models/pmModel_RGAUSS.c (modified) (2 diffs)
-
objects/pmGrowthCurveGenerate.c (modified) (1 diff)
-
objects/pmPSF_IO.c (modified) (3 diffs)
-
objects/pmSource.c (modified) (8 diffs)
-
objects/pmSource.h (modified) (5 diffs)
-
objects/pmSourceDiffStats.c (copied) (copied from branches/eam_branches/20100225/psModules/src/objects/pmSourceDiffStats.c )
-
objects/pmSourceDiffStats.h (copied) (copied from branches/eam_branches/20100225/psModules/src/objects/pmSourceDiffStats.h )
-
objects/pmSourceIO.c (modified) (4 diffs)
-
objects/pmSourceIO.h (modified) (2 diffs)
-
objects/pmSourceIO_CMF_PS1_DV1.c (copied) (copied from branches/eam_branches/20100225/psModules/src/objects/pmSourceIO_CMF_PS1_DV1.c )
-
objects/pmSourceMoments.c (modified) (1 diff)
-
objects/pmSourcePhotometry.c (modified) (6 diffs)
-
objects/pmSourcePhotometry.h (modified) (2 diffs)
-
psmodules.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/objects/Makefile.am
r26162 r27531 22 22 pmSourceMasks.c \ 23 23 pmSourceMoments.c \ 24 pmSourceDiffStats.c \ 24 25 pmSourceExtendedPars.c \ 25 26 pmSourceUtils.c \ … … 40 41 pmSourceIO_CMF_PS1_V1.c \ 41 42 pmSourceIO_CMF_PS1_V2.c \ 43 pmSourceIO_CMF_PS1_DV1.c \ 42 44 pmSourceIO_MatchedRefs.c \ 43 45 pmSourcePlots.c \ … … 79 81 pmSource.h \ 80 82 pmSourceMasks.h \ 83 pmSourceDiffStats.h \ 81 84 pmSourceExtendedPars.h \ 82 85 pmSourceUtils.h \ -
trunk/psModules/src/objects/models/pmModel_PGAUSS.c
r26916 r27531 236 236 psF64 PM_MODEL_RADIUS (const psVector *params, psF64 flux) 237 237 { 238 psF64 z , f;238 psF64 z; 239 239 int Nstep = 0; 240 240 psEllipseShape shape; … … 271 271 z0 = 0.0; 272 272 273 // perform a type of bisection to find the value 274 float f0 = 1.0 / (1 + z0 + z0*z0/2.0 + z0*z0*z0/6.0); 275 float f1 = 1.0 / (1 + z1 + z1*z1/2.0 + z1*z1*z1/6.0); 276 while ((Nstep < 10) && (fabs(z1 - z0) > 0.5)) { 277 z = 0.5*(z0 + z1); 278 f = 1.0 / (1 + z + z*z/2.0 + z*z*z/6.0); 279 if (f > limit) { 280 z0 = z; 281 f0 = f; 282 } else { 283 z1 = z; 284 f1 = f; 285 } 286 Nstep ++; 287 } 273 // starting guess: 274 z = 0.5*(z0 + z1); 275 float dz = 1.0; 276 277 for (int i = 0; (i < 10) && (fabs(dz) > 0.0001); i++) { 278 // use Newton-Raphson to minimize f(z) - limit = 0 279 float dqdz = (1.0 + z + z*z/2.0); 280 float q = (dqdz + z*z*z/6.0); 281 282 float f = 1.0 / q; 283 float dfdz = -dqdz * f / q; 284 285 dz = (f - limit) / dfdz; 286 287 // fprintf (stderr, "%f %f %f : %f %f\n", f, z, dz, dfdz, q); 288 z -= dz; 289 } 290 288 291 psF64 radius = sigma * sqrt (2.0 * z); 289 292 -
trunk/psModules/src/objects/models/pmModel_PS1_V1.c
r26916 r27531 267 267 psF64 PM_MODEL_RADIUS (const psVector *params, psF64 flux) 268 268 { 269 psF64 z , f;269 psF64 z; 270 270 int Nstep = 0; 271 271 psEllipseShape shape; … … 273 273 psF32 *PAR = params->data.F32; 274 274 275 if (flux <= 0) { 276 return 1.0; 277 } 278 if (PAR[PM_PAR_I0] <= 0) { 279 return 1.0; 280 } 281 if (flux >= PAR[PM_PAR_I0]) { 282 return 1.0; 283 } 284 if (PAR[PM_PAR_7] == 0.0) { 285 return powf(PAR[PM_PAR_I0] / flux - 1.0, 1.0 / ALPHA); 286 } 275 if (flux <= 0) return 1.0; 276 if (PAR[PM_PAR_I0] <= 0) return 1.0; 277 if (flux >= PAR[PM_PAR_I0]) return 1.0; 278 if (PAR[PM_PAR_7] == 0.0) return powf(PAR[PM_PAR_I0] / flux - 1.0, 1.0 / ALPHA); 287 279 288 280 shape.sx = PAR[PM_PAR_SXX] / M_SQRT2; … … 305 297 if (PAR[PM_PAR_7] < 0.0) z1 *= 2.0; 306 298 307 // perform a type of bisection to find the value 308 float f0 = 1.0 / (1 + PAR[PM_PAR_7]*z0 + pow(z0, ALPHA)); 309 float f1 = 1.0 / (1 + PAR[PM_PAR_7]*z1 + pow(z1, ALPHA)); 310 while ((Nstep < 10) && (fabs(z1 - z0) > 0.5)) { 311 z = 0.5*(z0 + z1); 312 f = 1.0 / (1 + PAR[PM_PAR_7]*z + pow(z, ALPHA)); 313 if (f > limit) { 314 z0 = z; 315 f0 = f; 316 } else { 317 z1 = z; 318 f1 = f; 319 } 320 Nstep ++; 299 // starting guess: 300 z = 0.5*(z0 + z1); 301 float dz = 1.0; 302 303 // use Newton-Raphson to minimize f(z) - limit = 0 304 for (int i = 0; (i < 10) && (fabs(dz) > 0.0001); i++) { 305 float q = (1.0 + PAR[PM_PAR_7]*z + pow(z, ALPHA)); 306 float dqdz = (PAR[PM_PAR_7] + ALPHA*pow(z, ALPHA - 1.0)); 307 308 float f = 1.0 / q; 309 float dfdz = -dqdz * f / q; 310 311 dz = (f - limit) / dfdz; 312 313 // fprintf (stderr, "%f %f %f : %f %f\n", f, z, dz, dfdz, q); 314 z -= dz; 321 315 } 322 316 psF64 radius = sigma * sqrt (2.0 * z); … … 350 344 // convert to shape terms (SXX,SYY,SXY) 351 345 if (!pmPSF_FitToModel (out, 0.1)) { 352 // psError(PM_ERR_PSF, false, "Failed to fit object at (r,c) = (%.1f,%.1f)", in[PM_PAR_YPOS], in[PM_PAR_XPOS]);353 346 psTrace("psModules.objects", 5, "Failed to fit object at (r,c) = (%.1f,%.1f)", in[PM_PAR_YPOS], in[PM_PAR_XPOS]); 354 347 return false; … … 475 468 } 476 469 477 478 470 # undef PM_MODEL_FUNC 479 471 # undef PM_MODEL_FLUX -
trunk/psModules/src/objects/models/pmModel_QGAUSS.c
r26916 r27531 39 39 # define PM_MODEL_SET_LIMITS pmModelSetLimits_QGAUSS 40 40 41 # define ALPHA 2.250 42 # define ALPHA_M 1.250 43 41 44 // the model is a function of the pixel coordinate (pixcoord[0,1] = x,y) 42 45 // 0.5 PIX: the parameters are defined in terms of pixel coords, so the incoming pixcoords … … 44 47 45 48 // Lax parameter limits 46 static float paramsMinLax[] = { -1.0e3, 1.0e-2, -100, -100, 0.5, 0.5, -1.0, 0.1};49 static float paramsMinLax[] = { -1.0e3, 1.0e-2, -100, -100, 0.5, 0.5, -1.0, -1.0 }; 47 50 static float paramsMaxLax[] = { 1.0e5, 1.0e8, 1.0e4, 1.0e4, 100, 100, 1.0, 20.0 }; 48 51 49 52 // Moderate parameter limits 50 static float *paramsMinModerate = paramsMinLax; 51 static float *paramsMaxModerate = paramsMaxLax; 53 // Tolerate a small divot (k < 0) 54 static float paramsMinModerate[] = { -1.0e3, 1.0e-2, -100, -100, 0.5, 0.5, -1.0, -0.05 }; 55 static float paramsMaxModerate[] = { 1.0e5, 1.0e8, 1.0e4, 1.0e4, 100, 100, 1.0, 20.0 }; 52 56 53 57 // Strict parameter limits 54 static float *paramsMinStrict = paramsMinLax; 55 static float *paramsMaxStrict = paramsMaxLax; 58 // k = PAR_7 < 0 is very undesirable (big divot in the middle) 59 static float paramsMinStrict[] = { -1.0e3, 1.0e-2, -100, -100, 0.5, 0.5, -1.0, 0.0 }; 60 static float paramsMaxStrict[] = { 1.0e5, 1.0e8, 1.0e4, 1.0e4, 100, 100, 1.0, 20.0 }; 56 61 57 62 // Parameter limits to use 58 63 static float *paramsMinUse = paramsMinLax; 59 64 static float *paramsMaxUse = paramsMaxLax; 60 static float betaUse[] = { 1000, 3e6, 5, 5, 1.0, 1.0, 0.5 };65 static float betaUse[] = { 1000, 3e6, 5, 5, 1.0, 1.0, 0.5, 2.0 }; 61 66 62 67 static bool limitsApply = true; // Apply limits? … … 81 86 assert (z >= 0); 82 87 83 psF32 zp = pow(z, 1.25);88 psF32 zp = pow(z,ALPHA_M); 84 89 psF32 r = 1.0 / (1 + PAR[PM_PAR_7]*z + z*zp); 85 90 … … 92 97 // note difference from a pure gaussian: q = params->data.F32[PM_PAR_I0]*r 93 98 psF32 t = r1*r; 94 psF32 q = t*(PAR[PM_PAR_7] + 2.25*zp);99 psF32 q = t*(PAR[PM_PAR_7] + ALPHA*zp); 95 100 96 101 dPAR[PM_PAR_SKY] = +1.0; … … 246 251 float f1, f2; 247 252 for (z = DZ; z < 50; z += DZ) { 248 f1 = 1.0 / (1 + PAR[PM_PAR_7]*z + pow(z, 2.25));253 f1 = 1.0 / (1 + PAR[PM_PAR_7]*z + pow(z, ALPHA)); 249 254 z += DZ; 250 f2 = 1.0 / (1 + PAR[PM_PAR_7]*z + pow(z, 2.25));255 f2 = 1.0 / (1 + PAR[PM_PAR_7]*z + pow(z, ALPHA)); 251 256 norm += f0 + 4*f1 + f2; 252 257 f0 = f2; … … 263 268 psF64 PM_MODEL_RADIUS (const psVector *params, psF64 flux) 264 269 { 265 psF64 z , f;270 psF64 z; 266 271 int Nstep = 0; 267 272 psEllipseShape shape; … … 269 274 psF32 *PAR = params->data.F32; 270 275 271 if (flux <= 0) 272 return (1.0); 273 if (PAR[PM_PAR_I0] <= 0) 274 return (1.0); 275 if (flux >= PAR[PM_PAR_I0]) 276 return (1.0); 276 if (flux <= 0) return 1.0; 277 if (PAR[PM_PAR_I0] <= 0) return 1.0; 278 if (flux >= PAR[PM_PAR_I0]) return 1.0; 279 if (PAR[PM_PAR_7] == 0.0) return powf(PAR[PM_PAR_I0] / flux - 1.0, 1.0 / ALPHA); 277 280 278 281 shape.sx = PAR[PM_PAR_SXX] / M_SQRT2; … … 290 293 291 294 // choose a z value guaranteed to be beyond our limit 292 float z0 = pow((1.0 / limit), (1.0 / 2.25)); 293 psAssert (isfinite(z0), "fix this code: z0 should not be nan for %f", PAR[PM_PAR_7]); 294 float z1 = (1.0 / limit) / PAR[PM_PAR_7]; 295 float z0 = 0.0; 296 float z1 = pow((1.0 / limit), (1.0 / ALPHA)); 295 297 psAssert (isfinite(z1), "fix this code: z1 should not be nan for %f", PAR[PM_PAR_7]); 296 z1 = PS_MAX (z0, z1); 297 z0 = 0.0; 298 299 // perform a type of bisection to find the value 300 float f0 = 1.0 / (1 + PAR[PM_PAR_7]*z0 + pow(z0, 2.25)); 301 float f1 = 1.0 / (1 + PAR[PM_PAR_7]*z1 + pow(z1, 2.25)); 302 while ((Nstep < 10) && (fabs(z1 - z0) > 0.5)) { 303 z = 0.5*(z0 + z1); 304 f = 1.0 / (1 + PAR[PM_PAR_7]*z + pow(z, 2.25)); 305 if (f > limit) { 306 z0 = z; 307 f0 = f; 308 } else { 309 z1 = z; 310 f1 = f; 311 } 312 Nstep ++; 298 if (PAR[PM_PAR_7] < 0.0) z1 *= 2.0; 299 300 // starting guess: 301 z = 0.5*(z0 + z1); 302 float dz = 1.0; 303 304 // use Newton-Raphson to minimize f(z) - limit = 0 305 for (int i = 0; (i < 10) && (fabs(dz) > 0.0001); i++) { 306 float q = (1.0 + PAR[PM_PAR_7]*z + pow(z, ALPHA)); 307 float dqdz = (PAR[PM_PAR_7] + ALPHA*pow(z, ALPHA - 1.0)); 308 309 float f = 1.0 / q; 310 float dfdz = -dqdz * f / q; 311 312 dz = (f - limit) / dfdz; 313 314 // fprintf (stderr, "%f %f %f : %f %f\n", f, z, dz, dfdz, q); 315 z -= dz; 313 316 } 314 317 psF64 radius = sigma * sqrt (2.0 * z); … … 475 478 # undef PM_MODEL_FIT_STATUS 476 479 # undef PM_MODEL_SET_LIMITS 480 # undef ALPHA 481 # undef ALPHA_M -
trunk/psModules/src/objects/models/pmModel_RGAUSS.c
r26916 r27531 257 257 psF64 PM_MODEL_RADIUS (const psVector *params, psF64 flux) 258 258 { 259 psF64 z , f;259 psF64 z; 260 260 int Nstep = 0; 261 261 psEllipseShape shape; … … 291 291 z0 = 0.0; 292 292 293 // perform a type of bisection to find the value 294 float f0 = 1.0 / (1 + z0 + pow(z0, PAR[PM_PAR_7])); 295 float f1 = 1.0 / (1 + z1 + pow(z1, PAR[PM_PAR_7])); 296 while ((Nstep < 10) && (fabs(z1 - z0) > 0.5)) { 297 z = 0.5*(z0 + z1); 298 f = 1.0 / (1 + z + pow(z, PAR[PM_PAR_7])); 299 if (f > limit) { 300 z0 = z; 301 f0 = f; 302 } else { 303 z1 = z; 304 f1 = f; 305 } 306 Nstep ++; 307 } 293 // starting guess: 294 z = 0.5*(z0 + z1); 295 float dz = 1.0; 296 297 for (int i = 0; (i < 10) && (fabs(dz) > 0.0001); i++) { 298 // use Newton-Raphson to minimize f(z) - limit = 0 299 float q = (1 + z + pow(z,PAR[PM_PAR_7])); 300 float dqdz = (1.0 + PAR[PM_PAR_7]*pow(z,PAR[PM_PAR_7] - 1.0)); 301 302 float f = 1.0 / q; 303 float dfdz = -dqdz * f / q; 304 305 dz = (f - limit) / dfdz; 306 307 // fprintf (stderr, "%f %f %f : %f %f\n", f, z, dz, dfdz, q); 308 z -= dz; 309 } 310 308 311 psF64 radius = sigma * sqrt (2.0 * z); 309 312 -
trunk/psModules/src/objects/pmGrowthCurveGenerate.c
r25754 r27531 157 157 158 158 // measure the fitMag for this model 159 pmSourcePhotometryModel (&fitMag, model);159 pmSourcePhotometryModel (&fitMag, NULL, model); 160 160 growth->fitMag = fitMag; 161 161 -
trunk/psModules/src/objects/pmPSF_IO.c
r27178 r27531 491 491 psMetadataAddS32 (header, PS_LIST_TAIL, "YCENTER", 0, "", psf->residuals->yCenter); 492 492 493 // write the residuals as three planes of the image 494 // this call creates an extension with NAXIS3 = 3 493 // write the residuals as planes of the image 494 psArray *images = psArrayAllocEmpty (1); 495 psArrayAdd (images, 1, psf->residuals->Ro); // z = 0 is Ro 496 495 497 if (psf->residuals->Rx) { 496 // this call creates an extension with NAXIS3 = 3497 psArray *images = psArrayAllocEmpty (3);498 psArrayAdd (images, 1, psf->residuals->Ro);499 498 psArrayAdd (images, 1, psf->residuals->Rx); 500 499 psArrayAdd (images, 1, psf->residuals->Ry); 501 502 if (!psFitsWriteImageCube (file->fits, header, images, residName)) { 503 psError(psErrorCodeLast(), false, "Unable to write PSF residuals."); 504 psFree(images); 505 psFree(residName); 506 psFree(header); 507 return false; 508 } 509 psFree (images); 510 } else { 511 // this call creates an extension with NAXIS3 = 1 512 if (!psFitsWriteImage(file->fits, header, psf->residuals->Ro, 0, residName)) { 513 psError(psErrorCodeLast(), false, "Unable to write PSF residuals."); 514 psFree(residName); 515 psFree(header); 516 return false; 517 } 518 } 500 } 501 502 // note that all N plane are implicitly of the same type, so we convert the mask 503 if (psf->residuals->mask) { 504 psImage *mask = psImageCopy (NULL, psf->residuals->mask, psf->residuals->Ro->type.type); 505 psArrayAdd (images, 1, mask); 506 psFree (mask); 507 } 508 509 // psFitsWriteImageCube (file->fits, header, images, residName); 510 // psFree (images); 511 512 if (!psFitsWriteImageCube (file->fits, header, images, residName)) { 513 psError(psErrorCodeLast(), false, "Unable to write PSF residuals."); 514 psFree(images); 515 psFree(residName); 516 psFree(header); 517 return false; 518 } 519 psFree (images); 519 520 psFree (residName); 520 521 psFree (header); … … 1017 1018 return false; 1018 1019 } 1019 if (Nz > 1) { 1020 assert (Nz == 3); 1020 1021 // note that all N plane are implicitly of the same type, so we convert the mask 1022 psImage *mask = psImageCopy(NULL, psf->residuals->mask, psf->residuals->Ro->type.type); 1023 psImageInit (psf->residuals->mask, 0); 1024 psImageInit (psf->residuals->Rx, 0.0); 1025 psImageInit (psf->residuals->Ry, 0.0); 1026 switch (Nz) { 1027 case 1: // Ro only 1028 break; 1029 case 2: // Ro and mask 1030 if (!psFitsReadImageBuffer(mask, file->fits, fullImage, 1)) { 1031 psError(psErrorCodeLast(), false, "Unable to read PSF residual image."); 1032 return false; 1033 } 1034 psImageCopy (psf->residuals->mask, mask, PM_TYPE_RESID_MASK); 1035 break; 1036 case 3: // Ro, Rx and Ry, no mask 1021 1037 if (!psFitsReadImageBuffer(psf->residuals->Rx, file->fits, fullImage, 1)) { 1022 1038 psError(psErrorCodeLast(), false, "Unable to read PSF residual image."); … … 1027 1043 return false; 1028 1044 } 1029 } 1030 // XXX notice that we are not saving the resid->mask 1045 break; 1046 case 4: // Ro, Rx, Ry, and mask: 1047 if (!psFitsReadImageBuffer(psf->residuals->Rx, file->fits, fullImage, 1)) { 1048 psError(psErrorCodeLast(), false, "Unable to read PSF residual image."); 1049 return false; 1050 } 1051 if (!psFitsReadImageBuffer(psf->residuals->Ry, file->fits, fullImage, 2)) { 1052 psError(psErrorCodeLast(), false, "Unable to read PSF residual image."); 1053 return false; 1054 } 1055 if (!psFitsReadImageBuffer(mask, file->fits, fullImage, 3)) { 1056 psError(psErrorCodeLast(), false, "Unable to read PSF residual image."); 1057 return false; 1058 } 1059 psImageCopy (psf->residuals->mask, mask, PM_TYPE_RESID_MASK); 1060 break; 1061 } 1062 psFree (mask); 1031 1063 } 1032 1064 -
trunk/psModules/src/objects/pmSource.c
r26893 r27531 46 46 psFree(tmp->maskView); 47 47 psFree(tmp->modelFlux); 48 psFree(tmp->psf Flux);48 psFree(tmp->psfImage); 49 49 psFree(tmp->moments); 50 50 psFree(tmp->modelPSF); … … 52 52 psFree(tmp->modelFits); 53 53 psFree(tmp->extpars); 54 psFree(tmp->moments); 55 psFree(tmp->diffStats); 54 56 psFree(tmp->blends); 55 57 psTrace("psModules.objects", 10, "---- end ----\n"); … … 68 70 psFree (source->maskView); 69 71 psFree (source->modelFlux); 70 psFree (source->psf Flux);72 psFree (source->psfImage); 71 73 72 74 source->pixels = NULL; … … 75 77 source->maskView = NULL; 76 78 source->modelFlux = NULL; 77 source->psf Flux= NULL;79 source->psfImage = NULL; 78 80 return; 79 81 } … … 103 105 source->maskView = NULL; 104 106 source->modelFlux = NULL; 105 source->psf Flux= NULL;107 source->psfImage = NULL; 106 108 source->moments = NULL; 107 109 source->blends = NULL; … … 113 115 source->tmpFlags = 0; 114 116 source->extpars = NULL; 117 source->diffStats = NULL; 118 115 119 source->region = psRegionSet(NAN, NAN, NAN, NAN); 116 120 psMemSetDeallocator(source, (psFreeFunc) sourceFree); 117 121 118 122 // default values are NAN 119 source->psfMag = NAN; 123 source->psfMag = NAN; 124 source->psfFlux = NAN; 125 source->psfFluxErr = NAN; 120 126 source->extMag = NAN; 121 127 source->errMag = NAN; … … 259 265 mySource->modelFlux = NULL; 260 266 261 // drop the old psf Fluxpixels and force the user to re-create262 psFree (mySource->psf Flux);263 mySource->psf Flux= NULL;267 // drop the old psfImage pixels and force the user to re-create 268 psFree (mySource->psfImage); 269 mySource->psfImage = NULL; 264 270 } 265 271 return extend; … … 873 879 874 880 // if we already have a cached image, re-use that memory 875 source->psf Flux = psImageCopy (source->psfFlux, source->pixels, PS_TYPE_F32);876 psImageInit (source->psf Flux, 0.0);881 source->psfImage = psImageCopy (source->psfImage, source->pixels, PS_TYPE_F32); 882 psImageInit (source->psfImage, 0.0); 877 883 878 884 // in some places (psphotEnsemble), we need a normalized version 879 885 // in others, we just want the model. which is more commonly used? 880 // psf Fluxalways has unity normalization (I0 = 1.0)881 pmModelAdd (source->psf Flux, source->maskObj, source->modelPSF, PM_MODEL_OP_FULL | PM_MODEL_OP_NORM, maskVal);886 // psfImage always has unity normalization (I0 = 1.0) 887 pmModelAdd (source->psfImage, source->maskObj, source->modelPSF, PM_MODEL_OP_FULL | PM_MODEL_OP_NORM, maskVal); 882 888 return true; 883 889 } -
trunk/psModules/src/objects/pmSource.h
r26893 r27531 16 16 #include "pmMoments.h" 17 17 #include "pmSourceExtendedPars.h" 18 #include "pmSourceDiffStats.h" 18 19 19 20 /// @addtogroup Objects Object Detection / Analysis Functions … … 38 39 39 40 typedef enum { 40 PM_SOURCE_TMPF_MODEL_GUESS = 0x0001, 41 PM_SOURCE_TMPF_SUBTRACTED = 0x0002, 42 PM_SOURCE_TMPF_SIZE_MEASURED = 0x0004, 41 PM_SOURCE_TMPF_MODEL_GUESS = 0x0001, 42 PM_SOURCE_TMPF_SUBTRACTED = 0x0002, 43 PM_SOURCE_TMPF_SIZE_MEASURED = 0x0004, 44 PM_SOURCE_TMPF_SIZE_CR_CANDIDATE = 0x0008, 43 45 } pmSourceTmpF; 44 46 … … 64 66 psImage *maskView; ///< view into global image mask for this object region 65 67 psImage *modelFlux; ///< cached copy of the best model for this source 66 psImage *psf Flux; ///< cached copy of the psf model for this source68 psImage *psfImage; ///< cached copy of the psf model for this source 67 69 pmMoments *moments; ///< Basic moments measured for the object. 68 70 pmModel *modelPSF; ///< PSF Model fit (parameters and type) … … 74 76 psArray *blends; ///< collection of sources thought to be confused with object 75 77 float psfMag; ///< calculated from flux in modelPSF 78 float psfFlux; ///< calculated from flux in modelPSF 79 float psfFluxErr; ///< calculated from flux in modelPSF 76 80 float extMag; ///< calculated from flux in modelEXT 77 81 float errMag; ///< error in psfMag OR extMag (depending on type) … … 85 89 psRegion region; ///< area on image covered by selected pixels 86 90 pmSourceExtendedPars *extpars; ///< extended source parameters 91 pmSourceDiffStats *diffStats; ///< extra parameters for difference detections 87 92 }; 88 93 -
trunk/psModules/src/objects/pmSourceIO.c
r26893 r27531 539 539 status &= pmSourcesWrite_CMF_PS1_V2 (file->fits, readout, sources, file->header, outhead, dataname); 540 540 } 541 if (!strcmp (exttype, "PS1_DV1")) { 542 status &= pmSourcesWrite_CMF_PS1_DV1 (file->fits, readout, sources, file->header, outhead, dataname); 543 } 541 544 542 545 if (xsrcname) { … … 553 556 status &= pmSourcesWrite_CMF_PS1_V2_XSRC (file->fits, sources, xsrcname, recipe); 554 557 } 558 if (!strcmp (exttype, "PS1_DV1")) { 559 status &= pmSourcesWrite_CMF_PS1_DV1_XSRC (file->fits, sources, xsrcname, recipe); 560 } 555 561 } 556 562 if (xfitname) { … … 567 573 status &= pmSourcesWrite_CMF_PS1_V2_XFIT (file->fits, sources, xfitname); 568 574 } 575 if (!strcmp (exttype, "PS1_DV1")) { 576 status &= pmSourcesWrite_CMF_PS1_DV1_XFIT (file->fits, sources, xfitname); 577 } 569 578 } 570 579 psFree (outhead); … … 1015 1024 sources = pmSourcesRead_CMF_PS1_V2 (file->fits, hdu->header); 1016 1025 } 1026 if (!strcmp (exttype, "PS1_DV1")) { 1027 sources = pmSourcesRead_CMF_PS1_DV1 (file->fits, hdu->header); 1028 } 1017 1029 1018 1030 if (!pmReadoutReadDetEff(file->fits, readout, deteffname)) { -
trunk/psModules/src/objects/pmSourceIO.h
r24694 r27531 43 43 bool pmSourcesWrite_CMF_PS1_V2_XFIT (psFits *fits, psArray *sources, char *extname); 44 44 45 bool pmSourcesWrite_CMF_PS1_DV1 (psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname); 46 bool pmSourcesWrite_CMF_PS1_DV1_XSRC (psFits *fits, psArray *sources, char *extname, psMetadata *recipe); 47 bool pmSourcesWrite_CMF_PS1_DV1_XFIT (psFits *fits, psArray *sources, char *extname); 48 45 49 bool pmSource_CMF_WritePHU (const pmFPAview *view, pmFPAfile *file, pmConfig *config); 46 50 … … 53 57 psArray *pmSourcesRead_CMF_PS1_V1 (psFits *fits, psMetadata *header); 54 58 psArray *pmSourcesRead_CMF_PS1_V2 (psFits *fits, psMetadata *header); 59 psArray *pmSourcesRead_CMF_PS1_DV1 (psFits *fits, psMetadata *header); 55 60 56 61 bool pmSourcesWritePSFs (psArray *sources, char *filename); -
trunk/psModules/src/objects/pmSourceMoments.c
r26893 r27531 163 163 } 164 164 165 // if we have less than (1/2) of the possible pixels, force a retry 165 // if we have less than (1/4) of the possible pixels (in circle or box), force a retry 166 int minPixels = PS_MIN(0.75*R2, source->pixels->numCols*source->pixels->numRows/4.0); 167 166 168 // XXX EAM - the limit is a bit arbitrary. make it user defined? 167 if ((numPixels < 0.75*R2) || (Sum <= 0)) {168 psTrace ("psModules.objects", 3, "insufficient valid pixels (%d vs %d; %f) for source\n", numPixels, (int)(0.75*R2), Sum);169 if ((numPixels < minPixels) || (Sum <= 0)) { 170 psTrace ("psModules.objects", 3, "insufficient valid pixels (%d vs %d; %f) for source\n", numPixels, minPixels, Sum); 169 171 return (false); 170 172 } -
trunk/psModules/src/objects/pmSourcePhotometry.c
r25980 r27531 109 109 psAssert (isfinite(fluxScale), "how can the flux scale be invalid? source at %d, %d\n", source->peak->x, source->peak->y); 110 110 psAssert (fluxScale > 0.0, "how can the flux scale be negative? source at %d, %d\n", source->peak->x, source->peak->y); 111 source->psfMag = -2.5*log10(fluxScale * source->modelPSF->params->data.F32[PM_PAR_I0]); 111 source->psfFlux = fluxScale * source->modelPSF->params->data.F32[PM_PAR_I0]; 112 source->psfFluxErr = fluxScale * source->modelPSF->dparams->data.F32[PM_PAR_I0]; 113 source->psfMag = -2.5*log10(source->psfFlux); 112 114 } else { 113 status = pmSourcePhotometryModel (&source->psfMag, source->modelPSF); 115 status = pmSourcePhotometryModel (&source->psfMag, &source->psfFlux, source->modelPSF); 116 source->psfFluxErr = source->psfFlux * (source->modelPSF->dparams->data.F32[PM_PAR_I0] / source->modelPSF->params->data.F32[PM_PAR_I0]); 114 117 } 115 118 … … 119 122 for (int i = 0; i < source->modelFits->n; i++) { 120 123 pmModel *model = source->modelFits->data[i]; 121 status = pmSourcePhotometryModel (&model->mag, model);124 status = pmSourcePhotometryModel (&model->mag, NULL, model); 122 125 if (model == source->modelEXT) foundEXT = true; 123 126 } … … 125 128 source->extMag = source->modelEXT->mag; 126 129 } else { 127 status = pmSourcePhotometryModel (&source->extMag, source->modelEXT);130 status = pmSourcePhotometryModel (&source->extMag, NULL, source->modelEXT); 128 131 } 129 132 } else { 130 133 if (source->modelEXT) { 131 status = pmSourcePhotometryModel (&source->extMag, source->modelEXT);134 status = pmSourcePhotometryModel (&source->extMag, NULL, source->modelEXT); 132 135 } 133 136 } … … 143 146 if (mode & PM_SOURCE_PHOT_WEIGHT) { 144 147 pmSourcePixelWeight (&source->pixWeight, model, source->maskObj, maskVal); 148 } 149 150 // measure the contribution of included pixels 151 if (mode & PM_SOURCE_PHOT_DIFFSTATS) { 152 pmSourceMeasureDiffStats (source, maskVal); 145 153 } 146 154 … … 217 225 218 226 // return source model magnitude 219 bool pmSourcePhotometryModel (float *fitMag, pmModel *model) 220 { 221 PS_ASSERT_PTR_NON_NULL(fitMag, false); 222 if (model == NULL) { 223 return false; 224 } 225 226 float fitSum = 0; 227 *fitMag = NAN; 227 bool pmSourcePhotometryModel (float *fitMag, float *fitFlux, pmModel *model) 228 { 229 psAssert (fitMag || fitFlux, "at least one of magnitude or flux must be requested (not NULL)"); 230 if (model == NULL) return false; 231 232 float mag = NAN; 233 float flux = NAN; 228 234 229 235 // measure fitMag 230 fitSum = model->modelFlux (model->params); 231 if (fitSum <= 0) 232 return false; 233 if (!isfinite(fitSum)) 234 return false; 235 *fitMag = -2.5*log10(fitSum); 236 flux = model->modelFlux (model->params); 237 if (flux > 0) { 238 mag = -2.5*log10(flux); 239 } 240 if (fitMag) { 241 *fitMag = mag; 242 } 243 if (fitFlux) { 244 *fitFlux = flux; 245 } 246 247 if (flux <= 0) return false; 248 if (!isfinite(flux)) return false; 236 249 237 250 return (true); … … 356 369 357 370 *pixWeight = validSum / modelSum; 371 return (true); 372 } 373 374 # define FLUX_LIMIT 3.0 375 376 // return source aperture magnitude 377 bool pmSourceMeasureDiffStats (pmSource *source, psImageMaskType maskVal) 378 { 379 PS_ASSERT_PTR_NON_NULL(source, false); 380 381 if (source->diffStats == NULL) { 382 source->diffStats = pmSourceDiffStatsAlloc(); 383 } 384 385 float fGood = 0.0; 386 float fBad = 0.0; 387 int nGood = 0; 388 int nMask = 0; 389 int nBad = 0; 390 391 psImage *flux = source->pixels; 392 psImage *variance = source->variance; 393 psImage *mask = source->maskObj; 394 395 for (int iy = 0; iy < flux->numRows; iy++) { 396 for (int ix = 0; ix < flux->numCols; ix++) { 397 if (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & maskVal) { 398 nMask ++; 399 continue; 400 } 401 402 float SN = flux->data.F32[iy][ix] / sqrt(variance->data.F32[iy][ix]); 403 404 if (SN > +FLUX_LIMIT) { 405 nGood ++; 406 fGood += fabs(flux->data.F32[iy][ix]); 407 } 408 409 if (SN < -FLUX_LIMIT) { 410 nBad ++; 411 fBad += fabs(flux->data.F32[iy][ix]); 412 } 413 } 414 } 415 416 source->diffStats->nGood = nGood; 417 source->diffStats->fRatio = (fGood + fBad == 0.0) ? NAN : fGood / (fGood + fBad); 418 source->diffStats->nRatioBad = (nGood + nBad == 0) ? NAN : nGood / (float) (nGood + nBad); 419 source->diffStats->nRatioMask = (nGood + nMask == 0) ? NAN : nGood / (float) (nGood + nMask); 420 source->diffStats->nRatioAll = (nGood + nMask + nBad == 0) ? NAN : nGood / (float) (nGood + nMask + nBad); 421 358 422 return (true); 359 423 } -
trunk/psModules/src/objects/pmSourcePhotometry.h
r25980 r27531 29 29 30 30 typedef enum { 31 PM_SOURCE_PHOT_NONE = 0x0000, 32 PM_SOURCE_PHOT_GROWTH = 0x0001, 33 PM_SOURCE_PHOT_APCORR = 0x0002, 34 PM_SOURCE_PHOT_WEIGHT = 0x0004, 35 PM_SOURCE_PHOT_INTERP = 0x0008, 31 PM_SOURCE_PHOT_NONE = 0x0000, 32 PM_SOURCE_PHOT_GROWTH = 0x0001, 33 PM_SOURCE_PHOT_APCORR = 0x0002, 34 PM_SOURCE_PHOT_WEIGHT = 0x0004, 35 PM_SOURCE_PHOT_INTERP = 0x0008, 36 PM_SOURCE_PHOT_DIFFSTATS = 0x0010, 36 37 } pmSourcePhotometryMode; 37 38 38 39 bool pmSourcePhotometryModel( 39 40 float *fitMag, ///< integrated fit magnitude 41 float *fitFlux, ///< integrated fit magnitude 40 42 pmModel *model ///< model used for photometry 41 43 ); … … 54 56 bool pmSourceChisq (pmModel *model, psImage *image, psImage *mask, psImage *weight, psImageMaskType maskVal, const float covarFactor); 55 57 58 bool pmSourceMeasureDiffStats (pmSource *source, psImageMaskType maskVal); 56 59 57 60 double pmSourceDataDotModel (const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum, const float covarFactor); -
trunk/psModules/src/psmodules.h
r26893 r27531 115 115 #include <pmDetections.h> 116 116 #include <pmMoments.h> 117 #include <pmSourceExtendedPars.h> 118 #include <pmSourceDiffStats.h> 117 119 #include <pmResiduals.h> 118 120 #include <pmGrowthCurve.h>
Note:
See TracChangeset
for help on using the changeset viewer.
