IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 15, 2008, 1:18:30 PM (17 years ago)
Author:
Paul Price
Message:

Using new pmSourceMatch and pmSourceMatchRelphot to do the source matching and relative photometry. This should be more accurate than measuring the magnitude difference image by image.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppStack/src/ppStackLoop.c

    r20837 r20995  
    252252    // Preparation iteration: Load the sources, and get a target PSF model
    253253    psTrace("ppStack", 1, "Determining target PSF....\n");
    254     psArray *globalSources = NULL;      // Global list of sources for matching (haveSources = TRUE)
    255     psArray *indSources = psArrayAlloc(num); // Individual lists of sources for matching (haveSources = FALSE)
     254    psArray *sourceLists = psArrayAlloc(num); // Individual lists of sources for matching
    256255    pmPSF *targetPSF = NULL;            // Target PSF
    257     bool haveSources = psMetadataLookupBool(NULL, config->arguments, "HAVE.SOURCES"); // Global sources?
    258256    if (psMetadataLookupBool(NULL, config->arguments, "HAVE.PSF")) {
    259257        pmFPAfileActivate(config->files, false, NULL);
     
    269267        psMetadataItem *fileItem; // Item from iteration
    270268        psArray *psfs = psArrayAlloc(num); // PSFs for PSF envelope
    271         psArray *sourceLists = NULL;    // Source lists for merging sources from multiple readouts
    272269        int numCols = 0, numRows = 0;   // Size of image
    273270        int index = 0;                  // Index for file
     
    280277                psError(PS_ERR_UNKNOWN, false, "Unable to find PSF.");
    281278                psFree(view);
    282                 psFree(globalSources);
    283                 psFree(indSources);
    284279                psFree(sourceLists);
    285280                psFree(fileIter);
     
    298293                psError(PS_ERR_UNKNOWN, false, "Unable to determine size of image from PSF.");
    299294                psFree(view);
    300                 psFree(globalSources);
    301                 psFree(indSources);
    302295                psFree(sourceLists);
    303296                psFree(fileIter);
     
    310303            }
    311304
    312             if (!haveSources) {
    313                 pmReadout *ro = pmFPAviewThisReadout(view, inputFile->fpa); // Readout with sources
    314                 psArray *sources = psMetadataLookupPtr(NULL, ro->analysis, "PSPHOT.SOURCES"); // Sources
    315                 if (!sources) {
    316                     psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find sources in readout.");
    317                     return NULL;
    318                 }
    319                 indSources->data[index] = psMemIncrRefCounter(sources);
    320 
    321 
    322                 // Calculate zero points if we don't trust the source lists
    323                 if (psMetadataLookupBool(NULL, recipe, "ZP")) {
    324                     psTrace("ppStack", 2, "Photometering input %d of %d....\n", index, num);
    325                     pmFPAfileActivate(config->files, false, NULL);
    326                     fileActivationSingle(config, convolveFiles, true, index);
    327                     pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PPSTACK.INPUT",
    328                                                             index);// File of interest
    329                     pmFPAview *view = filesIterateDown(config);
    330                     if (!view) {
    331                         psFree(globalSources);
    332                         psFree(indSources);
    333                         psFree(targetPSF);
    334                         return false;
    335                     }
    336 
    337                     pmReadout *ro = pmFPAviewThisReadout(view, file->fpa); // Readout of interest
    338 
    339                     if (!ppStackInputPhotometry(ro, sources, config)) {
    340                         psError(PS_ERR_UNKNOWN, false, "Unable to do photometry on input sources");
    341                         psFree(globalSources);
    342                         psFree(indSources);
    343                         psFree(targetPSF);
    344                         return false;
    345                     }
    346 
    347                     psFree(view);
    348                     if (!filesIterateUp(config)) {
    349                         psFree(globalSources);
    350                         psFree(indSources);
    351                         psFree(targetPSF);
    352                         return false;
    353                     }
    354                     pmFPAfileActivate(config->files, false, NULL);
    355                     fileActivation(config, prepareFiles, true);
    356                 }
    357 
    358 
    359 #ifdef TESTING
    360                 ppStackSourcesPrint(sources);
    361 #endif
    362                 sourceLists = ppStackSourceListAdd(sourceLists, sources, config);
    363                 if (!sourceLists) {
    364                     psError(PS_ERR_UNKNOWN, false, "Unable to add sources to list.");
    365                     psFree(view);
    366                     psFree(globalSources);
    367                     psFree(indSources);
    368                     psFree(fileIter);
    369                     psFree(psfs);
     305            pmReadout *ro = pmFPAviewThisReadout(view, inputFile->fpa); // Readout with sources
     306            psArray *sources = psMetadataLookupPtr(NULL, ro->analysis, "PSPHOT.SOURCES"); // Sources
     307            if (!sources) {
     308                psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find sources in readout.");
     309                return NULL;
     310            }
     311            sourceLists->data[index] = psMemIncrRefCounter(sources);
     312
     313            // Re-do photometry if we don't trust the source lists
     314            if (psMetadataLookupBool(NULL, recipe, "PHOT")) {
     315                psTrace("ppStack", 2, "Photometering input %d of %d....\n", index, num);
     316                pmFPAfileActivate(config->files, false, NULL);
     317                fileActivationSingle(config, convolveFiles, true, index);
     318                pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PPSTACK.INPUT", index); // File
     319                pmFPAview *view = filesIterateDown(config);
     320                if (!view) {
     321                    psFree(sourceLists);
     322                    psFree(targetPSF);
    370323                    return false;
    371324                }
     325
     326                pmReadout *ro = pmFPAviewThisReadout(view, file->fpa); // Readout of interest
     327
     328                if (!ppStackInputPhotometry(ro, sources, config)) {
     329                    psError(PS_ERR_UNKNOWN, false, "Unable to do photometry on input sources");
     330                    psFree(sourceLists);
     331                    psFree(targetPSF);
     332                    return false;
     333                }
     334
     335                psFree(view);
     336                if (!filesIterateUp(config)) {
     337                    psFree(sourceLists);
     338                    psFree(targetPSF);
     339                    return false;
     340                }
     341                pmFPAfileActivate(config->files, false, NULL);
     342                fileActivation(config, prepareFiles, true);
    372343            }
    373344
     
    375346        }
    376347        psFree(fileIter);
     348
     349        // Zero point calibration
     350        if (!ppStackSourcesTransparency(sourceLists, view, config)) {
     351            psError(PS_ERR_UNKNOWN, false, "Unable to calculate transparency differences");
     352            psFree(sourceLists);
     353            psFree(targetPSF);
     354            return false;
     355        }
     356
     357        exit(1);
    377358
    378359        targetPSF = ppStackPSF(config, numCols, numRows, psfs);
     
    380361        if (!targetPSF) {
    381362            psError(PS_ERR_UNKNOWN, false, "Unable to determine output PSF.");
    382             psFree(globalSources);
    383             psFree(indSources);
     363            psFree(sourceLists);
    384364            psFree(view);
    385365            return false;
     
    390370                         "Target PSF", targetPSF);
    391371        outChip->data_exists = true;
    392 
    393         if (haveSources) {
    394             // We want to hang on to the 'sources' even when its host FPA is blown away
    395             pmReadout *sourcesRO = pmFPAfileThisReadout(config->files, view, "PPSTACK.INPUT.SOURCES");
    396             globalSources = psMetadataLookupPtr(NULL, sourcesRO->analysis, "PSPHOT.SOURCES");
    397             psMemIncrRefCounter(globalSources);
    398             if (!globalSources) {
    399                 psError(PS_ERR_UNKNOWN, true, "Unable to find sources.");
    400                 psFree(view);
    401                 return false;
    402             }
    403         } else {
    404             globalSources = ppStackSourceListCombine(sourceLists, config);
    405             psFree(sourceLists);
    406             if (!globalSources) {
    407                 psError(PS_ERR_UNKNOWN, false, "Unable to add sources to list.");
    408                 psFree(view);
    409                 psFree(psfs);
    410                 return false;
    411             }
    412 #ifdef TESTING
    413             ppStackSourcesPrint(globalSources);
    414 #endif
    415         }
    416372
    417373        psFree(view);
     
    460416        pmFPAview *view = filesIterateDown(config);
    461417        if (!view) {
    462             psFree(globalSources);
    463             psFree(indSources);
     418            psFree(sourceLists);
    464419            psFree(targetPSF);
    465420            psFree(rng);
     
    478433            psError(PS_ERR_UNKNOWN, true, "Sizes of input images don't match: %dx%d vs %dx%d",
    479434                    readout->image->numCols, readout->image->numRows, numCols, numRows);
    480             psFree(globalSources);
    481             psFree(indSources);
     435            psFree(sourceLists);
    482436            psFree(targetPSF);
    483437            psFree(rng);
     
    489443        // Background subtraction, scaling and normalisation is performed automatically by the image matching
    490444        psArray *regions = NULL, *kernels = NULL; // Regions and kernels used in subtraction
    491         psArray *sources = haveSources ? globalSources : indSources->data[i]; // Sources for matching
    492445        psTimerStart("PPSTACK_MATCH");
    493446        if (!ppStackMatch(readout, &regions, &kernels, &matchChi2->data.F32[i], &weightings->data.F32[i],
    494                           sources, targetPSF, rng, config)) {
     447                          sourceLists->data[i], targetPSF, rng, config)) {
    495448            psErrorStackPrint(stderr, "Unable to match image %d --- ignoring.", i);
    496449            inputMask->data.U8[i] = PPSTACK_MASK_MATCH;
     
    532485        memDump("match");
    533486    }
    534     psFree(globalSources);
    535     psFree(indSources);
     487    psFree(sourceLists);
    536488    psFree(targetPSF);
    537489    psFree(rng);
Note: See TracChangeset for help on using the changeset viewer.