- Timestamp:
- May 3, 2010, 8:45:22 AM (16 years ago)
- Location:
- branches/simmosaic_branches
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/simmosaic_branches
- Property svn:mergeinfo changed
-
branches/simmosaic_branches/psModules
-
Property svn:mergeinfo
set to (toggle deleted branches)
/trunk/psModules merged eligible /branches/eam_branches/stackphot.20100406/psModules 27623-27653 /branches/pap_delete/psModules 27530-27595
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
branches/simmosaic_branches/psModules/src/objects/pmSource.c
r24576 r27839 3 3 * Functions to define and manipulate sources on images 4 4 * 5 * @author GLG, MHPCC6 * @author EAM, IfA: significant modifications.5 * @author EAM, IfA 6 * @author GLG, MHPCC (initial code base) 7 7 * 8 8 * @version $Revision: 1.70 $ $Name: not supported by cvs2svn $ 9 9 * @date $Date: 2009-02-16 22:29:59 $ 10 * 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 12 * 10 * Copyright 2009 Institute for Astronomy, University of Hawaii 13 11 */ 14 12 … … 48 46 psFree(tmp->maskView); 49 47 psFree(tmp->modelFlux); 50 psFree(tmp->psf Flux);48 psFree(tmp->psfImage); 51 49 psFree(tmp->moments); 52 50 psFree(tmp->modelPSF); … … 54 52 psFree(tmp->modelFits); 55 53 psFree(tmp->extpars); 54 psFree(tmp->moments); 55 psFree(tmp->diffStats); 56 56 psFree(tmp->blends); 57 57 psTrace("psModules.objects", 10, "---- end ----\n"); … … 70 70 psFree (source->maskView); 71 71 psFree (source->modelFlux); 72 psFree (source->psf Flux);72 psFree (source->psfImage); 73 73 74 74 source->pixels = NULL; … … 77 77 source->maskView = NULL; 78 78 source->modelFlux = NULL; 79 source->psf Flux= NULL;79 source->psfImage = NULL; 80 80 return; 81 81 } … … 105 105 source->maskView = NULL; 106 106 source->modelFlux = NULL; 107 source->psf Flux= NULL;107 source->psfImage = NULL; 108 108 source->moments = NULL; 109 109 source->blends = NULL; … … 115 115 source->tmpFlags = 0; 116 116 source->extpars = NULL; 117 source->diffStats = NULL; 118 117 119 source->region = psRegionSet(NAN, NAN, NAN, NAN); 118 120 psMemSetDeallocator(source, (psFreeFunc) sourceFree); 119 121 120 122 // default values are NAN 121 source->psfMag = NAN; 123 source->psfMag = NAN; 124 source->psfFlux = NAN; 125 source->psfFluxErr = NAN; 122 126 source->extMag = NAN; 123 127 source->errMag = NAN; … … 176 180 source->type = in->type; 177 181 source->mode = in->mode; 182 source->imageID = in->imageID; 178 183 179 184 return(source); … … 242 247 extend |= (mySource->maskView == NULL); 243 248 244 // extend = true;245 249 if (extend) { 246 250 // re-create the subimage … … 250 254 251 255 mySource->pixels = psImageSubset(readout->image, newRegion); 252 mySource->variance = psImageSubset(readout->variance, newRegion);256 mySource->variance = psImageSubset(readout->variance, newRegion); 253 257 mySource->maskView = psImageSubset(readout->mask, newRegion); 254 258 mySource->region = newRegion; … … 262 266 mySource->modelFlux = NULL; 263 267 264 // drop the old psf Fluxpixels and force the user to re-create265 psFree (mySource->psf Flux);266 mySource->psf Flux= NULL;268 // drop the old psfImage pixels and force the user to re-create 269 psFree (mySource->psfImage); 270 mySource->psfImage = NULL; 267 271 } 268 272 return extend; … … 278 282 // psphot-specific function which applies the recipe values 279 283 // only apply selection to sources within specified region 280 pmPSFClump pmSourcePSFClump(ps Region *region, psArray *sources, psMetadata *recipe)284 pmPSFClump pmSourcePSFClump(psImage **savedImage, psRegion *region, psArray *sources, float PSF_SN_LIM, float PSF_CLUMP_GRID_SCALE, psF32 SX_MAX, psF32 SY_MAX, psF32 AR_MAX) 281 285 { 282 286 psTrace("psModules.objects", 10, "---- begin ----\n"); 283 287 284 288 psArray *peaks = NULL; 285 pmPSFClump errorClump = {-1.0, -1.0, 0.0, 0.0 };286 pmPSFClump emptyClump = {+0.0, +0.0, 0.0, 0.0 };289 pmPSFClump errorClump = {-1.0, -1.0, 0.0, 0.0, 0, 0.0}; 290 pmPSFClump emptyClump = {+0.0, +0.0, 0.0, 0.0, 0, 0.0}; 287 291 pmPSFClump psfClump; 288 292 289 293 PS_ASSERT_PTR_NON_NULL(sources, errorClump); 290 PS_ASSERT_PTR_NON_NULL(recipe, errorClump);291 292 bool status = true; // Status of MD lookup293 float PSF_SN_LIM = psMetadataLookupF32(&status, recipe, "PSF_SN_LIM");294 if (!status) {295 PSF_SN_LIM = 0;296 }297 float PSF_CLUMP_GRID_SCALE = psMetadataLookupF32(&status, recipe, "PSF_CLUMP_GRID_SCALE");298 if (!status) {299 PSF_CLUMP_GRID_SCALE = 0.1;300 }301 294 302 295 // find the sigmaX, sigmaY clump 303 296 { 304 psF32 SX_MAX = psMetadataLookupF32(&status, recipe, "MOMENTS_SX_MAX");305 if (!status) {306 psWarning("MOMENTS_SX_MAX not set in recipe");307 SX_MAX = 10.0;308 }309 psF32 SY_MAX = psMetadataLookupF32(&status, recipe, "MOMENTS_SY_MAX");310 if (!status) {311 psWarning("MOMENTS_SY_MAX not set in recipe");312 SY_MAX = 10.0;313 }314 psF32 AR_MAX = psMetadataLookupF32(&status, recipe, "MOMENTS_AR_MAX");315 if (!status) {316 psWarning("MOMENTS_AR_MAX not set in recipe");317 AR_MAX = 3.0;318 }319 297 psF32 AR_MIN = 1.0 / AR_MAX; 320 298 321 299 // construct a sigma-plane image 322 int numCols = SX_MAX / PSF_CLUMP_GRID_SCALE, numRows = SY_MAX / PSF_CLUMP_GRID_SCALE; // Size of sigma-plane image 300 int numCols = 1 + SX_MAX / PSF_CLUMP_GRID_SCALE; // Size of sigma-plane image 301 int numRows = 1 + SY_MAX / PSF_CLUMP_GRID_SCALE; // Size of sigma-plane image 323 302 psTrace("psModules.objects", 10, "sigma-plane dimensions: %dx%d\n", numCols, numRows); 324 303 psImage *splane = psImageAlloc(numCols, numRows, PS_TYPE_F32); // sigma-plane image … … 333 312 } 334 313 335 int x = src->peak->x, y = src->peak->y; // Coordinates of peak 336 if (x < region->x0 || x > region->x1 || y < region->y0 || y > region->y1) { 337 continue; 338 } 314 if (region) { 315 int x = src->peak->x, y = src->peak->y; // Coordinates of peak 316 if (x < region->x0 || x > region->x1 || y < region->y0 || y > region->y1) { 317 continue; 318 } 319 } 339 320 340 321 if (src->mode & PM_SOURCE_MODE_BLEND) { 341 322 continue; 342 323 } 324 325 if (!src->moments->nPixels) continue; 343 326 344 327 if (src->moments->SN < PSF_SN_LIM) { … … 385 368 386 369 // find the peak in this image 387 psStats *stats = psStatsAlloc (PS_STAT_MAX );370 psStats *stats = psStatsAlloc (PS_STAT_MAX | PS_STAT_SAMPLE_STDEV); 388 371 if (!psImageStats (stats, splane, NULL, 0)) { 389 372 psError(PS_ERR_UNKNOWN, false, "Unable to get image statistics.\n"); … … 395 378 psTrace ("psModules.objects", 2, "clump threshold is %f\n", stats[0].max/2); 396 379 397 const bool keep_psf_clump = psMetadataLookupBool(NULL, recipe, "KEEP_PSF_CLUMP"); 398 if (keep_psf_clump) 399 { 400 psMetadataAdd(recipe, PS_LIST_TAIL, 401 "PSF_CLUMP", PS_DATA_IMAGE, "Image of PSF coefficients", splane); 380 psfClump.nSigma = stats->sampleStdev; 381 382 if (savedImage) { 383 *savedImage = psMemIncrRefCounter(splane); 402 384 } 403 385 psFree (splane); … … 405 387 406 388 // if we failed to find a valid peak, return the empty clump (failure signal) 407 if (peaks == NULL) 389 if (peaks == NULL) { 390 psError(PS_ERR_UNKNOWN, false, "failure in peak analysis for PSF clump.\n"); 391 psFree (peaks); 392 return emptyClump; 393 } 394 395 if (peaks->n == 0) 408 396 { 409 397 psLogMsg ("psphot", 3, "failed to find a peak in the PSF clump image\n"); … … 413 401 psLogMsg ("psphot", 3, "no significant peak\n"); 414 402 } 403 psFree (peaks); 415 404 return (emptyClump); 416 405 } … … 431 420 psTrace ("psModules.objects", 2, "clump is at %d, %d (%f)\n", clump->x, clump->y, clump->value); 432 421 422 // XXX store the mean sigma? 423 float meanSigma = psfClump.nSigma; 424 psfClump.nStars = clump->value; 425 psfClump.nSigma = clump->value / meanSigma; 426 433 427 // define section window for clump 434 428 minSx = clump->x * PSF_CLUMP_GRID_SCALE - 2.0*PSF_CLUMP_GRID_SCALE; … … 453 447 continue; 454 448 455 if (tmpSrc->peak->x < region->x0) continue; 456 if (tmpSrc->peak->x > region->x1) continue; 457 if (tmpSrc->peak->y < region->y0) continue; 458 if (tmpSrc->peak->y > region->y1) continue; 449 if (region) { 450 if (tmpSrc->peak->x < region->x0) continue; 451 if (tmpSrc->peak->x > region->x1) continue; 452 if (tmpSrc->peak->y < region->y0) continue; 453 if (tmpSrc->peak->y > region->y1) continue; 454 } 459 455 460 456 if (tmpSrc->moments->Mxx < minSx) … … 512 508 *****************************************************************************/ 513 509 514 bool pmSourceRoughClass(psRegion *region, psArray *sources, psMetadata *recipe, pmPSFClump clump, psImageMaskType maskSat)510 bool pmSourceRoughClass(psRegion *region, psArray *sources, float PSF_SN_LIM, float PSF_CLUMP_NSIGMA, pmPSFClump clump, psImageMaskType maskSat) 515 511 { 516 512 psTrace("psModules.objects", 10, "---- begin ----"); 517 513 518 514 PS_ASSERT_PTR_NON_NULL(sources, false); 519 PS_ASSERT_PTR_NON_NULL(recipe, false);520 515 521 516 int Nsat = 0; … … 530 525 psVector *starsn_peaks = psVectorAllocEmpty (sources->n, PS_TYPE_F32); 531 526 psVector *starsn_moments = psVectorAllocEmpty (sources->n, PS_TYPE_F32); 532 533 // get basic parameters, or set defaults534 bool status;535 float PSF_SN_LIM = psMetadataLookupF32 (&status, recipe, "PSF_SN_LIM");536 if (!status) PSF_SN_LIM = 20.0;537 float PSF_CLUMP_NSIGMA = psMetadataLookupF32 (&status, recipe, "PSF_CLUMP_NSIGMA");538 if (!status) PSF_CLUMP_NSIGMA = 1.5;539 540 // float INNER_RADIUS = psMetadataLookupF32 (&status, recipe, "SKY_INNER_RADIUS");541 527 542 528 pmSourceMode noMoments = PM_SOURCE_MODE_MOMENTS_FAILURE | PM_SOURCE_MODE_SKYVAR_FAILURE | PM_SOURCE_MODE_SKY_FAILURE | PM_SOURCE_MODE_BELOW_MOMENTS_SN; … … 894 880 895 881 // if we already have a cached image, re-use that memory 896 source->psf Flux = psImageCopy (source->psfFlux, source->pixels, PS_TYPE_F32);897 psImageInit (source->psf Flux, 0.0);882 source->psfImage = psImageCopy (source->psfImage, source->pixels, PS_TYPE_F32); 883 psImageInit (source->psfImage, 0.0); 898 884 899 885 // in some places (psphotEnsemble), we need a normalized version 900 886 // in others, we just want the model. which is more commonly used? 901 // psf Fluxalways has unity normalization (I0 = 1.0)902 pmModelAdd (source->psf Flux, source->maskObj, source->modelPSF, PM_MODEL_OP_FULL | PM_MODEL_OP_NORM, maskVal);887 // psfImage always has unity normalization (I0 = 1.0) 888 pmModelAdd (source->psfImage, source->maskObj, source->modelPSF, PM_MODEL_OP_FULL | PM_MODEL_OP_NORM, maskVal); 903 889 return true; 904 890 } … … 919 905 pmModel *model = pmSourceGetModel (NULL, source); 920 906 if (model == NULL) return false; // model must be defined 907 908 bool addNoise = mode & PM_MODEL_OP_NOISE; 921 909 922 910 if (source->modelFlux) { … … 941 929 942 930 psF32 **target = source->pixels->data.F32; 943 if ( mode & PM_MODEL_OP_NOISE) {944 // XXX need to scale by the gain... 931 if (addNoise) { 932 // when adding noise, we assume the shape and Io have been modified 945 933 target = source->variance->data.F32; 946 934 } 947 935 948 // XXX need to respect the source and model masks?949 936 for (int iy = 0; iy < source->modelFlux->numRows; iy++) { 950 937 int oy = iy + dY; … … 960 947 } 961 948 } 949 if (!addNoise) { 950 if (add) { 951 source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED; 952 } else { 953 source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED; 954 } 955 } 962 956 return true; 963 957 } 964 958 965 959 psImage *target = source->pixels; 966 if ( mode & PM_MODEL_OP_NOISE) {960 if (addNoise) { 967 961 target = source->variance; 968 962 } 969 963 970 if (add) { 971 status = pmModelAddWithOffset (target, source->maskObj, model, PM_MODEL_OP_FULL, maskVal, dx, dy); 972 } else { 973 status = pmModelSubWithOffset (target, source->maskObj, model, PM_MODEL_OP_FULL, maskVal, dx, dy); 964 if (!addNoise) { 965 if (add) { 966 status = pmModelAddWithOffset (target, source->maskObj, model, PM_MODEL_OP_FULL, maskVal, dx, dy); 967 source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED; 968 } else { 969 status = pmModelSubWithOffset (target, source->maskObj, model, PM_MODEL_OP_FULL, maskVal, dx, dy); 970 source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED; 971 } 974 972 } 975 973 … … 1061 1059 psF32 fA = (A->peak == NULL) ? 0 : A->peak->y; 1062 1060 psF32 fB = (B->peak == NULL) ? 0 : B->peak->y; 1061 1062 psF32 diff = fA - fB; 1063 if (diff > FLT_EPSILON) return (+1); 1064 if (diff < FLT_EPSILON) return (-1); 1065 return (0); 1066 } 1067 1068 // sort by X (ascending) 1069 int pmSourceSortByX (const void **a, const void **b) 1070 { 1071 pmSource *A = *(pmSource **)a; 1072 pmSource *B = *(pmSource **)b; 1073 1074 psF32 fA = (A->peak == NULL) ? 0 : A->peak->x; 1075 psF32 fB = (B->peak == NULL) ? 0 : B->peak->x; 1063 1076 1064 1077 psF32 diff = fA - fB;
Note:
See TracChangeset
for help on using the changeset viewer.
