Changeset 20082
- Timestamp:
- Oct 12, 2008, 4:04:51 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psphotChoosePSF.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotChoosePSF.c
r20035 r20082 43 43 // array to store candidate PSF stars 44 44 int NSTARS = psMetadataLookupS32 (&status, recipe, "PSF_MAX_NSTARS"); 45 assert (status);46 47 float PSF_MIN_DS = psMetadataLookupF32 (&status, recipe, "PSF_MIN_DS");48 45 assert (status); 49 46 … … 258 255 pmPSFtry *try = models->data[bestN]; 259 256 260 // measure and save the median value of dparams[PM_PAR_SXX],dparams[PM_PAR_SYY]261 // these are used by psphotEvalPSF to identify extended sources262 // XXX is this still needed?263 psVector *Sx = psVectorAllocEmpty (try->sources->n, PS_TYPE_F32);264 psVector *Sy = psVectorAllocEmpty (try->sources->n, PS_TYPE_F32);265 psVector *dSx = psVectorAllocEmpty (try->sources->n, PS_TYPE_F32);266 psVector *dSy = psVectorAllocEmpty (try->sources->n, PS_TYPE_F32);267 psVector *dSN = psVectorAllocEmpty (try->sources->n, PS_TYPE_F32);268 for (int i = 0; i < try->sources->n; i++) {269 // masked for: bad model fit, outlier in parameters270 if (try->mask->data.U8[i] & PSFTRY_MASK_ALL)271 continue;272 273 pmSource *source = try->sources->data[i];274 Sx->data.F32[Sx->n] = source->modelPSF->params->data.F32[PM_PAR_SXX];275 Sy->data.F32[Sy->n] = source->modelPSF->params->data.F32[PM_PAR_SYY];276 dSN->data.F32[dSN->n] = source->modelPSF->dparams->data.F32[PM_PAR_I0] / source->modelPSF->params->data.F32[PM_PAR_I0];277 dSx->data.F32[dSx->n] = source->modelPSF->dparams->data.F32[PM_PAR_SXX];278 dSy->data.F32[dSy->n] = source->modelPSF->dparams->data.F32[PM_PAR_SYY];279 Sx->n ++;280 Sy->n ++;281 dSN->n ++;282 dSx->n ++;283 dSy->n ++;284 }285 psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV);286 287 psVectorStats (stats, dSx, NULL, NULL, 0);288 float dSxo = stats->sampleMean;289 psLogMsg ("psphot.choosePSF", PS_LOG_INFO, "dSxo: mean: %f, median: %f, stdev: %f, npts: %ld", stats->sampleMean, stats->sampleMedian, stats->sampleStdev, dSx->n);290 291 psVectorStats (stats, dSy, NULL, NULL, 0);292 float dSyo = stats->sampleMean;293 psLogMsg ("psphot.choosePSF", PS_LOG_INFO, "dSyo: mean: %f, median: %f, stdev: %f, npts: %ld", stats->sampleMean, stats->sampleMedian, stats->sampleStdev, dSy->n);294 295 for (int i = 0; i < dSN->n; i++) {296 dSx->data.F32[i] = (dSx->data.F32[i] - dSxo) / PS_MAX (PSF_MIN_DS, Sx->data.F32[i]*dSN->data.F32[i]);297 dSy->data.F32[i] = (dSy->data.F32[i] - dSyo) / PS_MAX (PSF_MIN_DS, Sy->data.F32[i]*dSN->data.F32[i]);298 }299 300 psVectorStats (stats, dSx, NULL, NULL, 0);301 float nSx = stats->sampleStdev;302 psLogMsg ("psphot.choosePSF", PS_LOG_INFO, "ndSx: mean: %f, median: %f, stdev: %f, npts: %ld", stats->sampleMean, stats->sampleMedian, stats->sampleStdev, dSx->n);303 psVectorStats (stats, dSy, NULL, NULL, 0);304 float nSy = stats->sampleStdev;305 psLogMsg ("psphot.choosePSF", PS_LOG_INFO, "ndSy: mean: %f, median: %f, stdev: %f, npts: %ld", stats->sampleMean, stats->sampleMedian, stats->sampleStdev, dSy->n);306 307 psFree (Sx);308 psFree (Sy);309 psFree (dSx);310 psFree (dSy);311 psFree (dSN);312 psFree (stats);313 314 psMetadataAddF32 (recipe, PS_LIST_TAIL, "DSX_MEAN", PS_META_REPLACE, "mean offset of dSXX", dSxo);315 psMetadataAddF32 (recipe, PS_LIST_TAIL, "DSY_MEAN", PS_META_REPLACE, "mean offset of dSYY", dSyo);316 psMetadataAddF32 (recipe, PS_LIST_TAIL, "DSX_STDV", PS_META_REPLACE, "stdev of mean-corrected dSXX", nSx);317 psMetadataAddF32 (recipe, PS_LIST_TAIL, "DSY_STDV", PS_META_REPLACE, "stdev of mean-corrected dSYY", nSy);318 319 // psphotCountPSFStars (sources);320 321 257 // unset the PSFSTAR flag for stars not used for PSF model 322 258 for (int i = 0; i < try->sources->n; i++) { … … 326 262 } 327 263 } 328 329 // psphotCountPSFStars (sources);330 264 331 265 // build a PSF residual image … … 337 271 } 338 272 339 // build a PSF residual image273 // build the flux-to-magnitude conversion information 340 274 if (!psphotMakeFluxScale (readout->image, recipe, try->psf)) { 341 275 psError(PSPHOT_ERR_PSF, false, "Unable to construct flux scale for PSF"); … … 345 279 } 346 280 281 // build curve-of-growth vector for this psf 282 if (!psphotMakeGrowthCurve (readout, recipe, try->psf)) { 283 psError(PSPHOT_ERR_PSF, false, "Unable to construct flux scale for PSF"); 284 psFree (models); 285 psFree(options); 286 return NULL; 287 } 288 347 289 // XXX test dump of psf star data and psf-subtracted image 348 290 if (psTraceGetLevel("psphot.psfstars") > 5) { 349 psphotSaveImage (NULL, readout->image, "rawstars.fits"); 350 351 for (int i = 0; i < try->sources->n; i++) { 352 // masked for: bad model fit, outlier in parameters 353 if (try->mask->data.U8[i] & PSFTRY_MASK_ALL) 354 continue; 355 356 pmSource *source = try->sources->data[i]; 357 float x = source->modelPSF->params->data.F32[PM_PAR_XPOS]; 358 float y = source->modelPSF->params->data.F32[PM_PAR_YPOS]; 359 360 // set the mask and subtract the PSF model 361 // XXX should we be using maskObj? should we be unsetting the mask? 362 // use pmModelSub because modelFlux has not been generated 363 assert (source->maskObj); 364 psImageKeepCircle (source->maskObj, x, y, options->radius, "OR", markVal); 365 pmModelSub (source->pixels, source->maskObj, source->modelPSF, PM_MODEL_OP_FULL, maskVal); 366 psImageKeepCircle (source->maskObj, x, y, options->radius, "AND", PS_NOT_U8(markVal)); 367 } 368 369 FILE *f = fopen ("shapes.dat", "w"); 370 for (int i = 0; i < try->sources->n; i++) { 371 psF32 inPar[10]; // must be psF32 to pmPSF_FitToModel 372 373 // masked for: bad model fit, outlier in parameters 374 if (try->mask->data.U8[i] & PSFTRY_MASK_ALL) continue; 375 376 pmSource *source = try->sources->data[i]; 377 psF32 *outPar = source->modelEXT->params->data.F32; 378 379 psEllipseShape shape; 380 381 shape.sx = outPar[PM_PAR_SXX] / M_SQRT2; 382 shape.sy = outPar[PM_PAR_SYY] / M_SQRT2; 383 shape.sxy = outPar[PM_PAR_SXY]; 384 385 psEllipsePol pol = pmPSF_ModelToFit (outPar); 386 inPar[PM_PAR_E0] = pol.e0; 387 inPar[PM_PAR_E1] = pol.e1; 388 inPar[PM_PAR_E2] = pol.e2; 389 pmPSF_FitToModel (inPar, 0.1); 390 391 psEllipseAxes axes1 = psEllipseShapeToAxes (shape, 20.0); 392 psEllipseAxes axes2 = psEllipsePolToAxes(pol, 0.1); 393 394 psEllipsePol pol2 = psEllipseAxesToPol (axes1); 395 396 fprintf (f, "%3d %7.2f %7.2f %7.4f %7.4f %7.4f -- %7.4f %7.4f %7.4f : %7.4f %7.4f %7.4f -- %7.4f %7.4f %7.4f : %7.4f %7.4f %6.1f : %7.4f %7.4f %6.1f\n", 397 i, outPar[PM_PAR_XPOS], outPar[PM_PAR_YPOS], 398 outPar[PM_PAR_SXX], outPar[PM_PAR_SXY], outPar[PM_PAR_SYY], 399 pol.e0, pol.e1, pol.e2, 400 pol2.e0, pol2.e1, pol2.e2, 401 inPar[PM_PAR_SXX], inPar[PM_PAR_SXY], inPar[PM_PAR_SYY], 402 axes1.major, axes1.minor, axes1.theta*PM_DEG_RAD, 403 axes2.major, axes2.minor, axes2.theta*PM_DEG_RAD 404 ); 405 } 406 fclose (f); 407 408 psphotSaveImage (NULL, readout->image, "psfstars.fits"); 409 pmSourcesWritePSFs (try->sources, "psfstars.dat"); 410 pmSourcesWriteEXTs (try->sources, "extstars.dat", false); 411 // XXX need alternative output function 412 // psMetadata *psfData = pmPSFtoMetadata (NULL, try->psf); 413 // psMetadataConfigWrite (psfData, "psfmodel.dat"); 414 psLogMsg ("psphot.choosePSF", PS_LOG_INFO, "wrote out psf-subtracted image, psf data, exiting\n"); 291 psphotDumpPSFStars (readout, try, options->radius, maskVal, markVal); 415 292 } 416 293
Note:
See TracChangeset
for help on using the changeset viewer.
