IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 20, 2008, 7:32:37 PM (18 years ago)
Author:
eugene
Message:

allow model or fixed value for masked-replacement

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppImage/src/ppImageReplaceBackground.c

    r18217 r18255  
    44
    55# include "ppImage.h"
     6
     7enum {MODE_NONE, MODE_MODEL, MODE_VALUE};
    68
    79// In this function, we perform the psphot analysis routine for the chip-mosaicked images
     
    1921    }
    2022
    21     // find the model data, if it exists yet (if not, we build it below)
    22     pmFPAfile *modelFile = psMetadataLookupPtr(&status, config->files, "PSPHOT.BACKMDL");
     23    // select the appropriate recipe information
     24    psMetadata *ppImageRecipe  = psMetadataLookupPtr (&status, config->recipes, "PPIMAGE");
    2325
    24     // select the appropriate recipe information
    25     psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE);
     26    // select the appropriate recipe information (needed by psphotModelBackground)
     27    psMetadata *psphotRecipe  = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE);
     28
     29    char *replaceSkyModeWord = psMetadataLookupStr (&status, ppImageRecipe, "REPLACE.MODE");
     30    float replaceSkyValue = 0.0;
     31
     32    int replaceSkyMode = MODE_NONE;
     33    if (!strcasecmp (replaceSkyModeWord, "MODEL")) {
     34        replaceSkyMode = MODE_MODEL;
     35    }
     36    if (!strcasecmp (replaceSkyModeWord, "VALUE")) {
     37        replaceSkyMode = MODE_VALUE;
     38        replaceSkyValue = psMetadataLookupF32 (&status, ppImageRecipe, "REPLACE.VALUE");
     39    }
     40    psAssert (replaceSkyMode != MODE_NONE, "replace sky mode not defined");
    2641
    2742    // define the mask value to be used in ppImage
    2843    psMaskType maskVal  = options->satMask | options->badMask | options->flatMask | options->blankMask;
    2944
    30     // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
    31     psMetadataAddU8 (recipe, PS_LIST_TAIL, "MASK.PSPHOT", PS_META_REPLACE, "user-defined mask", maskVal);
     45    pmFPAfile *modelFile = NULL;
     46    if (replaceSkyMode == MODE_MODEL) {
     47        // find the model data, if it exists yet (if not, we build it below)
     48        modelFile = psMetadataLookupPtr(&status, config->files, "PSPHOT.BACKMDL");
    3249
    33     float meanValue = psMetadataLookupF32 (&status, recipe, "SKY_MEAN");
    34     bool replaceSkyMean = psMetadataLookupBool (&status, recipe, "REPLACE.SKY_MEAN");
     50        // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
     51        psMetadataAddU8 (psphotRecipe, PS_LIST_TAIL, "MASK.PSPHOT", PS_META_REPLACE, "user-defined mask", maskVal);
     52    }
    3553
    3654    // iterate over the cells and readout for this chip
     
    4563
    4664            // replace masked pixels with values from model (unbinning not needed)
    47 
    48             // we are using this pmFPAfile as an I/O file: select readout or create
    4965            pmReadout *modelReadout = NULL;
    50             if (modelFile) {
    51                 modelReadout = pmFPAviewThisReadout (view, modelFile->fpa);
     66            psImageBinning *binning = NULL;
     67            psImage *model = NULL;
     68            if (replaceSkyMode == MODE_MODEL) {
     69                // we are using this pmFPAfile as an I/O file: select readout or create
     70                if (modelFile) {
     71                    modelReadout = pmFPAviewThisReadout (view, modelFile->fpa);
     72                }
     73                if (!modelReadout) {
     74                    psphotModelBackground (config, view, "PPIMAGE.CHIP");
     75                    modelFile = psMetadataLookupPtr(&status, config->files, "PSPHOT.BACKMDL");
     76                    assert (modelFile);
     77                    if (modelFile->mode == PM_FPA_MODE_INTERNAL) {
     78                        modelReadout = modelFile->readout;
     79                    } else {
     80                        modelReadout = pmFPAviewThisReadout (view, modelFile->fpa);
     81                    }
     82                    assert (modelReadout);
     83                }
     84                binning = psMetadataLookupPtr(&status, psphotRecipe, "PSPHOT.BACKGROUND.BINNING");
     85                model = modelReadout->image;
    5286            }
    53             if (!modelReadout) {
    54                 psphotModelBackground (config, view, "PPIMAGE.CHIP");
    55                 modelFile = psMetadataLookupPtr(&status, config->files, "PSPHOT.BACKMDL");
    56                 assert (modelFile);
    57                 if (modelFile->mode == PM_FPA_MODE_INTERNAL) {
    58                   modelReadout = modelFile->readout;
    59                 } else {
    60                   modelReadout = pmFPAviewThisReadout (view, modelFile->fpa);
    61                 }
    62                 assert (modelReadout);
    63             }
    64 
    65             psImageBinning *binning = psMetadataLookupPtr(&status, recipe, "PSPHOT.BACKGROUND.BINNING");
    6687
    6788            psImage *mask = readout->mask;
    6889            psImage *image = readout->image;
    69             psImage *model = modelReadout->image;
    7090
    7191            for (int iy = 0; iy < image->numRows; iy++) {
    7292                for (int ix = 0; ix < image->numCols; ix++) {
    7393                    if (!(mask->data.U8[iy][ix] && maskVal)) continue;
    74                     if (replaceSkyMean) {
    75                         image->data.F32[iy][ix] = meanValue;
     94                    if (replaceSkyMode == MODE_MODEL) {
     95                        image->data.F32[iy][ix] = psImageUnbinPixel_V2(ix, iy, model, binning);
    7696                    } else {
    77                         image->data.F32[iy][ix] = psImageUnbinPixel_V2(ix, iy, model, binning);
     97                        image->data.F32[iy][ix] = replaceSkyValue;
    7898                    }
    7999                }
     
    81101        }
    82102    }
    83     pmFPAfileDropInternal (config->files, "PSPHOT.BACKMDL");
    84     pmFPAfileDropInternal (config->files, "PSPHOT.BACKMDL.STDEV");
     103
     104    if (replaceSkyMode == MODE_MODEL) {
     105        pmFPAfileDropInternal (config->files, "PSPHOT.BACKMDL");
     106        pmFPAfileDropInternal (config->files, "PSPHOT.BACKMDL.STDEV");
     107    }
     108
    85109    return true;
    86110}
Note: See TracChangeset for help on using the changeset viewer.