Changeset 14671 for trunk/psModules/src/imcombine/pmSubtractionMatch.c
- Timestamp:
- Aug 27, 2007, 10:55:23 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/imcombine/pmSubtractionMatch.c
r14606 r14671 9 9 #include "pmHDU.h" 10 10 #include "pmFPA.h" 11 #include "pmSubtractionParams.h" 11 12 #include "pmSubtractionKernels.h" 12 13 #include "pmSubtractionStamps.h" … … 44 45 45 46 47 static bool getStamps(psArray **stamps, // Stamps to read 48 const psArray *stampsData, // Stamp data from a file 49 const pmReadout *reference, // Reference readout 50 const pmReadout *input, // Input readout, or NULL to generate fake stamps 51 const psImage *subMask, // Mask for subtraction, or NULL 52 psImage *weight, // Weight map 53 const psRegion *region, // Region of interest, or NULL 54 float threshold, // Threshold for stamp finding 55 float stampSpacing, // Spacing between stamps 56 float targetWidth,// Target width for fake stamps 57 int size, // Kernel half-size 58 int footprint // Convolution footprint for stamps 59 ) 60 { 61 62 psImage *inImage = NULL; // Input image 63 if (input) { 64 inImage = input->image; 65 } 66 67 if (stampsData) { 68 psVector *xStamp = NULL, *yStamp = NULL, *fluxStamp = NULL; // Stamp positions and fluxes 69 if (input) { 70 // We have x, y because the target is provided by the input image 71 xStamp = stampsData->data[0]; 72 yStamp = stampsData->data[1]; 73 } else { 74 // We have x, y and flux in order to generate a target 75 xStamp = stampsData->data[0]; 76 yStamp = stampsData->data[1]; 77 fluxStamp = stampsData->data[2]; 78 } 79 80 psFree(*stamps); 81 *stamps = pmSubtractionSetStamps(xStamp, yStamp, fluxStamp, subMask, region); 82 } else { 83 psTrace("psModules.imcombine", 3, "Finding stamps...\n"); 84 *stamps = pmSubtractionFindStamps(*stamps, reference->image, subMask, region, 85 threshold, stampSpacing); 86 } 87 if (!stamps) { 88 psError(PS_ERR_UNKNOWN, false, "Unable to find stamps."); 89 return false; 90 } 91 92 memCheck(" find stamps"); 93 94 if (!input && !pmSubtractionGenerateStamps(*stamps, targetWidth, footprint, size)) { 95 psError(PS_ERR_UNKNOWN, false, "Unable to generate target stamps."); 96 return false; 97 } 98 99 psTrace("psModules.imcombine", 3, "Extracting stamps...\n"); 100 if (!pmSubtractionExtractStamps(*stamps, reference->image, inImage, weight, footprint, size)) { 101 psError(PS_ERR_UNKNOWN, false, "Unable to extract stamps."); 102 return false; 103 } 104 105 memCheck(" extract stamps"); 106 107 return true; 108 } 109 110 111 112 113 46 114 bool pmSubtractionMatch(pmReadout *convolved, const pmReadout *reference, const pmReadout *input, 47 115 int footprint, float regionSize, float stampSpacing, float threshold, 48 116 const char *stampsName, float targetWidth, pmSubtractionKernelsType type, 49 int size, int order, const psVector *isisWidths, const psVector *isisOrders, 50 int inner, int ringsOrder, int binning, int iter, float rej, psMaskType maskBad, 117 int size, int spatialOrder, const psVector *isisWidths, const psVector *isisOrders, 118 int inner, int ringsOrder, int binning, bool optimum, psVector *optFWHMs, 119 int optOrder, float optThreshold, int iter, float rej, psMaskType maskBad, 51 120 psMaskType maskBlank) 52 121 { … … 88 157 // We'll check kernel type when we allocate the kernels 89 158 PS_ASSERT_INT_POSITIVE(size, false); 90 PS_ASSERT_INT_NONNEGATIVE( order, false);159 PS_ASSERT_INT_NONNEGATIVE(spatialOrder, false); 91 160 if (isisWidths || isisOrders) { 92 161 PS_ASSERT_VECTOR_NON_NULL(isisWidths, false); … … 99 168 PS_ASSERT_INT_NONNEGATIVE(ringsOrder, false); 100 169 PS_ASSERT_INT_POSITIVE(binning, false); 170 if (optimum) { 171 PS_ASSERT_VECTOR_NON_NULL(optFWHMs, false); 172 PS_ASSERT_INT_NONNEGATIVE(optOrder, false); 173 PS_ASSERT_FLOAT_LARGER_THAN(optThreshold, 0.0, false); 174 PS_ASSERT_FLOAT_LESS_THAN_OR_EQUAL(optThreshold, 1.0, false); 175 } 101 176 PS_ASSERT_INT_POSITIVE(iter, false); 102 177 PS_ASSERT_FLOAT_LARGER_THAN(rej, 0.0, false); … … 136 211 } 137 212 213 // Read stamps from file 214 psArray *stampsData = NULL; // Stamps data read from file 215 if (stampsName && strlen(stampsName) > 0) { 216 psTrace("psModules.imcombine", 3, "Reading stamps from %s...\n", stampsName); 217 psVector *xStamp = NULL, *yStamp = NULL; // Stamp positions and fluxes 218 if (input) { 219 // We have x, y because the target is provided by the input image 220 stampsData = psVectorsReadFromFile(stampsName, "%f %f"); // Stamp positions 221 } else { 222 // We have x, y and flux in order to generate a target 223 stampsData = psVectorsReadFromFile(stampsName, "%f %f %f"); // Stamp positions 224 } 225 226 // Correct for IRAF/FITS (unit-offset) positions to C (zero-offset) positions 227 xStamp = stampsData->data[0]; 228 yStamp = stampsData->data[1]; 229 psBinaryOp(xStamp, xStamp, "-", psScalarAlloc(1.0, PS_TYPE_F32)); 230 psBinaryOp(yStamp, yStamp, "-", psScalarAlloc(1.0, PS_TYPE_F32)); 231 } 232 138 233 int numCols = reference->image->numCols, numRows = reference->image->numRows; // Image dimensions 139 234 … … 145 240 memCheck("mask"); 146 241 147 // Kernel basis functions 148 pmSubtractionKernels *kernels = pmSubtractionKernelsGenerate(type, size, order, isisWidths, isisOrders, 149 inner, binning, ringsOrder); 242 243 psArray *stamps = NULL; // Stamps for matching PSF 244 245 pmSubtractionKernels *kernels = NULL; // Kernel basis functions 246 if (optimum && (type == PM_SUBTRACTION_KERNEL_ISIS || type == PM_SUBTRACTION_KERNEL_GUNK)) { 247 if (!getStamps(&stamps, stampsData, reference, input, subMask, weight, NULL, 248 threshold, stampSpacing, targetWidth, size, footprint)) { 249 goto ERROR; 250 } 251 kernels = pmSubtractionKernelsOptimumISIS(type, size, inner, spatialOrder, optFWHMs, optOrder, 252 stamps, footprint, optThreshold); 253 // XXX This is not quite the best thing to do here--- we'll find the same set of stamps again later, 254 // but since we may not be interested in the entire image on the first pass through, we have to blow 255 // the whole lot away. The alternative is to mark stamps that are outside the region of interest, and 256 // ignore them when generating sums and rejecting. 257 psFree(stamps); 258 stamps = NULL; 259 260 if (!kernels) { 261 psErrorClear(); 262 psWarning("Unable to derive optimum ISIS kernel --- switching to default."); 263 } 264 } 265 266 if (kernels == NULL) { 267 // Not an ISIS/GUNK kernel, or the optimum kernel search failed 268 kernels = pmSubtractionKernelsGenerate(type, size, spatialOrder, isisWidths, isisOrders, 269 inner, binning, ringsOrder); 270 } 271 150 272 psMetadataAddPtr(convolved->analysis, PS_LIST_TAIL, "SUBTRACTION.KERNEL", PS_DATA_UNKNOWN, 151 273 "Subtraction kernels", kernels); 152 psArray *stamps = NULL; // Stamps for matching PSF153 274 psVector *solution = NULL; // Solution to match PSF 154 275 … … 186 307 psTrace("psModules.imcombine", 2, "Iteration %d...\n", k); 187 308 188 if (stampsName && strlen(stampsName) > 0) { 189 psTrace("psModules.imcombine", 3, "Reading stamps from %s...\n", stampsName); 190 iter = 1; // There is no iterating because we use all the stamps we have 191 psVector *xStamp = NULL, *yStamp = NULL, *fluxStamp = NULL; // Stamp positions and fluxes 192 if (input) { 193 // We have x, y because the target is provided by the input image 194 psArray *stampData = psVectorsReadFromFile(stampsName, "%f %f"); // Stamp positions 195 xStamp = stampData->data[0]; 196 yStamp = stampData->data[1]; 197 } else { 198 // We have x, y and flux in order to generate a target 199 psArray *stampData = psVectorsReadFromFile(stampsName, "%f %f %f"); // Stamp positions 200 xStamp = stampData->data[0]; 201 yStamp = stampData->data[1]; 202 fluxStamp = stampData->data[2]; 203 } 204 205 // Correct for IRAF/FITS (unit-offset) positions to C (zero-offset) positions 206 psBinaryOp(xStamp, xStamp, "-", psScalarAlloc(1.0, PS_TYPE_F32)); 207 psBinaryOp(yStamp, yStamp, "-", psScalarAlloc(1.0, PS_TYPE_F32)); 208 209 stamps = pmSubtractionSetStamps(xStamp, yStamp, fluxStamp, subMask, region); 210 } else { 211 psTrace("psModules.imcombine", 3, "Finding stamps...\n"); 212 stamps = pmSubtractionFindStamps(stamps, reference->image, subMask, region, 213 threshold, stampSpacing); 214 } 215 if (!stamps) { 216 psError(PS_ERR_UNKNOWN, false, "Unable to find stamps."); 309 if (!getStamps(&stamps, stampsData, reference, input, subMask, weight, region, 310 threshold, stampSpacing, targetWidth, size, footprint)) { 217 311 goto ERROR; 218 312 } 219 220 memCheck(" find stamps");221 222 if (!input && !pmSubtractionGenerateStamps(stamps, targetWidth, footprint, kernels)) {223 psError(PS_ERR_UNKNOWN, false, "Unable to generate target stamps.");224 goto ERROR;225 }226 227 psTrace("psModules.imcombine", 3, "Extracting stamps...\n");228 if (!pmSubtractionExtractStamps(stamps, reference->image, inImage, weight,229 footprint, kernels)) {230 psError(PS_ERR_UNKNOWN, false, "Unable to extract stamps.");231 goto ERROR;232 }233 234 memCheck(" extract stamps");235 313 236 314 psTrace("psModules.imcombine", 3, "Calculating equation...\n"); … … 376 454 psFree(subMask); 377 455 subMask = NULL; 456 psFree(stampsData); 457 stampsData = NULL; 378 458 379 459 if (!pmSubtractionBorder(convolved->image, convolved->weight, convolved->mask, kernels, maskBlank)) { … … 395 475 psFree(stamps); 396 476 psFree(solution); 477 psFree(stampsData); 397 478 return false; 398 479 }
Note:
See TracChangeset
for help on using the changeset viewer.
