IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 11, 2010, 5:08:29 PM (16 years ago)
Author:
eugene
Message:

updates to support psphotStack

Location:
trunk/psphot
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot

  • trunk/psphot/src

    • Property svn:ignore
      •  

        old new  
        2121psphotForced
        2222psphotMakePSF
         23psphotStack
  • trunk/psphot/src/psphotStackReadout.c

    r26894 r27657  
    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    // This finds the detections on Chisq image as well as the individuals
     62    if (!psphotFindDetections (config, view, true)) { // pass 1
     63        // this only happens if we had an error in psphotFindDetections
     64        psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis");
     65        return psphotReadoutCleanup (config, view);
    5066    }
    5167
    52     // construct sources and measure basic stats
    53     psArray *sources = psphotSourceStats (config, readout, detections, true);
    54     if (!sources) return false;
    55     if (!strcasecmp (breakPt, "PEAKS")) {
    56         return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources);
     68    // construct sources and measure basic stats (saved on detections->newSources)
     69    // only run this on detections from the input images, not chisq image
     70    if (!psphotSourceStats (config, view, true)) { // pass 1
     71        psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources");
     72        return psphotReadoutCleanup (config, view);
    5773    }
    5874
    59     // find blended neighbors of very saturated stars
    60     // XXX merge this with Basic Deblend?
    61     psphotDeblendSatstars (readout, sources, recipe);
     75    // *** generate the objects (which unify the sources from the different images)
     76    psArray *objects = psphotMatchSources (config, view);
    6277
    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);
     78    // construct sources for the newly-generated sources (from other images)
     79    if (!psphotSourceStats (config, view, false)) { // pass 1
     80        psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources");
     81        return psphotReadoutCleanup (config, view);
    6782    }
    6883
     84    // find blended neighbors of very saturated stars (detections->newSources)
     85    // if (!psphotDeblendSatstars (config, view)) {
     86    //     psError (PSPHOT_ERR_UNKNOWN, false, "failed on satstar deblend analysis");
     87    //     return psphotReadoutCleanup (config, view);
     88    // }
     89
     90    // mark blended peaks PS_SOURCE_BLEND (detections->newSources)
     91    // if (!psphotBasicDeblend (config, view)) {
     92    //     psError (PSPHOT_ERR_UNKNOWN, false, "failed on deblend analysis");
     93    //     return psphotReadoutCleanup (config, view);
     94    // }
     95
    6996    // 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);
     97    // only run this on detections from the input images, not chisq image
     98    if (!psphotRoughClass (config, view)) {
     99        psError (PSPHOT_ERR_UNKNOWN, false, "failed to determine rough classifications");
     100        return psphotReadoutCleanup (config, view);
     101    }
     102    // if we were not supplied a PSF model, determine the IQ stats here (detections->newSources)
     103    // only run this on detections from the input images, not chisq image
     104    if (!psphotImageQuality (config, view)) { // pass 1
     105        psError (PSPHOT_ERR_UNKNOWN, false, "failed to measure image quality");
     106        return psphotReadoutCleanup(config, view);
    73107    }
    74108    if (!strcasecmp (breakPt, "MOMENTS")) {
    75         return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources);
     109        return psphotReadoutCleanup (config, view);
    76110    }
    77111
    78     if (!havePSF && !psphotImageQuality (recipe, sources)) {
    79         psLogMsg("psphot", 3, "failed to measure image quality");
    80         return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources);
     112    // use bright stellar objects to measure PSF if we were supplied a PSF for any input file,
     113    // this step is skipped
     114    if (!psphotChoosePSF (config, view)) { // pass 1
     115        psLogMsg ("psphot", 3, "failure to construct a psf model");
     116        return psphotReadoutCleanup (config, view);
     117    }
     118    if (!strcasecmp (breakPt, "PSFMODEL")) {
     119        return psphotReadoutCleanup (config, view);
    81120    }
    82121
    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 
    100122    // include externally-supplied sources
    101     psphotLoadExtSources (config, view, sources);
     123    // XXX fix this in the new multi-input context
     124    // psphotLoadExtSources (config, view); // pass 1
    102125
    103126    // construct an initial model for each object, set the radius to fitRadius, set circular fit mask
    104     psphotGuessModels (config, readout, sources, psf);
     127    psphotGuessModels (config, view);
     128
     129    // merge the newly selected sources into the existing list
     130    // NOTE: merge OLD and NEW
     131    psphotMergeSources (config, view);
    105132
    106133    // 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);
     134    psphotFitSourcesLinearStack (config, objects, FALSE);
     135    psFree (objects);
    112136
    113137    // 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);
     138    psphotSourceSize (config, view, TRUE);
    180139
    181140    // measure aperture photometry corrections
    182     if (!psphotApResid (config, readout, sources, psf)) {
     141    if (!psphotApResid (config, view)) {
    183142        psLogMsg ("psphot", 3, "failed on psphotApResid");
    184         return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);
     143        return psphotReadoutCleanup (config, view);
    185144    }
    186145
    187146    // calculate source magnitudes
    188     psphotMagnitudes(config, readout, view, sources, psf);
     147    psphotMagnitudes(config, view);
    189148
    190     if (!psphotEfficiency(config, readout, view, psf, recipe, sources)) {
     149    if (!psphotEfficiency(config, view)) {
    191150        psErrorStackPrint(stderr, "Unable to determine detection efficiencies from fake sources");
    192151        psErrorClear();
     
    200159
    201160    // drop the references to the image pixels held by each source
    202     psphotSourceFreePixels (sources);
     161    psphotSourceFreePixels (config, view);
     162
     163    // remove chisq image from config->file:PSPHOT.INPUT (why?)
     164    psphotStackRemoveChisqFromInputs(config);
    203165
    204166    // create the exported-metadata and free local data
    205     return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources);
     167    return psphotReadoutCleanup (config, view);
    206168}
    207169
Note: See TracChangeset for help on using the changeset viewer.