Changeset 32695 for trunk/psphot
- Timestamp:
- Nov 17, 2011, 2:17:35 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 14 edited
-
. (modified) (1 prop)
-
psphot (modified) (1 prop)
-
psphot/src/psphot.h (modified) (3 diffs)
-
psphot/src/psphotBlendFit.c (modified) (1 diff)
-
psphot/src/psphotEfficiency.c (modified) (1 diff)
-
psphot/src/psphotFake.c (modified) (1 diff)
-
psphot/src/psphotFitSourcesLinear.c (modified) (1 diff)
-
psphot/src/psphotMergeSources.c (modified) (10 diffs)
-
psphot/src/psphotOutput.c (modified) (2 diffs)
-
psphot/src/psphotReadout.c (modified) (6 diffs)
-
psphot/src/psphotReplaceUnfit.c (modified) (9 diffs)
-
psphot/src/psphotSourceFits.c (modified) (1 diff)
-
psphot/src/psphotStackChisqImage.c (modified) (1 diff)
-
psphot/src/psphotStackReadout.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/eam_branches/ipp-20111110 (added) merged: 32645-32647,32660-32663,32685-32686,32689-32694
- Property svn:mergeinfo changed
-
trunk/psphot
- Property svn:mergeinfo changed
/branches/eam_branches/ipp-20111110/psphot (added) merged: 32685-32686,32689,32692,32694
- Property svn:mergeinfo changed
-
trunk/psphot/src/psphot.h
r32633 r32695 108 108 bool psphotBlendFit_Threaded (psThreadJob *job); 109 109 110 bool psphotReplaceAllSources (pmConfig *config, const pmFPAview *view, const char *filerule );111 bool psphotReplaceAllSourcesReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe );110 bool psphotReplaceAllSources (pmConfig *config, const pmFPAview *view, const char *filerule, bool ignoreState); 111 bool psphotReplaceAllSourcesReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe, bool ignoreState); 112 112 113 113 bool psphotAddNoise (pmConfig *config, const pmFPAview *view, const char *filerule); … … 176 176 177 177 // in psphotReplaceUnfit.c: 178 bool psphotRemoveAllSources (const psArray *sources, const psMetadata *recipe); 178 bool psphotRemoveAllSourcesByArray (const psArray *sources, const psMetadata *recipe); 179 bool psphotRemoveAllSources (pmConfig *config, const pmFPAview *view, const char *filerule, bool ignoreState); 180 bool psphotRemoveAllSourcesReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe, bool ignoreState); 179 181 bool psphotReplaceUnfitSources (psArray *sources, psImageMaskType maskVal); 180 182 … … 453 455 psArray *psphotSourceChildrenByObject (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *objectsSrc); 454 456 457 bool psphotSourceParents (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc); 458 bool psphotSourceParentsReadout (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc, int index); 459 460 bool psphotCopyPeaks (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc); 461 bool psphotCopyPeaksReadout (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc, int index); 462 455 463 bool psphotSersicModelClassGuessPCM (pmPCMdata *pcm, pmSource *source); 456 464 void psphotSersicModelClassInit (); -
trunk/psphot/src/psphotBlendFit.c
r32348 r32695 236 236 pmSource *source = sources->data[i]; 237 237 238 # define TEST_X -420.0 239 # define TEST_Y 300.0 238 # if (0) 239 # define TEST_X 34 240 # define TEST_Y 28 240 241 241 242 if ((fabs(source->peak->xf - TEST_X) < 5) && (fabs(source->peak->yf - TEST_Y) < 5)) { 242 fprintf (stderr, "test galaxy\n");243 fprintf (stderr, "test object\n"); 243 244 } 244 245 245 246 # undef TEST_X 246 247 # undef TEST_Y 248 # endif 247 249 248 250 // skip non-astronomical objects (very likely defects) -
trunk/psphot/src/psphotEfficiency.c
r32348 r32695 255 255 256 256 // remove all sources, adding noise for subtracted sources 257 psphotRemoveAllSources (realSources, recipe);257 psphotRemoveAllSourcesByArray(realSources, recipe); 258 258 259 259 #if TESTING -
trunk/psphot/src/psphotFake.c
r26894 r32695 166 166 167 167 // remove all sources, adding noise for subtracted sources 168 psphotRemoveAllSources (realSources, recipe);168 psphotRemoveAllSourcesByArray(realSources, recipe); 169 169 psphotAddNoise(readout, realSources, recipe); 170 170 -
trunk/psphot/src/psphotFitSourcesLinear.c
r32633 r32695 342 342 psLogMsg ("psphot.ensemble", PS_LOG_MINUTIA, "solve matrix: %f sec (%d elements)\n", psTimerMark ("psphot.linear"), sparse->Nelem); 343 343 344 // XXXX **** philosophical question: 345 // we measure bright objects in three passes: 1) linear fit; 2) non-linear fit; 3) linear fit: 346 // should retain the chisq and errors from the intermediate non-linear fit? 347 // the non-linear fit provides better values for the position errors, and for 348 // extended sources, the shape errors 344 // Philosophical question: we measure bright objects in three passes: 1) linear fit; 2) 345 // non-linear fit; 3) linear fit: should we retain the chisq and errors from the 346 // intermediate non-linear fit? the non-linear fit provides better values for the position 347 // errors, and for extended sources, the shape errors 349 348 350 349 // adjust I0 for fitSources and subtract -
trunk/psphot/src/psphotMergeSources.c
r31452 r32695 520 520 } 521 521 522 // copy the newPeaks from the detections of one pmFPAfile to another 523 bool psphotCopyPeaks (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc) 524 { 525 bool status = true; 526 527 int num = psphotFileruleCount(config, ruleSrc); 528 529 // skip the chisq image because it is a duplicate of the detection version 530 int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM"); 531 if (!status) chisqNum = -1; 532 533 // loop over the available readouts 534 for (int i = 0; i < num; i++) { 535 if (i == chisqNum) continue; // skip chisq image 536 if (!psphotCopyPeaksReadout (config, view, ruleOut, ruleSrc, i)) { 537 psError (PSPHOT_ERR_CONFIG, false, "failed to copy peaks from %s to %s entry %d", ruleSrc, ruleOut, i); 538 return false; 539 } 540 } 541 return true; 542 } 543 544 // add newly detected peaks to the existing list of sources 545 bool psphotCopyPeaksReadout (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc, int index) { 546 547 bool status; 548 549 // find the currently selected readout 550 pmFPAfile *fileSrc = pmFPAfileSelectSingle(config->files, ruleSrc, index); // File of interest 551 psAssert (fileSrc, "missing file?"); 552 553 pmReadout *readoutSrc = pmFPAviewThisReadout(view, fileSrc->fpa); 554 psAssert (readoutSrc, "missing readout?"); 555 556 pmDetections *detections = psMetadataLookupPtr (&status, readoutSrc->analysis, "PSPHOT.DETECTIONS"); 557 psAssert (detections, "missing detections?"); 558 559 // find the currently selected readout 560 pmFPAfile *fileOut = pmFPAfileSelectSingle(config->files, ruleOut, index); // File of interest 561 psAssert (fileOut, "missing file?"); 562 563 pmReadout *readoutOut = pmFPAviewThisReadout(view, fileOut->fpa); 564 psAssert (readoutOut, "missing readout?"); 565 566 // generate a new detection structure for the output filerule 567 pmDetections *detectionsOut = psMetadataLookupPtr (&status, readoutOut->analysis, "PSPHOT.DETECTIONS"); 568 psAssert (detectionsOut, "missing PSPHOT.DETECTIONS?"); 569 570 psAssert (detectionsOut->peaks, "programming error"); 571 psAssert (!detectionsOut->oldPeaks, "programming error"); 572 psAssert (detections->peaks, "programming error"); 573 574 // save the OUT existing peaks on oldPeaks 575 detectionsOut->oldPeaks = detectionsOut->peaks; 576 detectionsOut->peaks = psArrayAllocEmpty(detections->peaks->n); 577 578 for (int i = 0; i < detections->peaks->n; i++) { 579 psAssert (detections->peaks->data[i], "programming error"); 580 pmPeak *peak = pmPeakAlloc (0, 0, 0.0, PM_PEAK_LONE); 581 pmPeakCopy(peak, detections->peaks->data[i]); 582 psArrayAdd (detectionsOut->peaks, 100, peak); 583 psFree (peak); 584 } 585 return true; 586 } 587 588 // create source parents children from ruleSrc for ruleOut for orphans 589 bool psphotSourceParents (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc) 590 { 591 bool status = true; 592 593 int num = psphotFileruleCount(config, ruleSrc); 594 595 // skip the chisq image because it is a duplicate of the detection version 596 int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM"); 597 if (!status) chisqNum = -1; 598 599 // loop over the available readouts 600 for (int i = 0; i < num; i++) { 601 if (i == chisqNum) continue; // skip chisq image 602 if (!psphotSourceParentsReadout (config, view, ruleOut, ruleSrc, i)) { 603 psError (PSPHOT_ERR_CONFIG, false, "failed to copy sources from %s to %s entry %d", ruleSrc, ruleOut, i); 604 return false; 605 } 606 } 607 return true; 608 } 609 610 // create source parents from ruleSrc for ruleOut for orphaned children for this readout. 611 bool psphotSourceParentsReadout (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc, int index) { 612 613 bool status; 614 int nParents = 0; 615 int nNonOrphans = 0; 616 617 // find the currently selected readout 618 pmFPAfile *fileSrc = pmFPAfileSelectSingle(config->files, ruleSrc, index); // File of interest 619 psAssert (fileSrc, "missing file?"); 620 621 pmReadout *readoutSrc = pmFPAviewThisReadout(view, fileSrc->fpa); 622 psAssert (readoutSrc, "missing readout?"); 623 624 pmDetections *detectionsSrc = psMetadataLookupPtr (&status, readoutSrc->analysis, "PSPHOT.DETECTIONS"); 625 psAssert (detectionsSrc, "missing detections?"); 626 627 psArray *sourcesSrc = detectionsSrc->allSources; 628 psAssert (sourcesSrc, "missing sources?"); 629 630 // find the currently selected readout 631 pmFPAfile *fileOut = pmFPAfileSelectSingle(config->files, ruleOut, index); // File of interest 632 psAssert (fileOut, "missing file?"); 633 634 pmReadout *readoutOut = pmFPAviewThisReadout(view, fileOut->fpa); 635 psAssert (readoutOut, "missing readout?"); 636 637 // generate a new detection structure for the output filerule 638 pmDetections *detectionsOut = psMetadataLookupPtr (&status, readoutOut->analysis, "PSPHOT.DETECTIONS"); 639 psAssert (detectionsOut, "missing PSPHOT.DETECTIONS?"); 640 641 // loop over the sources, redefine their pixels to point at the new filerule image, 642 // copy the source data, and add a reference back to the original source 643 644 // copy the sources from sourceSrcs to the new detection structure 645 for (int i = 0; i < sourcesSrc->n; i++) { 646 pmSource *sourceSrc = sourcesSrc->data[i]; 647 if (sourceSrc->parent) { 648 nNonOrphans ++; 649 continue; // Not an orphan 650 } 651 652 pmSource *sourceOut = pmSourceCopy(sourceSrc); 653 sourceOut->parent = sourceSrc; 654 655 // keep the original source flags 656 sourceOut->seq = sourceSrc->seq; 657 sourceOut->type = sourceSrc->type; 658 sourceOut->mode = sourceSrc->mode; 659 sourceOut->mode2 = sourceSrc->mode2; 660 sourceOut->tmpFlags = sourceSrc->tmpFlags; 661 662 // does this copy all model data? (NO) 663 sourceOut->modelPSF = pmModelCopy(sourceSrc->modelPSF); 664 sourceOut->modelEXT = pmModelCopy(sourceSrc->modelEXT); 665 666 if (sourceSrc->modelFits) { 667 sourceOut->modelFits = psArrayAlloc(sourceSrc->modelFits->n); 668 for (int j = 0; j < sourceSrc->modelFits->n; j++) { 669 sourceOut->modelFits->data[j] = pmModelCopy(sourceSrc->modelFits->data[j]); 670 } 671 } 672 673 // drop the references to the original image pixels: 674 pmSourceFreePixels (sourceOut); 675 676 // allocate image, weight, mask for the new image for each peak 677 if (sourceOut->modelPSF) { 678 pmSourceRedefinePixels (sourceOut, readoutOut, sourceOut->peak->x, sourceOut->peak->y, sourceOut->modelPSF->fitRadius); 679 } 680 681 // child sources have not been subtracted in this image, but this flag may be raised if 682 // they were subtracted in the parent's image 683 sourceOut->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED; 684 685 nParents ++; 686 psArrayAdd (detectionsOut->allSources, 100, sourceOut); 687 psFree (sourceOut); 688 } 689 psLogMsg ("psphot", 3, "%d parents created, %d unorphaned children, %ld input vs %ld output", nParents, nNonOrphans, sourcesSrc->n, detectionsOut->allSources->n); 690 691 return true; 692 } 693 522 694 // create source children from ruleSrc for ruleOut 523 695 bool psphotSourceChildren (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc) … … 542 714 } 543 715 544 // create source children from ruleSrc for ruleOut for this entry. XXX currently, this is only716 // Create source children from ruleSrc for ruleOut for this entry. Currently, this is only 545 717 // used by psphotStackReadout (sources go on allSources so that psphotChoosePSF can be called 546 // repeatedly) 718 // repeatedly). 547 719 bool psphotSourceChildrenReadout (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc, int index) { 548 720 … … 569 741 psAssert (readoutOut, "missing readout?"); 570 742 571 // generate a new detection structure for the output filerule 572 pmDetections *detectionsOut = psMetadataLookupPtr (&status, readoutOut->analysis, "PSPHOT.DETECTIONS"); 573 if (!detectionsOut) { 574 detectionsOut = pmDetectionsAlloc(); 575 detectionsOut->allSources = psArrayAllocEmpty (100); 576 // save detections on the readout->analysis 577 if (!psMetadataAddPtr (readoutOut->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_META_REPLACE | PS_DATA_UNKNOWN, "psphot detections", detectionsOut)) { 578 psError (PSPHOT_ERR_CONFIG, false, "problem saving detections on readout"); 579 return false; 580 } 581 psFree(detectionsOut); // a copy remains on the analysis metadata 743 // replace any existing DETECTION container on readoutOut->analysis with the new one 744 pmDetections *detectionsOut = pmDetectionsAlloc(); 745 detectionsOut->allSources = psArrayAllocEmpty (100); 746 if (!psMetadataAddPtr (readoutOut->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_META_REPLACE | PS_DATA_UNKNOWN, "psphot detections", detectionsOut)) { 747 psError (PSPHOT_ERR_CONFIG, false, "problem saving detections on readout"); 748 return false; 582 749 } 583 750 … … 593 760 594 761 // keep the original source flags 762 sourceOut->seq = sourceSrc->seq; 595 763 sourceOut->type = sourceSrc->type; 596 764 sourceOut->mode = sourceSrc->mode; … … 612 780 pmSourceFreePixels (sourceOut); 613 781 782 // XXX do we need to skip the Chisq image sources? 783 614 784 // allocate image, weight, mask for the new image for each peak 615 if (sourceOut->modelPSF) { 616 pmSourceRedefinePixels (sourceOut, readoutOut, sourceOut->peak->x, sourceOut->peak->y, sourceOut->modelPSF->fitRadius); 617 } 785 pmSourceRedefinePixels (sourceOut, readoutOut, sourceOut->peak->x, sourceOut->peak->y, sourceOut->windowRadius); 618 786 619 787 // child sources have not been subtracted in this image, but this flag may be raised if … … 624 792 psFree (sourceOut); 625 793 } 626 psLogMsg ("psphot", 3, "%ld known sources supplied", detectionsOut->allSources->n); 627 628 629 return true; 630 } 631 632 // create source children associated with 'filerule' from the objectsSrc. XXX currently, this 633 // is only used by psphotStackReadout (sources go on allSources so that psphotChoosePSF can be 634 // called repeatedly) 794 psLogMsg ("psphot", 3, "created %ld children", detectionsOut->allSources->n); 795 796 psFree(detectionsOut); // a copy remains on the analysis metadata 797 798 return true; 799 } 800 801 // create source children associated with 'filerule' from the objectsSrc. returns a new object 802 // array containing the child sources. XXX currently, this is only used by psphotStackReadout 803 // (sources go on allSources so that psphotChoosePSF can be called repeatedly) 635 804 psArray *psphotSourceChildrenByObject (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *objectsSrc) { 636 805 … … 652 821 psAssert (readout, "missing readout?"); 653 822 823 // create DETECTIONS containers for each image, in case one lacks it 654 824 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS"); 655 825 if (!detections) { … … 665 835 psAssert (detections, "missing detections?"); 666 836 } 837 838 // we need to save the new sources on the detection arrays of the appropriate image 667 839 detArrays->data[i] = psMemIncrRefCounter(detections); 668 840 readouts->data[i] = psMemIncrRefCounter(readout); … … 695 867 696 868 pmSource *sourceOut = pmSourceCopy(sourceSrc); 869 sourceOut->parent = sourceSrc; 870 871 // save on the output object array at the same location 697 872 objectOut->sources->data[i] = sourceOut; 698 699 sourceOut->parent = sourceSrc;700 873 701 874 // keep the original source flags and sequence ID (if set) … … 720 893 pmSourceFreePixels (sourceOut); 721 894 722 // set the output reado tu895 // set the output readout 723 896 int index = sourceOut->imageID; 724 897 if (index >= readouts->n) continue; // skip the sources generated by the chisq image -
trunk/psphot/src/psphotOutput.c
r32348 r32695 407 407 return true; 408 408 } 409 410 // for now, let's store the detections on the readout->analysis for each readout 411 bool psphotDumpTest (pmConfig *config, const pmFPAview *view, const char *filerule) 412 { 413 static int npass = 0; 414 char filename[64]; 415 416 // XXX dump tests are disabled unless this is commented out: 417 return true; 418 419 bool status = true; 420 421 int num = psphotFileruleCount(config, filerule); 422 423 snprintf (filename, 64, "testdump.%02d.dat", npass); 424 FILE *f = fopen (filename, "w"); 425 426 // loop over the available readouts 427 for (int i = 0; i < num; i++) { 428 429 // find the currently selected readout 430 pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, i); // File of interest 431 psAssert (file, "missing file?"); 432 433 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); 434 psAssert (readout, "missing readout?"); 435 436 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS"); 437 psAssert (detections, "missing detections?"); 438 439 psArray *sources = detections->newSources ? detections->newSources : detections->allSources; 440 psAssert (sources, "missing sources?"); 441 442 if (detections->newSources) { 443 fprintf (f, "## --- from new sources ---\n"); 444 } else { 445 fprintf (f, "## --- from all sources ---\n"); 446 } 447 448 for (int i = 0; i < sources->n; i++) { 449 pmSource *source = sources->data[i]; 450 if (!source) continue; 451 452 pmPeak *peak = source->peak; 453 if (!peak) continue; 454 455 // XXX only dump a given region 456 // if (peak->xf < 20) continue; 457 // if (peak->yf < 20) continue; 458 // if (peak->xf > 40) continue; 459 // if (peak->yf > 70) continue; 460 461 float Msum = source->moments ? source->moments->Sum : NAN; 462 float Mx = source->moments ? source->moments->Mx : NAN; 463 float My = source->moments ? source->moments->My : NAN; 464 // float Npix = source->moments ? source->moments->nPixels : NAN; 465 float Io = source->modelPSF ? source->modelPSF->params->data.F32[PM_PAR_I0] : NAN; 466 fprintf (f, "%d %f %f : %f %f : %f %f\n", source->imageID, peak->xf, peak->yf, Mx, My, Msum, Io); 467 } 468 } 469 fclose (f); 470 npass ++; 471 472 return true; 473 } 474 475 # if (0) 409 476 bool psphotDumpTest (pmConfig *config, const pmFPAview *view, const char *filerule, char *filename) { 410 477 … … 449 516 return true; 450 517 } 451 518 # endif -
trunk/psphot/src/psphotReadout.c
r32633 r32695 9 9 } 10 10 11 // for now, let's store the detections on the readout->analysis for each readout12 bool psphotDumpChisqs (pmConfig *config, const pmFPAview *view, const char *filerule)13 {14 static int npass = 0;15 char filename[64];16 17 return true;18 19 bool status = true;20 21 int num = psphotFileruleCount(config, filerule);22 23 snprintf (filename, 64, "chisq.%02d.dat", npass);24 FILE *f = fopen (filename, "w");25 26 // loop over the available readouts27 for (int i = 0; i < num; i++) {28 29 // find the currently selected readout30 pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, i); // File of interest31 psAssert (file, "missing file?");32 33 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa);34 psAssert (readout, "missing readout?");35 36 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");37 psAssert (detections, "missing detections?");38 39 psArray *sources = detections->allSources;40 psAssert (sources, "missing sources?");41 42 for (int i = 0; i < sources->n; i++) {43 pmSource *source = sources->data[i];44 if (!source) continue;45 46 pmModel *model = pmSourceGetModel (NULL, source);47 if (!model) continue;48 49 if (source->mode & PM_SOURCE_MODE_NONLINEAR_FIT) {50 fprintf (f, "%f %f %f %d %d %f 1 NONLINEAR\n", model->mag, model->params->data.F32[1], model->chisq, model->nDOF, model->nPix, model->chisqNorm);51 } else {52 fprintf (f, "%f %f %f %d %d %f 0 LINEAR\n", model->mag, model->params->data.F32[1], model->chisq, model->nDOF, model->nPix, model->chisqNorm);53 }54 }55 }56 fclose (f);57 npass ++;58 59 return true;60 }61 62 11 bool psphotReadout(pmConfig *config, const pmFPAview *view, const char *filerule) { 63 12 … … 188 137 // linear PSF fit to source peaks, subtract the models from the image (in PSF mask) 189 138 psphotFitSourcesLinear (config, view, filerule, false); // pass 1 (detections->allSources) 190 psphotDumpChisqs (config, view, filerule);191 139 192 140 // measure the radial profiles to the sky … … 208 156 // replace model flux, adjust mask as needed, fit, subtract the models (full stamp) 209 157 psphotBlendFit (config, view, filerule); // pass 1 (detections->allSources) 210 psphotDumpChisqs (config, view, filerule);211 158 212 159 // replace all sources 213 psphotReplaceAllSources (config, view, filerule ); // pass 1 (detections->allSources)160 psphotReplaceAllSources (config, view, filerule, false); // pass 1 (detections->allSources) 214 161 215 162 // linear fit to include all sources (subtract again) 216 163 // NOTE : apply to ALL sources (extended + psf) 217 164 psphotFitSourcesLinear (config, view, filerule, true); // pass 2 (detections->allSources) 218 psphotDumpChisqs (config, view, filerule);219 165 220 166 // if we only do one pass, skip to extended source analysis … … 253 199 // replace all sources so fit below applies to all at once 254 200 // NOTE: apply only to OLD sources (which have been subtracted) 255 psphotReplaceAllSources (config, view, filerule ); // pass 2201 psphotReplaceAllSources (config, view, filerule, false); // pass 2 256 202 257 203 // merge the newly selected sources into the existing list … … 262 208 // NOTE: apply to ALL sources 263 209 psphotFitSourcesLinear (config, view, filerule, true); // pass 3 (detections->allSources) 264 psphotDumpChisqs (config, view, filerule);265 210 } 266 211 … … 295 240 // replace all sources so fit below applies to all at once 296 241 // NOTE: apply only to OLD sources (which have been subtracted) 297 psphotReplaceAllSources (config, view, filerule ); // pass 2242 psphotReplaceAllSources (config, view, filerule, false); // pass 2 298 243 299 244 // merge the newly selected sources into the existing list -
trunk/psphot/src/psphotReplaceUnfit.c
r31452 r32695 9 9 10 10 for (int i = 0; i < sources->n; i++) { 11 source = sources->data[i];12 13 // replace other sources?14 if (source->mode & PM_SOURCE_MODE_FAIL) goto replace;15 continue;11 source = sources->data[i]; 12 13 // replace other sources? 14 if (source->mode & PM_SOURCE_MODE_FAIL) goto replace; 15 continue; 16 16 17 17 replace: … … 23 23 24 24 // for now, let's store the detections on the readout->analysis for each readout 25 bool psphotReplaceAllSources (pmConfig *config, const pmFPAview *view, const char *filerule )25 bool psphotReplaceAllSources (pmConfig *config, const pmFPAview *view, const char *filerule, bool ignoreState) 26 26 { 27 27 bool status = true; … … 35 35 // loop over the available readouts 36 36 for (int i = 0; i < num; i++) { 37 if (!psphotReplaceAllSourcesReadout (config, view, filerule, i, recipe )) {37 if (!psphotReplaceAllSourcesReadout (config, view, filerule, i, recipe, ignoreState)) { 38 38 psError (PSPHOT_ERR_CONFIG, false, "failed to replace all sources for %s entry %d", filerule, i); 39 39 return false; … … 43 43 } 44 44 45 bool psphotReplaceAllSourcesReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe) { 46 47 bool status; 48 pmSource *source; 45 bool psphotReplaceAllSourcesReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe, bool ignoreState) { 46 47 bool status; 49 48 50 49 psTimerStart ("psphot.replace"); … … 75 74 76 75 for (int i = 0; i < sources->n; i++) { 77 source = sources->data[i]; 78 79 // replace other sources? 80 if (!(source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED)) continue; 81 82 pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 76 pmSource *source = sources->data[i]; 77 78 if (ignoreState) { 79 // rely on the type of source to decide if we subtract it or not 80 81 // skip non-astronomical objects (very likely defects) 82 if (source->type == PM_SOURCE_TYPE_DEFECT) continue; 83 if (source->type == PM_SOURCE_TYPE_SATURATED) continue; 84 85 // do not include CRs in the full ensemble fit 86 if (source->mode & PM_SOURCE_MODE_CR_LIMIT) continue; 87 88 // do not include MOMENTS_FAILURES in the fit 89 if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) continue; 90 } else { 91 // if we respect the state, do not replace unsubtracted sources 92 if (!(source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED)) continue; 93 } 94 95 pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 83 96 } 84 97 … … 88 101 } 89 102 90 bool psphotRemoveAllSources (const psArray *sources, const psMetadata *recipe) { 103 // for now, let's store the detections on the readout->analysis for each readout 104 bool psphotRemoveAllSources (pmConfig *config, const pmFPAview *view, const char *filerule, bool ignoreState) 105 { 106 bool status = true; 107 108 // select the appropriate recipe information 109 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE); 110 psAssert (recipe, "missing recipe?"); 111 112 int num = psphotFileruleCount(config, filerule); 113 114 // loop over the available readouts 115 for (int i = 0; i < num; i++) { 116 if (!psphotRemoveAllSourcesReadout (config, view, filerule, i, recipe, ignoreState)) { 117 psError (PSPHOT_ERR_CONFIG, false, "failed to replace all sources for %s entry %d", filerule, i); 118 return false; 119 } 120 } 121 return true; 122 } 123 124 bool psphotRemoveAllSourcesReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe, bool ignoreState) { 125 126 bool status; 127 128 psTimerStart ("psphot.replace"); 129 130 // find the currently selected readout 131 pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest 132 psAssert (file, "missing file?"); 133 134 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); 135 psAssert (readout, "missing readout?"); 136 137 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS"); 138 psAssert (detections, "missing detections?"); 139 140 psArray *sources = detections->allSources; 141 psAssert (sources, "missing sources?"); 142 143 // user-defined masks to test for good/bad pixels (build from recipe list if not yet set) 144 psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels 145 psAssert (maskVal, "missing mask value?"); 146 147 // bit-mask to mark pixels not used in analysis 148 psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT"); 149 assert (markVal); 150 151 // maskVal is used to test for rejected pixels, and must include markVal 152 maskVal |= markVal; 153 154 for (int i = 0; i < sources->n; i++) { 155 pmSource *source = sources->data[i]; 156 157 if (ignoreState) { 158 // rely on the type of source to decide if we subtract it or not 159 160 // skip non-astronomical objects (very likely defects) 161 if (source->type == PM_SOURCE_TYPE_DEFECT) continue; 162 if (source->type == PM_SOURCE_TYPE_SATURATED) continue; 163 164 // do not include CRs in the full ensemble fit 165 if (source->mode & PM_SOURCE_MODE_CR_LIMIT) continue; 166 167 // do not include MOMENTS_FAILURES in the fit 168 if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) continue; 169 } else { 170 // if we respect the state, only remove unsubtracted sources 171 if ((source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED)) continue; 172 } 173 174 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 175 } 176 177 psphotVisualShowImage(readout); 178 psLogMsg ("psphot.replace", PS_LOG_INFO, "replaced models for %ld objects: %f sec\n", sources->n, psTimerMark ("psphot.replace")); 179 return true; 180 } 181 182 bool psphotRemoveAllSourcesByArray (const psArray *sources, const psMetadata *recipe) { 91 183 92 184 bool status; … … 100 192 101 193 for (int i = 0; i < sources->n; i++) { 102 source = sources->data[i];103 104 // replace other sources?105 if (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED) continue;106 107 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);194 source = sources->data[i]; 195 196 // replace other sources? 197 if (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED) continue; 198 199 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 108 200 } 109 201 psLogMsg ("psphot.replace", PS_LOG_INFO, "replaced models for %ld objects: %f sec\n", sources->n, psTimerMark ("psphot.replace")); … … 158 250 159 251 for (int i = 0; i < sources->n; i++) { 160 source = sources->data[i];161 162 // sources have not yet been subtracted in this image (but this flag may be raised)163 source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED;164 if (!source->modelPSF) continue;165 166 float Xo = source->modelPSF->params->data.F32[PM_PAR_XPOS];167 float Yo = source->modelPSF->params->data.F32[PM_PAR_YPOS];168 float radius = source->modelPSF->fitRadius;169 170 // force a redefine to this image171 pmSourceFreePixels(source);172 pmSourceRedefinePixels (source, readout, Xo, Yo, radius);252 source = sources->data[i]; 253 254 // sources have not yet been subtracted in this image (but this flag may be raised) 255 source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED; 256 if (!source->modelPSF) continue; 257 258 float Xo = source->modelPSF->params->data.F32[PM_PAR_XPOS]; 259 float Yo = source->modelPSF->params->data.F32[PM_PAR_YPOS]; 260 float radius = source->modelPSF->fitRadius; 261 262 // force a redefine to this image 263 pmSourceFreePixels(source); 264 pmSourceRedefinePixels (source, readout, Xo, Yo, radius); 173 265 } 174 266 return true; … … 229 321 230 322 for (int i = 0; i < sources->n; i++) { 231 source = sources->data[i];232 233 // *** we need to cache the 'best' model, and we have 3 cases:234 // 1) model is the psf model --> generate from the new psf235 // 2) model is an unconvolved extended model --> just cache the copy (not perfect)236 // 3) model is a convolved extended model --> re-generate237 238 // use the 'best' model to cache the model (PSF or EXT : EXT may point at one of modelFits239 bool isPSF = false;240 pmModel *model = pmSourceGetModel(&isPSF, source);241 if (!model) continue;242 243 float radius = model->fitRadius; // save for future use below244 245 // regenerate the PSF if the model is a PSF, or if we need the PSF for a PCM246 if (isPSF || model->isPCM) {247 // the guess central intensity comes from the peak:248 float Io = source->peak->rawFlux;249 float Xo = source->modelPSF->params->data.F32[PM_PAR_XPOS];250 float Yo = source->modelPSF->params->data.F32[PM_PAR_YPOS];251 252 // generate a model for this object with Io = 1.0253 pmModel *modelPSF = pmModelFromPSFforXY(psf, Xo, Yo, Io);254 if (modelPSF == NULL) {255 psWarning ("Failed to determine PSF model for source at (%f,%f), skipping", Xo, Yo);256 continue;257 }258 259 // set the source PSF model260 psFree (source->modelPSF);261 source->modelPSF = modelPSF;262 source->modelPSF->fitRadius = radius;263 }264 265 if (model->isPCM) {266 psAssert(false, "this section is not complete");267 268 pmSourceCachePSF (source, maskVal);269 270 psKernel *psfKernel = pmPCMkernelFromPSF(source, psfSize);271 if (!psfKernel) {272 psWarning ("no psf kernel");273 }274 275 // generate an image of the right size276 psImage *rawModelFlux = psImageCopy (NULL, source->pixels, PS_TYPE_F32);277 psImageInit (rawModelFlux, 0.0);323 source = sources->data[i]; 324 325 // *** we need to cache the 'best' model, and we have 3 cases: 326 // 1) model is the psf model --> generate from the new psf 327 // 2) model is an unconvolved extended model --> just cache the copy (not perfect) 328 // 3) model is a convolved extended model --> re-generate 329 330 // use the 'best' model to cache the model (PSF or EXT : EXT may point at one of modelFits 331 bool isPSF = false; 332 pmModel *model = pmSourceGetModel(&isPSF, source); 333 if (!model) continue; 334 335 float radius = model->fitRadius; // save for future use below 336 337 // regenerate the PSF if the model is a PSF, or if we need the PSF for a PCM 338 if (isPSF || model->isPCM) { 339 // the guess central intensity comes from the peak: 340 float Io = source->peak->rawFlux; 341 float Xo = source->modelPSF->params->data.F32[PM_PAR_XPOS]; 342 float Yo = source->modelPSF->params->data.F32[PM_PAR_YPOS]; 343 344 // generate a model for this object with Io = 1.0 345 pmModel *modelPSF = pmModelFromPSFforXY(psf, Xo, Yo, Io); 346 if (modelPSF == NULL) { 347 psWarning ("Failed to determine PSF model for source at (%f,%f), skipping", Xo, Yo); 348 continue; 349 } 350 351 // set the source PSF model 352 psFree (source->modelPSF); 353 source->modelPSF = modelPSF; 354 source->modelPSF->fitRadius = radius; 355 } 356 357 if (model->isPCM) { 358 psAssert(false, "this section is not complete"); 359 360 pmSourceCachePSF (source, maskVal); 361 362 psKernel *psfKernel = pmPCMkernelFromPSF(source, psfSize); 363 if (!psfKernel) { 364 psWarning ("no psf kernel"); 365 } 366 367 // generate an image of the right size 368 psImage *rawModelFlux = psImageCopy (NULL, source->pixels, PS_TYPE_F32); 369 psImageInit (rawModelFlux, 0.0); 278 370 279 // insert the model image normalized to 1.0280 pmModelAdd (rawModelFlux, NULL, model, PM_MODEL_OP_FULL | PM_MODEL_OP_NORM, maskVal);281 282 psImageConvolveFFT (source->modelFlux, rawModelFlux, NULL, 0, psfKernel);371 // insert the model image normalized to 1.0 372 pmModelAdd (rawModelFlux, NULL, model, PM_MODEL_OP_FULL | PM_MODEL_OP_NORM, maskVal); 373 374 psImageConvolveFFT (source->modelFlux, rawModelFlux, NULL, 0, psfKernel); 283 375 284 psFree (psfKernel);285 psFree (rawModelFlux);286 }287 288 pmSourceCacheModel (source, maskVal); // ALLOC x14 (!)376 psFree (psfKernel); 377 psFree (rawModelFlux); 378 } 379 380 pmSourceCacheModel (source, maskVal); // ALLOC x14 (!) 289 381 } 290 382 -
trunk/psphot/src/psphotSourceFits.c
r32633 r32695 257 257 okDBL = psphotEvalDBL (tmpSrc, DBL->data[0]); 258 258 okDBL &= psphotEvalDBL (tmpSrc, DBL->data[1]); 259 okDBL = false; // XXX this is failing badly... 259 260 // XXX should I keep / save the flags set in the eval functions? 260 261 -
trunk/psphot/src/psphotStackChisqImage.c
r31154 r32695 13 13 psAssert (chisqFile, "missing chisq image FPA?"); 14 14 15 // the readout containing the chisq image is generated in the first pass of this loop and 16 // used by the successive passes 15 17 pmReadout *chiReadout = NULL; 16 18 -
trunk/psphot/src/psphotStackReadout.c
r32633 r32695 82 82 } 83 83 84 // XXX I think this is not defined correctly for an array of images.85 // XXX I probably need to subtract the model (same model?) for both RAW and OUT.86 // XXX But, probably not a problem in practice since the stacks are constructed with 0.0 mean level.87 88 84 // generate a background model (median, smoothed image) 89 85 if (!psphotModelBackground (config, view, STACK_DET)) { … … 91 87 } 92 88 if (!psphotSubtractBackground (config, view, STACK_DET)) { 89 return psphotReadoutCleanup (config, view, STACK_SRC); 90 } 91 if (!psphotSubtractBackground (config, view, STACK_SRC)) { 93 92 return psphotReadoutCleanup (config, view, STACK_SRC); 94 93 } … … 114 113 } 115 114 116 // if DET and SRC are different images, copy the detections from DET to SRC 115 // If DET and SRC are different images, copy the detections from DET to SRC. This 'copy' 116 // is just a copy of the container pointer; the sources on both DET and SRC are the same 117 // memory objects 117 118 if (strcmp(STACK_SRC, STACK_DET)) { 118 119 if (!psphotCopySources (config, view, STACK_SRC, STACK_DET)) { … … 130 131 return psphotReadoutCleanup (config, view, STACK_SRC); 131 132 } 133 // psphotDumpTest (config, view, STACK_SRC); 132 134 psMemDump("sourcestats"); 133 135 … … 166 168 167 169 // linear PSF fit to source peaks, subtract the models from the image (in PSF mask) 168 // XXX why do this as a stack operation?169 // psphotFitSourcesLinearStack (config, objects, false);170 170 psphotFitSourcesLinear (config, view, STACK_SRC, false); 171 171 psphotStackVisualFilerule(config, view, STACK_SRC); … … 186 186 psphotBlendFit (config, view, STACK_SRC); // pass 1 (detections->allSources) 187 187 188 // replace all sources 189 psphotReplaceAllSources (config, view, STACK_SRC ); // pass 1 (detections->allSources)188 // replace all sources (do NOT ignore subtraction state) 189 psphotReplaceAllSources (config, view, STACK_SRC, false); // pass 1 (detections->allSources) 190 190 191 191 // if we only do one pass, skip to extended source analysis … … 194 194 // linear fit to include all sources (subtract again) 195 195 // NOTE : apply to ALL sources (extended + psf) 196 // NOTE 2 : this function subtracts the models from the given filerule (SRC), not DET 196 197 psphotFitSourcesLinear (config, view, STACK_SRC, true); // pass 2 (detections->allSources) 197 198 … … 200 201 // NOTE: this block performs the 2nd pass low-significance PSF detection stage 201 202 { 203 // if DET and SRC are different images, generate children sources for all sources in 204 // the SRC image. This operation replaces the existing DETECTION container on DET 205 // which is currently a view to the one on SRC). children sources go to 206 // det->allSources 207 if (strcmp(STACK_SRC, STACK_DET)) { 208 psphotSourceChildren (config, view, STACK_DET, STACK_SRC); 209 210 // subtract all sources from DET (this will subtract using the psf model for SRC, which 211 // will somewhat oversubtract the sources -- this is OK 212 psphotRemoveAllSources (config, view, STACK_DET, false); // ignore subtraction state for sources 213 } 214 202 215 // add noise for subtracted objects 203 216 psphotAddNoise (config, view, STACK_DET); // pass 1 (detections->allSources) … … 212 225 213 226 // if DET and SRC are different images, copy the detections from DET to SRC 227 // (this operation just ensures the metadata container has a view on SRC as well 214 228 if (strcmp(STACK_SRC, STACK_DET)) { 215 // XXX how does this handle 1st vs 2nd pass sources? 216 if (!psphotCopySources (config, view, STACK_SRC, STACK_DET)) { 229 // replace all sources in DET 230 psphotReplaceAllSources (config, view, STACK_DET, false); // ignore subtraction state for sources 231 232 // copy the newly detected peaks from DET to SRC so SourceStats below can operate on them 233 if (!psphotCopyPeaks (config, view, STACK_SRC, STACK_DET)) { 217 234 psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis"); 218 235 return psphotReadoutCleanup (config, view, STACK_SRC); … … 237 254 // replace all sources so fit below applies to all at once 238 255 // NOTE: apply only to OLD sources (which have been subtracted) 239 psphotReplaceAllSources (config, view, STACK_SRC ); // pass 2256 psphotReplaceAllSources (config, view, STACK_SRC, false); // pass 2 240 257 241 258 // merge the newly selected sources into the existing list … … 312 329 313 330 // replace the flux in the image so it is returned to its original state 314 psphotReplaceAllSources (config, view, STACK_OUT );331 psphotReplaceAllSources (config, view, STACK_OUT, false); 315 332 316 333 // smooth to the next FWHM, or set 'smoothAgain' to false if no more
Note:
See TracChangeset
for help on using the changeset viewer.
