Changeset 33953
- Timestamp:
- May 29, 2012, 5:16:09 PM (14 years ago)
- Location:
- branches/eam_branches/ipp-20120405/psphot
- Files:
-
- 17 edited
-
. (modified) (1 prop)
-
src (modified) (1 prop)
-
src/psphot.h (modified) (2 diffs)
-
src/psphotFindDetections.c (modified) (5 diffs)
-
src/psphotFindPeaks.c (modified) (2 diffs)
-
src/psphotKronIterate.c (modified) (22 diffs)
-
src/psphotMergeSources.c (modified) (1 diff)
-
src/psphotRadialProfileWings.c (modified) (4 diffs)
-
src/psphotReadout.c (modified) (1 diff)
-
src/psphotReadoutMinimal.c (modified) (1 diff)
-
src/psphotSetThreads.c (modified) (1 diff)
-
src/psphotSourceStats.c (modified) (1 diff)
-
src/psphotStackImageLoop.c (modified) (1 diff, 1 prop)
-
src/psphotStackMatchPSFsUtils.c (modified) (1 diff)
-
src/psphotStackObjects.c (modified) (1 diff)
-
src/psphotStackParseCamera.c (modified) (5 diffs)
-
src/psphotStackReadout.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20120405/psphot
- Property svn:mergeinfo changed
/trunk/psphot (added) merged: 33731,33761,33837,33839-33842,33877,33879,33881,33883,33889-33890,33894,33910,33913-33915,33917,33935
- Property svn:mergeinfo changed
-
branches/eam_branches/ipp-20120405/psphot/src
- Property svn:mergeinfo changed
/trunk/psphot/src (added) merged: 33731,33761,33837,33839-33842,33877,33879,33881,33883,33889-33890,33894,33910,33913-33915,33917,33935
- Property svn:mergeinfo changed
-
branches/eam_branches/ipp-20120405/psphot/src/psphot.h
r33946 r33953 189 189 // used by psphotFindDetections 190 190 pmReadout *psphotSignificanceImage (pmReadout *readout, psMetadata *recipe, psImageMaskType maskVal); 191 psArray *psphotFindPeaks (pmReadout *significance, pmReadout *readout, psMetadata *recipe, const float threshold, const int nMax );191 psArray *psphotFindPeaks (pmReadout *significance, pmReadout *readout, psMetadata *recipe, const float threshold, const int nMax, int *totalPeaks); 192 192 bool psphotFindFootprints (pmDetections *detections, pmReadout *significance, pmReadout *readout, psMetadata *recipe, const float threshold, const int pass, psImageMaskType maskVal); 193 193 psErrorCode psphotCullPeaks(const pmReadout *readout, const pmReadout *signifRO, const psMetadata *recipe, psArray *footprints); … … 472 472 473 473 bool psphotKronIterate (pmConfig *config, const pmFPAview *view, const char *filerule); 474 bool psphotKronIterateReadout(pmConfig *config, psMetadata *recipe, const pmFPAview *view, pmReadout *readout, psArray *sources, pmPSF *psf);474 bool psphotKronIterateReadout(pmConfig *config, psMetadata *recipe, const pmFPAview *view, const char * filerule, pmReadout *readout, psArray *sources, pmPSF *psf, int index); 475 475 bool psphotKronIterate_Threaded (psThreadJob *job); 476 476 -
branches/eam_branches/ipp-20120405/psphot/src/psphotFindDetections.c
r32348 r33953 48 48 // Use the new pmFootprints approach? 49 49 const bool useFootprints = psMetadataLookupBool(NULL, recipe, "USE_FOOTPRINTS"); 50 const bool footprintUseUnsubtracted = psMetadataLookupBool(NULL, recipe, "FOOTPRINT_USE_UNSUBTRACTED"); 50 51 51 52 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS"); … … 64 65 } 65 66 67 bool replaceSourcesForFootprints = false; 66 68 if (firstPass) { 67 69 pass = 1; … … 70 72 } else { 71 73 pass = 2; 74 replaceSourcesForFootprints = footprintUseUnsubtracted; 72 75 NSIGMA_PEAK = psMetadataLookupF32 (&status, recipe, "PEAKS_NSIGMA_LIMIT_2"); PS_ASSERT (status, NULL); 73 76 NMAX = 0; // unlimited number of peaks in final pass: allow a limit (PEAKS_NMAX_2) ? … … 96 99 97 100 // detect the peaks in the significance image 98 detections->peaks = psphotFindPeaks (significance, readout, recipe, threshold, NMAX); 101 int totalPeaks = 0; 102 detections->peaks = psphotFindPeaks (significance, readout, recipe, threshold, NMAX, &totalPeaks); 99 103 psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "PEAK_THRESHOLD", PS_META_REPLACE, "Peak Detection Threshold", threshold); 100 104 if (!detections->peaks) { … … 105 109 return false; 106 110 } 111 // hard limit on number of peaks we will accept. (To avoid memory overload in psphotStack) 112 int maxPeaks = psMetadataLookupS32 (&status, recipe, "PEAKS_NMAX_TOTAL"); PS_ASSERT (status, NULL); 113 if (maxPeaks && (totalPeaks > maxPeaks)) { 114 psFree (detections); 115 psError (PSPHOT_ERR_DATA, true, "Too many peaks %d found PEAKS_NMAX_TOTAL: %d", totalPeaks, maxPeaks); 116 return false; 117 } 107 118 108 119 // optionally merge peaks into footprints 109 120 if (useFootprints) { 121 if (replaceSourcesForFootprints) { 122 psphotAddOrSubNoiseReadout(config, view, filerule, index, recipe, false); 123 psphotReplaceAllSourcesReadout (config, view, filerule, index, recipe, false); 124 psFree (significance); 125 significance = psphotSignificanceImage (readout, recipe, maskVal); 126 } 127 110 128 psphotFindFootprints (detections, significance, readout, recipe, threshold, pass, maskVal); 129 130 if (replaceSourcesForFootprints) { 131 psphotRemoveAllSourcesReadout (config, view, filerule, index, recipe, false); 132 } 111 133 } 112 134 -
branches/eam_branches/ipp-20120405/psphot/src/psphotFindPeaks.c
r32348 r33953 4 4 // image must be constructed to represent (S/N)^2. If nMax is non-zero, only return a maximum 5 5 // of nMax peaks 6 psArray *psphotFindPeaks (pmReadout *significance, pmReadout *readout, psMetadata *recipe, const float threshold, const int nMax ) {6 psArray *psphotFindPeaks (pmReadout *significance, pmReadout *readout, psMetadata *recipe, const float threshold, const int nMax, int *totalPeaks) { 7 7 8 8 bool status = false; … … 18 18 psError(PSPHOT_ERR_DATA, false, "no peaks found in this image"); 19 19 return NULL; 20 } 21 // return the total number of peaks found before the nMax limit is applied 22 if (totalPeaks) { 23 *totalPeaks = peaks->n; 20 24 } 21 25 -
branches/eam_branches/ipp-20120405/psphot/src/psphotKronIterate.c
r33946 r33953 1 1 # include "psphotInternal.h" 2 # ifndef ROUND 3 # define ROUND(X) ((int) ((X) + 0.5*SIGN(X))) 4 # endif 5 6 bool psphotKronWindowSetSource(pmSource *source, psImage *kronWindow, bool useKronRadius, bool insert); 7 bool psphotKronWindowMag (pmSource *source, psImage *kronWindow, float radius, float minKronRadius, psImageMaskType maskVal); 2 3 bool psphotKronWindowSetSource(pmSource *source, psImage *kronWindow, bool useKronRadius, bool insert, bool oldWindow); 4 bool psphotKronWindowMag (pmSource *source, psImage *kronWindow, float radius, float minKronRadius, psImageMaskType maskVal, bool applyWeight, psImage *smoothedPixels); 5 8 6 9 7 bool psphotKronIterate (pmConfig *config, const pmFPAview *view, const char *filerule) … … 11 9 bool status = true; 12 10 13 // return true;14 15 11 fprintf (stdout, "\n"); 16 12 psLogMsg ("psphot", PS_LOG_INFO, "--- psphot Kron Iterate ---"); … … 46 42 // psAssert (psf, "missing psf?"); 47 43 48 if (!psphotKronIterateReadout (config, recipe, view, readout, sources, psf)) {44 if (!psphotKronIterateReadout (config, recipe, view, filerule, readout, sources, psf, i)) { 49 45 psError (PSPHOT_ERR_CONFIG, false, "failed to measure magnitudes for %s entry %d", filerule, i); 50 46 return false; … … 58 54 bool psphotVisualRangeImage (int kapaFD, psImage *inImage, const char *name, int channel, float min, float max); 59 55 60 bool psphotKronIterateReadout(pmConfig *config, psMetadata *recipe, const pmFPAview *view, pmReadout *readout, psArray *sources, pmPSF *psf) {56 bool psphotKronIterateReadout(pmConfig *config, psMetadata *recipe, const pmFPAview *view, const char * filerule, pmReadout *readout, psArray *sources, pmPSF *psf, int index) { 61 57 62 58 bool status = false; … … 69 65 psTimerStart ("psphot.kron"); 70 66 67 71 68 // determine the number of allowed threads 72 69 int nThreads = psMetadataLookupS32(&status, config->arguments, "NTHREADS"); // Number of threads … … 87 84 int KRON_ITERATIONS = psMetadataLookupS32 (&status, recipe, "KRON_ITERATIONS"); 88 85 if (!status) { 89 KRON_ITERATIONS = 2; 86 KRON_ITERATIONS = 1; 87 } 88 89 bool KRON_APPLY_WEIGHT = psMetadataLookupBool (&status, recipe, "KRON_APPLY_WEIGHT"); 90 if (!status) { 91 KRON_APPLY_WEIGHT = true; 92 } 93 94 bool KRON_APPLY_WINDOW = psMetadataLookupBool (&status, recipe, "KRON_APPLY_WINDOW"); 95 if (!status) { 96 KRON_APPLY_WINDOW = false; 97 } 98 bool KRON_SMOOTH = psMetadataLookupBool (&status, recipe, "KRON_SMOOTH"); 99 if (!status) { 100 KRON_SMOOTH = false; 101 } 102 float KRON_SMOOTH_SIGMA = psMetadataLookupF32 (&status, recipe, "KRON_SMOOTH_SIGMA"); 103 if (!status) { 104 KRON_SMOOTH_SIGMA = 1.7; 105 } 106 float KRON_SMOOTH_NSIGMA = psMetadataLookupS32 (&status, recipe, "KRON_SMOOTH_NSIGMA"); 107 if (!status) { 108 KRON_SMOOTH_NSIGMA = 2; 90 109 } 91 110 … … 119 138 // set a window function for each source based on the moments 120 139 // (this skips really bad sources (no peak, no moments, DEFECT) 121 psphotKronWindowSetSource (source, kronWindow, false, true); 140 psphotKronWindowSetSource (source, kronWindow, false, true, KRON_APPLY_WINDOW); 141 } 142 143 // We measure the Kron Radius on a smoothed copy of the readout image 144 psImage *smoothedImage = NULL; 145 if (KRON_SMOOTH) { 146 // Build the smoothed source image 147 // Replace the subtracted sources 148 psphotReplaceAllSourcesReadout(config, view, filerule, index, recipe, false); 149 // Copy the image and smooth 150 psTimerStart ("psphot.kron.smooth"); 151 smoothedImage = psImageCopy(NULL, readout->image, PS_TYPE_F32); 152 psImageSmooth(smoothedImage, KRON_SMOOTH_SIGMA, KRON_SMOOTH_NSIGMA); 153 psLogMsg ("psphot.kron", PS_LOG_INFO, "smoothed image %f sec\n", psTimerMark ("psphot.kron.smooth")); 154 155 // remove the sources 156 psphotRemoveAllSourcesReadout( config, view, filerule, index, recipe, false ); 157 // Now subtract smooth versions of the sources from the smoothed image 158 psTimerStart ("psphot.kron.smooth.sources"); 159 for (int i=0; i< sources->n; i++) { 160 pmSource *source = sources->data[i]; 161 // If source has been subtracted from the readout image subtract a "smoothed" version from the smoothedImage 162 if (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED) { 163 // cache copy of smoothedPixels in the source 164 // tmpPtr is for use by a single "module" and must be null otherwise 165 psAssert(source->tmpPtr == NULL, "source->tmpPtr is not null!"); 166 167 psImage *smoothedPixels = psImageSubset(smoothedImage, source->region); 168 source->tmpPtr = (psPtr) smoothedPixels; 169 pmSourceSmoothOp(source, PM_MODEL_OP_FUNC, smoothedPixels, KRON_SMOOTH_SIGMA, false, maskVal, 0, 0); 170 } 171 } 172 psLogMsg ("psphot.kron", PS_LOG_INFO, "removed %ld smoothed sources %f sec\n", sources->n, psTimerMark ("psphot.kron.smooth.sources")); 173 122 174 } 123 175 … … 146 198 PS_ARRAY_ADD_SCALAR(job->args, MIN_KRON_RADIUS, PS_TYPE_F32); 147 199 PS_ARRAY_ADD_SCALAR(job->args, KRON_ITERATIONS, PS_TYPE_S32); 200 PS_ARRAY_ADD_SCALAR(job->args, (psS32) KRON_APPLY_WEIGHT, PS_TYPE_S32); 201 PS_ARRAY_ADD_SCALAR(job->args, (psS32) KRON_APPLY_WINDOW, PS_TYPE_S32); 202 PS_ARRAY_ADD_SCALAR(job->args, KRON_SMOOTH_SIGMA, PS_TYPE_F32); 203 psArrayAdd(job->args, 1, smoothedImage); 148 204 149 205 // set this to 0 to run without threading 150 # if ( 0)206 # if (1) 151 207 if (!psThreadJobAddPending(job)) { 152 208 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); … … 156 212 if (!psphotKronIterate_Threaded(job)) { 157 213 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 214 // psFree(AnalysisRegion); 158 215 return false; 159 216 } … … 179 236 psFree (cellGroups); 180 237 psFree (kronWindow); 238 psFree (smoothedImage); 181 239 182 240 psLogMsg ("psphot.kron", PS_LOG_WARN, "measure masked kron magnitudes : %f sec for %ld objects\n", psTimerMark ("psphot.kron"), sources->n); … … 194 252 float MIN_KRON_RADIUS = PS_SCALAR_VALUE(job->args->data[6],F32); 195 253 int KRON_ITERATIONS = PS_SCALAR_VALUE(job->args->data[7],S32); 196 197 // XXX TEST : set iteration to 1 254 bool KRON_APPLY_WEIGHT = PS_SCALAR_VALUE(job->args->data[8],S32); 255 bool KRON_APPLY_WINDOW = PS_SCALAR_VALUE(job->args->data[9],S32); 256 float KRON_SMOOTH_SIGMA = PS_SCALAR_VALUE(job->args->data[10],F32); 257 psImage *smoothedImage = job->args->data[11]; 258 259 // psImage *smoothedPixels = NULL; 198 260 for (int j = 0; j < KRON_ITERATIONS; j++) { 199 261 for (int i = 0; i < sources->n; i++) { … … 202 264 if (!source->peak) continue; // XXX how can we have a peak-less source? 203 265 204 // allocate space formoments266 // check status of this source's moments 205 267 if (!source->moments) continue; 268 if (!source->tmpFlags & PM_SOURCE_TMPF_MOMENTS_MEASURED) continue; 269 if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) continue; 206 270 207 271 // replace object in image 208 272 bool reSubtract = false; 273 psImage *smoothedPixels = NULL; 209 274 if (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED) { 210 pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 275 pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 276 smoothedPixels = (psImage *) source->tmpPtr; 277 if (smoothedPixels) { 278 // psFree(source->tmpPtr); 279 // smoothedPixels = psImageSubset(smoothedImage, source->region); 280 pmSourceSmoothOp(source, PM_MODEL_OP_FUNC, smoothedPixels, KRON_SMOOTH_SIGMA, true, maskVal, 0, 0); 281 // source->tmpPtr = smoothedPixels; 282 } 211 283 reSubtract = true; 212 284 } … … 223 295 // XXX float windowRadius = PS_MIN(PS_MAX(RADIUS, 4.0*source->moments->Mrf), maxWindow); 224 296 225 // Sextractor apparently takes something like the skyRadius window, measures the moments inside that window,226 // then uses an elliptical outline based on the 2nd moments, but 6x the size227 228 297 // XXX TEST : use a window based on the radial profile numbers: max is skyRadius, min is RADIUS 229 298 // if we lack the skyRadius (eg MATCHED sources), go to the default value 230 float maxWindow, windowRadius; 231 232 if (j == 0) { 233 maxWindow = isfinite(source->skyRadius) ? source->skyRadius : RADIUS; 234 windowRadius = PS_MAX(RADIUS, maxWindow); 235 } else { 236 maxWindow = isfinite(source->moments->Mrf) ? 6.0*source->moments->Mrf : RADIUS; 237 windowRadius = PS_MAX(RADIUS, maxWindow); 238 } 239 240 #ifdef notdef 241 fprintf(stderr, "Redefining pixels for source: %d %4d %4d new radius: %f\n", 242 i, source->peak->x, source->peak->y, windowRadius+2); 243 #endif 299 float maxWindow; 300 if (j == 0) { 301 maxWindow = isfinite(source->skyRadius) ? source->skyRadius : RADIUS; 302 } else { 303 maxWindow = isfinite(source->moments->Mrf) ? 6.0*source->moments->Mrf : RADIUS; 304 } 305 float windowRadius = PS_MAX(RADIUS, maxWindow); 306 244 307 // re-allocate image, weight, mask arrays for each peak with box big enough to fit BIG_RADIUS 245 pmSourceRedefinePixels (source, readout, source->peak->x, source->peak->y, windowRadius + 2);308 bool extend = pmSourceRedefinePixels (source, readout, source->peak->x, source->peak->y, windowRadius + 2); 246 309 psAssert (source->pixels, "WTF?"); 310 if (extend && smoothedPixels) { 311 psFree(source->tmpPtr); 312 smoothedPixels = psImageSubset(smoothedImage, source->region); 313 psAssert (smoothedPixels, "WTF?"); 314 source->tmpPtr = (psPtr) smoothedPixels ; 315 } 316 247 317 248 318 // clear the window function for this source based on the moments 249 psphotKronWindowSetSource (source, kronWindow, (j > 0), false); 250 251 // this function populates moments->Mrf,KronFlux,KronFluxErr 252 psphotKronWindowMag (source, kronWindow, windowRadius, MIN_KRON_RADIUS, maskVal); 253 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal)); 254 255 // set a window function for each source based on the moments 256 psphotKronWindowSetSource (source, kronWindow, true, true); 319 // Note this function also applies cuts on the source and returns false if it 320 // does not meet the requirements for measuring the Kron Radius or Magnitude. 321 // Not that it performs that function even if KRON_APPLY_WINDOW is false 322 if (psphotKronWindowSetSource (source, kronWindow, (j > 0), false, KRON_APPLY_WINDOW)) { 323 324 // this function populates moments->Mrf,KronFlux,KronFluxErr 325 psphotKronWindowMag (source, kronWindow, windowRadius, MIN_KRON_RADIUS, maskVal, KRON_APPLY_WEIGHT, smoothedPixels); 326 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal)); 327 328 // set a window function for each source based on the moments 329 psphotKronWindowSetSource (source, kronWindow, true, true, KRON_APPLY_WINDOW); 330 } 257 331 258 332 // if we subtracted it above, re-subtract the object, leave local sky 259 333 if (reSubtract) { 260 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 334 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 335 if (smoothedPixels) { 336 pmSourceSmoothOp(source, PM_MODEL_OP_FUNC, smoothedPixels, KRON_SMOOTH_SIGMA, false, maskVal, 0, 0); 337 if (j + 1 == KRON_ITERATIONS) { 338 // We're done with the smoothedPixels 339 psFree(source->tmpPtr); 340 source->tmpPtr = NULL; 341 smoothedPixels = NULL; 342 } 343 } 261 344 } 262 345 } 263 346 } 347 // psFree(smoothedPixels); 264 348 return true; 265 349 } 266 350 267 bool psphotKronWindowMag (pmSource *source, psImage *kronWindow, float radius, float minKronRadius, psImageMaskType maskVal) { 351 bool psphotKronWindowMag (pmSource *source, psImage *kronWindow, float radius, float minKronRadius, psImageMaskType maskVal, 352 bool applyWeight, psImage *smoothedPixels) { 268 353 269 354 PS_ASSERT_PTR_NON_NULL(source, false); … … 273 358 274 359 psF32 R2 = PS_SQR(radius); 275 float rsigma2 = 0.5 / PS_SQR(radius/2.0);360 float rsigma2 = applyWeight ? 0.5 / R2 : 0; 276 361 277 362 // a note about coordinates: coordinates of objects throughout psphot refer to the primary … … 286 371 // Xn = SUM (x - xc)^n * (z - sky) 287 372 373 288 374 psF32 RF = 0.0; 289 375 psF32 RS = 0.0; … … 304 390 int Ywo = source->pixels->row0; 305 391 306 psF32 **vPix = source->pixels->data.F32; 392 psF32 **vPix; 393 if (smoothedPixels) { 394 vPix = smoothedPixels->data.F32; 395 } else { 396 vPix = source->pixels->data.F32; 397 } 307 398 psF32 **vWin = kronWindow->data.F32; 308 399 psF32 **vWgt = source->variance->data.F32; … … 377 468 float Var = 0.0; 378 469 float Win = 0.0; 470 471 // set vPix to the source pixels (it may have been set to the 472 // smoothed image above) 473 vPix = source->pixels->data.F32; 474 379 475 380 476 for (psS32 row = 0; row < source->pixels->numRows ; row++) { … … 415 511 } 416 512 417 bool psphotKronWindowSetSource(pmSource *source, psImage *kronWindow, bool useKronRadius, bool insert ) {513 bool psphotKronWindowSetSource(pmSource *source, psImage *kronWindow, bool useKronRadius, bool insert, bool applyWindow) { 418 514 419 515 if (!source) return false; … … 422 518 if (source->type == PM_SOURCE_TYPE_DEFECT) return false; 423 519 if (source->type == PM_SOURCE_TYPE_SATURATED) return false; 520 if (!source->tmpFlags & PM_SOURCE_TMPF_MOMENTS_MEASURED) return false; 521 if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) return false; 424 522 psAssert(kronWindow, "need a window"); 523 524 if (!isfinite(source->moments->Mrf) || source->moments->Mrf < 0 ) return false; 525 526 if (!applyWindow) { 527 return true; 528 } 425 529 426 530 // we have a source with moments Mx, My, Mxx, Mxy, Myy. we just need to define a Gaussian that has … … 433 537 float Yo = source->moments->My; 434 538 435 float Mxx = source->moments->Mxx; 436 float Mxy = source->moments->Mxy; 437 float Myy = source->moments->Myy; 438 439 float Mmajor = 0.5*(Mxx + Myy) + 0.5*sqrt(PS_SQR(Mxx - Myy) + 4.0*PS_SQR(Mxy)); 440 float Mminor = 0.5*(Mxx + Myy) - 0.5*sqrt(PS_SQR(Mxx - Myy) + 4.0*PS_SQR(Mxy)); 441 442 // Mxx, Mxy, Myy define the elliptical shape, but Mrf defines the width 443 float scale = PS_SQR(0.5 * source->moments->Mrf) / Mmajor; 444 445 float Sxx = scale * Mmajor * Mminor / Myy; // sigma_x^2 446 float Sxy = Mxy / (scale * Mmajor * Mminor); 447 float Syy = scale * Mmajor * Mminor / Mxx; // sigma_y^2 448 449 float Smajor = sqrt(Mmajor); 539 psEllipseMoments moments; 540 moments.x2 = source->moments->Mxx; 541 moments.y2 = source->moments->Myy; 542 moments.xy = source->moments->Mxy; 543 544 psEllipseAxes axes = psEllipseMomentsToAxes(moments, 20.0); 545 if (! (isfinite(axes.major) && isfinite(axes.minor) && isfinite(axes.theta)) ) { 546 // Shall we log a proper warning? This happens often with matched sources (forced photometry) 547 // fprintf(dump, "invalid axes found id: %4d major: %f minor: %f theta: %f\n", source->id, axes.major, axes.minor, axes.theta); 548 return false; 549 } 550 551 // Why this factor of 0.5 ? 552 float scale = 0.5 * source->moments->Mrf / axes.major; 553 axes.major *= scale; 554 axes.minor *= scale; 555 556 psEllipseShape shape = psEllipseAxesToShape(axes); 557 if (! (isfinite(shape.sx) && isfinite(shape.sy) && isfinite(shape.sxy)) ) { 558 // Shall we log a proper warning? This happens often with matched sources (forced photometry) 559 // fprintf(dump, "invalid shape found id: %d sx: %f sy %f sxy: %f\n", source->id, shape.sx, shape.sy, shape.sxy); 560 return false; 561 } 562 563 float Smajor = axes.major; 450 564 451 565 int minX = PS_MIN(PS_MAX(Xo - 5*Smajor, 0), Nx - 1); … … 454 568 int maxY = PS_MIN(PS_MAX(Yo + 5*Smajor, 0), Ny - 1); 455 569 456 float rMxx = 0.5 / Sxx; 457 float rMyy = 0.5 / Syy; 458 570 float rMxx = 0.5 / PS_SQR(shape.sx); 571 float rMyy = 0.5 / PS_SQR(shape.sy); 572 float Sxy = -1. * shape.sxy; // factor of -1 is included to match the previous window function 573 // implementation. XXX: Is this correct? 574 459 575 for (int iy = minY; iy < maxY; iy++) { 460 576 for (int ix = minX; ix < maxX; ix++) { … … 467 583 float f = insert ? 1.001 - exp(-z) : 1.0 / (1.001 - exp(-z)); 468 584 469 kronWindow->data.F32[iy][ix] *= f;585 kronWindow->data.F32[iy][ix] *= f; 470 586 } 471 587 } 588 472 589 return true; 473 590 } -
branches/eam_branches/ipp-20120405/psphot/src/psphotMergeSources.c
r33444 r33953 744 744 psAssert (readoutOut, "missing readout?"); 745 745 746 pmDetections *detectionsOutOld = psMetadataLookupPtr (&status, readoutOut->analysis, "PSPHOT.DETECTIONS"); 747 psArray *oldFootprints = detectionsOutOld ? detectionsOutOld->footprints : NULL; 748 746 749 // replace any existing DETECTION container on readoutOut->analysis with the new one 747 750 pmDetections *detectionsOut = pmDetectionsAlloc(); 751 if (oldFootprints) { 752 // ... but hang on to any existing footprints so that they can be merged with new footprints in pass 2 753 detectionsOut->footprints = psMemIncrRefCounter(oldFootprints); 754 } 748 755 detectionsOut->allSources = psArrayAllocEmpty (100); 749 756 if (!psMetadataAddPtr (readoutOut->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_META_REPLACE | PS_DATA_UNKNOWN, "psphot detections", detectionsOut)) { -
branches/eam_branches/ipp-20120405/psphot/src/psphotRadialProfileWings.c
r33411 r33953 55 55 static float MIN_RADIUS = NAN; 56 56 static float SKY_STDEV = NAN; 57 static float SKY_SLOPE_MIN = NAN; 57 58 // static FILE *file = NULL; 58 59 … … 81 82 82 83 MIN_RADIUS = psMetadataLookupF32 (&status, readout->analysis, "PSF_MOMENTS_RADIUS"); 83 if (!status ) {84 if (!status || (MIN_RADIUS > MAX_RADIUS)) { 84 85 MIN_RADIUS = psMetadataLookupF32 (&status, recipe, "PSF_MOMENTS_RADIUS"); 85 86 } … … 89 90 if (!status) { 90 91 SKY_STDEV = 1.0; // a crude default value (why would this not exist?) 92 } 93 94 // SKY_SLOPE_MIN is the sigma of the sky model (ie, smoothed on large scales) 95 SKY_SLOPE_MIN = psMetadataLookupF32 (&status, recipe, "SKY_SLOPE_MIN"); 96 if (!status) { 97 SKY_SLOPE_MIN = 3.0; 91 98 } 92 99 … … 302 309 limitSlope = slope; 303 310 } 304 if (!limit && isfinite(slope) && (fabs(slope) < 3.0)) {311 if (!limit && isfinite(slope) && (fabs(slope) < SKY_SLOPE_MIN)) { 305 312 // SB no longer changing. 306 313 limit = true; 307 314 // linearly interpolate to the radius at which we hit the sky, using the last flux and the limiting slope 308 315 if (isfinite(lastFlux)) { 309 float interpolatedRadius = lastRadius + lastFlux / 3.0;316 float interpolatedRadius = lastRadius + lastFlux / SKY_SLOPE_MIN; 310 317 if (interpolatedRadius < MAX_RADIUS) { 311 318 limitRadius = interpolatedRadius; -
branches/eam_branches/ipp-20120405/psphot/src/psphotReadout.c
r33089 r33953 185 185 // remove noise for subtracted objects (ie, return to normal noise level) 186 186 // NOTE: this needs to operate only on the OLD sources 187 psphotSubNoise (config, view, filerule); // pass 1 (detections->allSources) 187 bool footprintUseUnsubtracted = psMetadataLookupBool(NULL, recipe, "FOOTPRINT_USE_UNSUBTRACTED"); 188 // Note: if footprintUseUnsubtracted is true the noise was already subtracted in psphotFindDetections() 189 if (!footprintUseUnsubtracted) { 190 psphotSubNoise (config, view, filerule); // pass 1 (detections->allSources) 191 } 188 192 189 193 // define new sources based on only the new peaks & measure moments -
branches/eam_branches/ipp-20120405/psphot/src/psphotReadoutMinimal.c
r32996 r33953 64 64 // Construct an initial model for each object, set the radius to fitRadius, set circular 65 65 // fit mask. NOTE: only applied to sources without guess models 66 psphotGuessModels (config, view, filerule); 66 if (!psphotGuessModels (config, view, filerule)) { 67 psLogMsg ("psphot", 3, "failure to Guess Model"); 68 return psphotReadoutCleanup (config, view, filerule); 69 } 67 70 68 71 // linear PSF fit to source peaks -
branches/eam_branches/ipp-20120405/psphot/src/psphotSetThreads.c
r33946 r33953 30 30 psFree(task); 31 31 32 task = psThreadTaskAlloc("PSPHOT_KRON_ITERATE", 8);32 task = psThreadTaskAlloc("PSPHOT_KRON_ITERATE", 12); 33 33 task->function = &psphotKronIterate_Threaded; 34 34 psThreadTaskAdd(task); -
branches/eam_branches/ipp-20120405/psphot/src/psphotSourceStats.c
r33089 r33953 605 605 } 606 606 psAssert (isfinite(Sigma), "did we miss a case?"); 607 if (!isfinite(minKronRadius)) { 608 minKronRadius = Sigma; 609 } 607 610 608 611 // choose a grid scale that is a fixed fraction of the psf sigma^2 -
branches/eam_branches/ipp-20120405/psphot/src/psphotStackImageLoop.c
- Property svn:mergeinfo changed
/trunk/psphot/src/psphotStackImageLoop.c merged: 33731
r33946 r33953 42 42 // XXX for now, just load the full set of images up front except for EXPNUM which we defer 43 43 pmFPAfileActivate (config->files, false, "PSPHOT.STACK.EXPNUM.RAW"); 44 pmFPAfileActivate (config->files, false, "PSPHOT.STACK.EXPNUM.CNV"); 44 45 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE ("failed input for fpa in psphot."); 45 46 - Property svn:mergeinfo changed
-
branches/eam_branches/ipp-20120405/psphot/src/psphotStackMatchPSFsUtils.c
r32348 r33953 105 105 psAssert(psphotRecipe, "Need PSPHOT recipe"); 106 106 107 #if (0) 108 // DON'T OVERWRITE PSPHOT recipe value 107 109 psString maskBadStr = psMetadataLookupStr(NULL, ppStackRecipe, "MASK.BAD");// Name of bits to mask for bad 108 110 psMaskType maskBad = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels 109 111 110 112 // user-defined masks to test for good/bad pixels (build from recipe list if not yet set) 111 psMetadataAddU8(psphotRecipe, PS_LIST_TAIL, "MASK.PSPHOT", PS_META_REPLACE, "user-defined mask", maskBad); 113 psMetadataAddImageMask(psphotRecipe, PS_LIST_TAIL, "MASK.PSPHOT", PS_META_REPLACE, "user-defined mask", maskBad); 114 #endif 112 115 113 116 psImage *binned = psphotModelBackgroundReadoutNoFile(ro, config); // Binned background model -
branches/eam_branches/ipp-20120405/psphot/src/psphotStackObjects.c
r32633 r33953 119 119 } 120 120 if (!skipSourcePetro) keepObjectPetro = true; 121 122 keepObjectPetro = true;123 121 } 124 122 -
branches/eam_branches/ipp-20120405/psphot/src/psphotStackParseCamera.c
r33690 r33953 129 129 } 130 130 131 psS64 stack_id = psMetadataLookupS64(&status, input, "STACK_ID"); 132 if (!status) { 133 psError(PS_ERR_UNKNOWN, false, "Unable to find STACK_ID from sources %d", i); 134 return false; 135 } 131 136 // generate an pmFPAimage for the output convolved image 132 137 // XXX output of these files should be optional … … 139 144 } 140 145 outputImage->save = true; 141 outputImage->fileID = i; // this is used to generate output names146 outputImage->fileID = stack_id; // this is used to generate output names 142 147 143 148 pmFPAfile *outputMask = pmFPAfileDefineOutput(config, outputImage->fpa, "PSPHOT.STACK.OUTPUT.MASK"); … … 151 156 } 152 157 outputMask->save = true; 153 outputMask->fileID = i; // this is used to generate output names158 outputMask->fileID = stack_id; // this is used to generate output names 154 159 155 160 pmFPAfile *outputVariance = pmFPAfileDefineOutput(config, outputImage->fpa, "PSPHOT.STACK.OUTPUT.VARIANCE"); … … 163 168 } 164 169 outputVariance->save = true; 165 outputVariance->fileID = i; // this is used to generate output names170 outputVariance->fileID = stack_id; // this is used to generate output names 166 171 167 172 // the output sources are carried on the outputImage->fpa structures … … 172 177 } 173 178 outsources->save = true; 174 outsources->fileID = i; // this is used to generate output names179 outsources->fileID = stack_id; // this is used to generate output names 175 180 } 176 181 } -
branches/eam_branches/ipp-20120405/psphot/src/psphotStackReadout.c
r32996 r33953 89 89 return psphotReadoutCleanup (config, view, STACK_SRC); 90 90 } 91 if (!psphotSubtractBackground (config, view, STACK_SRC)) { 92 return psphotReadoutCleanup (config, view, STACK_SRC); 91 if (strcmp(STACK_SRC, STACK_DET)) { 92 #define MODEL_BACKGROUND_SRC 1 93 #ifdef MODEL_BACKGROUND_SRC 94 // work around the fact that the background levels on the convolved 95 // and unconvolved stacks can be different 96 if (!psphotModelBackground (config, view, STACK_SRC)) { 97 return psphotReadoutCleanup (config, view, STACK_SRC); 98 } 99 #endif 100 if (!psphotSubtractBackground (config, view, STACK_SRC)) { 101 return psphotReadoutCleanup (config, view, STACK_SRC); 102 } 93 103 } 94 104 if (!strcasecmp (breakPt, "BACKMDL")) { … … 190 200 psphotReplaceAllSources (config, view, STACK_SRC, false); // pass 1 (detections->allSources) 191 201 202 192 203 // if we only do one pass, skip to extended source analysis 193 204 if (!strcasecmp (breakPt, "PASS1")) goto pass1finish; … … 211 222 // subtract all sources from DET (this will subtract using the psf model for SRC, which 212 223 // will somewhat oversubtract the sources -- this is OK 213 psphotRemoveAllSources (config, view, STACK_DET, false); // ignore subtraction state for sources224 psphotRemoveAllSources (config, view, STACK_DET, false); // do not ignore subtraction state for sources 214 225 } 215 226 … … 223 234 // remove noise for subtracted objects (ie, return to normal noise level) 224 235 // NOTE: this needs to operate only on the OLD sources 225 psphotSubNoise (config, view, STACK_DET); // pass 1 (detections->allSources) 236 // NOTE: if fooprintsUseUnsubtracted, the noise has already been removed by psphotFindDetections 237 bool footprintsUseUnsubtracted = psMetadataLookupBool(NULL, recipe, "FOOTPRINT_USE_UNSUBTRACTED"); 238 if (!footprintsUseUnsubtracted) { 239 psphotSubNoise (config, view, STACK_DET); // pass 1 (detections->allSources) 240 } 226 241 227 242 // if DET and SRC are different images, copy the detections from DET to SRC … … 303 318 304 319 // create source children for the OUT filerule (for radial aperture photometry) 305 psArray *objectsRadial = psphotSourceChildrenByObject (config, view, STACK_OUT, objects); 306 if (!objectsRadial) { 320 // (These are not just for radial aperture photomoetry. If they aren't defined we 321 // get no sources output 322 psArray *objectsOut = psphotSourceChildrenByObject (config, view, STACK_OUT, objects); 323 if (!objectsOut) { 307 324 psFree(objects); 308 325 psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis"); … … 310 327 } 311 328 312 // measure circular, radial apertures (objects sorted by S/N) 313 // this forces photometry on the undetected sources from other images 314 psphotRadialApertures (config, view, STACK_SRC, 0); // XXX entry 0 == unmatched? 315 psMemDump("extmeas"); 316 317 int nRadialEntries = psphotStackMatchPSFsEntries(config, view, STACK_OUT); 318 319 for (int entry = 1; entry < nRadialEntries; entry++) { 320 // NOTE: entry 0 is the unmatched image set 321 322 // re-measure the PSF for the smoothed image (using entries in 'allSources') 323 psphotChoosePSF (config, view, STACK_OUT, false); 324 325 // this is necessary to update the models based on the new PSF 326 psphotResetModels (config, view, STACK_OUT); 327 328 // this is necessary to get the right normalization for the new models 329 psphotFitSourcesLinear (config, view, STACK_OUT, false); 330 331 // measure circular, radial apertures (objects sorted by S/N) 332 // entry 0 == unmatched? pass entry + 1? 333 psphotRadialApertures (config, view, STACK_OUT, entry); 334 335 // replace the flux in the image so it is returned to its original state 336 psphotReplaceAllSources (config, view, STACK_OUT, false); 337 338 // smooth to the next FWHM, or set 'smoothAgain' to false if no more 339 psphotStackMatchPSFsNext(config, view, STACK_OUT, entry); 340 psMemDump("matched"); 329 330 bool radial_apertures = psMetadataLookupBool(NULL, recipe, "RADIAL_APERTURES"); 331 if (radial_apertures) { 332 // measure circular, radial apertures (objects sorted by S/N) 333 // this forces photometry on the undetected sources from other images 334 psphotRadialApertures (config, view, STACK_SRC, 0); // XXX entry 0 == unmatched? 335 psMemDump("extmeas"); 336 337 int nRadialEntries = psphotStackMatchPSFsEntries(config, view, STACK_OUT); 338 339 for (int entry = 1; entry < nRadialEntries; entry++) { 340 // NOTE: entry 0 is the unmatched image set 341 342 // re-measure the PSF for the smoothed image (using entries in 'allSources') 343 psphotChoosePSF (config, view, STACK_OUT, false); 344 345 // this is necessary to update the models based on the new PSF 346 psphotResetModels (config, view, STACK_OUT); 347 348 // this is necessary to get the right normalization for the new models 349 psphotFitSourcesLinear (config, view, STACK_OUT, false); 350 351 // measure circular, radial apertures (objects sorted by S/N) 352 // entry 0 == unmatched? pass entry + 1? 353 psphotRadialApertures (config, view, STACK_OUT, entry); 354 355 // replace the flux in the image so it is returned to its original state 356 psphotReplaceAllSources (config, view, STACK_OUT, false); 357 358 // smooth to the next FWHM, or set 'smoothAgain' to false if no more 359 psphotStackMatchPSFsNext(config, view, STACK_OUT, entry); 360 psMemDump("matched"); 361 } 341 362 } 342 363 … … 344 365 if (!psphotApResid (config, view, STACK_SRC)) { 345 366 psFree (objects); 367 psFree (objectsOut); 346 368 psLogMsg ("psphot", 3, "failed on psphotApResid"); 347 369 return psphotReadoutCleanup (config, view, STACK_SRC); … … 375 397 376 398 psFree (objects); 377 psFree (objects Radial);399 psFree (objectsOut); 378 400 379 401 // create the exported-metadata and free local data
Note:
See TracChangeset
for help on using the changeset viewer.
