Changeset 14107 for trunk/ppSub/src/ppSubReadout.c
- Timestamp:
- Jul 10, 2007, 2:15:40 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/ppSub/src/ppSubReadout.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppSub/src/ppSubReadout.c
r13738 r14107 6 6 #include <pslib.h> 7 7 #include <psmodules.h> 8 #include <psphot.h>9 8 10 9 #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) 11 13 12 14 bool ppSubReadout(pmConfig *config, const pmFPAview *view) … … 14 16 pmReadout *inRO = pmFPAfileThisReadout(config->files, view, "PPSUB.INPUT"); // Input readout 15 17 pmReadout *refRO = pmFPAfileThisReadout(config->files, view, "PPSUB.REF"); // Reference readout 18 #if 0 16 19 pmCell *outCell = pmFPAfileThisCell(config->files, view, "PPSUB.OUTPUT"); // Output cell 17 20 pmReadout *outRO = pmReadoutAlloc(outCell); // Output readout 21 #endif 18 22 19 23 psImage *input = inRO->image; // Input image … … 34 38 psVector *widths = psMetadataLookupPtr(NULL, config->arguments, "ISIS.WIDTHS"); // ISIS Gaussian widths 35 39 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 36 42 psMaskType maskBad = psMetadataLookupU8(NULL, config->arguments, "MASK.BAD"); // Value to mask 37 43 psMaskType maskBlank = psMetadataLookupU8(NULL, config->arguments, "MASK.BLANK"); // Mask for blank reg. 38 44 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; 43 48 } 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; 47 60 } 48 61 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 } 51 71 52 72 #if 0 … … 66 86 #endif 67 87 68 pmSubtractionKernels *kernels = pmSubtractionKernelsGenerate(type, size, order, 69 widths, orders); // Kernel basis functions88 pmSubtractionKernels *kernels = pmSubtractionKernelsGenerate(type, size, order, widths, orders, 89 inner, binning); // Kernel basis functions 70 90 psArray *stamps = NULL; // Stamps for matching PSF 71 91 psVector *solution = NULL; // Solution to match PSF … … 73 93 int numRejected = -1; // Number of rejected stamps in each iteration 74 94 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); 76 97 if (!stamps) { 77 98 psError(PS_ERR_UNKNOWN, false, "Unable to find stamps on reference image."); … … 91 112 } 92 113 93 numRejected = pmSubtractionRejectStamps(stamps, refRO->image, inRO->image, s ubMask,114 numRejected = pmSubtractionRejectStamps(stamps, refRO->image, inRO->image, stampMask, MASK_STAMP, 94 115 solution, footprint, rej, kernels); 95 116 if (numRejected < 0) { … … 99 120 psLogMsg("ppSub", PS_LOG_INFO, "%d stamps rejected on iteration %d.", numRejected, i); 100 121 } 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); 109 123 110 124 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)) { 113 128 psError(PS_ERR_UNKNOWN, false, "Unable to convolve reference image."); 114 129 goto ERROR; 115 130 } 116 psFree(subMask);117 131 118 132 // Do the subtraction 119 133 if (reverse) { 120 outRO->image = (psImage*)psBinaryOp(NULL, convImage, "-", inRO->image);134 (void)psBinaryOp(inRO->image, convImage, "-", inRO->image); 121 135 } else { 122 outRO->image = (psImage*)psBinaryOp(NULL, inRO->image, "-", convImage);136 (void)psBinaryOp(inRO->image, inRO->image, "-", convImage); 123 137 } 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); 128 140 129 141 psFree(convImage); 130 142 psFree(convMask); 131 143 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 }141 144 142 145 #if 0 … … 173 176 #endif 174 177 175 psFree(kernels);176 psFree(stamps);177 psFree(solution);178 178 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; 182 183 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; 195 189 }
Note:
See TracChangeset
for help on using the changeset viewer.
