IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 21108


Ignore:
Timestamp:
Jan 12, 2009, 4:14:01 PM (17 years ago)
Author:
Paul Price
Message:

Adding API for background model calculation that doesn't require definition of pmFPAfiles.

Location:
trunk/psphot/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/psphot.h

    r20938 r21108  
    213213bool psphotKapaClose ();
    214214bool psphotImageBackgroundCellHistogram (psVector *values, float mean, float sigma, int ix, int iy);
    215 bool psphotDiagnosticPlots (pmConfig *config, char *name, ...);
     215bool psphotDiagnosticPlots (const pmConfig *config, const char *name, ...);
    216216
    217217bool psphotMakeFluxScale (psImage *image, psMetadata *recipe, pmPSF *psf);
     
    222222int psphotSupplementStars (psArray *stars, psArray *sources, psImageBinning *binning, int ix, int iy);
    223223
     224
     225// Create a background model for a readout
     226// Essentially identical to psphotModelBackground, but with a more convenient API for outsiders.
     227psImage *psphotBackgroundModel(pmReadout *ro, // Readout for which to generate background model
     228                               const pmConfig *config // Configuration
     229    );
     230
     231
    224232#endif
  • trunk/psphot/src/psphotDiagnosticPlots.c

    r18846 r21108  
    135135}
    136136
    137 bool psphotDiagnosticPlots (pmConfig *config, char *name, ...) {
     137bool psphotDiagnosticPlots (const pmConfig *config, const char *name, ...) {
    138138
    139139    va_list argPtr;
  • trunk/psphot/src/psphotModelBackground.c

    r20770 r21108  
    11# include "psphotInternal.h"
    22static int npass = 0;
    3 
    4 // generate the median in NxN boxes, clipping heavily
    5 // linear interpolation to generate full-scale model
    6 bool psphotModelBackground (pmConfig *config, const pmFPAview *view, const char *filename)
     3static char *defaultStatsName = "FITTED_MEAN";
     4
     5// Determine the binning characteristics for the background model
     6// Sets the ruff image size and skip based on recipe values for the binning
     7static psImageBinning *backgroundBinning(const psImage *image, // Image for which to generate a bg model
     8                                         const pmConfig *config // Configuration
     9                                         )
    710{
    811    bool status = true;
    9     static char *defaultStatsName = "FITTED_MEAN";
    10 
     12
     13    // select the appropriate recipe information
     14    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE);
     15    assert (recipe);
     16
     17    // I have the fine image size, I know the binning factor, determine the ruff image size
     18    psImageBinning *binning = psImageBinningAlloc();
     19    binning->nXfine = image->numCols;
     20    binning->nYfine = image->numRows;
     21    binning->nXbin  = psMetadataLookupS32(&status, recipe, "BACKGROUND.XBIN");
     22    binning->nYbin  = psMetadataLookupS32(&status, recipe, "BACKGROUND.YBIN");
     23
     24    psImageBinningSetRuffSize(binning, PS_IMAGE_BINNING_CENTER);
     25    psImageBinningSetSkip(binning, image);
     26
     27    return binning;
     28}
     29
     30// Generate the background model
     31static bool backgroundModel(psImage *model,  // Model image
     32                            psImage *modelStdev, // Model stdev image
     33                            psImage *image, // Image for which to generate a background model
     34                            psImage *mask, // Mask for image
     35                            psImageBinning *binning, // Binning parameters
     36                            const pmConfig *config // Configuration
     37                            )
     38{
    1139    psTimerStart ("psphot.background");
    1240
    13     // find the currently selected readout
    14     pmFPAfile *file = psMetadataLookupPtr (&status, config->files, filename);
    15     pmFPA *inFPA = file->fpa;
    16     pmReadout *readout = pmFPAviewThisReadout (view, inFPA);
    17     psImage *image = readout->image;
    18     psImage *mask  = readout->mask;
     41    bool status = true;
    1942
    2043    // select the appropriate recipe information
     
    116139    *statsDefaults = *stats;
    117140
    118     // I have the fine image size, I know the binning factor, determine the ruff image size
    119     psImageBinning *binning = psImageBinningAlloc();
    120     binning->nXfine = image->numCols;
    121     binning->nYfine = image->numRows;
    122     binning->nXbin  = psMetadataLookupS32 (&status, recipe, "BACKGROUND.XBIN");
    123     binning->nYbin  = psMetadataLookupS32 (&status, recipe, "BACKGROUND.YBIN");
    124 
    125     psImageBinningSetRuffSize(binning, PS_IMAGE_BINNING_CENTER);
    126     psImageBinningSetSkip(binning, image);
     141    // we save the binning structure for use in psphotMagnitudes
    127142    status = psMetadataAddPtr(recipe, PS_LIST_TAIL, "PSPHOT.BACKGROUND.BINNING", PS_DATA_UNKNOWN | PS_META_REPLACE, "Background binning", binning);
    128143    PS_ASSERT (status, false);
    129144
    130     // we save the binning structure for use in psphotMagnitudes
    131     pmReadout *model      = pmFPAGenerateReadout (config, view, "PSPHOT.BACKMDL",       inFPA, binning);
    132     pmReadout *modelStdev = pmFPAGenerateReadout (config, view, "PSPHOT.BACKMDL.STDEV", inFPA, binning);
    133 
    134     psF32 **modelData = model->image->data.F32;
    135     psF32 **modelStdevData = modelStdev->image->data.F32;
     145
     146    psF32 **modelData = model->data.F32;
     147    psF32 **modelStdevData = modelStdev->data.F32;
    136148
    137149    // XXXX we can thread this here by running blocks in parallel
     
    140152    psRegion ruffRegion = {0,0,0,0};
    141153    psRegion fineRegion = {0,0,0,0};
    142     for (int iy = 0; iy < model->image->numRows; iy++) {
    143         for (int ix = 0; ix < model->image->numCols; ix++) {
     154    for (int iy = 0; iy < model->numRows; iy++) {
     155        for (int ix = 0; ix < model->numCols; ix++) {
    144156
    145157            // convert the ruff grid cell to the equivalent fine grid cell
     
    229241        char name[256];
    230242        sprintf (name, "backraw.%02d.fits", npass);
    231         psphotSaveImage (NULL, model->image, name);
     243        psphotSaveImage (NULL, model, name);
    232244    }
    233245
     
    237249    double Value = 0;                   // sum of good pixel's value
    238250    double ValueStdev = 0;              // sum of good pixel's standard deviations
    239     for (int iy = 0; iy < model->image->numRows; iy++) {
    240         for (int ix = 0; ix < model->image->numCols; ix++) {
     251    for (int iy = 0; iy < model->numRows; iy++) {
     252        for (int ix = 0; ix < model->numCols; ix++) {
    241253            if (!isnan(modelData[iy][ix])) {
    242254                Value += modelData[iy][ix];
     
    250262            for (int jy = iy - 1; jy <= iy + 1; jy++) {
    251263                if (jy <   0) continue;
    252                 if (jy >= model->image->numRows) continue;
     264                if (jy >= model->numRows) continue;
    253265                for (int jx = ix - 1; jx <= ix + 1; jx++) {
    254266                    if (!jx && !jy) continue;
    255267                    if (jx   <   0) continue;
    256                     if (jx   >= model->image->numCols) continue;
     268                    if (jx   >= model->numCols) continue;
    257269                    value += modelData[jy][jx];
    258270                    count += 1.0;
     
    275287
    276288    // patch over remaining bad regions (use global average)
    277     for (int iy = 0; iy < model->image->numRows; iy++) {
    278         for (int ix = 0; ix < model->image->numCols; ix++) {
     289    for (int iy = 0; iy < model->numRows; iy++) {
     290        for (int ix = 0; ix < model->numCols; ix++) {
    279291            if (!isnan(modelData[iy][ix])) continue;
    280292            modelData[iy][ix] = Value;
     
    294306                                      PS_STAT_MIN |
    295307                                      PS_STAT_MAX);
    296     psImageStats (statsBck, model->image, NULL, 0);
     308    psImageStats (statsBck, model, NULL, 0);
    297309    psMetadataAddF32 (recipe, PS_LIST_TAIL, "MSKY_MN",
    298310                      PS_META_REPLACE, "sky model mean",          statsBck->sampleMean);
     
    304316                      PS_META_REPLACE, "sky model minimum value", statsBck->min);
    305317    psMetadataAddS32 (recipe, PS_LIST_TAIL, "MSKY_NX",
    306                       PS_META_REPLACE, "sky model size (x)",      model->image->numCols);
     318                      PS_META_REPLACE, "sky model size (x)",      model->numCols);
    307319    psMetadataAddS32 (recipe, PS_LIST_TAIL, "MSKY_NY",
    308                       PS_META_REPLACE, "sky model size (y)",      model->image->numRows);
     320                      PS_META_REPLACE, "sky model size (y)",      model->numRows);
    309321    psLogMsg ("psphot", PS_LOG_INFO, "background sky : min %f mean %f max %f stdev %f",
    310322              statsBck->min, statsBck->sampleMean, statsBck->max, statsBck->sampleStdev);
     
    316328    psFree(rng);
    317329
     330    return model;
     331}
     332
     333
     334
     335psImage *psphotBackgroundModel(pmReadout *ro, const pmConfig *config)
     336{
     337    PM_ASSERT_READOUT_NON_NULL(ro, NULL);
     338    PM_ASSERT_READOUT_IMAGE(ro, NULL);
     339    PS_ASSERT_PTR_NON_NULL(config, NULL);
     340
     341    psImageBinning *binning = backgroundBinning(ro->image, config); // Image binning parameters
     342    psImage *model = psImageAlloc(binning->nXruff, binning->nYruff, PS_TYPE_F32); // Background model
     343    psImage *modelStdev = psImageAlloc(binning->nXruff, binning->nYruff, PS_TYPE_F32); // Standard deviation
     344
     345    if (!backgroundModel(model, modelStdev, ro->image, ro->mask, binning, config)) {
     346        psFree(model);
     347        psFree(modelStdev);
     348        psError(PS_ERR_UNKNOWN, false, "Unable to generate background model");
     349        return NULL;
     350    }
     351
     352    psFree(modelStdev);
     353
     354    return model;
     355}
     356
     357
     358// generate the median in NxN boxes, clipping heavily
     359// linear interpolation to generate full-scale model
     360bool psphotModelBackground (pmConfig *config, const pmFPAview *view, const char *filename)
     361{
     362    bool status = true;
     363
     364    // find the currently selected readout
     365    pmFPAfile *file = psMetadataLookupPtr (&status, config->files, filename);
     366    pmFPA *inFPA = file->fpa;
     367    pmReadout *readout = pmFPAviewThisReadout (view, inFPA);
     368    psImage *image = readout->image;
     369    psImage *mask  = readout->mask;
     370
     371    psImageBinning *binning = backgroundBinning(image, config); // Image binning parameters
     372    pmReadout *model = pmFPAGenerateReadout(config, view, "PSPHOT.BACKMDL", inFPA, binning);
     373    pmReadout *modelStdev = pmFPAGenerateReadout(config, view, "PSPHOT.BACKMDL.STDEV", inFPA, binning);
     374
     375    if (!backgroundModel(model->image, modelStdev->image, image, mask, binning, config)) {
     376        psError(PS_ERR_UNKNOWN, false, "Unable to generate background model");
     377        return false;
     378    }
     379
    318380    npass ++;
    319381    return true;
Note: See TracChangeset for help on using the changeset viewer.