IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 17, 2009, 2:31:20 PM (17 years ago)
Author:
Paul Price
Message:

Cleaning up. Had trouble getting the output photometry file written out, but works now.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppSub/src/ppSubReadoutSubtract.c

    r21424 r21524  
    66 *
    77 *  @author IfA
    8  *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2009-02-09 21:26:05 $
     8 *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2009-02-18 00:31:20 $
    1010 *  Copyright 2009 Institute for Astronomy, University of Hawaii
    1111 */
    1212
     13#ifdef HAVE_CONFIG_H
     14#include <config.h>
     15#endif
     16
     17#include <stdio.h>
     18#include <pslib.h>
     19#include <psmodules.h>
     20
    1321#include "ppSub.h"
     22
    1423#define WCS_TOLERANCE 0.001             // Tolerance for WCS
    1524
    16 bool ppSubReadoutSubtract (pmConfig *config, const pmFPAview *view) {
     25bool ppSubReadoutSubtract(pmConfig *config, const pmFPAview *view)
     26{
     27    psAssert(config, "Require configuration");
     28    psAssert(view, "Require view");
    1729
    18     bool mdok = false;
    1930
    2031    // Look up recipe values
    21     psMetadata *recipe = psMetadataLookupMetadata(&mdok, config->recipes, PPSUB_RECIPE); // Recipe for ppSim
     32    bool mdok = false;                  // Status of MD lookup
     33    psMetadata *recipe = psMetadataLookupMetadata(&mdok, config->recipes, PPSUB_RECIPE); // Recipe for ppSub
    2234    psAssert(recipe, "We checked this earlier, so it should be here.");
    2335
     
    2537
    2638    // Subtraction is: minuend - subtrahend
    27     pmReadout *minuend = NULL;
    28     pmReadout *subtrahend = NULL;
     39    pmReadout *minuend = NULL;          // Positive image
     40    pmReadout *subtrahend = NULL;       // Negative image
    2941    if (reverse) {
    3042        minuend = pmFPAfileThisReadout(config->files, view, "PPSUB.REF.CONV");
     
    5971    outRO->mask = (psImage*)psBinaryOp(outRO->mask, minuend->mask, "|", subtrahend->mask);
    6072
     73    psArray *covars = psArrayAlloc(2);  // Covariance pseudo-matrices
     74    covars->data[0] = psMemIncrRefCounter(minuend->covariance);
     75    covars->data[1] = psMemIncrRefCounter(subtrahend->covariance);
     76    outRO->covariance = psImageCovarianceSum(covars);
     77    psFree(covars);
     78
    6179    outRO->data_exists = true;
    6280    outRO->parent->data_exists = true;
     
    6583    pmSubtractionVisualShowSubtraction(minuend->image, subtrahend->image, outRO->image);
    6684
    67     // copy concepts from the input to the output (XXX should this always use minuend?)
    68     pmFPAfile *inFile = psMetadataLookupPtr (&mdok, config->files, "PPSUB.INPUT");
    69     pmFPA *inFPA = inFile->fpa;
    70 
    71     pmFPAfile *outFile = psMetadataLookupPtr (&mdok, config->files, "PPSUB.OUTPUT");
    72     pmFPA *outFPA = outFile->fpa;
    73 
     85    // Copy concepts from the input to the output
     86    pmFPAfile *inFile = psMetadataLookupPtr(&mdok, config->files, "PPSUB.INPUT"); // Input file
     87    pmFPA *inFPA = inFile->fpa;         // Input FPA
     88    pmFPAfile *outFile = psMetadataLookupPtr(&mdok, config->files, "PPSUB.OUTPUT"); // Output file
     89    pmFPA *outFPA = outFile->fpa;       // Output FPA
    7490    if (!pmFPACopyConcepts(outFPA, inFPA)) {
    7591        psError(PS_ERR_UNKNOWN, false, "Unable to copy concepts from input to output.");
     
    7894    }
    7995
    80     // get the HDUs and output Chip to copy the astrometry
    81     pmHDU *inHDU = inFPA->hdu;        // input HDU
    82     pmHDU *outHDU = outFPA->hdu;
    83     pmChip *outChip = pmFPAfileThisChip(config->files, view, "PPSUB.OUTPUT");
    84 
     96    // Copy astrometry over
     97    // It should find its way into the output images and photometry
     98    pmHDU *inHDU = inFPA->hdu;          // Input HDU
     99    pmHDU *outHDU = outFPA->hdu;        // Output HDU
     100    pmChip *outChip = pmFPAfileThisChip(config->files, view, "PPSUB.OUTPUT"); // Output chip
    85101    if (!outHDU || !inHDU) {
    86102        psError(PS_ERR_UNKNOWN, false, "Unable to find HDU at FPA level to copy astrometry.");
    87103        return false;
    88104    }
    89 
    90     // Copy astrometry over
    91     // It should get into the output images and photometry
    92105    if (!pmAstromReadWCS(outFPA, outChip, inHDU->header, 1.0)) {
    93106        psError(PS_ERR_UNKNOWN, false, "Unable to read WCS astrometry from input FPA.");
    94107        return false;
    95108    }
    96 
    97109    if (!pmAstromWriteWCS(outHDU->header, outFPA, outChip, WCS_TOLERANCE)) {
    98110        psError(PS_ERR_UNKNOWN, false, "Unable to write WCS astrometry to output FPA.");
     
    102114    return true;
    103115}
    104 
    105 // XXX this test code was in place to check for and squash unexpected NANs
    106 
    107 #if 0
    108     pmReadoutMaskApply(outRO, maskBad);
    109 
    110     for (int y = 0; y < outRO->image->numRows; y++) {
    111         for (int x = 0; x < outRO->image->numCols; x++) {
    112             if (isnan(outRO->image->data.F32[y][x]) && !(outRO->mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskVal)) {
    113                 printf("Unmasked NAN at %d %d --> %d\n", x, y, outRO->mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x]);
    114             }
    115         }
    116     }
    117 #endif
    118 
Note: See TracChangeset for help on using the changeset viewer.