IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 10, 2007, 2:15:40 PM (19 years ago)
Author:
Paul Price
Message:

Supporting new kernel types.

File:
1 edited

Legend:

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

    r13738 r14107  
    66#include <pslib.h>
    77#include <psmodules.h>
    8 #include <psphot.h>
    98
    109#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)
    1113
    1214bool ppSubReadout(pmConfig *config, const pmFPAview *view)
     
    1416    pmReadout *inRO = pmFPAfileThisReadout(config->files, view, "PPSUB.INPUT"); // Input readout
    1517    pmReadout *refRO = pmFPAfileThisReadout(config->files, view, "PPSUB.REF"); // Reference readout
     18#if 0
    1619    pmCell *outCell = pmFPAfileThisCell(config->files, view, "PPSUB.OUTPUT"); // Output cell
    1720    pmReadout *outRO = pmReadoutAlloc(outCell); // Output readout
     21#endif
    1822
    1923    psImage *input = inRO->image;       // Input image
     
    3438    psVector *widths = psMetadataLookupPtr(NULL, config->arguments, "ISIS.WIDTHS"); // ISIS Gaussian widths
    3539    psVector *orders = psMetadataLookupPtr(NULL, config->arguments, "ISIS.ORDERS"); // ISIS Polynomial orders
     40    int inner = psMetadataLookupS32(NULL, config->arguments, "INNER"); // Inner radius
     41    int binning = psMetadataLookupS32(NULL, config->arguments, "SPAM.BINNING"); // Binning for SPAM kernel
    3642    psMaskType maskBad = psMetadataLookupU8(NULL, config->arguments, "MASK.BAD"); // Value to mask
    3743    psMaskType maskBlank = psMetadataLookupU8(NULL, config->arguments, "MASK.BLANK"); // Mask for blank reg.
    3844
    39     int numCols = input->numCols, numRows = input->numRows; // Image dimensions
    40     if (!inRO->mask) {
    41         inRO->mask = psImageAlloc(numCols, numRows, PS_TYPE_MASK);
    42         psImageInit(inRO->mask, 0);
     45    if (!inRO->mask && !pmReadoutGenerateMask(inRO)) {
     46        psError(PS_ERR_UNKNOWN, false, "Unable to generate mask for input image");
     47        return false;
    4348    }
    44     if (!refRO->mask) {
    45         refRO->mask = psImageAlloc(numCols, numRows, PS_TYPE_MASK);
    46         psImageInit(refRO->mask, 0);
     49    if (!inRO->weight && !pmReadoutGenerateWeight(inRO, true)) {
     50        psError(PS_ERR_UNKNOWN, false, "Unable to generate weight map for input image");
     51        return false;
     52    }
     53    if (!refRO->mask && !pmReadoutGenerateMask(refRO)) {
     54        psError(PS_ERR_UNKNOWN, false, "Unable to generate mask for reference image");
     55        return false;
     56    }
     57    if (!refRO->weight && !pmReadoutGenerateWeight(refRO, true)) {
     58        psError(PS_ERR_UNKNOWN, false, "Unable to generate weight map for reference image");
     59        return false;
    4760    }
    4861
    49     // Mask for subtraction
    50     psImage *subMask = pmSubtractionMask(inRO->mask, refRO->mask, maskBad, size, footprint);
     62    // Worried about the masks for bad pixels and bad stamps colliding, so make our own mask
     63    int numCols = input->numCols, numRows = input->numRows; // Image dimensions
     64    psImage *stampMask = psImageAlloc(numCols, numRows, PS_TYPE_MASK); // Mask to use for stamps
     65    for (int y = 0; y < numRows; y++) {
     66        for (int x = 0; x < numCols; x++) {
     67            stampMask->data.PS_TYPE_MASK_DATA[y][x] =
     68                (refRO->mask->data.PS_TYPE_MASK_DATA[y][x] & maskBad) ? MASK_BAD : 0;
     69        }
     70    }
    5171
    5272#if 0
     
    6686#endif
    6787
    68     pmSubtractionKernels *kernels = pmSubtractionKernelsGenerate(type, size, order,
    69                                                                  widths, orders); // Kernel basis functions
     88    pmSubtractionKernels *kernels = pmSubtractionKernelsGenerate(type, size, order, widths, orders,
     89                                                                 inner, binning); // Kernel basis functions
    7090    psArray *stamps = NULL;             // Stamps for matching PSF
    7191    psVector *solution = NULL;          // Solution to match PSF
     
    7393    int numRejected = -1;               // Number of rejected stamps in each iteration
    7494    for (int i = 0; i < iter && numRejected != 0; i++) {
    75         stamps = pmSubtractionFindStamps(stamps, refRO->image, subMask, threshold, spacing);
     95        stamps = pmSubtractionFindStamps(stamps, refRO->image, stampMask, MASK_BAD, MASK_STAMP,
     96                                         threshold, spacing, size + footprint);
    7697        if (!stamps) {
    7798            psError(PS_ERR_UNKNOWN, false, "Unable to find stamps on reference image.");
     
    91112        }
    92113
    93         numRejected = pmSubtractionRejectStamps(stamps, refRO->image, inRO->image, subMask,
     114        numRejected = pmSubtractionRejectStamps(stamps, refRO->image, inRO->image, stampMask, MASK_STAMP,
    94115                                                solution, footprint, rej, kernels);
    95116        if (numRejected < 0) {
     
    99120        psLogMsg("ppSub", PS_LOG_INFO, "%d stamps rejected on iteration %d.", numRejected, i);
    100121    }
    101 
    102     if (numRejected > 0) {
    103         solution = pmSubtractionSolveEquation(solution, stamps);
    104         if (!solution) {
    105             psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation.");
    106             goto ERROR;
    107         }
    108     }
     122    psFree(stampMask);
    109123
    110124    psImage *convImage = NULL, *convWeight = NULL, *convMask = NULL; // Convolved images
    111     if (!pmSubtractionConvolve(&convImage, &convWeight, &convMask, refRO->image, refRO->weight, subMask,
    112                                maskBlank, solution, kernels)) {
     125    if (!pmSubtractionConvolve(&convImage, &convWeight, &convMask,
     126                               refRO->image, refRO->weight, refRO->mask,
     127                               MASK_BAD, maskBlank, solution, kernels)) {
    113128        psError(PS_ERR_UNKNOWN, false, "Unable to convolve reference image.");
    114129        goto ERROR;
    115130    }
    116     psFree(subMask);
    117131
    118132    // Do the subtraction
    119133    if (reverse) {
    120         outRO->image = (psImage*)psBinaryOp(NULL, convImage, "-", inRO->image);
     134        (void)psBinaryOp(inRO->image, convImage, "-", inRO->image);
    121135    } else {
    122         outRO->image = (psImage*)psBinaryOp(NULL, inRO->image, "-", convImage);
     136        (void)psBinaryOp(inRO->image, inRO->image, "-", convImage);
    123137    }
    124     outRO->mask = (psImage*)psBinaryOp(NULL, convMask, "|", inRO->mask);
    125     if (convWeight) {
    126         outRO->weight = (psImage*)psBinaryOp(NULL, convWeight, "+", inRO->weight);
    127     }
     138    (void)psBinaryOp(inRO->mask, convMask, "|", inRO->mask);
     139    (void)psBinaryOp(inRO->weight, convWeight, "+", inRO->weight);
    128140
    129141    psFree(convImage);
    130142    psFree(convMask);
    131143    psFree(convWeight);
    132 
    133     outRO->data_exists = true;
    134     outCell->data_exists = true;
    135     outCell->parent->data_exists = true;
    136 
    137     if (!pmFPACopyConcepts(outCell->parent->parent, inRO->parent->parent->parent)) {
    138         psError(PS_ERR_UNKNOWN, false, "Unable to copy concepts from input to output.");
    139         return false;
    140     }
    141144
    142145#if 0
     
    173176#endif
    174177
    175     psFree(kernels);
    176     psFree(stamps);
    177     psFree(solution);
    178178
    179     if (psMetadataLookupBool(NULL, config->arguments, "PHOTOMETRY")) {
    180         pmFPAfile *photFile = psMetadataLookupPtr(NULL, config->files, "PSPHOT.INPUT");
    181         pmFPACopy(photFile->fpa, inRO->parent->parent->parent);
     179        psFree(kernels);
     180        psFree(stamps);
     181        psFree(solution);
     182        return true;
    182183
    183         psphotReadout(config, view);
    184 
    185         pmFPAfileActivate(config->files, false, "PSPHOT.INPUT");
    186     }
    187 
    188     return true;
    189 
    190 ERROR:
    191     psFree(kernels);
    192     psFree(stamps);
    193     psFree(solution);
    194     return false;
     184    ERROR:
     185        psFree(kernels);
     186        psFree(stamps);
     187        psFree(solution);
     188        return false;
    195189}
Note: See TracChangeset for help on using the changeset viewer.