IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 10, 2010, 7:36:29 PM (16 years ago)
Author:
eugene
Message:

updates from eam_branches/20091201 (substantially changes to the psphotReadout APIs to support future stack photometry; improvements to the CR masking code)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/psphotModelBackground.c

    r26452 r26894  
    3030
    3131// Generate the background model
    32 static bool backgroundModel(psImage *model,  // Model image
    33                             psImage *modelStdev, // Model stdev image
    34                             psMetadata *analysis, // Analysis metadata for outputs
    35                             pmReadout *readout, // Readout for which to generate a background model
    36                             psImageBinning *binning, // Binning parameters
    37                             const pmConfig *config // Configuration
    38                             )
     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    )
    3946{
    4047    psTimerStart ("psphot.background");
     
    138145
    139146    // we save the binning structure for use in psphotMagnitudes
    140     psMetadataAddPtr(analysis, PS_LIST_TAIL, "PSPHOT.BACKGROUND.BINNING",
    141                      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);
    142148
    143149    psF32 **modelData = model->data.F32;
     
    304310    psLogMsg ("psphot", PS_LOG_INFO, "built background image: %f sec\n", psTimerMark ("psphot.background"));
    305311
    306     psMetadataAddF32(recipe, PS_LIST_TAIL, "SKY_MEAN", PS_META_REPLACE, "sky mean", Value);
    307     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);
    308314    psLogMsg ("psphot", PS_LOG_INFO, "image sky : mean %f stdev %f", Value, ValueStdev);
    309315
     
    314320                                      PS_STAT_MAX);
    315321    psImageStats (statsBck, model, NULL, 0);
    316     psMetadataAddF32 (recipe, PS_LIST_TAIL, "MSKY_MN",
    317                       PS_META_REPLACE, "sky model mean",          statsBck->sampleMean);
    318     psMetadataAddF32 (recipe, PS_LIST_TAIL, "MSKY_SIG",
    319                       PS_META_REPLACE, "sky model stdev",         statsBck->sampleStdev);
    320     psMetadataAddF32 (recipe, PS_LIST_TAIL, "MSKY_MAX",
    321                       PS_META_REPLACE, "sky model maximum value", statsBck->max);
    322     psMetadataAddF32 (recipe, PS_LIST_TAIL, "MSKY_MIN",
    323                       PS_META_REPLACE, "sky model minimum value", statsBck->min);
    324     psMetadataAddS32 (recipe, PS_LIST_TAIL, "MSKY_NX",
    325                       PS_META_REPLACE, "sky model size (x)",      model->numCols);
    326     psMetadataAddS32 (recipe, PS_LIST_TAIL, "MSKY_NY",
    327                       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);
    328328    psLogMsg ("psphot", PS_LOG_INFO, "background sky : min %f mean %f max %f stdev %f",
    329329              statsBck->min, statsBck->sampleMean, statsBck->max, statsBck->sampleStdev);
     
    338338}
    339339
    340 
    341 
    342 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)
    343342{
    344     PM_ASSERT_READOUT_NON_NULL(ro, NULL);
    345     PM_ASSERT_READOUT_IMAGE(ro, NULL);
     343    PM_ASSERT_READOUT_NON_NULL(readout, NULL);
     344    PM_ASSERT_READOUT_IMAGE(readout, NULL);
    346345    PS_ASSERT_PTR_NON_NULL(config, NULL);
    347346
    348     psImageBinning *binning = psphotBackgroundBinning(ro->image, config); // Image binning parameters
     347    psImageBinning *binning = psphotBackgroundBinning(readout->image, config); // Image binning parameters
    349348    psImage *model = psImageAlloc(binning->nXruff, binning->nYruff, PS_TYPE_F32); // Background model
    350349    psImage *modelStdev = psImageAlloc(binning->nXruff, binning->nYruff, PS_TYPE_F32); // Standard deviation
    351350
    352     if (!backgroundModel(model, modelStdev, ro->analysis, ro, binning, config)) {
     351    if (!psphotModelBackgroundReadout(model, modelStdev, readout->analysis, readout, binning, config)) {
    353352        psFree(model);
    354353        psFree(modelStdev);
     
    356355        return NULL;
    357356    }
    358 
    359357    psFree(modelStdev);
    360 
    361358    return model;
    362359}
    363360
    364 
    365 // generate the median in NxN boxes, clipping heavily
    366 // linear interpolation to generate full-scale model
    367 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)
    368363{
    369     bool status = true;
    370 
    371364    // find the currently selected readout
    372     pmFPAfile *file = psMetadataLookupPtr (&status, config->files, filename);
     365    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest
     366    psAssert (file, "missing file?");
     367
    373368    pmFPA *inFPA = file->fpa;
    374369    pmReadout *readout = pmFPAviewThisReadout(view, inFPA);
     370    psAssert (readout, "missing readout?");
    375371
    376372    psImageBinning *binning = psphotBackgroundBinning(readout->image, config); // Image binning parameters
     
    378374    pmReadout *modelStdev = pmFPAGenerateReadout(config, view, "PSPHOT.BACKMDL.STDEV", inFPA, binning);
    379375
    380     if (!backgroundModel(model->image, modelStdev->image, model->analysis, readout, binning, config)) {
     376    if (!psphotModelBackgroundReadout(model->image, modelStdev->image, model->analysis, readout, binning, config)) {
    381377        psError(PS_ERR_UNKNOWN, false, "Unable to generate background model");
    382378        return false;
     
    386382    return true;
    387383}
     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.