IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 13, 2007, 10:47:50 AM (19 years ago)
Author:
Paul Price
Message:

Restoring changes that were wiped when uploading the code to provide additional kernels.

File:
1 edited

Legend:

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

    r14193 r14196  
    66#include <pslib.h>
    77#include <psmodules.h>
     8#include <psphot.h>
    89
    910#include "ppSub.h"
    10 
    11 #define MASK_BAD      0x01              // Mask value for bad pixel
    12 #define MASK_STAMP    0x02              // Mask value for bad stamp (and bad stamp region)
    1311
    1412bool ppSubReadout(pmConfig *config, const pmFPAview *view)
     
    1614    pmReadout *inRO = pmFPAfileThisReadout(config->files, view, "PPSUB.INPUT"); // Input readout
    1715    pmReadout *refRO = pmFPAfileThisReadout(config->files, view, "PPSUB.REF"); // Reference readout
    18 #if 0
    1916    pmCell *outCell = pmFPAfileThisCell(config->files, view, "PPSUB.OUTPUT"); // Output cell
    2017    pmReadout *outRO = pmReadoutAlloc(outCell); // Output readout
    21 #endif
    2218
    2319    psImage *input = inRO->image;       // Input image
     
    4541                                        config); // Mask for blank reg.
    4642
    47     if (!inRO->mask && !pmReadoutGenerateMask(inRO, pmConfigMask("SAT", config),
    48         pmConfigMask("BAD", config))) {
    49         psError(PS_ERR_UNKNOWN, false, "Unable to generate mask for input image");
    50         return false;
     43    int numCols = input->numCols, numRows = input->numRows; // Image dimensions
     44    if (!inRO->mask) {
     45        inRO->mask = psImageAlloc(numCols, numRows, PS_TYPE_MASK);
     46        psImageInit(inRO->mask, 0);
    5147    }
    52     if (!inRO->weight && !pmReadoutGenerateWeight(inRO, true)) {
    53         psError(PS_ERR_UNKNOWN, false, "Unable to generate weight map for input image");
    54         return false;
    55     }
    56     if (!refRO->mask && !pmReadoutGenerateMask(refRO, pmConfigMask("SAT", config),
    57         pmConfigMask("BAD", config))) {
    58         psError(PS_ERR_UNKNOWN, false, "Unable to generate mask for reference image");
    59         return false;
    60     }
    61     if (!refRO->weight && !pmReadoutGenerateWeight(refRO, true)) {
    62         psError(PS_ERR_UNKNOWN, false, "Unable to generate weight map for reference image");
    63         return false;
     48    if (!refRO->mask) {
     49        refRO->mask = psImageAlloc(numCols, numRows, PS_TYPE_MASK);
     50        psImageInit(refRO->mask, 0);
    6451    }
    6552
    66     // Worried about the masks for bad pixels and bad stamps colliding, so make our own mask
    67     int numCols = input->numCols, numRows = input->numRows; // Image dimensions
    68     psImage *stampMask = psImageAlloc(numCols, numRows, PS_TYPE_MASK); // Mask to use for stamps
    69     for (int y = 0; y < numRows; y++) {
    70         for (int x = 0; x < numCols; x++) {
    71             stampMask->data.PS_TYPE_MASK_DATA[y][x] =
    72                 (refRO->mask->data.PS_TYPE_MASK_DATA[y][x] & maskBad) ? MASK_BAD : 0;
    73         }
    74     }
     53    // Mask for subtraction
     54    psImage *subMask = pmSubtractionMask(inRO->mask, refRO->mask, maskBad, size, footprint);
    7555
    7656#if 0
     
    9777    int numRejected = -1;               // Number of rejected stamps in each iteration
    9878    for (int i = 0; i < iter && numRejected != 0; i++) {
    99         stamps = pmSubtractionFindStamps(stamps, refRO->image, stampMask, MASK_BAD, MASK_STAMP,
    100                                          threshold, spacing, size + footprint);
     79        stamps = pmSubtractionFindStamps(stamps, refRO->image, subMask, threshold, spacing);
    10180        if (!stamps) {
    10281            psError(PS_ERR_UNKNOWN, false, "Unable to find stamps on reference image.");
     
    11695        }
    11796
    118         numRejected = pmSubtractionRejectStamps(stamps, refRO->image, inRO->image, stampMask, MASK_STAMP,
     97        numRejected = pmSubtractionRejectStamps(stamps, refRO->image, inRO->image, subMask,
    11998                                                solution, footprint, rej, kernels);
    12099        if (numRejected < 0) {
     
    124103        psLogMsg("ppSub", PS_LOG_INFO, "%d stamps rejected on iteration %d.", numRejected, i);
    125104    }
    126     psFree(stampMask);
     105    psFree(subMask);
    127106
    128107    psImage *convImage = NULL, *convWeight = NULL, *convMask = NULL; // Convolved images
    129     if (!pmSubtractionConvolve(&convImage, &convWeight, &convMask,
    130                                refRO->image, refRO->weight, refRO->mask,
    131                                MASK_BAD, maskBlank, solution, kernels)) {
     108    if (!pmSubtractionConvolve(&convImage, &convWeight, &convMask, refRO->image, refRO->weight, subMask,
     109                               maskBlank, solution, kernels)) {
    132110        psError(PS_ERR_UNKNOWN, false, "Unable to convolve reference image.");
    133111        goto ERROR;
     
    136114    // Do the subtraction
    137115    if (reverse) {
    138         (void)psBinaryOp(inRO->image, convImage, "-", inRO->image);
     116        outRO->image = (psImage*)psBinaryOp(NULL, convImage, "-", inRO->image);
    139117    } else {
    140         (void)psBinaryOp(inRO->image, inRO->image, "-", convImage);
     118        outRO->image = (psImage*)psBinaryOp(NULL, inRO->image, "-", convImage);
    141119    }
    142     (void)psBinaryOp(inRO->mask, convMask, "|", inRO->mask);
    143     (void)psBinaryOp(inRO->weight, convWeight, "+", inRO->weight);
     120    outRO->mask = (psImage*)psBinaryOp(NULL, convMask, "|", inRO->mask);
     121    if (convWeight) {
     122        outRO->weight = (psImage*)psBinaryOp(NULL, convWeight, "+", inRO->weight);
     123    }
    144124
    145125    psFree(convImage);
    146126    psFree(convMask);
    147127    psFree(convWeight);
     128
     129    outRO->data_exists = true;
     130    outCell->data_exists = true;
     131    outCell->parent->data_exists = true;
     132
     133    if (!pmFPACopyConcepts(outCell->parent->parent, inRO->parent->parent->parent)) {
     134        psError(PS_ERR_UNKNOWN, false, "Unable to copy concepts from input to output.");
     135        return false;
     136    }
    148137
    149138#if 0
     
    180169#endif
    181170
     171    psFree(kernels);
     172    psFree(stamps);
     173    psFree(solution);
    182174
    183         psFree(kernels);
    184         psFree(stamps);
    185         psFree(solution);
    186         return true;
     175    if (psMetadataLookupBool(NULL, config->arguments, "PHOTOMETRY")) {
     176        pmFPAfile *photFile = psMetadataLookupPtr(NULL, config->files, "PSPHOT.INPUT");
     177        pmFPACopy(photFile->fpa, inRO->parent->parent->parent);
    187178
    188     ERROR:
    189         psFree(kernels);
    190         psFree(stamps);
    191         psFree(solution);
    192         return false;
     179        psphotReadout(config, view);
     180
     181        pmFPAfileActivate(config->files, false, "PSPHOT.INPUT");
     182    }
     183
     184    return true;
     185
     186ERROR:
     187    psFree(kernels);
     188    psFree(stamps);
     189    psFree(solution);
     190    return false;
    193191}
Note: See TracChangeset for help on using the changeset viewer.