IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 6, 2010, 1:36:51 PM (16 years ago)
Author:
eugene
Message:

working on stackphot

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/stackphot.20100406/psphot/src/psphotStackReadout.c

    r26894 r27625  
    1313        return false;
    1414    }
     15    // optional break-point for processing
     16    char *breakPt = psMetadataLookupStr (NULL, recipe, "BREAK_POINT");
     17    PS_ASSERT_PTR_NON_NULL (breakPt, false);
    1518
    16     // set the photcode for this image (XXX currently goes into recipe, should it go into analysis?)
     19    // set the photcode for each image
    1720    if (!psphotAddPhotcode (config, view)) {
    1821        psError (PSPHOT_ERR_CONFIG, false, "trouble defining the photcode");
     
    2023    }
    2124
    22     // generate a background model (median, smoothed image)
    23     if (!psphotSetMaskAndVariance (config, view, recipe)) {
    24         return psphotReadoutCleanup (config, NULL, recipe, NULL, NULL, NULL);
     25    // Generate the mask and weight images
     26    if (!psphotSetMaskAndVariance (config, view)) {
     27        return psphotReadoutCleanup (config, view);
    2528    }
    2629    if (!strcasecmp (breakPt, "NOTHING")) {
    27         return psphotReadoutCleanup(config, NULL, recipe, NULL, NULL, NULL);
     30        return psphotReadoutCleanup (config, view);
    2831    }
    2932
    30     // optional break-point for processing
    31     char *breakPt = psMetadataLookupStr (NULL, recipe, "BREAK_POINT");
    32     PS_ASSERT_PTR_NON_NULL (breakPt, false);
    33 
    3433    // generate a background model (median, smoothed image)
     34    // XXX I think this is not defined correctly for an array of images.
    3535    if (!psphotModelBackground (config, view)) {
    36         return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL);
     36        return psphotReadoutCleanup (config, view);
    3737    }
    3838    if (!psphotSubtractBackground (config, view)) {
    39         return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL);
     39        return psphotReadoutCleanup (config, view);
    4040    }
    4141    if (!strcasecmp (breakPt, "BACKMDL")) {
    42         return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL);
     42        return psphotReadoutCleanup (config, view);
     43    }
     44
     45    // load the psf model, if suppled.  FWHM_X,FWHM_Y,etc are determined and saved on
     46    // readout->analysis XXX this function currently only works with a single PSPHOT.INPUT
     47    if (!psphotLoadPSF (config, view)) {
     48        psError (PSPHOT_ERR_UNKNOWN, false, "error loading psf model");
     49        return psphotReadoutCleanup (config, view);
     50    }
     51
     52    if (!psphotStackChisqImage(config, view)) {
     53        psError (PSPHOT_ERR_UNKNOWN, false, "failure to generate chisq image");
     54        return psphotReadoutCleanup (config, view);
     55    }
     56    if (!strcasecmp (breakPt, "CHISQ")) {
     57        return psphotReadoutCleanup (config, view);
    4358    }
    4459
    4560    // find the detections (by peak and/or footprint) in the image.
    46     pmDetections *detections = psphotFindDetections (NULL, readout, recipe);
    47     if (!detections) {
    48         psLogMsg ("psphot", 3, "unable to find detections in this image");
    49         return psphotReadoutCleanup (config, readout, recipe, detections, psf, NULL);
     61    if (!psphotFindDetections (config, view, true)) { // pass 1
     62        // this only happens if we had an error in psphotFindDetections
     63        psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis");
     64        return psphotReadoutCleanup (config, view);
    5065    }
    5166
    52     // construct sources and measure basic stats
    53     psArray *sources = psphotSourceStats (config, readout, detections, true);
    54     if (!sources) return false;
     67    // construct sources and measure basic stats (saved on detections->newSources)
     68    if (!psphotSourceStats (config, view, true)) { // pass 1
     69        psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources");
     70        return psphotReadoutCleanup (config, view);
     71    }
    5572    if (!strcasecmp (breakPt, "PEAKS")) {
    56         return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources);
     73        return psphotReadoutCleanup(config, view);
    5774    }
    5875
    59     // find blended neighbors of very saturated stars
    60     // XXX merge this with Basic Deblend?
    61     psphotDeblendSatstars (readout, sources, recipe);
     76    // find blended neighbors of very saturated stars (detections->newSources)
     77    if (!psphotDeblendSatstars (config, view)) {
     78        psError (PSPHOT_ERR_UNKNOWN, false, "failed on satstar deblend analysis");
     79        return psphotReadoutCleanup (config, view);
     80    }
    6281
    63     // mark blended peaks PS_SOURCE_BLEND
    64     if (!psphotBasicDeblend (sources, recipe)) {
    65         psLogMsg ("psphot", 3, "failed on deblend analysis");
    66         return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);
     82    // mark blended peaks PS_SOURCE_BLEND (detections->newSources)
     83    if (!psphotBasicDeblend (config, view)) {
     84        psError (PSPHOT_ERR_UNKNOWN, false, "failed on deblend analysis");
     85        return psphotReadoutCleanup (config, view);
    6786    }
    6887
    6988    // classify sources based on moments, brightness
    70     if (!psphotRoughClass (readout, sources, recipe, havePSF)) {
    71         psLogMsg ("psphot", 3, "failed to find a valid PSF clump for image");
    72         return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);
     89    if (!psphotRoughClass (config, view)) {
     90        psError (PSPHOT_ERR_UNKNOWN, false, "failed to determine rough classifications");
     91        return psphotReadoutCleanup (config, view);
     92    }
     93    // if we were not supplied a PSF model, determine the IQ stats here (detections->newSources)
     94    if (!psphotImageQuality (config, view)) { // pass 1
     95        psError (PSPHOT_ERR_UNKNOWN, false, "failed to measure image quality");
     96        return psphotReadoutCleanup(config, view);
    7397    }
    7498    if (!strcasecmp (breakPt, "MOMENTS")) {
    75         return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources);
     99        return psphotReadoutCleanup (config, view);
    76100    }
    77101
    78     if (!havePSF && !psphotImageQuality (recipe, sources)) {
    79         psLogMsg("psphot", 3, "failed to measure image quality");
    80         return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources);
     102    // use bright stellar objects to measure PSF if we were supplied a PSF for any input file,
     103    // this step is skipped
     104    if (!psphotChoosePSF (config, view)) { // pass 1
     105        psLogMsg ("psphot", 3, "failure to construct a psf model");
     106        return psphotReadoutCleanup (config, view);
     107    }
     108    if (!strcasecmp (breakPt, "PSFMODEL")) {
     109        return psphotReadoutCleanup (config, view);
    81110    }
    82111
    83     // if we were not supplied a PSF, choose one here
    84     if (psf == NULL) {
    85         // use bright stellar objects to measure PSF
    86         // XXX if we do not have enough stars to generate the PSF, build one
    87         // from the SEEING guess and model class
    88         psf = psphotChoosePSF (readout, sources, recipe);
    89         if (psf == NULL) {
    90             psLogMsg ("psphot", 3, "failure to construct a psf model");
    91             return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);
    92         }
    93         havePSF = true;
    94     }
    95     if (!strcasecmp (breakPt, "PSFMODEL")) {
    96         return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);
    97     }
    98     psphotVisualShowPSFModel (readout, psf);
    99 
    100112    // include externally-supplied sources
    101     psphotLoadExtSources (config, view, sources);
     113    // XXX fix this in the new multi-input context
     114    // psphotLoadExtSources (config, view); // pass 1
    102115
    103116    // construct an initial model for each object, set the radius to fitRadius, set circular fit mask
    104     psphotGuessModels (config, readout, sources, psf);
     117    psphotGuessModels (config, view);
    105118
     119    // merge the newly selected sources into the existing list
     120    // NOTE: merge OLD and NEW
     121    psphotMergeSources (config, view);
     122
     123    // *** generate the objects (which unify the sources from the different images)
     124    // pmArray *objects = psphotMatchSources (config, view);
     125   
    106126    // linear PSF fit to source peaks, subtract the models from the image (in PSF mask)
    107     psphotFitSourcesLinear (readout, sources, recipe, psf, FALSE);
    108 
    109     // We have to place these visualizations here because the models are not realized until
    110     // psphotGuessModels or fitted until psphotFitSourcesLinear.
    111     psphotVisualShowPSFStars (recipe, psf, sources);
     127    // psphotFitSourcesLinearStack (config, objects, FALSE);
    112128
    113129    // identify CRs and extended sources
    114     psphotSourceSize (config, readout, sources, recipe, psf, 0);
    115     if (!strcasecmp (breakPt, "ENSEMBLE")) {
    116         goto finish;
    117     }
    118     psphotVisualShowSatStars (recipe, psf, sources);
    119 
    120     // non-linear PSF and EXT fit to brighter sources
    121     // replace model flux, adjust mask as needed, fit, subtract the models (full stamp)
    122     psphotBlendFit (config, readout, sources, psf);
    123 
    124     // replace all sources
    125     psphotReplaceAllSources (sources, recipe);
    126 
    127     // linear fit to include all sources (subtract again)
    128     psphotFitSourcesLinear (readout, sources, recipe, psf, TRUE);
    129 
    130     // if we only do one pass, skip to extended source analysis
    131     if (!strcasecmp (breakPt, "PASS1")) {
    132         goto pass1finish;
    133     }
    134     // NOTE: possibly re-measure background model here with objects subtracted
    135 
    136     // add noise for subtracted objects
    137     psphotAddNoise (readout, sources, recipe);
    138 
    139     // find fainter sources (pass 2)
    140     detections = psphotFindDetections (detections, readout, recipe);
    141 
    142     // remove noise for subtracted objects (ie, return to normal noise level)
    143     psphotSubNoise (readout, sources, recipe);
    144 
    145     // define new sources based on only the new peaks
    146     psArray *newSources = psphotSourceStats (config, readout, detections, false);
    147 
    148     // set source type
    149     if (!psphotRoughClass (readout, newSources, recipe, havePSF)) {
    150         psLogMsg ("psphot", 3, "failed to find a valid PSF clump for image");
    151         return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);
    152     }
    153 
    154     // create full input models, set the radius to fitRadius, set circular fit mask
    155     psphotGuessModels (config, readout, newSources, psf);
    156 
    157     // replace all sources so fit below applies to all at once
    158     psphotReplaceAllSources (sources, recipe);
    159 
    160     // merge the newly selected sources into the existing list
    161     psphotMergeSources (sources, newSources);
    162     psFree (newSources);
    163 
    164     // linear fit to all sources
    165     psphotFitSourcesLinear (readout, sources, recipe, psf, TRUE);
    166 
    167 pass1finish:
    168 
    169     // measure source size for the remaining sources
    170     psphotSourceSize (config, readout, sources, recipe, psf, 0);
    171 
    172     psphotExtendedSourceAnalysis (readout, sources, recipe);
    173 
    174     psphotExtendedSourceFits (readout, sources, recipe);
    175 
    176 finish:
    177 
    178     // plot positive sources
    179     // psphotSourcePlots (readout, sources, recipe);
     130    psphotSourceSize (config, view, TRUE);
    180131
    181132    // measure aperture photometry corrections
    182     if (!psphotApResid (config, readout, sources, psf)) {
     133    if (!psphotApResid (config, view)) {
    183134        psLogMsg ("psphot", 3, "failed on psphotApResid");
    184         return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);
     135        return psphotReadoutCleanup (config, view);
    185136    }
    186137
    187138    // calculate source magnitudes
    188     psphotMagnitudes(config, readout, view, sources, psf);
     139    psphotMagnitudes(config, view);
    189140
    190     if (!psphotEfficiency(config, readout, view, psf, recipe, sources)) {
     141    if (!psphotEfficiency(config, view)) {
    191142        psErrorStackPrint(stderr, "Unable to determine detection efficiencies from fake sources");
    192143        psErrorClear();
     
    200151
    201152    // drop the references to the image pixels held by each source
    202     psphotSourceFreePixels (sources);
     153    psphotSourceFreePixels (config, view);
    203154
    204155    // create the exported-metadata and free local data
    205     return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources);
     156    return psphotReadoutCleanup (config, view);
    206157}
    207158
Note: See TracChangeset for help on using the changeset viewer.