IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 5, 2012, 6:03:49 PM (14 years ago)
Author:
watersc1
Message:

Incomplete.

Location:
branches/czw_branch/20120906/ppStack/src
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/20120906/ppStack/src/ppStack.h

    r34092 r34516  
    3838    PPSTACK_FILES_STACK,                // Stack files
    3939    PPSTACK_FILES_UNCONV,               // Unconvolved stack files
    40     PPSTACK_FILES_PHOT                  // Files for photometry
     40    PPSTACK_FILES_PHOT,                 // Files for photometry
     41    PPSTACK_FILES_BKG                   // Files for bkg
    4142} ppStackFileList;
    4243
     
    111112bool ppStackReadoutFinalThread(psThreadJob *job // Job to process
    112113    );
     114// Perform median stacking for background
     115bool ppStackCombineBackground(ppStackThreadData *stack, ppStackOptions *options, pmConfig *config);
    113116
    114117// Return software version
  • branches/czw_branch/20120906/ppStack/src/ppStackCamera.c

    r30620 r34516  
    156156            psString psf = psMetadataLookupStr(&mdok, input, "PSF"); // Name of PSF
    157157            psString sources = psMetadataLookupStr(&mdok, input, "SOURCES"); // Name of sources
    158 
     158            psString bkgmodel = psMetadataLookupStr(&mdok, input, "BKGMODEL"); // Name of warped background model
     159           
    159160            pmFPAfile *imageFile = defineFile(config, NULL, "PPSTACK.INPUT",
    160161                                              image, PM_FPA_FILE_IMAGE); // File for image
     
    215216            }
    216217
     218            // Grab bkgmodel information here
     219            if (!bkgmodel ||  strlen(bkgmodel) == 0) {
     220              // We have no background models.
     221            }
     222            else {
     223              pmFPAfile *inputBKG = defineFile(config,NULL,"PPSTACK.INPUT.BKGMODEL",bkgmodel,
     224                                               PM_FPA_FILE_IMAGE);
     225              fprintf(stderr,"ppSC: %s\n",bkgmodel);
     226              if (!inputBKG) {
     227                psError(psErrorCodeLast(), false,
     228                        "Unable to define file from bkgmodel %d (%s)",i,bkgmodel);
     229                return(false);
     230              }
     231            }// End bkgmodel
     232
     233
     234           
     235           
    217236            i++;
    218237        }
     
    460479    jpeg2->save = true;
    461480
     481    // Output background
     482    pmFPAfile *outBkg = pmFPAfileDefineOutput(config,NULL,"PPSTACK.OUTPUT.BKGMODEL");
     483    if (!outBkg) {
     484      psError(psErrorCodeLast(), false, _("Unable to generate output file from PPSTACK.OUTPUT.BKGMODEL"));
     485      return(false);
     486    }
     487    if (outBkg->type != PM_FPA_FILE_IMAGE) {
     488      psError(PPSTACK_ERR_CONFIG, true, "PPSTACK.OUTPUT.BKGMODEL is not of type IMAGE");
     489      return(false);
     490    }
     491    outBkg->save = true;
     492    pmFPAfile *outBkgRest = pmFPAfileDefineOutput(config,NULL,"PPSTACK.OUTPUT.BKGREST");
     493    if (!outBkgRest) {
     494      psError(psErrorCodeLast(), false, _("Unable to generate output file from PPSTACK.OUTPUT.BKGREST"));
     495      return(false);
     496    }
     497    if (outBkgRest->type != PM_FPA_FILE_IMAGE) {
     498      psError(PPSTACK_ERR_CONFIG, true, "PPSTACK.OUTPUT.BKGREST is not of type IMAGE");
     499      return(false);
     500    }
     501   
    462502    // For photometry, we operate on the chip-mosaicked image
    463503    // we create a copy of the mosaicked image for psphot so we can write out a clean image
     
    496536    }
    497537
     538    // Define output file here.
     539   
    498540    return true;
    499541}
  • branches/czw_branch/20120906/ppStack/src/ppStackCleanup.c

    r30874 r34516  
    2828    options->expRO = NULL;
    2929
     30    options->bkgRO->data_exists = false;
     31    options->bkgRO->parent->data_exists = false;
     32    options->bkgRO->parent->parent->data_exists = false;
     33    psFree(options->bkgRO);
     34    options->bkgRO = NULL;
     35   
    3036    for (int i = 0; i < options->num; i++) {
    3137        pmCellFreeData(options->cells->data[i]);
  • branches/czw_branch/20120906/ppStack/src/ppStackCombineFinal.c

    r33093 r34516  
    33// This is the doomsday switch.
    44// #define TESTING                         // Enable test output
     5bool ppStackCombineBackground(ppStackThreadData *stack, ppStackOptions *options, pmConfig *config)
     6{
     7  psAssert(stack, "Require stack");
     8  psAssert(options, "Require options");
     9  psAssert(config, "Require configuration");
     10
     11  psTimerStart("PPSTACK_BKGMED");
     12
     13
     14  pmReadout *bkgRO = options->bkgRO;
     15 
     16  psArray *inputs  = psArrayAlloc(options->num);
     17  //  const psArray *cells = options->cells;
     18  for (int i = 0; i < options->num; i++) {
     19    ppStackFileActivationSingle(config, PPSTACK_FILES_BKG, true, i);
     20    pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PPSTACK.INPUT.BKGMODEL", i);
     21    pmFPAview *view = ppStackFilesIterateDown(config);
     22    pmReadout *ro = pmFPAviewThisReadout(view,file->fpa);
     23    inputs->data[i] = ro;
     24    pmFPAfileClose(file,view);
     25    ppStackFileActivationSingle(config, PPSTACK_FILES_BKG, false, i);
     26  }
     27  if (!pmStackSimpleMedianCombine(bkgRO,inputs)) {
     28    psFree(inputs);
     29    return(false);
     30  }
     31/*   for (int i = 0; i < options->num; i++) { */
     32/*     //    ppStackFilesIterateUp(config); */
     33/* /\*     pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PPSTACK.INPUT.BKGMODEL", i); *\/ */
     34/* /\*     pmFPAview *view = ppStackFilesIterateDown(config); *\/ */
     35/*     pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PPSTACK.INPUT.BKGMODEL", i); */
     36   
     37/*     ppStackFileActivationSingle(config, PPSTACK_FILES_BKG, false, i); */
     38/*   }   */
     39  psFree(inputs);
     40  //  psFree(stack->bkgFits);
     41  bkgRO->data_exists = true;
     42  return(true);
     43}
     44 
     45
     46
    547
    648bool ppStackCombineFinal(ppStackThreadData *stack, psArray *covariances, ppStackOptions *options,
  • branches/czw_branch/20120906/ppStack/src/ppStackCombinePrepare.c

    r30620 r34516  
    11#include "ppStack.h"
    22
    3 bool ppStackCombinePrepare(const char *outName, const char *expName,
     3bool ppStackCombinePrepare(const char *outName, const char *expName, const char *bkgName,
    44                           ppStackFileList files, ppStackThreadData *stack,
    55                           ppStackOptions *options, pmConfig *config)
     
    2626    pmCell *cell = pmFPAfileThisCell(config->files, view, outName); // Output cell
    2727    options->outRO = pmReadoutAlloc(cell); // Output readout
    28 
     28   
    2929    pmCell *expCell = pmFPAfileThisCell(config->files, view, expName); // Exposure cell
    3030    options->expRO = pmReadoutAlloc(expCell); // Output readout
     31
     32    pmCell *bkgCell;
     33    if (bkgName) {
     34      bkgCell = pmFPAfileThisCell(config->files, view, bkgName); // Bkg cell
     35      options->bkgRO = pmReadoutAlloc(bkgCell); // BKG readout
     36    }
    3137
    3238    psFree(view);
     
    4753    }
    4854
     55    if (bkgName) {
     56      if (!pmReadoutStackDefineOutput(options->bkgRO, col0, row0, numCols, numRows, false, false, 0)) {
     57        psError(PPSTACK_ERR_ARGUMENTS, false, "Unable to prepare output.");
     58        return false;
     59      }
     60    }
     61
    4962    return true;
    5063}
  • branches/czw_branch/20120906/ppStack/src/ppStackFiles.c

    r31158 r34516  
    1414/// Files required for the convolution
    1515static char *filesConvolve[] = { "PPSTACK.INPUT", "PPSTACK.INPUT.MASK", "PPSTACK.INPUT.VARIANCE", NULL };
     16
     17/// Files required for the background
     18static char *filesBkg[] = { "PPSTACK.INPUT.BKGMODEL", NULL };
    1619
    1720/// Regular (convolved) stack files
     
    1922                              "PPSTACK.OUTPUT.EXP", "PPSTACK.OUTPUT.EXPNUM", "PPSTACK.OUTPUT.EXPWT",
    2023                              "PPSTACK.OUTPUT.JPEG1", "PPSTACK.OUTPUT.JPEG2",
     24                              "PPSTACK.OUTPUT.BKGMODEL",
    2125                              NULL };
    2226/// Unconvolved stack files
    2327static char *filesUnconv[] = { "PPSTACK.UNCONV", "PPSTACK.UNCONV.MASK", "PPSTACK.UNCONV.VARIANCE",
    2428                               "PPSTACK.UNCONV.EXP", "PPSTACK.UNCONV.EXPNUM", "PPSTACK.UNCONV.EXPWT",
     29                               "PPSTACK.OUTPUT.BKGMODEL",
    2530                               NULL };
    2631
     
    4146      case PPSTACK_FILES_UNCONV:   return filesUnconv;
    4247      case PPSTACK_FILES_PHOT:     return filesPhot;
     48    case PPSTACK_FILES_BKG:        return filesBkg;
    4349      default:
    4450        psAbort("Unrecognised file list: %x", list);
     
    8692    for (int i = 0; files[i] != NULL; i++) {
    8793        pmFPAfileActivate(config->files, state, files[i]);
     94        fprintf(stderr,"ACTIVE: %d %s %d\n",i,files[i],state);
    8895    }
    8996    return;
  • branches/czw_branch/20120906/ppStack/src/ppStackLoop.c

    r31435 r34516  
    6363
    6464    // Prepare for combination
    65     if (!ppStackCombinePrepare("PPSTACK.OUTPUT", "PPSTACK.OUTPUT.EXP", PPSTACK_FILES_STACK, stack, options, config)) {
     65    if (!ppStackCombinePrepare("PPSTACK.OUTPUT", "PPSTACK.OUTPUT.EXP", "PPSTACK.OUTPUT.BKGMODEL", PPSTACK_FILES_STACK, stack, options, config)) {
    6666        psError(psErrorCodeLast(), false, "Unable to prepare for combination.");
    6767        psFree(stack);
     
    8484        pmCellFreeData(options->cells->data[i]);
    8585    }
    86     psFree(stack);
     86    //    psFree(stack);
    8787
    8888    // Pixel rejection
     
    142142    }
    143143
     144    // Generate median background stack here.
     145    if (!ppStackCombineBackground(stack, options, config)) {
     146      psError(psErrorCodeLast(), false, "Unable to generate median of background images.");
     147      psFree(stack);
     148      return false;
     149    }
     150    ppStackFileActivation(config,PPSTACK_FILES_BKG ,false);   
    144151    // Photometry
    145152    psTrace("ppStack", 1, "Photometering stacked image....\n");
     
    171178        return false;
    172179    }
    173     psFree(stack);
     180    //    psFree(stack);
    174181    psLogMsg("ppStack", PS_LOG_INFO, "Stage 7: Cleanup, WCS & JPEGS: %f sec", psTimerClear("PPSTACK_STEPS"));
    175182    ppStackMemDump("cleanup");
     
    186193
    187194        // Prepare for combination
    188         if (!ppStackCombinePrepare("PPSTACK.UNCONV", "PPSTACK.UNCONV.EXP", PPSTACK_FILES_UNCONV,
     195        if (!ppStackCombinePrepare("PPSTACK.UNCONV", "PPSTACK.UNCONV.EXP", "PPSTACK.OUTPUT.BKGMODEL", PPSTACK_FILES_UNCONV,
    189196                                   stack, options, config)) {
    190197            psError(psErrorCodeLast(), false, "Unable to prepare for combination.");
  • branches/czw_branch/20120906/ppStack/src/ppStackLoop.h

    r30620 r34516  
    3232    const char *outName,                // Name of output file
    3333    const char *expName,                // Name of exposure file
     34    const char *bkgName,                // Name of background file
    3435    ppStackFileList files,              // Files of interest
    3536    ppStackThreadData *stack,           // Stack
  • branches/czw_branch/20120906/ppStack/src/ppStackOptions.h

    r34093 r34516  
    4848    // Rejection
    4949    psArray *rejected;                  // Rejected pixels
     50    // Background
     51    pmReadout *bkgRO;                   // Output background readout
     52    psArray   *bkgImages;               // Input background images
    5053} ppStackOptions;
    5154
  • branches/czw_branch/20120906/ppStack/src/ppStackReadout.c

    r30620 r34516  
    194194
    195195
    196 
    197196bool ppStackReadoutFinal(const pmConfig *config, pmReadout *outRO, pmReadout *expRO, const psArray *readouts,
    198197                         const psVector *mask, const psArray *rejected, const psVector *weightings,
  • branches/czw_branch/20120906/ppStack/src/ppStackSetup.c

    r31158 r34516  
    8989    options->origMasks = psArrayAlloc(num);
    9090    options->origVariances = psArrayAlloc(num);
     91    options->bkgImages = psArrayAlloc(num);
    9192    pmFPAview *view = pmFPAviewAlloc(0);
    9293    for (int i = 0; i < num; i++) {
     
    103104            options->origVariances->data[i] = pmFPAfileName(file, view, config);
    104105        }
     106/*      { */
     107/*        pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PPSTACK.INPUT.BKGMODEL", i); */
     108/*        options->bkgImages->data[i] = pmFPAfileName(file, view, config); */
     109/*      } */
    105110    }
    106111    psFree(view);
  • branches/czw_branch/20120906/ppStack/src/ppStackThread.c

    r31158 r34516  
    3535            psFitsClose(stack->varianceFits->data[i]);
    3636        }
     37/*         if (stack->bkgFits->data[i]) { */
     38/*             psFitsClose(stack->bkgFits->data[i]); */
     39/*         } */
    3740        stack->imageFits->data[i] = stack->maskFits->data[i] = stack->varianceFits->data[i] = NULL;
    3841    }
     
    4043    psFree(stack->maskFits);
    4144    psFree(stack->varianceFits);
     45    psFree(stack->bkgFits);
    4246    return;
    4347}
     
    5357    const psArray *varianceNames = conv ? options->convVariances : options->origVariances; // Variance names
    5458    const psArray *covariances = conv ? options->convCovars : options->origCovars; // Covariance matrices
    55 
     59    const psArray *bkgNames = options->bkgImages;
    5660    PS_ASSERT_ARRAY_NON_NULL(cells, NULL);
    5761    if (imageNames) {
     
    7781    stack->maskFits   = psArrayAlloc(numInputs);
    7882    stack->varianceFits = psArrayAlloc(numInputs);
     83    stack->bkgFits    = psArrayAlloc(numInputs);
    7984    for (int i = 0; i < numInputs; i++) {
    8085        if (!cells->data[i]) {
     
    95100            psFree(resolved); \
    96101        }
    97 
     102        fprintf(stderr,"%d %s\n",i,(char*) bkgNames->data[i]);
    98103        IMAGE_OPEN(imageNames, stack->imageFits, i);
    99104        IMAGE_OPEN(maskNames, stack->maskFits, i);
    100105        IMAGE_OPEN(varianceNames, stack->varianceFits, i);
     106        //      IMAGE_OPEN(bkgNames, stack->bkgFits, i);
    101107    }
    102108
  • branches/czw_branch/20120906/ppStack/src/ppStackThread.h

    r31158 r34516  
    2525    psArray *maskFits;                  // FITS file pointers for masks
    2626    psArray *varianceFits;              // FITS file pointers for variances
     27    psArray *bkgFits;                   // FITS file pointers for background models
    2728} ppStackThreadData;
    2829
Note: See TracChangeset for help on using the changeset viewer.