IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 26542


Ignore:
Timestamp:
Jan 7, 2010, 5:07:54 PM (16 years ago)
Author:
eugene
Message:

upgrade psphot functions to work in the stack context (see doc/stack.txt)

Location:
branches/eam_branches/20091201/psphot
Files:
1 added
14 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20091201/psphot/doc/stack.txt

    r24583 r26542  
     1
     220100107 : updates for stack processing
     3
     4  I am building a new version of psphot that operates on a set of
     5  images (eg, multi-filter or multi-epoch).  The assumptions are:
     6
     7  * each input image represents the same sky pixels : they are warped to a common frame.
     8  * each image has been previously processed, with the background
     9    subtracted (and the psf model determined?)
     10  * all planes are / can be loaded into memory at once (otherwise I
     11    need to add a lot of I/O layers)
     12
     13  psphot currently expects the pmFPAfile of interest to be available in
     14  config->files with the name PSPHOT.INPUT.  To update the code for
     15  stacks, I am extending this concept with the pmFPAfileSelectSingle
     16  API: config->files may contain multiple PSPHOT.INPUT entries, and
     17  functions which access this file / these files need to specify
     18  *which* image they want.  The number of PSPHOT.INPUT entries is
     19  saved in config->arguments as PSPHOT.INPUT.NUM (this can be
     20  generated from the filerule PSPHOT.INPUT for extension).
     21
     22  As a result, we need a number of wrapper functions which loop over
     23  all PSPHOT.INPUT.NUM entries and perform a particular operation on
     24  one of the entries.  Here are the functions which I have modified
     25  in this way (function -> child)
     26
     27  * psphotAddPhotcode -> psphotAddPhotcodeReadout
     28    * note that the photcode is now saved on readout->analysis
     29  * psphotSetMaskAndVariance -> psphotSetMaskAndVarianceReadout
     30  * psphotModelBackground -> psphotModelBackgroundReadoutFileIndex
     31  * psphotSubtractBackground -> psphotSubtractBackgroundReadout
     32
     33  side notes on
     34 
     35  * psphotModelBackground vs psphotBackgroundModel : I've renamed
     36    psphotBackgroundModel (used only by ppStack for now) to
     37    psphotModelBackgroundReadoutNoFile.  I've also named the
     38    single-readout version used by psphotModelBackground to
     39    psphotModelBackgroundReadoutFileIndex.  These two functions do the
     40    same thing, but psphotModelBackgroundReadoutNoFile does not save
     41    a pmFPAfile on config->files
     42
    143
    24420090606 : design notes on the multi-image photometry analysis
  • branches/eam_branches/20091201/psphot/src/psphot.h

    r26425 r26542  
    4040
    4141// psphotReadout functions
    42 bool            psphotModelBackground (pmConfig *config, const pmFPAview *view, const char *filename);
    43 bool            psphotSubtractBackground (pmConfig *config, const pmFPAview *view, const char *filename) ;
     42bool            psphotModelBackground (pmConfig *config, const pmFPAview *view);
     43bool            psphotModelBackgroundReadoutFileIndex (pmConfig *config, const pmFPAview *view, const char *filename, int index);
     44
     45// Create a background model for a readout, without saving the result as a pmFPAfile on
     46// config->files.  Otherwise identical to psphotModelBackgroundFileIndex.
     47psImage        *psphotModelBackgroundReadoutNoFile(pmReadout *readout, const pmConfig *config);
     48
     49// worker function for above background model functions
     50bool psphotModelBackgroundReadout(psImage *model,  // Model image
     51                                  psImage *modelStdev, // Model stdev image
     52                                  psMetadata *analysis, // Analysis metadata for outputs
     53                                  pmReadout *readout, // Readout for which to generate a background model
     54                                  psImageBinning *binning, // Binning parameters
     55                                  const pmConfig *config // Configuration
     56    );
    4457
    4558psImageBinning *psphotBackgroundBinning(const psImage *, const pmConfig *);
     59
     60
     61
     62bool            psphotSubtractBackground (pmConfig *config, const pmFPAview *view);
     63bool            psphotSubtractBackgroundReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index);
     64
    4665
    4766pmDetections   *psphotFindDetections (pmDetections *detections, pmReadout *readout, psMetadata *recipe);
     
    103122void            psphotModelClassInit (void);
    104123bool            psphotGrowthCurve (pmReadout *readout, pmPSF *psf, bool ignore, psImageMaskType maskVal);
    105 bool            psphotSetMaskAndVariance (pmConfig *config, pmReadout *readout, psMetadata *recipe);
     124bool            psphotSetMaskAndVariance (pmConfig *config, const pmFPAview *view, psMetadata *recipe);
     125bool            psphotSetMaskAndVarianceReadout (pmConfig *config, pmReadout *readout, psMetadata *recipe);
    106126void            psphotSourceFreePixels (psArray *sources);
    107127
     
    115135
    116136// output functions
    117 bool            psphotAddPhotcode (psMetadata *recipe, pmConfig *config, const pmFPAview *view, const char *filerule);
     137bool            psphotAddPhotcodeReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index);
     138bool            psphotAddPhotcode (pmConfig *config, const pmFPAview *view);
     139
    118140bool            psphotDumpMoments (psMetadata *recipe, psArray *sources);
    119141psMetadata     *psphotDefineHeader (psMetadata *recipe);
     
    279301
    280302
    281 // Create a background model for a readout
    282 // Essentially identical to psphotModelBackground, but with a more convenient API for outsiders.
    283 psImage *psphotBackgroundModel(pmReadout *ro, // Readout for which to generate background model
    284                                const pmConfig *config // Configuration
    285     );
    286 
    287303pmConfig *psphotForcedArguments(int argc, char **argv);
    288304bool psphotForcedImageLoop (pmConfig *config);
  • branches/eam_branches/20091201/psphot/src/psphotForcedReadout.c

    r25981 r26542  
    2020
    2121    // set the photcode for this image
    22     if (!psphotAddPhotcode (recipe, config, view, "PSPHOT.INPUT")) {
     22    if (!psphotAddPhotcode (config, view)) {
    2323        psError (PSPHOT_ERR_CONFIG, false, "trouble defining the photcode");
    2424        return false;
     
    3434
    3535    // Generate the mask and weight images, including the user-defined analysis region of interest
    36     psphotSetMaskAndVariance (config, readout, recipe);
     36    psphotSetMaskAndVariance (config, view, recipe);
    3737    if (!strcasecmp (breakPt, "NOTHING")) {
    3838        return psphotReadoutCleanup(config, readout, recipe, NULL, NULL, NULL);
     
    4343
    4444    // generate a background model (median, smoothed image)
    45     if (!psphotModelBackground (config, view, "PSPHOT.INPUT")) {
     45    if (!psphotModelBackground (config, view)) {
    4646        return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL);
    4747    }
    48     if (!psphotSubtractBackground (config, view, "PSPHOT.INPUT")) {
     48    if (!psphotSubtractBackground (config, view)) {
    4949        return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL);
    5050    }
  • branches/eam_branches/20091201/psphot/src/psphotMakePSFReadout.c

    r25982 r26542  
    1919
    2020    // set the photcode for this image
    21     if (!psphotAddPhotcode (recipe, config, view, "PSPHOT.INPUT")) {
     21    if (!psphotAddPhotcode (config, view)) {
    2222        psError (PSPHOT_ERR_CONFIG, false, "trouble defining the photcode");
    2323        return false;
     
    3333
    3434    // Generate the mask and weight images, including the user-defined analysis region of interest
    35     psphotSetMaskAndVariance (config, readout, recipe);
     35    psphotSetMaskAndVariance (config, view, recipe);
    3636    if (!strcasecmp (breakPt, "NOTHING")) {
    3737        return psphotReadoutCleanup(config, readout, recipe, NULL, NULL, NULL);
     
    4242
    4343    // generate a background model (median, smoothed image)
    44     if (!psphotModelBackground (config, view, "PSPHOT.INPUT")) {
     44    if (!psphotModelBackground (config, view)) {
    4545        return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL);
    4646    }
    47     if (!psphotSubtractBackground (config, view, "PSPHOT.INPUT")) {
     47    if (!psphotSubtractBackground (config, view)) {
    4848        return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL);
    4949    }
  • branches/eam_branches/20091201/psphot/src/psphotMaskReadout.c

    r26523 r26542  
    22
    33// generate mask and variance if not defined, additional mask for restricted subregion
    4 bool psphotSetMaskAndVariance (pmConfig *config, pmReadout *readout, psMetadata *recipe) {
     4bool psphotSetMaskAndVarianceReadout (pmConfig *config, pmReadout *readout, psMetadata *recipe) {
    55
    66    bool status;
     
    7676}
    7777
    78 bool psphotStackSetMaskAndVariance (pmConfig *config, const pmFPAview *view, psMetadata *recipe) {
     78bool psphotSetMaskAndVariance (pmConfig *config, const pmFPAview *view, psMetadata *recipe) {
    7979
    80     int num = psMetadataAddS32 (&status, config->arguments, "INPUTS.NUM");
    81     psAbort (!status, "programming error: must define INPUTS.NUM");
     80    bool status = false;
     81
     82    int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
     83    psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
    8284
    8385    // loop over the available readouts
     
    8587
    8688        pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PSPHOT.INPUT", i); // File of interest
     89        PS_ASSERT_PTR_NON_NULL (file, false);
    8790
    8891        // find the currently selected readout
     
    9194
    9295        // Generate the mask and weight images, including the user-defined analysis region of interest
    93         psphotSetMaskAndVariance (config, readout, recipe);
     96        if (!psphotSetMaskAndVarianceReadout (config, readout, recipe)) {
     97            psError (PSPHOT_ERR_CONFIG, false, "failed to generate mask for PSPHOT.INPUT entry %d", i);
     98            return false;
     99        }
    94100
    95101        // display the image, weight, mask (ch 1,2,3)
    96102        psphotVisualShowImage (readout);
    97103    }
    98 
     104    return true;
    99105}
  • branches/eam_branches/20091201/psphot/src/psphotModelBackground.c

    r26523 r26542  
    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
     34bool psphotModelBackgroundReadout(psImage *model,  // Model image
     35                                  psImage *modelStdev, // Model stdev image
     36                                  psMetadata *analysis, // Analysis metadata for outputs
     37                                  pmReadout *readout, // Readout for which to generate a background model
     38                                  psImageBinning *binning, // Binning parameters
     39                                  const pmConfig *config // Configuration
     40    )
    3941{
    4042    psTimerStart ("psphot.background");
     
    328330}
    329331
    330 // XXX these two functions are absurdly-named and very similar -- fix!
    331 
    332 psImage *psphotBackgroundModel(pmReadout *ro, const pmConfig *config)
    333 {
    334     PM_ASSERT_READOUT_NON_NULL(ro, NULL);
    335     PM_ASSERT_READOUT_IMAGE(ro, NULL);
     332// generate a background model for a single readout. do not save an associated pmFPAfile for possible output
     333psImage *psphotModelBackgroundReadoutNoFile(pmReadout *readout, const pmConfig *config)
     334{
     335    PM_ASSERT_READOUT_NON_NULL(readout, NULL);
     336    PM_ASSERT_READOUT_IMAGE(readout, NULL);
    336337    PS_ASSERT_PTR_NON_NULL(config, NULL);
    337338
    338     psImageBinning *binning = psphotBackgroundBinning(ro->image, config); // Image binning parameters
     339    psImageBinning *binning = psphotBackgroundBinning(readout->image, config); // Image binning parameters
    339340    psImage *model = psImageAlloc(binning->nXruff, binning->nYruff, PS_TYPE_F32); // Background model
    340341    psImage *modelStdev = psImageAlloc(binning->nXruff, binning->nYruff, PS_TYPE_F32); // Standard deviation
    341342
    342     if (!backgroundModel(model, modelStdev, ro->analysis, ro, binning, config)) {
     343    if (!psphotModelBackgroundReadout(model, modelStdev, readout->analysis, readout, binning, config)) {
    343344        psFree(model);
    344345        psFree(modelStdev);
     
    346347        return NULL;
    347348    }
    348 
    349349    psFree(modelStdev);
    350 
    351350    return model;
    352351}
    353352
    354 
    355 // generate the median in NxN boxes, clipping heavily
    356 // linear interpolation to generate full-scale model
    357 bool psphotModelBackground (pmConfig *config, const pmFPAview *view, const char *filename)
    358 {
    359     bool status = true;
    360 
     353// generate a background model for readout number index; save an associated pmFPAfile for possible output
     354bool psphotModelBackgroundReadoutFileIndex (pmConfig *config, const pmFPAview *view, const char *filename, int index)
     355{
    361356    // find the currently selected readout
    362     pmFPAfile *file = psMetadataLookupPtr (&status, config->files, filename);
     357    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest
     358    PS_ASSERT_PTR_NON_NULL (file, false);
     359
    363360    pmFPA *inFPA = file->fpa;
    364361    pmReadout *readout = pmFPAviewThisReadout(view, inFPA);
     
    368365    pmReadout *modelStdev = pmFPAGenerateReadout(config, view, "PSPHOT.BACKMDL.STDEV", inFPA, binning);
    369366
    370     if (!backgroundModel(model->image, modelStdev->image, model->analysis, readout, binning, config)) {
     367    if (!psphotModelBackgroundReadout(model->image, modelStdev->image, model->analysis, readout, binning, config)) {
    371368        psError(PS_ERR_UNKNOWN, false, "Unable to generate background model");
    372369        return false;
     
    378375
    379376// XXX supply filename or keep PSPHOT.INPUT fixed?
    380 bool psphotStackModelBackground (pmConfig *config, const pmFPAview *view)
    381 {
    382     bool status = true;
    383 
    384     int num = psMetadataAddS32 (&status, config->arguments, "INPUTS.NUM");
    385     psAbort (!status, "programming error: must define INPUTS.NUM");
     377bool psphotModelBackground (pmConfig *config, const pmFPAview *view)
     378{
     379    bool status = false;
     380
     381    int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
     382    psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
    386383
    387384    // loop over the available readouts
    388385    for (int i = 0; i < num; i++) {
    389 
    390         pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PSPHOT.INPUT", i); // File of interest
    391 
    392         // find the currently selected readout
    393         pmReadout  *readout = pmFPAviewThisReadout (view, file->fpa);
    394         PS_ASSERT_PTR_NON_NULL (readout, false);
    395 
    396         psImageBinning *binning = psphotBackgroundBinning(readout->image, config); // Image binning parameters
    397         pmReadout *model = pmFPAGenerateReadout(config, view, "PSPHOT.BACKMDL", inFPA, binning); // this needs to be a MULTI like PSPHOT.INPUT
    398         pmReadout *modelStdev = pmFPAGenerateReadout(config, view, "PSPHOT.BACKMDL.STDEV", inFPA, binning); // this needs to be a MULTI like PSPHOT.INPUT
    399 
    400         // XXX save results on model->analysis or readout->analysis??
    401         if (!backgroundModel(model->image, modelStdev->image, model->analysis, readout, binning, config)) {
    402             psError(PS_ERR_UNKNOWN, false, "Unable to generate background model");
     386        if (!psphotModelBackgroundReadoutFileIndex(config, view, "PSPHOT.INPUT", i)) {
     387            psError (PSPHOT_ERR_CONFIG, false, "failed to model background for PSPHOT.INPUT entry %d", i);
    403388            return false;
    404389        }
    405         npass ++;
    406390    }
    407391    return true;
  • branches/eam_branches/20091201/psphot/src/psphotOutput.c

    r26422 r26542  
    126126}
    127127
    128 bool psphotAddPhotcode (psMetadata *recipe, pmConfig *config, const pmFPAview *view, const char *filerule) {
    129 
    130     bool status;
    131 
    132     pmFPAfile *input = psMetadataLookupPtr (&status, config->files, filerule);
    133     PS_ASSERT (status, false);
    134 
    135     // determine PHOTCODE from fpa & view, overwrite in recipe
    136     char *photcode = pmConceptsPhotcodeForView (input, view);
     128bool psphotAddPhotcodeReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index) {
     129
     130    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest
     131    PS_ASSERT (file, false);
     132
     133    pmReadout  *readout = pmFPAviewThisReadout (view, file->fpa);
     134
     135    // determine PHOTCODE from fpa & view, overwrite in readout->analysis
     136    char *photcode = pmConceptsPhotcodeForView (file, view);
    137137    PS_ASSERT (photcode, false);
    138138
    139     psMetadataAddStr (recipe, PS_LIST_TAIL, "PHOTCODE", PS_META_REPLACE, "photcode from FPA concepts", photcode);
     139    psMetadataAddStr (readout->analysis, PS_LIST_TAIL, "PHOTCODE", PS_META_REPLACE, "photcode from FPA concepts", photcode);
    140140    psLogMsg ("psphot", 3, "PHOTCODE is %s", photcode);
    141141
    142142    psFree (photcode);
     143    return true;
     144}
     145
     146bool psphotAddPhotcode (pmConfig *config, const pmFPAview *view) {
     147
     148    bool status = false;
     149
     150    int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
     151    psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     152
     153    // loop over the available readouts
     154    for (int i = 0; i < num; i++) {
     155        if (!psphotAddPhotcodeReadout (config, view, "PSPHOT.INPUT", i)) {
     156            psError (PSPHOT_ERR_CONFIG, false, "failed to add photcode to PSPHOT.INPUT entry %d", i);
     157            return false;
     158        }
     159    }
    143160    return true;
    144161}
     
    181198// these values are saved in an output header stub - they are added to either the
    182199// PHU header (CMP) or the MEF table header (CMF)
     200// XXX these are currently carried by the recipe -- this will not work in a Stack context
     201// XXX they should be place in the readout->analysis of the given image
    183202psMetadata *psphotDefineHeader (psMetadata *recipe) {
    184203
  • branches/eam_branches/20091201/psphot/src/psphotParseCamera.c

    r21458 r26542  
    3939        return NULL;
    4040    }
     41    // specify the number of psphot input images
     42    psMetadataAddS32 (config->arguments, PS_LIST_TAIL, "PSPHOT.INPUT.NUM", PS_META_REPLACE, "number of inputs", 1);
    4143
    4244    // define the additional input/output files associated with psphot
  • branches/eam_branches/20091201/psphot/src/psphotReadout.c

    r25755 r26542  
    2828
    2929    // set the photcode for this image
    30     if (!psphotAddPhotcode (recipe, config, view, "PSPHOT.INPUT")) {
     30    if (!psphotAddPhotcode (config, view)) {
    3131        psError (PSPHOT_ERR_CONFIG, false, "trouble defining the photcode");
    3232        return false;
     
    4242
    4343    // Generate the mask and weight images, including the user-defined analysis region of interest
    44     psphotSetMaskAndVariance (config, readout, recipe);
     44    psphotSetMaskAndVariance (config, view, recipe);
    4545    if (!strcasecmp (breakPt, "NOTHING")) {
    4646        return psphotReadoutCleanup(config, readout, recipe, NULL, NULL, NULL);
     
    5151
    5252    // generate a background model (median, smoothed image)
    53     if (!psphotModelBackground (config, view, "PSPHOT.INPUT")) {
     53    if (!psphotModelBackground (config, view)) {
    5454        return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL);
    5555    }
    56     if (!psphotSubtractBackground (config, view, "PSPHOT.INPUT")) {
     56    if (!psphotSubtractBackground (config, view)) {
    5757        return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL);
    5858    }
  • branches/eam_branches/20091201/psphot/src/psphotReadoutFindPSF.c

    r26421 r26542  
    1414    }
    1515
    16     // set the photcode for this image
    17     if (!psphotAddPhotcode(recipe, config, view, "PSPHOT.INPUT")) {
     16    // set the photcode for the PSPHOT.INPUT
     17    if (!psphotAddPhotcode(config, view)) {
    1818        psError(PSPHOT_ERR_CONFIG, false, "trouble defining the photcode");
    1919        return false;
     
    2525
    2626    // Generate the mask and variance images, including the user-defined analysis region of interest
    27     psphotSetMaskAndVariance (config, readout, recipe);
     27    psphotSetMaskAndVariance (config, view, recipe);
    2828
    2929    // display the image, weight, mask (ch 1,2,3)
  • branches/eam_branches/20091201/psphot/src/psphotReadoutKnownSources.c

    r25755 r26542  
    1515
    1616    // set the photcode for this image
    17     if (!psphotAddPhotcode(recipe, config, view, "PSPHOT.INPUT")) {
     17    if (!psphotAddPhotcode(config, view)) {
    1818        psError(PSPHOT_ERR_CONFIG, false, "trouble defining the photcode");
    1919        return false;
     
    2525
    2626    // Generate the mask and weight images, including the user-defined analysis region of interest
    27     psphotSetMaskAndVariance (config, readout, recipe);
     27    psphotSetMaskAndVariance (config, view, recipe);
    2828
    2929    // display the image, weight, mask (ch 1,2,3)
  • branches/eam_branches/20091201/psphot/src/psphotReadoutMinimal.c

    r26424 r26542  
    2525
    2626    // set the photcode for this image
    27     if (!psphotAddPhotcode(recipe, config, view, "PSPHOT.INPUT")) {
     27    if (!psphotAddPhotcode(config, view)) {
    2828        psError(PSPHOT_ERR_CONFIG, false, "trouble defining the photcode");
    2929        return false;
     
    3535
    3636    // Generate the mask and weight images, including the user-defined analysis region of interest
    37     psphotSetMaskAndVariance (config, readout, recipe);
     37    psphotSetMaskAndVariance (config, view, recipe);
    3838
    3939    // display the image, weight, mask (ch 1,2,3)
  • branches/eam_branches/20091201/psphot/src/psphotStackParseCamera.c

    r26523 r26542  
    5656    }
    5757    psMetadataRemoveKey(config->arguments, "FILENAMES");
    58     psMetadataAddS32 (config->arguments, PS_LIST_TAIL, "INPUTS.NUM", PS_META_REPLACE, "number of inputs", nInputs);
     58    psMetadataAddS32 (config->arguments, PS_LIST_TAIL, "PSPHOT.INPUT.NUM", PS_META_REPLACE, "number of inputs", nInputs);
    5959
    6060    // define the additional input/output files associated with psphot
  • branches/eam_branches/20091201/psphot/src/psphotSubtractBackground.c

    r26523 r26542  
    44// generate the median in NxN boxes, clipping heavily
    55// linear interpolation to generate full-scale model
    6 bool psphotSubtractBackground (pmConfig *config, const pmFPAview *view, const char *filename)
     6bool psphotSubtractBackgroundReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index)
    77{
    88    bool status = true;
     
    1313
    1414    // find the currently selected readout
    15     pmFPAfile *file = psMetadataLookupPtr (&status, config->files, filename);
     15    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest
     16
    1617    pmFPA *inFPA = file->fpa;
    1718    pmReadout *readout = pmFPAviewThisReadout (view, inFPA);
     
    1920    psImage *mask  = readout->mask;
    2021
    21     // find the currently selected readout
    22     pmReadout *model = pmFPAfileThisReadout (config->files, view, "PSPHOT.BACKMDL");
     22    // 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
     24    assert (modelFile);
     25    pmReadout *model = pmFPAviewThisReadout (view, modelFile->fpa);
    2326    assert (model);
    2427
     
    3538
    3639    // select background pixels, from output background file, or create
     40    // XXX for now, we will only allow a single background image to be generated
    3741    file = psMetadataLookupPtr (&status, config->files, "PSPHOT.BACKGND");
    3842    if (file) {
     
    6670
    6771    // back-sub image pixels, from output background file (don't create if not requested)
     72    // XXX for now, we will only allow a single background-subtracted image to be generated
    6873    file = psMetadataLookupPtr (&status, config->files, "PSPHOT.BACKSUB");
    6974    if (file) {
     
    113118}
    114119
    115 // XXX supply filename or keep PSPHOT.INPUT fixed?
    116 bool psphotStackSubtractBackground (pmConfig *config, const pmFPAview *view)
     120bool psphotSubtractBackground (pmConfig *config, const pmFPAview *view)
    117121{
    118     bool status = true;
     122    bool status = false;
    119123
    120     int num = psMetadataAddS32 (&status, config->arguments, "INPUTS.NUM");
    121     psAbort (!status, "programming error: must define INPUTS.NUM");
     124    int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
     125    psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
    122126
    123127    // loop over the available readouts
    124128    for (int i = 0; i < num; i++) {
    125 
    126         pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PSPHOT.INPUT", i); // File of interest
    127 
    128         // find the currently selected readout
    129         pmReadout  *readout = pmFPAviewThisReadout (view, file->fpa);
    130         PS_ASSERT_PTR_NON_NULL (readout, false);
    131 
    132         psImageBinning *binning = psphotBackgroundBinning(readout->image, config); // Image binning parameters
    133         pmReadout *model = pmFPAGenerateReadout(config, view, "PSPHOT.BACKMDL", inFPA, binning); // this needs to be a MULTI like PSPHOT.INPUT
    134         pmReadout *modelStdev = pmFPAGenerateReadout(config, view, "PSPHOT.BACKMDL.STDEV", inFPA, binning); // this needs to be a MULTI like PSPHOT.INPUT
    135 
    136         // XXX save results on model->analysis or readout->analysis??
    137         // XXX need to create a worker function from the function above...
    138         if (!backgroundModel(model->image, modelStdev->image, model->analysis, readout, binning, config)) {
    139             psError(PS_ERR_UNKNOWN, false, "Unable to generate background model");
     129        if (!psphotSubtractBackgroundReadout (config, view, "PSPHOT.INPUT", i)) {
     130            psError (PSPHOT_ERR_CONFIG, false, "failed to subtract background for PSPHOT.INPUT entry %d", i);
    140131            return false;
    141132        }
    142         // display the backsub and backgnd images
    143         psphotVisualShowBackground (config, view, readout);
    144 
    145         npass ++;
    146133    }
    147134    return true;
Note: See TracChangeset for help on using the changeset viewer.