Changeset 17298
- Timestamp:
- Apr 2, 2008, 3:59:35 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/ppSub/src/ppSubReadout.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppSub/src/ppSubReadout.c
r15817 r17298 11 11 12 12 #define WCS_TOLERANCE 0.001 // Tolerance for WCS 13 #define TESTING // For test output 14 13 15 14 16 bool ppSubReadout(pmConfig *config, const pmFPAview *view) … … 17 19 pmReadout *refRO = pmFPAfileThisReadout(config->files, view, "PPSUB.REF"); // Reference readout 18 20 pmReadout *sourcesRO = pmFPAfileThisReadout(config->files, view, "PPSUB.SOURCES"); // Readout with sources 21 pmReadout *inConv = pmReadoutAlloc(NULL); // Convolved version of input 22 pmReadout *refConv = pmReadoutAlloc(NULL); // Convolved version of reference 19 23 pmCell *outCell = pmFPAfileThisCell(config->files, view, "PPSUB.OUTPUT"); // Output cell 20 pmReadout *outRO = pmReadoutAlloc(outCell); // Output readout 24 pmReadout *outRO = pmReadoutAlloc(outCell); // Output readout: subtraction 21 25 pmFPA *outFPA = outCell->parent->parent; // Output FPA 22 26 pmHDU *outHDU = outFPA->hdu; // Output HDU … … 63 67 64 68 pmSubtractionMode mode = dual ? PM_SUBTRACTION_MODE_DUAL : PM_SUBTRACTION_MODE_UNSURE; // Subtraction mode 65 pmReadout *conv2 = NULL; // Convolved image, for dual convolution66 if (dual) {67 conv2 = pmReadoutAlloc(NULL);68 }69 69 70 70 // Generate masks if they don't exist … … 97 97 } 98 98 99 if (!pmSubtractionMatch( outRO, conv2, inRO, refRO, footprint, regionSize, spacing, threshold, sources,99 if (!pmSubtractionMatch(inConv, refConv, inRO, refRO, footprint, regionSize, spacing, threshold, sources, 100 100 stampsName, type, size, order, widths, orders, inner, ringsOrder, 101 101 binning, optimum, optWidths, optOrder, optThresh, iter, rej, maskBad, 102 102 maskBlank, badFrac, mode)) { 103 103 psError(PS_ERR_UNKNOWN, false, "Unable to match images."); 104 psFree(conv2); 104 psFree(inConv); 105 psFree(refConv); 105 106 psFree(outRO); 106 107 return false; … … 109 110 110 111 // Add kernel descrption to header 111 pmSubtractionKernels *kernels = psMetadataLookupPtr( NULL, outRO->analysis,112 pmSubtractionKernels *kernels = psMetadataLookupPtr(&mdok, inConv->analysis, 112 113 "SUBTRACTION.KERNEL"); // The subtraction kernels 114 if (!kernels) { 115 kernels = psMetadataLookupPtr(&mdok, refConv->analysis, "SUBTRACTION.KERNEL"); 116 } 117 if (!kernels) { 118 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find SUBTRACTION.KERNEL"); 119 psFree(inConv); 120 psFree(refConv); 121 psFree(outRO); 122 return false; 123 } 113 124 psMetadataAddStr(outHDU->header, PS_LIST_TAIL, "PPSUB.KERNEL", 0, 114 125 "Subtraction kernel", kernels->description); 115 126 116 psImage *kernelImage = psMetadataLookupPtr(NULL, outRO->analysis, 127 #ifdef TESTING 128 psImage *kernelImage = psMetadataLookupPtr(&mdok, inConv->analysis, 117 129 "SUBTRACTION.KERNEL.IMAGE"); // Image of the kernels 130 if (!kernelImage) { 131 kernelImage = psMetadataLookupPtr(&mdok, refConv->analysis, "SUBTRACTION.KERNEL.IMAGE"); 132 } 118 133 psFits *fits = psFitsOpen("kernel.fits", "w"); 119 134 psFitsWriteImage(fits, NULL, kernelImage, 0, NULL); 120 135 psFitsClose(fits); 136 #endif 121 137 122 138 // Do the subtraction 123 139 { 124 140 // Subtraction is: minuend - subtrahend 125 psImage *minuendImage = outRO->image; 126 psImage *subtrahendImage = (dual ? conv2->image : inRO->image); 127 psImage *minuendWeight = outRO->image; 128 psImage *subtrahendWeight = (dual ? conv2->weight : inRO->weight); 129 psImage *mask2 = (dual ? conv2->mask : inRO->mask); 141 pmReadout *minuend = inConv; 142 pmReadout *subtrahend = refConv; 130 143 131 144 if (reverse) { 132 psImage *temp = subtrahendImage; 133 subtrahendImage = minuendImage; 134 minuendImage = temp; 135 136 temp = subtrahendWeight; 137 subtrahendWeight = minuendWeight; 138 minuendWeight = temp; 139 } 140 141 psBinaryOp(outRO->image, minuendImage, "-", subtrahendImage); 142 psBinaryOp(outRO->mask, outRO->mask, "|", mask2); 143 if (minuendWeight && subtrahendWeight) { 144 psBinaryOp(outRO->weight, minuendWeight, "+", subtrahendWeight); 145 } 146 } 145 pmReadout *temp = subtrahend; 146 subtrahend = minuend; 147 minuend = temp; 148 } 149 150 outRO->image = (psImage*)psBinaryOp(outRO->image, minuend->image, "-", subtrahend->image); 151 outRO->mask = (psImage*)psBinaryOp(outRO->mask, minuend->mask, "|", subtrahend->mask); 152 if (minuend->weight && subtrahend->weight) { 153 outRO->weight = (psImage*)psBinaryOp(outRO->weight, minuend->weight, "+", subtrahend->weight); 154 } 155 outRO->data_exists = outCell->data_exists = outCell->parent->data_exists = true; 156 157 #ifdef TESTING 158 { 159 psFits *fits = psFitsOpen("minuend.fits", "w"); 160 psFitsWriteImage(fits, NULL, minuend->image, 0, NULL); 161 psFitsClose(fits); 162 } 163 { 164 psFits *fits = psFitsOpen("subtrahend.fits", "w"); 165 psFitsWriteImage(fits, NULL, subtrahend->image, 0, NULL); 166 psFitsClose(fits); 167 } 168 #endif 169 } 170 171 psFree(inConv); 172 psFree(refConv); 147 173 148 174 #ifdef TESTING
Note:
See TracChangeset
for help on using the changeset viewer.
