IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 25, 2010, 7:52:41 PM (16 years ago)
Author:
eugene
Message:

various API updates to work with multiple INPUT files (not yet finished)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/psphot.stack.20100120/src/psphotReadout.c

    r26643 r26681  
    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     // XXX move this into the loop above
    51     psphotVisualShowImage (readout);
     38        return psphotReadoutCleanup(config, view);
     39    }
    5240
    5341    // generate a background model (median, smoothed image)
    5442    if (!psphotModelBackground (config, view)) {
    55         return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL);
     43        return psphotReadoutCleanup (config, view);
    5644    }
    5745    if (!psphotSubtractBackground (config, view)) {
    58         return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL);
     46        return psphotReadoutCleanup (config, view);
    5947    }
    6048    if (!strcasecmp (breakPt, "BACKMDL")) {
    61         return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL);
    62     }
    63 
    64     // display the backsub and backgnd images
    65     // move this inthe the subtract background loop
    66     psphotVisualShowBackground (config, view, readout);
     49        return psphotReadoutCleanup (config, view);
     50    }
    6751
    6852    // run a single-model test if desired (exits from here if test is run)
    69     psphotModelTest (config, view, recipe);
     53    // XXX drop this and only keep the stand-alone program?
     54    // psphotModelTest (config, view, recipe);
    7055
    7156    // load the psf model, if suppled.  FWHM_X,FWHM_Y,etc are saved in the recipe
    72     pmPSF *psf = psphotLoadPSF (config, view, recipe);
    73 
    74     // several functions below behave differently if we have a PSF model already
    75     bool havePSF = (psf != NULL);
    76 
     57    // XXX this needs to save the PSF on the chip->analysis or readout->analysis
     58    if (!psphotLoadPSF (config, view, recipe)) {
     59        // this only happens if we had a programming error in psphotLoadPSF
     60        psError (PSPHOT_ERR_UNKNOWN, false, "error loading psf model");
     61        return psphotReadoutCleanup (config, view);
     62    }
     63       
    7764    // find the detections (by peak and/or footprint) in the image.
    7865    if (!psphotFindDetections (config, view)) {
    7966        // this only happens if we had an error in psphotFindDetections
    8067        psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis");
    81         return psphotReadoutCleanup (config, readout, recipe, detections, psf, NULL);
    82     }
     68        return psphotReadoutCleanup (config, view);
     69    }
     70
     71XXX: // need to handle or ignore this !!
    8372    if (!detections->peaks->n) {
    8473        psLogMsg ("psphot", 3, "unable to find detections in this image");
    85         return psphotReadoutCleanup (config, readout, recipe, detections, psf, NULL);
     74        return psphotReadoutCleanup (config, view);
    8675    }
    8776
    8877    // construct sources and measure basic stats
    8978    if (!psphotSourceStats (config, view, true)) {
    90         // XXX do I need to raise an error here?
    91         return false;
     79        psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources");
     80        return psphotReadoutCleanup (config, view);
    9281    }
    9382    if (!strcasecmp (breakPt, "PEAKS")) {
    94         return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources);
     83        return psphotReadoutCleanup(config, view);
    9584    }
    9685
    9786    // find blended neighbors of very saturated stars
    98     // XXX merge this with Basic Deblend?
    9987    if (!psphotDeblendSatstars (config, view)) {
    100         psLogMsg ("psphot", 3, "failed on satstar deblend analysis");
    101         return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);
     88        psError (PSPHOT_ERR_UNKNOWN, false, "failed on satstar deblend analysis");
     89        return psphotReadoutCleanup (config, view);
    10290    }
    10391
    10492    // mark blended peaks PS_SOURCE_BLEND
    10593    if (!psphotBasicDeblend (config, view)) {
    106         psLogMsg ("psphot", 3, "failed on deblend analysis");
    107         return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);
    108     }
    109 
    110     // classify sources based on moments, brightness
    111     if (!psphotRoughClass (config, view, havePSF)) {
    112         psLogMsg ("psphot", 3, "failed to find a valid PSF clump for image");
    113         return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);
     94        psError (PSPHOT_ERR_UNKNOWN, false, "failed on deblend analysis");
     95        return psphotReadoutCleanup (config, view);
     96    }
     97
     98    // classify sources based on moments, brightness.  if a PSF model has been loaded, the PSF
     99    // clump defined for it is used not measured
     100    if (!psphotRoughClass (config, view)) {
     101        psError (PSPHOT_ERR_UNKNOWN, false, "failed to determine rough classifications");
     102        return psphotReadoutCleanup (config, view);
    114103    }
    115104    if (!strcasecmp (breakPt, "MOMENTS")) {
    116         return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources);
    117     }
    118 
    119     if (!havePSF && !psphotImageQuality (recipe, sources)) {
     105        return psphotReadoutCleanup(config, view);
     106    }
     107
     108    // if we were not supplied a PSF model, determine the IQ stats here
     109    if (!psphotImageQuality (config, view)) {
    120110        psLogMsg("psphot", 3, "failed to measure image quality");
    121         return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources);
    122     }
    123 
    124     // if we were not supplied a PSF, choose one here
    125     if (psf == NULL) {
    126         // use bright stellar objects to measure PSF
    127         // XXX if we do not have enough stars to generate the PSF, build one
    128         // from the SEEING guess and model class
    129         if (!psphotChoosePSF (config, view)) {
    130             psLogMsg ("psphot", 3, "failure to construct a psf model");
    131             return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);
    132         }
    133         havePSF = true;
     111        return psphotReadoutCleanup(config, view);
     112    }
     113
     114    // use bright stellar objects to measure PSF if we were supplied a PSF for any input file,
     115    // this step is skipped
     116    if (!psphotChoosePSF (config, view)) {
     117        psLogMsg ("psphot", 3, "failure to construct a psf model");
     118        return psphotReadoutCleanup (config, view);
    134119    }
    135120    if (!strcasecmp (breakPt, "PSFMODEL")) {
    136         return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);
    137     }
    138     // move into psphotChoosePSF
    139     psphotVisualShowPSFModel (readout, psf);
     121        return psphotReadoutCleanup (config, view);
     122    }
    140123
    141124    // include externally-supplied sources
     125    // XXX hmm...
    142126    psphotLoadExtSources (config, view, sources);
    143127
    144128    // construct an initial model for each object, set the radius to fitRadius, set circular fit mask
    145     psphotGuessModels (config, readout, sources, psf);
     129    psphotGuessModels (config, view);
    146130
    147131    // linear PSF fit to source peaks, subtract the models from the image (in PSF mask)
    148     psphotFitSourcesLinear (readout, sources, recipe, psf, FALSE);
    149 
    150     // We have to place these visualizations here because the models are not realized until
    151     // psphotGuessModels or fitted until psphotFitSourcesLinear.
    152     psphotVisualShowPSFStars (recipe, psf, sources);
     132    psphotFitSourcesLinear (config, view, FALSE);
    153133
    154134    // identify CRs and extended sources
     
    157137        goto finish;
    158138    }
    159     psphotVisualShowSatStars (recipe, psf, sources);
    160139
    161140    // non-linear PSF and EXT fit to brighter sources
    162141    // replace model flux, adjust mask as needed, fit, subtract the models (full stamp)
    163     psphotBlendFit (config, readout, sources, psf);
     142    psphotBlendFit (config, view);
    164143
    165144    // replace all sources
    166     psphotReplaceAllSources (sources, recipe);
     145    psphotReplaceAllSources (config, view);
    167146
    168147    // linear fit to include all sources (subtract again)
    169     psphotFitSourcesLinear (readout, sources, recipe, psf, TRUE);
     148    psphotFitSourcesLinear (config, view, TRUE);
    170149
    171150    // if we only do one pass, skip to extended source analysis
     
    176155
    177156    // add noise for subtracted objects
    178     psphotAddNoise (readout, sources, recipe);
     157    psphotAddNoise (config, view);
    179158
    180159    // find fainter sources (pass 2)
    181     detections = psphotFindDetections (detections, readout, recipe);
     160    // XXX need to distinguish old from new sources
     161    psphotFindDetections (config, view);
    182162
    183163    // remove noise for subtracted objects (ie, return to normal noise level)
    184     psphotSubNoise (readout, sources, recipe);
     164    // XXX this needs to operate only on the OLD sources
     165    psphotSubNoise (config, view);
    185166
    186167    // define new sources based on only the new peaks
    187     psArray *newSources = psphotSourceStats (config, readout, detections, false);
     168    // XXX need to distinguish old from new sources
     169    psphotSourceStats (config, view, false);
    188170
    189171    // set source type
    190     if (!psphotRoughClass (config, view, havePSF)) {
     172    if (!psphotRoughClass (config, view)) {
    191173        psLogMsg ("psphot", 3, "failed to find a valid PSF clump for image");
    192         return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);
     174        return psphotReadoutCleanup (config, view);
    193175    }
    194176
    195177    // create full input models, set the radius to fitRadius, set circular fit mask
    196     psphotGuessModels (config, readout, newSources, psf);
     178    // XXX need to distinguish old from new sources
     179    psphotGuessModels (config, view);
    197180
    198181    // replace all sources so fit below applies to all at once
    199     psphotReplaceAllSources (sources, recipe);
     182    psphotReplaceAllSources (config, view);
    200183
    201184    // merge the newly selected sources into the existing list
    202     psphotMergeSources (sources, newSources);
     185    // XXX old vs new????
     186FIX:    psphotMergeSources (sources, newSources);
    203187    psFree (newSources);
    204188
    205189    // linear fit to all sources
    206     psphotFitSourcesLinear (readout, sources, recipe, psf, TRUE);
     190    psphotFitSourcesLinear (config, view, TRUE);
    207191
    208192pass1finish:
     
    211195    psphotSourceSize (config, view);
    212196
    213     psphotExtendedSourceAnalysis (readout, sources, recipe);
    214 
    215     psphotExtendedSourceFits (readout, sources, recipe);
     197FIX:    psphotExtendedSourceAnalysis (readout, sources, recipe);
     198FIX:    psphotExtendedSourceFits (readout, sources, recipe);
    216199
    217200finish:
     
    221204
    222205    // measure aperture photometry corrections
    223     if (!psphotApResid (config, readout, sources, psf)) {
     206FIX:    if (!psphotApResid (config, readout, sources, psf)) {
    224207        psLogMsg ("psphot", 3, "failed on psphotApResid");
    225         return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);
     208        return psphotReadoutCleanup (config, view);
    226209    }
    227210
    228211    // calculate source magnitudes
    229     psphotMagnitudes(config, readout, view, sources, psf);
    230 
    231     if (!psphotEfficiency(config, readout, view, psf, recipe, sources)) {
     212FIX:    psphotMagnitudes(config, readout, view, sources, psf);
     213
     214FIX:    if (!psphotEfficiency(config, readout, view, psf, recipe, sources)) {
    232215        psErrorStackPrint(stderr, "Unable to determine detection efficiencies from fake sources");
    233216        psErrorClear();
     
    238221
    239222    // replace background in residual image
    240     psphotSkyReplace (config, view);
     223FIX:    psphotSkyReplace (config, view);
    241224
    242225    // drop the references to the image pixels held by each source
    243     psphotSourceFreePixels (sources);
     226FIX:    psphotSourceFreePixels (sources);
    244227
    245228    // create the exported-metadata and free local data
    246     return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources);
     229    return psphotReadoutCleanup(config, view);
    247230}
    248 
Note: See TracChangeset for help on using the changeset viewer.