IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 3, 2010, 8:41:49 AM (16 years ago)
Author:
eugene
Message:

updates from trunk

Location:
branches/tap_branches
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/tap_branches

  • branches/tap_branches/psphot

  • branches/tap_branches/psphot/src

    • Property svn:ignore
      •  

        old new  
        1919psphotMomentsStudy
        2020psphotPetrosianStudy
         21psphotForced
         22psphotMakePSF
         23psphotStack
  • branches/tap_branches/psphot/src/psphotModelBackground.c

    r24188 r27838  
    55// Determine the binning characteristics for the background model
    66// Sets the ruff image size and skip based on recipe values for the binning
    7 static psImageBinning *backgroundBinning(const psImage *image, // Image for which to generate a bg model
     7psImageBinning *psphotBackgroundBinning(const psImage *image, // Image for which to generate a bg model
    88                                         const pmConfig *config // Configuration
    99                                         )
     
    2828}
    2929
     30
    3031// Generate the background model
    31 static bool backgroundModel(psImage *model,  // Model image
    32                             psImage *modelStdev, // Model stdev image
    33                             psMetadata *analysis, // Analysis metadata for outputs
    34                             pmReadout *readout, // Readout for which to generate a background model
    35                             psImageBinning *binning, // Binning parameters
    36                             const pmConfig *config // Configuration
    37                             )
     32// generate the median in NxN boxes, clipping heavily
     33// linear interpolation to generate full-scale model
     34//
     35// NOTE that the 'analysis' metedata pass in here is used to store the binning information.
     36// This may be the analysis for this readout, but it may be the analysis for the pmFPAfile
     37// corresponding to the model.  Other information about the background model is saved on the
     38// readout->analysis
     39static bool psphotModelBackgroundReadout(psImage *model,  // Model image
     40                                  psImage *modelStdev, // Model stdev image
     41                                  psMetadata *analysis, // Analysis metadata for outputs
     42                                  pmReadout *readout, // Readout for which to generate a background model
     43                                  psImageBinning *binning, // Binning parameters
     44                                  const pmConfig *config // Configuration
     45    )
    3846{
    3947    psTimerStart ("psphot.background");
     
    137145
    138146    // we save the binning structure for use in psphotMagnitudes
    139     psMetadataAddPtr(analysis, PS_LIST_TAIL, "PSPHOT.BACKGROUND.BINNING",
    140                      PS_DATA_UNKNOWN | PS_META_REPLACE, "Background binning", binning);
     147    psMetadataAddPtr(analysis, PS_LIST_TAIL, "PSPHOT.BACKGROUND.BINNING", PS_DATA_UNKNOWN | PS_META_REPLACE, "Background binning", binning);
    141148
    142149    psF32 **modelData = model->data.F32;
     
    144151
    145152    // XXXX we can thread this here by running blocks in parallel
     153
     154    int nFailures = 0;
     155    psImageBackgroundInit();
    146156
    147157    // measure clipped median for subimages
     
    211221                stats->options = PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV;
    212222                if (!psImageBackground(stats, &sample, subset, submask, maskVal, rng)) {
    213                     psLogMsg ("psphot", PS_LOG_WARN, "Failed to estimate background using ROBUST_MEDIAN for "
    214                                "(%dx%d, (row0,col0) = (%d,%d)",
    215                                subset->numRows, subset->numCols, subset->row0, subset->col0);
     223                    if ((nFailures < 3) || (nFailures % 100 == 0)) {
     224                        psLogMsg ("psphot", PS_LOG_WARN, "Failed to estimate background using ROBUST_MEDIAN for "
     225                                  "(%dx%d, (row0,col0) = (%d,%d)",
     226                                  subset->numRows, subset->numCols, subset->row0, subset->col0);
     227                    }
     228                    nFailures ++;
    216229                    modelData[iy][ix] = modelStdevData[iy][ix] = NAN;
    217230                } else {
     
    232245            psFree (submask);
    233246        }
     247    }
     248
     249    if (nFailures) {
     250        psLogMsg ("psphot", PS_LOG_WARN, "Failed to estimate background for %d of %d subimages", nFailures, (model->numRows*model->numCols));
    234251    }
    235252
     
    293310    psLogMsg ("psphot", PS_LOG_INFO, "built background image: %f sec\n", psTimerMark ("psphot.background"));
    294311
    295     psMetadataAddF32(recipe, PS_LIST_TAIL, "SKY_MEAN", PS_META_REPLACE, "sky mean", Value);
    296     psMetadataAddF32(recipe, PS_LIST_TAIL, "SKY_STDEV", PS_META_REPLACE, "sky stdev", ValueStdev);
     312    psMetadataAddF32(readout->analysis, PS_LIST_TAIL, "SKY_MEAN", PS_META_REPLACE, "sky mean", Value);
     313    psMetadataAddF32(readout->analysis, PS_LIST_TAIL, "SKY_STDEV", PS_META_REPLACE, "sky stdev", ValueStdev);
    297314    psLogMsg ("psphot", PS_LOG_INFO, "image sky : mean %f stdev %f", Value, ValueStdev);
    298315
     
    303320                                      PS_STAT_MAX);
    304321    psImageStats (statsBck, model, NULL, 0);
    305     psMetadataAddF32 (recipe, PS_LIST_TAIL, "MSKY_MN",
    306                       PS_META_REPLACE, "sky model mean",          statsBck->sampleMean);
    307     psMetadataAddF32 (recipe, PS_LIST_TAIL, "MSKY_SIG",
    308                       PS_META_REPLACE, "sky model stdev",         statsBck->sampleStdev);
    309     psMetadataAddF32 (recipe, PS_LIST_TAIL, "MSKY_MAX",
    310                       PS_META_REPLACE, "sky model maximum value", statsBck->max);
    311     psMetadataAddF32 (recipe, PS_LIST_TAIL, "MSKY_MIN",
    312                       PS_META_REPLACE, "sky model minimum value", statsBck->min);
    313     psMetadataAddS32 (recipe, PS_LIST_TAIL, "MSKY_NX",
    314                       PS_META_REPLACE, "sky model size (x)",      model->numCols);
    315     psMetadataAddS32 (recipe, PS_LIST_TAIL, "MSKY_NY",
    316                       PS_META_REPLACE, "sky model size (y)",      model->numRows);
     322    psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "MSKY_MN", PS_META_REPLACE, "sky model mean",          statsBck->sampleMean);
     323    psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "MSKY_SIG", PS_META_REPLACE, "sky model stdev",         statsBck->sampleStdev);
     324    psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "MSKY_MAX", PS_META_REPLACE, "sky model maximum value", statsBck->max);
     325    psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "MSKY_MIN", PS_META_REPLACE, "sky model minimum value", statsBck->min);
     326    psMetadataAddS32 (readout->analysis, PS_LIST_TAIL, "MSKY_NX", PS_META_REPLACE, "sky model size (x)",      model->numCols);
     327    psMetadataAddS32 (readout->analysis, PS_LIST_TAIL, "MSKY_NY", PS_META_REPLACE, "sky model size (y)",      model->numRows);
    317328    psLogMsg ("psphot", PS_LOG_INFO, "background sky : min %f mean %f max %f stdev %f",
    318329              statsBck->min, statsBck->sampleMean, statsBck->max, statsBck->sampleStdev);
     
    327338}
    328339
    329 
    330 
    331 psImage *psphotBackgroundModel(pmReadout *ro, const pmConfig *config)
     340// generate a background model for a single readout. do not save an associated pmFPAfile for possible output
     341psImage *psphotModelBackgroundReadoutNoFile(pmReadout *readout, const pmConfig *config)
    332342{
    333     PM_ASSERT_READOUT_NON_NULL(ro, NULL);
    334     PM_ASSERT_READOUT_IMAGE(ro, NULL);
     343    PM_ASSERT_READOUT_NON_NULL(readout, NULL);
     344    PM_ASSERT_READOUT_IMAGE(readout, NULL);
    335345    PS_ASSERT_PTR_NON_NULL(config, NULL);
    336346
    337     psImageBinning *binning = backgroundBinning(ro->image, config); // Image binning parameters
     347    psImageBinning *binning = psphotBackgroundBinning(readout->image, config); // Image binning parameters
    338348    psImage *model = psImageAlloc(binning->nXruff, binning->nYruff, PS_TYPE_F32); // Background model
    339349    psImage *modelStdev = psImageAlloc(binning->nXruff, binning->nYruff, PS_TYPE_F32); // Standard deviation
    340350
    341     if (!backgroundModel(model, modelStdev, ro->analysis, ro, binning, config)) {
     351    if (!psphotModelBackgroundReadout(model, modelStdev, readout->analysis, readout, binning, config)) {
    342352        psFree(model);
    343353        psFree(modelStdev);
     
    345355        return NULL;
    346356    }
    347 
    348357    psFree(modelStdev);
    349 
    350358    return model;
    351359}
    352360
    353 
    354 // generate the median in NxN boxes, clipping heavily
    355 // linear interpolation to generate full-scale model
    356 bool psphotModelBackground (pmConfig *config, const pmFPAview *view, const char *filename)
     361// generate a background model for readout number index; save an associated pmFPAfile for possible output
     362bool psphotModelBackgroundReadoutFileIndex (pmConfig *config, const pmFPAview *view, const char *filename, int index)
    357363{
    358     bool status = true;
    359 
    360364    // find the currently selected readout
    361     pmFPAfile *file = psMetadataLookupPtr (&status, config->files, filename);
     365    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest
     366    psAssert (file, "missing file?");
     367
    362368    pmFPA *inFPA = file->fpa;
    363369    pmReadout *readout = pmFPAviewThisReadout(view, inFPA);
    364 
    365     psImageBinning *binning = backgroundBinning(readout->image, config); // Image binning parameters
    366     pmReadout *model = pmFPAGenerateReadout(config, view, "PSPHOT.BACKMDL", inFPA, binning);
    367     pmReadout *modelStdev = pmFPAGenerateReadout(config, view, "PSPHOT.BACKMDL.STDEV", inFPA, binning);
    368 
    369     if (!backgroundModel(model->image, modelStdev->image, model->analysis, readout, binning, config)) {
     370    psAssert (readout, "missing readout?");
     371
     372    psImageBinning *binning = psphotBackgroundBinning(readout->image, config); // Image binning parameters
     373    pmReadout *model = pmFPAGenerateReadout(config, view, "PSPHOT.BACKMDL", inFPA, binning, index);
     374    pmReadout *modelStdev = pmFPAGenerateReadout(config, view, "PSPHOT.BACKMDL.STDEV", inFPA, binning, index);
     375
     376    if (!psphotModelBackgroundReadout(model->image, modelStdev->image, model->analysis, readout, binning, config)) {
    370377        psError(PS_ERR_UNKNOWN, false, "Unable to generate background model");
    371378        return false;
     
    375382    return true;
    376383}
     384
     385// XXX supply filename or keep PSPHOT.INPUT fixed?
     386bool psphotModelBackground (pmConfig *config, const pmFPAview *view)
     387{
     388    bool status = false;
     389
     390    int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
     391    psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     392
     393    // loop over the available readouts
     394    for (int i = 0; i < num; i++) {
     395        if (!psphotModelBackgroundReadoutFileIndex(config, view, "PSPHOT.INPUT", i)) {
     396            psError (PSPHOT_ERR_CONFIG, false, "failed to model background for PSPHOT.INPUT entry %d", i);
     397            return false;
     398        }
     399    }
     400    return true;
     401}
Note: See TracChangeset for help on using the changeset viewer.