IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 5, 2010, 1:38:43 PM (16 years ago)
Author:
eugene
Message:

updates to psphot APIs to enable stack photometry

Location:
branches/eam_branches/20091201/psphot
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20091201/psphot

  • branches/eam_branches/20091201/psphot/src/psphotReadout.c

    r26596 r26788  
    33// this should be called by every program that links against libpsphot
    44bool psphotInit (void) {
    5 
    65    psphotErrorRegister();              // register our error codes/messages
    76    psphotModelClassInit ();            // load implementation-specific models
     
    1211bool psphotReadout(pmConfig *config, const pmFPAview *view) {
    1312
    14     // measure the total elapsed time in psphotReadout.  XXX the current threading plan
    15     // for psphot envisions threading within psphotReadout, not multiple threads calling
    16     // the same psphotReadout.  In the current plan, this dtime is the elapsed time used
    17     // jointly by the multiple threads, not the total time used by all threads.
     13    // measure the total elapsed time in psphotReadout.  dtime is the elapsed time used jointly
     14    // by the multiple threads, not the total time used by all threads.
    1815    psTimerStart ("psphotReadout");
    1916
     
    2623        return false;
    2724    }
     25    // optional break-point for processing
     26    char *breakPt = psMetadataLookupStr (NULL, recipe, "BREAK_POINT");
     27    psAssert (breakPt, "configuration error: set BREAK_POINT");
    2828
    2929    // set the photcode for this image
     
    3333    }
    3434
    35     // find the currently selected readout
    36     pmReadout  *readout = pmFPAfileThisReadout (config->files, view, "PSPHOT.INPUT");
    37     PS_ASSERT_PTR_NON_NULL (readout, false);
    38 
    39     // optional break-point for processing
    40     char *breakPt = psMetadataLookupStr (NULL, recipe, "BREAK_POINT");
    41     PS_ASSERT_PTR_NON_NULL (breakPt, false);
    42 
    4335    // Generate the mask and weight images, including the user-defined analysis region of interest
    44     psphotSetMaskAndVariance (config, view, recipe);
     36    psphotSetMaskAndVariance (config, view);
    4537    if (!strcasecmp (breakPt, "NOTHING")) {
    46         return psphotReadoutCleanup(config, readout, recipe, NULL, NULL, NULL);
    47     }
    48 
    49     // display the image, weight, mask (ch 1,2,3)
    50     psphotVisualShowImage (readout);
     38        return psphotReadoutCleanup(config, view);
     39    }
    5140
    5241    // generate a background model (median, smoothed image)
    5342    if (!psphotModelBackground (config, view)) {
    54         return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL);
     43        return psphotReadoutCleanup (config, view);
    5544    }
    5645    if (!psphotSubtractBackground (config, view)) {
    57         return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL);
     46        return psphotReadoutCleanup (config, view);
    5847    }
    5948    if (!strcasecmp (breakPt, "BACKMDL")) {
    60         return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL);
    61     }
    62 
    63     // display the backsub and backgnd images
    64     psphotVisualShowBackground (config, view, readout);
    65 
    66     // run a single-model test if desired (exits from here if test is run)
    67     psphotModelTest (config, view, recipe);
    68 
    69     // load the psf model, if suppled.  FWHM_X,FWHM_Y,etc are saved in the recipe
    70     pmPSF *psf = psphotLoadPSF (config, view, recipe);
    71 
    72     // several functions below behave differently if we have a PSF model already
    73     bool havePSF = (psf != NULL);
    74 
     49        return psphotReadoutCleanup (config, view);
     50    }
     51
     52    // load the psf model, if suppled.  FWHM_X,FWHM_Y,etc are determined and saved on
     53    // readout->analysis XXX this function currently only works with a single PSPHOT.INPUT
     54    if (!psphotLoadPSF (config, view)) {
     55        psError (PSPHOT_ERR_UNKNOWN, false, "error loading psf model");
     56        return psphotReadoutCleanup (config, view);
     57    }
     58       
    7559    // find the detections (by peak and/or footprint) in the image.
    76     pmDetections *detections = psphotFindDetections (NULL, readout, recipe);
    77     if (!detections) {
     60    if (!psphotFindDetections (config, view, true)) { // pass 1
    7861        // this only happens if we had an error in psphotFindDetections
    7962        psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis");
    80         return psphotReadoutCleanup (config, readout, recipe, detections, psf, NULL);
    81     }
    82     if (!detections->peaks->n) {
    83         psLogMsg ("psphot", 3, "unable to find detections in this image");
    84         return psphotReadoutCleanup (config, readout, recipe, detections, psf, NULL);
    85     }
    86 
    87     // construct sources and measure basic stats
    88     psArray *sources = psphotSourceStats (config, readout, detections, true);
    89     if (!sources) return false;
     63        return psphotReadoutCleanup (config, view);
     64    }
     65
     66    // construct sources and measure basic stats (saved on detections->newSources)
     67    if (!psphotSourceStats (config, view, true)) { // pass 1
     68        psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources");
     69        return psphotReadoutCleanup (config, view);
     70    }
    9071    if (!strcasecmp (breakPt, "PEAKS")) {
    91         return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources);
    92     }
    93 
    94     // find blended neighbors of very saturated stars
    95     // XXX merge this with Basic Deblend?
    96     psphotDeblendSatstars (readout, sources, recipe);
    97 
    98     // mark blended peaks PS_SOURCE_BLEND
    99     if (!psphotBasicDeblend (sources, recipe)) {
    100         psLogMsg ("psphot", 3, "failed on deblend analysis");
    101         return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);
    102     }
    103 
    104     // classify sources based on moments, brightness
    105     if (!psphotRoughClass (readout, sources, recipe, havePSF)) {
    106         psLogMsg ("psphot", 3, "failed to find a valid PSF clump for image");
    107         return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);
     72        return psphotReadoutCleanup(config, view);
     73    }
     74
     75    // find blended neighbors of very saturated stars (detections->newSources)
     76    if (!psphotDeblendSatstars (config, view)) {
     77        psError (PSPHOT_ERR_UNKNOWN, false, "failed on satstar deblend analysis");
     78        return psphotReadoutCleanup (config, view);
     79    }
     80
     81    // mark blended peaks PS_SOURCE_BLEND (detections->newSources)
     82    if (!psphotBasicDeblend (config, view)) {
     83        psError (PSPHOT_ERR_UNKNOWN, false, "failed on deblend analysis");
     84        return psphotReadoutCleanup (config, view);
     85    }
     86
     87    // classify sources based on moments, brightness.  if a PSF model has been loaded, the PSF
     88    // clump defined for it is used not measured (detections->newSources)
     89    if (!psphotRoughClass (config, view)) { // pass 1
     90        psError (PSPHOT_ERR_UNKNOWN, false, "failed to determine rough classifications");
     91        return psphotReadoutCleanup (config, view);
    10892    }
    10993    if (!strcasecmp (breakPt, "MOMENTS")) {
    110         return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources);
    111     }
    112 
    113     if (!havePSF && !psphotImageQuality (recipe, sources)) {
    114         psLogMsg("psphot", 3, "failed to measure image quality");
    115         return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources);
    116     }
    117 
    118     // if we were not supplied a PSF, choose one here
    119     if (psf == NULL) {
    120         // use bright stellar objects to measure PSF
    121         // XXX if we do not have enough stars to generate the PSF, build one
    122         // from the SEEING guess and model class
    123         psf = psphotChoosePSF (readout, sources, recipe);
    124         if (psf == NULL) {
    125             psLogMsg ("psphot", 3, "failure to construct a psf model");
    126             return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);
    127         }
    128         havePSF = true;
     94        return psphotReadoutCleanup(config, view);
     95    }
     96
     97    // if we were not supplied a PSF model, determine the IQ stats here (detections->newSources)
     98    if (!psphotImageQuality (config, view)) { // pass 1
     99        psError (PSPHOT_ERR_UNKNOWN, false, "failed to measure image quality");
     100        return psphotReadoutCleanup(config, view);
     101    }
     102
     103    // use bright stellar objects to measure PSF if we were supplied a PSF for any input file,
     104    // this step is skipped
     105    if (!psphotChoosePSF (config, view)) { // pass 1
     106        psLogMsg ("psphot", 3, "failure to construct a psf model");
     107        return psphotReadoutCleanup (config, view);
    129108    }
    130109    if (!strcasecmp (breakPt, "PSFMODEL")) {
    131         return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);
    132     }
    133     psphotVisualShowPSFModel (readout, psf);
     110        return psphotReadoutCleanup (config, view);
     111    }
    134112
    135113    // include externally-supplied sources
    136     psphotLoadExtSources (config, view, sources);
    137 
    138     // construct an initial model for each object, set the radius to fitRadius, set circular fit mask
    139     psphotGuessModels (config, readout, sources, psf);
     114    // XXX fix this in the new multi-input context
     115    psphotLoadExtSources (config, view); // pass 1
     116
     117    // construct an initial model for each object, set the radius to fitRadius, set circular
     118    // fit mask (detections->newSources)
     119    psphotGuessModels (config, view); // pass 1
     120
     121    // merge the newly selected sources into the existing list
     122    // NOTE: merge OLD and NEW
     123    psphotMergeSources (config, view);
    140124
    141125    // linear PSF fit to source peaks, subtract the models from the image (in PSF mask)
    142     psphotFitSourcesLinear (readout, sources, recipe, psf, FALSE);
    143 
    144     // We have to place these visualizations here because the models are not realized until
    145     // psphotGuessModels or fitted until psphotFitSourcesLinear.
    146     psphotVisualShowPSFStars (recipe, psf, sources);
    147 
    148     // identify CRs and extended sources
    149     psphotSourceSize (config, readout, sources, recipe, psf, 0);
     126    psphotFitSourcesLinear (config, view, false); // pass 1 (detections->allSources)
     127
     128    // identify CRs and extended sources (only unmeasured sources are measured)
     129    psphotSourceSize (config, view, true); // pass 1 (detections->allSources)
    150130    if (!strcasecmp (breakPt, "ENSEMBLE")) {
    151131        goto finish;
    152132    }
    153     psphotVisualShowSatStars (recipe, psf, sources);
    154133
    155134    // non-linear PSF and EXT fit to brighter sources
    156135    // replace model flux, adjust mask as needed, fit, subtract the models (full stamp)
    157     psphotBlendFit (config, readout, sources, psf);
     136    psphotBlendFit (config, view); // pass 1 (detections->allSources)
    158137
    159138    // replace all sources
    160     psphotReplaceAllSources (sources, recipe);
     139    psphotReplaceAllSources (config, view); // pass 1 (detections->allSources)
    161140
    162141    // linear fit to include all sources (subtract again)
    163     psphotFitSourcesLinear (readout, sources, recipe, psf, TRUE);
     142    // NOTE : apply to ALL sources (extended + psf)
     143    psphotFitSourcesLinear (config, view, true); // pass 2 (detections->allSources)
    164144
    165145    // if we only do one pass, skip to extended source analysis
    166     if (!strcasecmp (breakPt, "PASS1")) {
    167         goto pass1finish;
    168     }
    169     // NOTE: possibly re-measure background model here with objects subtracted
     146    if (!strcasecmp (breakPt, "PASS1")) goto pass1finish;
     147
     148    // NOTE: possibly re-measure background model here with objects subtracted / or masked
    170149
    171150    // add noise for subtracted objects
    172     psphotAddNoise (readout, sources, recipe);
    173 
    174     // find fainter sources (pass 2)
    175     detections = psphotFindDetections (detections, readout, recipe);
     151    psphotAddNoise (config, view); // pass 1 (detections->allSources)
     152
     153    // find fainter sources
     154    // NOTE: finds new peaks and new footprints, OLD and FULL set are saved on detections
     155    psphotFindDetections (config, view, false); // pass 2 (detections->peaks, detections->footprints)
    176156
    177157    // remove noise for subtracted objects (ie, return to normal noise level)
    178     psphotSubNoise (readout, sources, recipe);
     158    // NOTE: this needs to operate only on the OLD sources
     159    psphotSubNoise (config, view); // pass 1 (detections->allSources)
    179160
    180161    // define new sources based on only the new peaks
    181     psArray *newSources = psphotSourceStats (config, readout, detections, false);
     162    // NOTE: new sources are saved on detections->newSources
     163    psphotSourceStats (config, view, false); // pass 2 (detections->newSources)
    182164
    183165    // set source type
    184     if (!psphotRoughClass (readout, newSources, recipe, havePSF)) {
     166    // NOTE: apply only to detections->newSources
     167    if (!psphotRoughClass (config, view)) { // pass 2 (detections->newSources)
    185168        psLogMsg ("psphot", 3, "failed to find a valid PSF clump for image");
    186         return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);
     169        return psphotReadoutCleanup (config, view);
    187170    }
    188171
    189172    // create full input models, set the radius to fitRadius, set circular fit mask
    190     psphotGuessModels (config, readout, newSources, psf);
     173    // NOTE: apply only to detections->newSources
     174    psphotGuessModels (config, view); // pass 2 (detections->newSources)
    191175
    192176    // replace all sources so fit below applies to all at once
    193     psphotReplaceAllSources (sources, recipe);
     177    // NOTE: apply only to OLD sources (which have been subtracted)
     178    psphotReplaceAllSources (config, view); // pass 2
    194179
    195180    // merge the newly selected sources into the existing list
    196     psphotMergeSources (sources, newSources);
    197     psFree (newSources);
    198 
    199     // linear fit to all sources
    200     psphotFitSourcesLinear (readout, sources, recipe, psf, TRUE);
     181    // NOTE: merge OLD and NEW
     182    // XXX check on free of sources...
     183    psphotMergeSources (config, view); // (detections->newSources + detections->allSources -> detections->allSources)
     184
     185    // NOTE: apply to ALL sources
     186    psphotFitSourcesLinear (config, view, true); // pass 3 (detections->allSources)
    201187
    202188pass1finish:
    203189
    204190    // measure source size for the remaining sources
    205     psphotSourceSize (config, readout, sources, recipe, psf, 0);
    206 
    207     psphotExtendedSourceAnalysis (readout, sources, recipe);
    208 
    209     psphotExtendedSourceFits (readout, sources, recipe);
     191    // NOTE: applies only to NEW (unmeasured) sources
     192    psphotSourceSize (config, view, false); // pass 2 (detections->allSources)
     193
     194    psphotExtendedSourceAnalysis (config, view); // pass 1 (detections->allSources)
     195    psphotExtendedSourceFits (config, view); // pass 1 (detections->allSources)
    210196
    211197finish:
     
    215201
    216202    // measure aperture photometry corrections
    217     if (!psphotApResid (config, readout, sources, psf)) {
     203    if (!psphotApResid (config, view)) { // pass 1 (detections->allSources)
    218204        psLogMsg ("psphot", 3, "failed on psphotApResid");
    219         return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);
     205        return psphotReadoutCleanup (config, view);
    220206    }
    221207
    222208    // calculate source magnitudes
    223     psphotMagnitudes(config, readout, view, sources, psf);
    224 
    225     if (!psphotEfficiency(config, readout, view, psf, recipe, sources)) {
     209    psphotMagnitudes(config, view); // pass 1 (detections->allSources)
     210
     211    if (!psphotEfficiency(config, view)) { // pass 1
    226212        psErrorStackPrint(stderr, "Unable to determine detection efficiencies from fake sources");
    227213        psErrorClear();
     
    232218
    233219    // replace background in residual image
    234     psphotSkyReplace (config, view);
     220    psphotSkyReplace (config, view); // pass 1
    235221
    236222    // drop the references to the image pixels held by each source
    237     psphotSourceFreePixels (sources);
     223    psphotSourceFreePixels (config, view); // pass 1
    238224
    239225    // create the exported-metadata and free local data
    240     return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources);
     226    return psphotReadoutCleanup(config, view);
    241227}
    242 
Note: See TracChangeset for help on using the changeset viewer.