Changeset 5742
- Timestamp:
- Dec 7, 2005, 2:35:14 PM (20 years ago)
- Location:
- trunk/pois/src
- Files:
-
- 2 edited
-
pois.c (modified) (10 diffs)
-
poisCalculateDeviations.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pois/src/pois.c
r5717 r5742 18 18 { 19 19 struct timeval tv; 20 20 21 21 gettimeofday(&tv, NULL); 22 22 return(tv.tv_sec + 1.e-6 * tv.tv_usec); … … 35 35 36 36 if (config->verbose) { 37 psTraceSetLevel("pois", 10);38 psTraceSetLevel("pois.config", 10);39 psTraceSetLevel("pois.time", 10);40 psTraceSetLevel("pois.solution", 0);41 psTraceSetLevel("pois.kernelBasisFunctions", 10);42 psTraceSetLevel("pois.calculateEquation", 10);43 psTraceSetLevel("pois.convolveImage", 10);44 psTraceSetLevel("pois.findStamps", 10);45 psTraceSetLevel("pois.parseConfig", 10);46 psTraceSetLevel("pois.makeMask", 10);47 psTraceSetLevel("pois.extractKernel", 10);48 psTraceSetLevel("pois.calculateDeviations", 10);49 psTraceSetLevel("pois.checkKernel", 10);50 if (config->stampFile) {51 psTraceSetLevel("pois.checkStamp", 10);52 } else {53 psTraceSetLevel("pois.checkStamp", 0);54 }55 // Set logging level56 psLogSetLevel(9);37 psTraceSetLevel("pois", 10); 38 psTraceSetLevel("pois.config", 10); 39 psTraceSetLevel("pois.time", 10); 40 psTraceSetLevel("pois.solution", 0); 41 psTraceSetLevel("pois.kernelBasisFunctions", 10); 42 psTraceSetLevel("pois.calculateEquation", 10); 43 psTraceSetLevel("pois.convolveImage", 10); 44 psTraceSetLevel("pois.findStamps", 10); 45 psTraceSetLevel("pois.parseConfig", 10); 46 psTraceSetLevel("pois.makeMask", 10); 47 psTraceSetLevel("pois.extractKernel", 10); 48 psTraceSetLevel("pois.calculateDeviations", 10); 49 psTraceSetLevel("pois.checkKernel", 10); 50 if (config->stampFile) { 51 psTraceSetLevel("pois.checkStamp", 10); 52 } else { 53 psTraceSetLevel("pois.checkStamp", 0); 54 } 55 // Set logging level 56 psLogSetLevel(9); 57 57 } 58 58 59 59 // Read inputs 60 psMetadata *header = NULL; // Header for output image60 psMetadata *header = NULL; // Header for output image 61 61 62 62 psRegion imageRegion = {0, 0, 0, 0}; 63 psFits *reference = psFits Alloc(config->refFile);63 psFits *reference = psFitsOpen(config->refFile, "r"); 64 64 if (config->reverse) { 65 header = psFitsReadHeader(NULL, reference);65 header = psFitsReadHeader(NULL, reference); 66 66 } 67 67 psImage *refImage = psFitsReadImage(NULL, reference, imageRegion, 0); 68 68 if (refImage == NULL) { 69 psErrorStackPrint(stderr, "Fatal error: unable to read %s\n", config->refFile);70 exit(EXIT_FAILURE);69 psErrorStackPrint(stderr, "Fatal error: unable to read %s\n", config->refFile); 70 exit(EXIT_FAILURE); 71 71 } 72 72 psTrace("pois", 3, "Read %s: %dx%d\n", config->refFile, refImage->numCols, refImage->numRows); 73 psF ree(reference);73 psFitsClose(reference); 74 74 // Convert to 32-bit floating point, in necessary 75 75 if (refImage->type.type != PS_TYPE_F32) { 76 psTrace("pois", 3, "Converting %s to floating point in memory....\n", config->refFile);77 psImage *temp = psImageCopy(NULL, refImage, PS_TYPE_F32);78 psFree(refImage);79 refImage = temp;80 } 81 82 psFits *input = psFits Alloc(config->inFile);76 psTrace("pois", 3, "Converting %s to floating point in memory....\n", config->refFile); 77 psImage *temp = psImageCopy(NULL, refImage, PS_TYPE_F32); 78 psFree(refImage); 79 refImage = temp; 80 } 81 82 psFits *input = psFitsOpen(config->inFile, "r"); 83 83 if (! config->reverse) { 84 header = psFitsReadHeader(NULL, input);84 header = psFitsReadHeader(NULL, input); 85 85 } 86 86 psImage *inImage = psFitsReadImage(NULL, input, imageRegion, 0); 87 87 if (inImage == NULL) { 88 psErrorStackPrint(stderr, "Fatal error: unable to read %s\n", config->inFile);89 exit(EXIT_FAILURE);88 psErrorStackPrint(stderr, "Fatal error: unable to read %s\n", config->inFile); 89 exit(EXIT_FAILURE); 90 90 } 91 91 psTrace("pois", 3, "Read %s: %dx%d\n", config->inFile, inImage->numCols, inImage->numRows); 92 psF ree(input);92 psFitsClose(input); 93 93 // Convert to 32-bit floating point, in necessary 94 94 if (inImage->type.type != PS_TYPE_F32) { 95 psTrace("pois", 3, "Converting %s to floating point in memory....\n", config->inFile);96 psImage *temp = psImageCopy(NULL, inImage, PS_TYPE_F32);97 psFree(inImage);98 inImage = temp;95 psTrace("pois", 3, "Converting %s to floating point in memory....\n", config->inFile); 96 psImage *temp = psImageCopy(NULL, inImage, PS_TYPE_F32); 97 psFree(inImage); 98 inImage = temp; 99 99 } 100 100 101 101 if ((refImage->numCols != inImage->numCols) || (refImage->numRows != inImage->numRows)) { 102 psError(PS_ERR_BAD_PARAMETER_SIZE, true,103 "Reference and input images must have the same dimensions: %dx%d vs %dx%d\n",104 refImage->numCols, refImage->numRows, inImage->numCols, inImage->numRows);105 exit(EXIT_FAILURE);102 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 103 "Reference and input images must have the same dimensions: %dx%d vs %dx%d\n", 104 refImage->numCols, refImage->numRows, inImage->numCols, inImage->numRows); 105 exit(EXIT_FAILURE); 106 106 } 107 107 config->xImage = refImage->numCols; … … 115 115 // as the square root of the value. 116 116 if (config->background != 0.0) { 117 (void)psBinaryOp(refImage, refImage, "+", psScalarAlloc(config->background, PS_TYPE_F32));118 (void)psBinaryOp(inImage, inImage, "+", psScalarAlloc(config->background, PS_TYPE_F32));117 (void)psBinaryOp(refImage, refImage, "+", psScalarAlloc(config->background, PS_TYPE_F32)); 118 (void)psBinaryOp(inImage, inImage, "+", psScalarAlloc(config->background, PS_TYPE_F32)); 119 119 } 120 120 … … 127 127 #ifdef TESTING 128 128 // Write the mask out 129 psFits *maskFile = psFits Alloc("mask.fits");129 psFits *maskFile = psFitsOpen("mask.fits", "w"); 130 130 if (!psFitsWriteImage(maskFile, NULL, mask, 0)) { 131 psErrorStackPrint(stderr, "Unable to write mask: mask.fits\n");131 psErrorStackPrint(stderr, "Unable to write mask: mask.fits\n"); 132 132 } 133 133 psTrace("pois", 1, "Mask written to mask.fits\n"); 134 psF ree(maskFile);135 #endif 136 137 psArray *stamps = NULL; // Array of stamps138 psVector *solution = NULL; // Solution vector139 140 FILE *stampsFP = NULL; // File pointer for stamps134 psFitsClose(maskFile); 135 #endif 136 137 psArray *stamps = NULL; // Array of stamps 138 psVector *solution = NULL; // Solution vector 139 140 FILE *stampsFP = NULL; // File pointer for stamps 141 141 if (config->stampFile) { 142 psTrace("pois", 5, "Opening stamp file, %s\n", config->stampFile);143 stampsFP = fopen(config->stampFile, "r");144 if (! stampsFP) {145 psError(PS_ERR_IO, true, "Unable to open stamps file, %s!\n", config->stampFile);146 exit(EXIT_FAILURE);147 }142 psTrace("pois", 5, "Opening stamp file, %s\n", config->stampFile); 143 stampsFP = fopen(config->stampFile, "r"); 144 if (! stampsFP) { 145 psError(PS_ERR_IO, true, "Unable to open stamps file, %s!\n", config->stampFile); 146 exit(EXIT_FAILURE); 147 } 148 148 } 149 149 150 150 // Iterate for a good solution 151 bool badStamps = true; // Do we have bad stamps, such that we need to continue to iterate?151 bool badStamps = true; // Do we have bad stamps, such that we need to continue to iterate? 152 152 for (int iterNum = 0; iterNum < config->numIter && badStamps; iterNum++) { 153 psTrace("pois", 1, "Iteration %d...\n", iterNum);154 155 // Find stamps156 if (config->stampFile) {157 stamps = poisReadStamps(stamps, &stampsFP, refImage, mask, config);158 } else {159 stamps = poisFindStamps(stamps, refImage, mask, config);160 }161 int numStamps = 0;162 for (int s = 0; s < stamps->n; s++) {163 poisStamp *stamp = stamps->data[s];// Stamp of interest164 if (stamp->status != POIS_STAMP_BAD) {165 numStamps++;166 }167 }168 psTrace("pois.time", 1, "%d stamps found at %f sec\n", numStamps, getTime() - startTime);169 if (numStamps == 0) {170 fprintf(stderr, "No stamps found. Check input parameters.\n");171 exit(EXIT_FAILURE);172 }173 174 // Calculate equation175 (void)poisCalculateEquation(stamps, refImage, inImage, kernelBasisFunctions, config);176 psTrace("pois.time", 1, "Equation calculated at %f sec\n", getTime() - startTime);177 178 // Solve the equation179 solution = poisSolveEquation(solution, stamps, config);180 psTrace("pois.time", 1, "Matrix equation solved at %f sec\n", getTime() - startTime);181 182 #ifdef TESTING 183 // Print solution184 psTrace("pois.solution", 5, "Solution:\n");185 for (int i = 0; i < solution->n - 1; i++) {186 poisKernelBasis *kernel = kernelBasisFunctions->data[i]; // The i-th kernel basis function187 psTrace("pois.solution", 7, "%d: (%d,%d) x^%d y^%d --> %f\n", i, kernel->u, kernel->v,188 kernel->xOrder, kernel->yOrder, solution->data.F64[i]);189 }190 #endif 191 192 #ifdef TESTING 193 // Save the kernel postage stamp194 char kernelName[MAXCHAR];// File name for kernel195 snprintf(kernelName, MAXCHAR, "kernel%d.fits", iterNum);196 psImage *kernelImage = poisExtractKernel(solution, kernelBasisFunctions, 0.0, 0.0, config);197 psFits *kernelFile = psFitsAlloc(kernelName);198 if (!psFitsWriteImage(kernelFile, NULL, kernelImage, 0)) {199 psErrorStackPrint(stderr, "Unable to write kernel: %s\n", kernelName);200 }201 psTrace("pois", 1, "Kernel written to %s\n", kernelName);202 psFree(kernelFile);203 psFree(kernelImage);204 #endif 205 206 // Calculate deviations for the stamps207 psVector *deviations = poisCalculateDeviations(NULL, stamps, refImage, inImage, mask,208 kernelBasisFunctions, solution, config);209 badStamps = poisRejectStamps(stamps, mask, deviations, config);210 211 psFree(deviations);153 psTrace("pois", 1, "Iteration %d...\n", iterNum); 154 155 // Find stamps 156 if (config->stampFile) { 157 stamps = poisReadStamps(stamps, &stampsFP, refImage, mask, config); 158 } else { 159 stamps = poisFindStamps(stamps, refImage, mask, config); 160 } 161 int numStamps = 0; 162 for (int s = 0; s < stamps->n; s++) { 163 poisStamp *stamp = stamps->data[s]; // Stamp of interest 164 if (stamp->status != POIS_STAMP_BAD) { 165 numStamps++; 166 } 167 } 168 psTrace("pois.time", 1, "%d stamps found at %f sec\n", numStamps, getTime() - startTime); 169 if (numStamps == 0) { 170 fprintf(stderr, "No stamps found. Check input parameters.\n"); 171 exit(EXIT_FAILURE); 172 } 173 174 // Calculate equation 175 (void)poisCalculateEquation(stamps, refImage, inImage, kernelBasisFunctions, config); 176 psTrace("pois.time", 1, "Equation calculated at %f sec\n", getTime() - startTime); 177 178 // Solve the equation 179 solution = poisSolveEquation(solution, stamps, config); 180 psTrace("pois.time", 1, "Matrix equation solved at %f sec\n", getTime() - startTime); 181 182 #ifdef TESTING 183 // Print solution 184 psTrace("pois.solution", 5, "Solution:\n"); 185 for (int i = 0; i < solution->n - 1; i++) { 186 poisKernelBasis *kernel = kernelBasisFunctions->data[i]; // The i-th kernel basis function 187 psTrace("pois.solution", 7, "%d: (%d,%d) x^%d y^%d --> %f\n", i, kernel->u, kernel->v, 188 kernel->xOrder, kernel->yOrder, solution->data.F64[i]); 189 } 190 #endif 191 192 #ifdef TESTING 193 // Save the kernel postage stamp 194 char kernelName[MAXCHAR]; // File name for kernel 195 snprintf(kernelName, MAXCHAR, "kernel%d.fits", iterNum); 196 psImage *kernelImage = poisExtractKernel(solution, kernelBasisFunctions, 0.0, 0.0, config); 197 psFits *kernelFile = psFitsOpen(kernelName, "w"); 198 if (!psFitsWriteImage(kernelFile, NULL, kernelImage, 0)) { 199 psErrorStackPrint(stderr, "Unable to write kernel: %s\n", kernelName); 200 } 201 psTrace("pois", 1, "Kernel written to %s\n", kernelName); 202 psFitsClose(kernelFile); 203 psFree(kernelImage); 204 #endif 205 206 // Calculate deviations for the stamps 207 psVector *deviations = poisCalculateDeviations(NULL, stamps, refImage, inImage, mask, 208 kernelBasisFunctions, solution, config); 209 badStamps = poisRejectStamps(stamps, mask, deviations, config); 210 211 psFree(deviations); 212 212 } // Iterating for good solution 213 213 214 214 // If there was rejection on the last round, re-solve the equation using only the good stamps 215 215 if (badStamps) { 216 solution = poisSolveEquation(solution, stamps, config);216 solution = poisSolveEquation(solution, stamps, config); 217 217 } 218 218 219 219 if (stampsFP) { 220 fclose(stampsFP);220 fclose(stampsFP); 221 221 } 222 222 223 223 // Undo the mask for bad stamp area 224 224 for (int j = 0; j < mask->numRows; j++) { 225 for (int i = 0; i < mask->numCols; i++) {226 if (mask->data.U8[j][i] & POIS_MASK_STAMP) {227 mask->data.U8[j][i] &= ~POIS_MASK_STAMP;228 }229 }225 for (int i = 0; i < mask->numCols; i++) { 226 if (mask->data.U8[j][i] & POIS_MASK_STAMP) { 227 mask->data.U8[j][i] &= ~POIS_MASK_STAMP; 228 } 229 } 230 230 } 231 231 … … 239 239 #ifdef TESTING 240 240 // Save the convolved image 241 char convName[MAXCHAR]; // Filename for convolved image241 char convName[MAXCHAR]; // Filename for convolved image 242 242 snprintf(convName, MAXCHAR, "%s.conv", config->outFile); 243 psFits *convFile = psFits Alloc(convName);243 psFits *convFile = psFitsOpen(convName, "w"); 244 244 if (!psFitsWriteImage(convFile, NULL, convImage, 0)) { 245 psErrorStackPrint(stderr, "Unable to write convolved image: %s\n", convName);246 } 247 psF ree(convFile);245 psErrorStackPrint(stderr, "Unable to write convolved image: %s\n", convName); 246 } 247 psFitsClose(convFile); 248 248 psTrace("pois", 1, "Convolved image written to %s\n", convName); 249 249 #endif … … 252 252 psImage *subImage = psImageAlloc(config->xImage, config->yImage, PS_TYPE_F32); 253 253 if (config->reverse) { 254 (void)psBinaryOp(subImage, convImage, "-", inImage);254 (void)psBinaryOp(subImage, convImage, "-", inImage); 255 255 } else { 256 (void)psBinaryOp(subImage, inImage, "-", convImage);256 (void)psBinaryOp(subImage, inImage, "-", convImage); 257 257 } 258 258 psTrace("pois.time", 1, "Subtraction completed at %f sec\n", getTime() - startTime); … … 260 260 #ifdef TESTING 261 261 { 262 psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV);263 (void)psImageStats(stats, subImage, mask, 0);264 psTrace("pois", 5, "Subtracted image statistics: %f %f\n", stats->sampleMean, stats->sampleStdev);265 psFree(stats);262 psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV); 263 (void)psImageStats(stats, subImage, mask, 0); 264 psTrace("pois", 5, "Subtracted image statistics: %f %f\n", stats->sampleMean, stats->sampleStdev); 265 psFree(stats); 266 266 } 267 267 #endif … … 269 269 // Mask out the edges 270 270 for (int y = config->yKernel; y < subImage->numRows - config->yKernel; y++) { 271 for (int x = config->xKernel; x < subImage->numCols - config->xKernel; x++) {272 273 for (int x = 0; x < config->xKernel; x++) {274 subImage->data.F32[y][x] = 0.0;275 }276 for (int x = subImage->numCols - config->xKernel; x < subImage->numCols; x++) {277 subImage->data.F32[y][x] = 0.0;278 }279 }271 for (int x = config->xKernel; x < subImage->numCols - config->xKernel; x++) { 272 273 for (int x = 0; x < config->xKernel; x++) { 274 subImage->data.F32[y][x] = 0.0; 275 } 276 for (int x = subImage->numCols - config->xKernel; x < subImage->numCols; x++) { 277 subImage->data.F32[y][x] = 0.0; 278 } 279 } 280 280 } 281 281 for (int y = 0; y < config->yKernel; y++) { 282 for (int x = 0; x < subImage->numCols; x++) {283 subImage->data.F32[y][x] = 0.0;284 }282 for (int x = 0; x < subImage->numCols; x++) { 283 subImage->data.F32[y][x] = 0.0; 284 } 285 285 } 286 286 for (int y = subImage->numRows - config->yKernel; y < subImage->numRows; y++) { 287 for (int x = 0; x < subImage->numCols; x++) {288 subImage->data.F32[y][x] = 0.0;289 }287 for (int x = 0; x < subImage->numCols; x++) { 288 subImage->data.F32[y][x] = 0.0; 289 } 290 290 } 291 291 … … 293 293 // Mask out bad pixels 294 294 for (int y = config->yKernel; y < subImage->numRows - config->yKernel; y++) { 295 for (int x = config->xKernel; x < subImage->numCols - config->xKernel; x++) {296 if (mask->data.U8[y][x]) {297 subImage->data.F32[y][x] = 0.0;298 }299 }295 for (int x = config->xKernel; x < subImage->numCols - config->xKernel; x++) { 296 if (mask->data.U8[y][x]) { 297 subImage->data.F32[y][x] = 0.0; 298 } 299 } 300 300 } 301 301 302 302 if (config->mask) { 303 char maskName[80];// Name of mask image304 sprintf(maskName, "%s.mask", config->outFile);305 psFits *maskFile = psFitsAlloc(maskName);303 char maskName[80]; // Name of mask image 304 sprintf(maskName, "%s.mask", config->outFile); 305 psFits *maskFile = psFitsOpen(maskName, "w"); 306 306 if (!psFitsWriteImage(maskFile, NULL, mask, 0)) { 307 307 psErrorStackPrint(stderr, "Unable to write image: %s\n", maskName); 308 308 } 309 309 psTrace("pois", 1, "Mask image written to %s\n", maskName); 310 psF ree(maskFile);310 psFitsClose(maskFile); 311 311 } 312 312 … … 314 314 int numNaN = psImageClipNaN(subImage, 0.0); 315 315 if (numNaN > 0) { 316 printf("Masked %d NAN pixels to zero.\n", numNaN);317 } 318 319 psFits *subFile = psFits Alloc(config->outFile);316 printf("Masked %d NAN pixels to zero.\n", numNaN); 317 } 318 319 psFits *subFile = psFitsOpen(config->outFile, "w"); 320 320 if (!psFitsWriteImage(subFile, header, subImage, 0)) { 321 psErrorStackPrint(stderr, "Unable to write subtracted image: %s\n", config->outFile);322 } 323 psF ree(subFile);321 psErrorStackPrint(stderr, "Unable to write subtracted image: %s\n", config->outFile); 322 } 323 psFitsClose(subFile); 324 324 psTrace("pois", 1, "Subtracted image written to %s\n", config->outFile); 325 325 psTrace("pois.time", 1, "I/O completed at %f sec\n", getTime() - startTime); -
trunk/pois/src/poisCalculateDeviations.c
r5717 r5742 6 6 #define MAXCHAR 80 7 7 8 psVector *poisCalculateDeviations(psVector *deviations, // Output array of deviations, or NULL9 psArray *stamps, // Array of stamps10 psImage *refImage, // Reference image11 psImage *inImage, // Input image12 psImage *mask, // Mask image13 psArray *kernelParams, // Array of kernel parameters14 psVector *solution, // Solution vector15 poisConfig *config // Configuration8 psVector *poisCalculateDeviations(psVector *deviations, // Output array of deviations, or NULL 9 psArray *stamps, // Array of stamps 10 psImage *refImage, // Reference image 11 psImage *inImage, // Input image 12 psImage *mask, // Mask image 13 psArray *kernelParams, // Array of kernel parameters 14 psVector *solution, // Solution vector 15 poisConfig *config // Configuration 16 16 ) 17 17 { … … 32 32 33 33 if (!deviations) { 34 deviations = psVectorAlloc(stamps->n, PS_TYPE_F32);34 deviations = psVectorAlloc(stamps->n, PS_TYPE_F32); 35 35 } 36 36 37 int footprint = config->footprint; // Size of stamp footprint37 int footprint = config->footprint; // Size of stamp footprint 38 38 int xSize = footprint + config->xKernel; // (Half) size of subimage in x 39 39 int ySize = footprint + config->yKernel; // (Half) size of subimage in y 40 psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN); // Statistics40 psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN); // Statistics 41 41 42 42 psImage *subStamp = psImageAlloc(2 * xSize, 2 * ySize, PS_TYPE_F32); // Subtraction of stamp 43 43 for (int s = 0; s < stamps->n; s++) { 44 poisStamp *stamp = stamps->data[s]; // The coordinates of the stamp of interest45 int x = stamp->x;// Stamp x coord46 int y = stamp->y;// Stamp y coord47 if (stamp->status == POIS_STAMP_USED) {48 psRegion stampRegion = {x - xSize, x + xSize, y - ySize, y + ySize};49 psImage *refStamp = psImageSubset(refImage, stampRegion);50 psImage *inStamp = psImageSubset(inImage, stampRegion);51 psImage *maskStamp = psImageSubset(mask, stampRegion);52 psImage *convRefStamp = poisConvolveImage(refStamp, maskStamp, solution, kernelParams, config);53 // Calculate chi^254 (void)psBinaryOp(subStamp, inStamp, "-", convRefStamp);55 (void)psBinaryOp(subStamp, subStamp, "*", subStamp);56 (void)psBinaryOp(subStamp, subStamp, "/", inStamp);57 psRegion stampTrim = { config->xKernel, config->xKernel + 2 * footprint, config->yKernel,58 config->yKernel + 2 * footprint };59 psImage *subStampTrim = psImageSubset(subStamp, stampTrim);60 psImage *maskStampTrim = psImageSubset(maskStamp, stampTrim);61 // Copy image to workaround bug 30562 psImage *tempImage = psImageCopy(NULL, subStampTrim, PS_TYPE_F32);63 psImage *tempMask = psImageCopy(NULL, maskStampTrim, PS_TYPE_U8);64 65 (void)psImageStats(stats, tempImage, tempMask, POIS_MASK_BAD | POIS_MASK_NEAR_BAD);66 67 psFree(tempImage);68 psFree(tempMask);69 70 deviations->data.F32[s] = sqrtf(stats->sampleMean / 2.0);71 psTrace("pois.calculateDeviations", 5, "Deviation of stamp %d (%d,%d) is %f\n", s, x, y,72 deviations->data.F32[s]);73 44 poisStamp *stamp = stamps->data[s]; // The coordinates of the stamp of interest 45 int x = stamp->x; // Stamp x coord 46 int y = stamp->y; // Stamp y coord 47 if (stamp->status == POIS_STAMP_USED) { 48 psRegion stampRegion = {x - xSize, x + xSize, y - ySize, y + ySize}; 49 psImage *refStamp = psImageSubset(refImage, stampRegion); 50 psImage *inStamp = psImageSubset(inImage, stampRegion); 51 psImage *maskStamp = psImageSubset(mask, stampRegion); 52 psImage *convRefStamp = poisConvolveImage(refStamp, maskStamp, solution, kernelParams, config); 53 // Calculate chi^2 54 (void)psBinaryOp(subStamp, inStamp, "-", convRefStamp); 55 (void)psBinaryOp(subStamp, subStamp, "*", subStamp); 56 (void)psBinaryOp(subStamp, subStamp, "/", inStamp); 57 psRegion stampTrim = { config->xKernel, config->xKernel + 2 * footprint, config->yKernel, 58 config->yKernel + 2 * footprint }; 59 psImage *subStampTrim = psImageSubset(subStamp, stampTrim); 60 psImage *maskStampTrim = psImageSubset(maskStamp, stampTrim); 61 // Copy image to workaround bug 305 62 psImage *tempImage = psImageCopy(NULL, subStampTrim, PS_TYPE_F32); 63 psImage *tempMask = psImageCopy(NULL, maskStampTrim, PS_TYPE_U8); 64 65 (void)psImageStats(stats, tempImage, tempMask, POIS_MASK_BAD | POIS_MASK_NEAR_BAD); 66 67 psFree(tempImage); 68 psFree(tempMask); 69 70 deviations->data.F32[s] = sqrtf(stats->sampleMean / 2.0); 71 psTrace("pois.calculateDeviations", 5, "Deviation of stamp %d (%d,%d) is %f\n", s, x, y, 72 deviations->data.F32[s]); 73 74 74 #ifdef TESTING 75 char stampName[MAXCHAR];// File name for stamp76 snprintf(stampName, MAXCHAR, "stamp%d.fits", s);77 psFits *stampFile = psFitsAlloc(stampName);78 if (!psFitsWriteImage(stampFile, NULL, subStampTrim, 0)) {79 psErrorStackPrint(stderr, "Unable to write stamp: %s\n", stampName);80 }81 psFree(stampFile);75 char stampName[MAXCHAR]; // File name for stamp 76 snprintf(stampName, MAXCHAR, "stamp%d.fits", s); 77 psFits *stampFile = psFitsOpen(stampName, "w"); 78 if (!psFitsWriteImage(stampFile, NULL, subStampTrim, 0)) { 79 psErrorStackPrint(stderr, "Unable to write stamp: %s\n", stampName); 80 } 81 psFitsClose(stampFile); 82 82 #endif 83 83 84 84 #if 0 85 psFree(convRefStamp);86 psFree(maskStampTrim);87 psFree(subStampTrim);88 psFree(maskStamp);89 psFree(refStamp);90 psFree(inStamp);85 psFree(convRefStamp); 86 psFree(maskStampTrim); 87 psFree(subStampTrim); 88 psFree(maskStamp); 89 psFree(refStamp); 90 psFree(inStamp); 91 91 #endif 92 }92 } 93 93 } 94 94
Note:
See TracChangeset
for help on using the changeset viewer.
