IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 34528 for trunk/psphot


Ignore:
Timestamp:
Oct 8, 2012, 12:06:06 PM (14 years ago)
Author:
bills
Message:

Teach psphotStack how to output several optional output files.
For the background related ones we created a new function to
get the appropriate file rule based on whether the process is psphotStack
or not. If not it uses the PSPHOT.XXX filerules, otherwise it returns
the PSPHOT.STACK.XXX variant

Location:
trunk/psphot/src
Files:
10 edited

Legend:

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

    r34418 r34528  
    525525bool psphotSourceMemoryReadout(pmConfig *config, const pmFPAview *view, const char *filerule, int index);
    526526
     527const char * psphotGetFilerule(const char *baseRule);
     528extern bool psphotINpsphotStack;
     529
    527530#endif
  • trunk/psphot/src/psphotDefineFiles.c

    r33963 r34528  
    11# include "psphotInternal.h"
     2
     3bool psphotINpsphotStack = false;
    24
    35// List of output files
     
    181183    return;
    182184}
     185
     186// psphotGetFilerule
     187// Since psphotStack processes multipe FPAs at a time it has a different file rule structure than regular psphot.
     188// For the background output files we define a function psphotGetFilerule which given a base psphot file rule
     189// returns the corresponding psphotStack rule *if* the program is psphotStack. That is indicated by a global
     190// boolean which defaults to false, and psphotStack only sets to true
     191
     192const char *psphotGetFilerule(const char *psphotRule) {
     193    const char *rule = psphotRule;
     194    if (psphotINpsphotStack) {
     195        if (!strcmp(psphotRule, "PSPHOT.BACKMDL")) {
     196            rule =  "PSPHOT.STACK.BACKMDL";
     197        } else if (!strcmp(psphotRule, "PSPHOT.BACKMDL.STDEV")) {
     198            rule = "PSPHOT.STACK.BACKMDL.STDEV";
     199        } else if (!strcmp(psphotRule, "PSPHOT.BACKSUB")) {
     200            rule = "PSPHOT.STACK.BACKSUB";
     201        } else if (!strcmp(psphotRule, "PSPHOT.BACKGND")) {
     202            rule = "PSPHOT.STACK.BACKGND";
     203        } else {
     204            psAssert(0, "unsupported file rule %s", psphotRule);
     205        }
     206    }
     207    return rule;
     208}
  • trunk/psphot/src/psphotMaskBackground.c

    r31154 r34528  
    1717
    1818    // find the currently selected readout (XXX note that the model is saved on PSPHOT.BACKMDL regardless of 'filename'
    19     pmFPAfile *modelFile = pmFPAfileSelectSingle(config->files, "PSPHOT.BACKMDL", index); // File of interest
     19    pmFPAfile *modelFile = pmFPAfileSelectSingle(config->files, psphotGetFilerule("PSPHOT.BACKMDL"), index); // File of interest
    2020    assert (modelFile);
    2121
    22     pmFPAfile *stdevFile = pmFPAfileSelectSingle(config->files, "PSPHOT.BACKMDL.STDEV", index);
     22    pmFPAfile *stdevFile = pmFPAfileSelectSingle(config->files, psphotGetFilerule("PSPHOT.BACKMDL.STDEV"), index);
    2323    assert (stdevFile);
    2424
  • trunk/psphot/src/psphotModelBackground.c

    r33963 r34528  
    405405
    406406    psImageBinning *binning = psphotBackgroundBinning(readout->image, config); // Image binning parameters
    407     pmReadout *model = pmFPAGenerateReadout(config, view, "PSPHOT.BACKMDL", inFPA, binning, index);
    408     pmReadout *modelStdev = pmFPAGenerateReadout(config, view, "PSPHOT.BACKMDL.STDEV", inFPA, binning, index);
     407    pmReadout *model = pmFPAGenerateReadout(config, view, psphotGetFilerule("PSPHOT.BACKMDL"), inFPA, binning, index);
     408    pmReadout *modelStdev = pmFPAGenerateReadout(config, view, psphotGetFilerule("PSPHOT.BACKMDL.STDEV"), inFPA, binning, index);
    409409
    410410    if (!psphotModelBackgroundReadout(model->image, modelStdev->image, model->analysis, readout, binning, config, false)) {
  • trunk/psphot/src/psphotOutput.c

    r32695 r34528  
    3434   
    3535
    36     pmFPAfile *file = psMetadataLookupPtr (&status, config->files, "PSPHOT.BACKMDL");
     36    pmFPAfile *file = psMetadataLookupPtr (&status, config->files, psphotGetFilerule("PSPHOT.BACKMDL"));
    3737    if (!file) return NULL;
    3838
     
    4545    bool status;
    4646
    47     pmFPAfile *file = psMetadataLookupPtr (&status, config->files, "PSPHOT.BACKMDL.STDEV");
     47    pmFPAfile *file = psMetadataLookupPtr (&status, config->files, psphotGetFilerule("PSPHOT.BACKMDL.STDEV"));
    4848    if (!file) return NULL;
    4949
  • trunk/psphot/src/psphotSkyReplace.c

    r31673 r34528  
    3636
    3737    // select background pixels, from output background file, or create
    38     pmReadout *background = pmFPAfileThisReadout (config->files, view, "PSPHOT.BACKGND");
     38    pmReadout *background = pmFPAfileThisReadout (config->files, view, psphotGetFilerule("PSPHOT.BACKGND"));
    3939    if (background == NULL) psAbort("background not defined");
    4040
  • trunk/psphot/src/psphotStack.c

    r34283 r34528  
    22
    33int main (int argc, char **argv) {
     4
     5    // Set flag to tell certain library functions that we are in the psphotStack program.
     6    // (This is defined in psphotDefineFiles.c)
     7    psphotINpsphotStack = true;
    48
    59    // uncomment to turn on memory dumps (move this to an option)
  • trunk/psphot/src/psphotStackImageLoop.c

    r34429 r34528  
    4343    if (!needConvolved) {
    4444        pmFPAfileActivate (config->files, false, "PSPHOT.STACK.INPUT.CNV");
     45        pmFPAfileActivate (config->files, false, "PSPHOT.STACK.MASK.CNV");
     46        pmFPAfileActivate (config->files, false, "PSPHOT.STACK.VARIANCE.CNV");
     47        pmFPAfileActivate (config->files, false, "PSPHOT.STACK.PSF.CNV");
    4548    }
    4649
     
    97100            // drop all versions of the internal files
    98101            status = true;
    99             status &= pmFPAfileDropInternal (config->files, "PSPHOT.BACKMDL");
    100             status &= pmFPAfileDropInternal (config->files, "PSPHOT.BACKMDL.STDEV");
    101             status &= pmFPAfileDropInternal (config->files, "PSPHOT.BACKGND");
     102            status &= pmFPAfileDropInternal (config->files, psphotGetFilerule("PSPHOT.BACKMDL"));
     103            status &= pmFPAfileDropInternal (config->files, psphotGetFilerule("PSPHOT.BACKMDL.STDEV"));
     104            status &= pmFPAfileDropInternal (config->files, psphotGetFilerule("PSPHOT.BACKGND"));
    102105            if (!status) {
    103106                psError(PSPHOT_ERR_PROG, false, "trouble dropping internal files");
  • trunk/psphot/src/psphotStackParseCamera.c

    r33913 r34528  
    1414        return false;
    1515    }
     16
     17    // select the appropriate recipe information
     18    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE);
     19    bool savePSF = psMetadataLookupBool(&status, recipe, "SAVE.PSF");
     20    bool saveBackgroundModel = psMetadataLookupBool(&status, recipe, "SAVE.BACKMDL");
     21    bool saveBackground = psMetadataLookupBool(&status, recipe, "SAVE.BACKGND");
     22    bool saveBackSub = psMetadataLookupBool(&status, recipe, "SAVE.BACKSUB");
     23    bool saveResid = psMetadataLookupBool(&status, recipe, "SAVE.RESID");
     24
     25    bool saveCnv = psMetadataLookupBool(&status, recipe, "SAVE.CNV");
     26    bool saveChisq = psMetadataLookupBool(&status, recipe, "SAVE.CHISQ");
     27    bool useRaw = psMetadataLookupBool(&status, recipe, "PSPHOT.STACK.USE.RAW");
     28
    1629
    1730    int nRaw = 0;
     
    120133            }
    121134        }
     135        pmFPAfile *inputTemplate;
     136        if (useRaw) {
     137            inputTemplate = rawInputFile;
     138        } else {
     139            inputTemplate = cnvInputFile;
     140        }
     141        if (!inputTemplate) {
     142            psError(PS_ERR_UNKNOWN, true, "cannot determinte inputTemplate: USE.RAW: %d\n", useRaw);
     143            return false;
     144        }
    122145
    123146        psString sources = psMetadataLookupStr(&status, input, "SOURCES"); // Name of mask
     
    135158        }
    136159        // generate an pmFPAimage for the output convolved image
    137         // XXX output of these files should be optional
    138160        {
    139161            // pmFPAfile *srcInputFile = rawInputFile ? rawInputFile : cnvInputFile;
     
    143165                return false;
    144166            }
    145             outputImage->save = true;
     167            outputImage->save = saveCnv;
    146168            outputImage->fileID = stack_id;             // this is used to generate output names
    147169
     
    155177                return NULL;
    156178            }
    157             outputMask->save = true;
     179            outputMask->save = saveCnv;
    158180            outputMask->fileID = stack_id;              // this is used to generate output names
    159181
     
    167189                return NULL;
    168190            }
    169             outputVariance->save = true;
     191            outputVariance->save = saveCnv;
    170192            outputVariance->fileID = stack_id;          // this is used to generate output names
    171193
     
    178200            outsources->save = true;
    179201            outsources->fileID = stack_id;              // this is used to generate output names
     202
     203            if (savePSF) {
     204                pmFPAfile *output = pmFPAfileDefineOutputFromFile (config, inputTemplate, "PSPHOT.STACK.PSF.SAVE");
     205                if (!output) {
     206                    psError(PSPHOT_ERR_CONFIG, false, "Cannot find a rule for PSPHOT.STACK.PSF.SAVE");
     207                    return false;
     208                }
     209                output->save = true;
     210                output->fileID = stack_id;
     211            }
     212            if (saveBackgroundModel) {
     213                int DX = psMetadataLookupS32 (&status, recipe, "BACKGROUND.XBIN");
     214                int DY = psMetadataLookupS32 (&status, recipe, "BACKGROUND.YBIN");
     215                pmFPAfile *output = pmFPAfileDefineFromFile (config, inputTemplate, DX, DY, "PSPHOT.STACK.BACKMDL");
     216                if (!output) {
     217                    psError(PSPHOT_ERR_CONFIG, false, "Cannot find a rule for PSPHOT.STACK.BACKMDL");
     218                    return false;
     219                }
     220
     221                output->save = true;
     222                output->fileID = stack_id;
     223            }
     224            if (saveBackground) {
     225                pmFPAfile *output = pmFPAfileDefineFromFile (config, inputTemplate, 1, 1, "PSPHOT.STACK.BACKGND");
     226                if (!output) {
     227                    psError(PSPHOT_ERR_CONFIG, false, "Cannot find a rule for PSPHOT.STACK.STACK.BACKGND");
     228                    return false;
     229                }
     230                output->save = true;
     231                output->fileID = stack_id;
     232            }
     233            if (saveBackSub) {
     234                pmFPAfile *output = pmFPAfileDefineFromFile (config, inputTemplate, 1, 1, "PSPHOT.STACK.BACKSUB");
     235                if (!output) {
     236                    psError(PSPHOT_ERR_CONFIG, false, "Cannot find a rule for PSPHOT.STACK.STACK.BACKSUB");
     237                    return false;
     238                }
     239                output->save = true;
     240                output->fileID = stack_id;
     241            }
     242            if (saveResid) {
     243                pmFPAfile *output = pmFPAfileDefineOutputFromFile (config, inputTemplate, "PSPHOT.STACK.RESID");
     244                if (!output) {
     245                    psError(PSPHOT_ERR_CONFIG, false, "Cannot find a rule for PSPHOT.STACK.RESID");
     246                    return false;
     247                }
     248                output->save = true;
     249                output->fileID = stack_id;
     250            }
    180251        }
    181252    }
     
    191262    }
    192263
    193     // select the appropriate recipe information
    194     psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE);
    195     bool saveCnv = psMetadataLookupBool(&status, recipe, "SAVE.CNV");
    196     bool saveChisq = psMetadataLookupBool(&status, recipe, "SAVE.CHISQ");
    197 
    198     // loop over the available readouts
    199     for (int i = 0; i < nInputs; i++) {
    200         pmFPAfile *file = NULL;
    201 
    202         file = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.OUTPUT.IMAGE", i);
    203         file->save = saveCnv;
    204 
    205         file = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.OUTPUT.MASK", i);
    206         file->save = saveCnv;
    207 
    208         file = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.OUTPUT.VARIANCE", i);
    209         file->save = saveCnv;
    210     }
    211 
    212264    // generate an pmFPAimage for the chisqImage
    213     // XXX output of these files should be optional
    214265    {
    215266        pmFPAfile *chisqImage = pmFPAfileDefineOutput(config, NULL, "PSPHOT.CHISQ.IMAGE");
  • trunk/psphot/src/psphotSubtractBackground.c

    r32348 r34528  
    2121
    2222    // find the currently selected readout (XXX note that the model is saved on PSPHOT.BACKMDL regardless of 'filename'
    23     pmFPAfile *modelFile = pmFPAfileSelectSingle(config->files, "PSPHOT.BACKMDL", index); // File of interest
     23    pmFPAfile *modelFile = pmFPAfileSelectSingle(config->files, psphotGetFilerule("PSPHOT.BACKMDL"), index); // File of interest
    2424    assert (modelFile);
    2525
     
    3636    // select background pixels, from output background file, or create
    3737    // XXX for now, we will only allow a single background image to be generated
    38     file = psMetadataLookupPtr (&status, config->files, "PSPHOT.BACKGND");
     38    file = psMetadataLookupPtr (&status, config->files, psphotGetFilerule("PSPHOT.BACKGND"));
    3939    if (file) {
    4040        // we are using PSPHOT.BACKGND as an I/O file: select readout or create
     
    5050        }
    5151    } else {
    52         background = pmFPAfileDefineInternal (config->files, "PSPHOT.BACKGND", image->numCols, image->numRows, PS_TYPE_F32);
     52        background = pmFPAfileDefineInternal (config->files, psphotGetFilerule("PSPHOT.BACKGND"), image->numCols, image->numRows, PS_TYPE_F32);
    5353    }
    5454    psF32 **backData = background->image->data.F32;
Note: See TracChangeset for help on using the changeset viewer.