Changeset 16693
- Timestamp:
- Feb 27, 2008, 3:19:23 PM (18 years ago)
- Location:
- trunk/ppStack/src
- Files:
-
- 3 edited
-
ppStack.h (modified) (2 diffs)
-
ppStackLoop.c (modified) (2 diffs)
-
ppStackReadout.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppStack/src/ppStack.h
r16605 r16693 2 2 #define PP_STACK_H 3 3 4 #define PPSTACK_RECIPE "PPSTACK" 4 #define PPSTACK_RECIPE "PPSTACK" // Name of the recipe 5 #define PPSTACK_REJECTED_PIXELS "PPSTACK.PIXELS" // Name of rejected pixels metadata items 5 6 6 7 #include <psmodules.h> … … 26 27 27 28 // Perform stacking on a readout 28 bool ppStackReadout (const pmConfig *config, // Configuration29 bool ppStackReadoutInitial(const pmConfig *config, // Configuration 29 30 pmReadout *outRO, // Output readout 30 31 const psArray *readouts, // Input readouts 31 32 const psArray *regions, // Array with array of regions used in each PSF matching 32 33 const psArray *kernels // Array with array of kernels used in each PSF matching 34 ); 35 36 // Perform stacking on a readout 37 bool ppStackReadoutFinal(const pmConfig *config, // Configuration 38 pmReadout *outRO, // Output readout 39 const psArray *readouts, // Input readouts 40 const psArray *rejected // Array with pixels rejected in each image 33 41 ); 34 42 -
trunk/ppStack/src/ppStackLoop.c
r16686 r16693 413 413 #endif 414 414 415 if (!ppStackReadout (config, outRO, readouts, subRegions, subKernels)) {415 if (!ppStackReadoutInitial(config, outRO, readouts, subRegions, subKernels)) { 416 416 psError(PS_ERR_UNKNOWN, false, "Unable to stack images.\n"); 417 417 psFree(readouts); … … 432 432 } 433 433 434 psFree(readouts); 434 // Reset for the second read 435 // Extract the rejection lists 435 436 psFree(subKernels); 436 437 psFree(subRegions); 438 psArray *rejected = psArrayAlloc(num); // Rejected pixels 439 for (int i = 0; i < num; i++) { 440 pmReadout *ro = readouts->data[i]; // Readout of interest 441 pmReadoutFreeData(ro); 442 443 psPixels *rejects = NULL; // Rejection list for this readout 444 psMetadataIterator *iter = psMetadataIteratorAlloc(ro->analysis, PS_LIST_HEAD, 445 "^" PPSTACK_REJECTED_PIXELS "$"); // Iterator 446 psMetadataItem *item; 447 while ((item = psMetadataGetAndIncrement(iter))) { 448 psPixels *pixels = item->data.V; // Rejected pixels 449 psTrace("ppStack", 5, "Adding %ld rejected pixels to image %d", pixels->n, i); 450 rejects = psPixelsConcatenate(rejects, pixels); 451 } 452 psFree(iter); 453 psTrace("ppStack", 5, "%ld rejected pixels rejected from image %d", rejects->n, i); 454 psMetadataRemoveKey(ro->analysis, PPSTACK_REJECTED_PIXELS); 455 rejected->data[i] = rejects; 456 } 457 458 459 // Read convolutions by chunks 460 more = true; 461 for (int numChunk = 0; more; numChunk++) { 462 for (int i = 0; i < num; i++) { 463 pmReadout *readout = readouts->data[i]; 464 assert(readout); 465 466 if (!pmReadoutReadChunk(readout, imageFits->data[i], 0, numScans, 0) || 467 !pmReadoutReadChunkMask(readout, maskFits->data[i], 0, numScans, 0) || 468 !pmReadoutReadChunkWeight(readout, weightFits->data[i], 0, numScans, 0)) { 469 psError(PS_ERR_IO, false, "Unable to read chunk %d for file %d", numChunk, i); 470 psFree(readouts); 471 psFree(rejected); 472 psFree(outRO); 473 psFree(view); 474 return false; 475 } 476 } 477 478 #ifdef TESTING 479 { 480 pmReadout *ro = readouts->data[0]; 481 psTrace("ppStack", 1, "Stack: [%d:%d,%d:%d]\n", ro->col0, ro->col0 + ro->image->numCols, 482 ro->row0, ro->row0 + ro->image->numRows); 483 } 484 #endif 485 486 if (!ppStackReadoutFinal(config, outRO, readouts, rejected)) { 487 psError(PS_ERR_UNKNOWN, false, "Unable to stack images.\n"); 488 psFree(readouts); 489 psFree(rejected); 490 psFree(outRO); 491 psFree(view); 492 return false; 493 } 494 495 for (int i = 0; i < num && more; i++) { 496 pmReadout *readout = readouts->data[i]; 497 assert(readout); 498 more &= pmReadoutMore(readout, imageFits->data[i], 0, numScans); 499 more &= pmReadoutMoreMask(readout, maskFits->data[i], 0, numScans); 500 more &= pmReadoutMoreWeight(readout, weightFits->data[i], 0, numScans); 501 } 502 } 503 504 psFree(readouts); 505 437 506 for (int i = 0; i < num; i++) { 438 507 psFitsClose(imageFits->data[i]); -
trunk/ppStack/src/ppStackReadout.c
r16686 r16693 16 16 #define COMBINED_FILES // Write combined images? 17 17 18 static int sectionNum = 0; // Section number; for debugging outputs 19 20 21 bool ppStackReadout(const pmConfig *config, pmReadout *outRO, const psArray *readouts, 22 const psArray *regions, const psArray *kernels) 18 19 20 bool ppStackReadoutInitial(const pmConfig *config, pmReadout *outRO, const psArray *readouts, 21 const psArray *regions, const psArray *kernels) 23 22 { 24 23 assert(config); … … 29 28 assert(readouts->n == regions->n); 30 29 assert(regions->n == kernels->n); 30 static int sectionNum = 0; // Section number; for debugging outputs 31 31 32 32 … … 43 43 int kernelSize = psMetadataLookupS32(NULL, ppsub, "KERNEL.SIZE"); // Kernel half-size 44 44 45 46 int num = readouts->n; // Number of inputs 47 psArray *stack = psArrayAlloc(num); // Array for stacking 48 49 for (int i = 0; i < num; i++) { 50 pmReadout *ro = readouts->data[i]; 51 assert(ro); 52 pmFPA *fpa = ro->parent->parent->parent; // Parent FPA 53 54 float weighting = psMetadataLookupF32(&mdok, fpa->analysis, "PPSTACK.WEIGHTING"); // Relative weight 55 if (!mdok || !isfinite(weighting)) { 56 psWarning("No WEIGHTING supplied for image %d --- set to unity.", i); 57 weighting = 1.0; 58 } 59 60 // Ensure there is a mask, or pmStackCombine will complain 61 if (!ro->mask) { 62 ro->mask = psImageAlloc(ro->image->numCols, ro->image->numRows, PS_TYPE_MASK); 63 psImageInit(ro->mask, 0); 64 } 65 66 stack->data[i] = pmStackDataAlloc(ro, weighting); 67 } 68 69 if (!pmStackCombine(outRO, stack, maskBad, maskBlank, kernelSize, iter, combineRej, useVariance, safe)) { 70 psError(PS_ERR_UNKNOWN, false, "Unable to combine input readouts with rejection."); 71 psFree(stack); 72 return false; 73 } 74 75 #ifdef COMBINED_FILES 76 { 77 psString name = NULL; // Name of image 78 psStringAppend(&name, "combined_initial_%03d.fits", sectionNum); 79 psFits *fits = psFitsOpen(name, "w"); 80 psFree(name); 81 psFitsWriteImage(fits, NULL, outRO->image, 0, NULL); 82 psFitsClose(fits); 83 } 84 #endif 85 #ifdef INSPECTION_FILES 86 for (int i = 0; i < stack->n; i++) { 87 pmStackData *data = stack->data[i]; // Data for this image 88 psImage *inspected = psPixelsToMask(NULL, data->pixels, 89 psRegionSet(0, outRO->image->numCols - 1, 90 0, outRO->image->numRows - 1), 91 maskBlank); 92 psString name = NULL; // Name of image 93 psStringAppend(&name, "inspect_%03d_%03d.fits", sectionNum, i); 94 psFits *fits = psFitsOpen(name, "w"); 95 psFree(name); 96 psFitsWriteImage(fits, NULL, inspected, 0, NULL); 97 psFree(inspected); 98 psFitsClose(fits); 99 } 100 #endif 101 102 // Reject pixels 103 for (int i = 0; i < num; i++) { 104 pmStackData *data = stack->data[i]; // Data for this image 105 pmReadout *readout = data->readout; // Readout of interest 106 int col0 = readout->col0, row0 = readout->row0; // Offset for readout 107 int numCols = readout->image->numCols, numRows = readout->image->numRows; // Size of image 108 109 psRegion *valid = psRegionAlloc(col0, col0 + numCols, row0, row0 + numRows); // Valid region for rej 110 psPixels *reject = pmStackReject(data->pixels, valid, threshold, regions->data[i], 111 kernels->data[i]); // Pixels to reject 112 psFree(valid); 113 114 psMetadataAddPtr(readout->analysis, PS_LIST_TAIL, PPSTACK_REJECTED_PIXELS, 115 PS_DATA_PIXELS | PS_META_DUPLICATE_OK, "Rejected pixels from initial combination", 116 reject); 117 psFree(reject); // Drop reference 118 } 119 120 psFree(stack); 121 122 sectionNum++; 123 124 return true; 125 } 126 127 128 129 bool ppStackReadoutFinal(const pmConfig *config, pmReadout *outRO, const psArray *readouts, 130 const psArray *rejected) 131 { 132 assert(config); 133 assert(outRO); 134 assert(readouts); 135 assert(rejected); 136 assert(readouts->n == rejected->n); 137 138 static int sectionNum = 0; // Section number; for debugging outputs 139 140 141 // Get the recipe values 142 bool mdok; // Status of MD lookup 143 psMaskType maskBad = psMetadataLookupU8(NULL, config->arguments, "MASK.BAD"); // Value to mask 144 psMaskType maskBlank = psMetadataLookupU8(NULL, config->arguments, "MASK.BLANK"); // Mask for blank reg. 145 bool useVariance = psMetadataLookupBool(&mdok, config->arguments, "VARIANCE"); // Use variance for rejection? 45 146 46 147 int num = readouts->n; // Number of inputs … … 110 211 psListAdd(cellList, PS_LIST_TAIL, ro->parent); 111 212 112 stack->data[i] = pmStackDataAlloc(ro, weighting); 113 } 114 115 if (!pmStackCombine(outRO, stack, maskBad, maskBlank, kernelSize, iter, combineRej, useVariance, safe)) { 116 psError(PS_ERR_UNKNOWN, false, "Unable to combine input readouts with rejection."); 117 psFree(fpaList); 118 psFree(cellList); 119 psFree(stack); 120 return false; 121 } 122 123 #ifdef COMBINED_FILES 124 { 125 psString name = NULL; // Name of image 126 psStringAppend(&name, "combined1_%03d.fits", sectionNum); 127 psFits *fits = psFitsOpen(name, "w"); 128 psFree(name); 129 psFitsWriteImage(fits, NULL, outRO->image, 0, NULL); 130 psFitsClose(fits); 131 } 132 #endif 133 #ifdef INSPECTION_FILES 134 for (int i = 0; i < stack->n; i++) { 135 pmStackData *data = stack->data[i]; // Data for this image 136 psImage *inspected = psPixelsToMask(NULL, data->pixels, 137 psRegionSet(0, data->readout->image->numCols - 1, 138 0, data->readout->image->numRows - 1), 139 maskBlank); 140 psString name = NULL; // Name of image 141 psStringAppend(&name, "inspect_%03d_%03d.fits", sectionNum, i); 142 psFits *fits = psFitsOpen(name, "w"); 143 psFree(name); 144 psFitsWriteImage(fits, NULL, inspected, 0, NULL); 145 psFree(inspected); 146 psFitsClose(fits); 147 } 148 #endif 149 150 // Reject pixels 151 for (int i = 0; i < num; i++) { 152 pmStackData *data = stack->data[i]; // Data for this image 153 pmReadout *readout = data->readout; // Readout of interest 154 int col0 = readout->col0, row0 = readout->row0; // Offset for readout 155 int numCols = readout->image->numCols, numRows = readout->image->numRows; // Size of image 156 157 psRegion *valid = psRegionAlloc(col0, col0 + numCols, row0, row0 + numRows); // Valid region for rej 158 psPixels *reject = pmStackReject(data->pixels, valid, threshold, regions->data[i], 159 kernels->data[i]); // Pixels to reject 160 psFree(valid); 161 psFree(data->pixels); 162 data->pixels = reject; 213 pmStackData *data = pmStackDataAlloc(ro, weighting); 214 data->pixels = psMemIncrRefCounter(rejected->data[i]); 215 stack->data[i] = data; 163 216 } 164 217 165 218 #ifdef REJECTION_FILES 166 for (int i = 0; i < stack->n; i++) { 167 pmStackData *data = stack->data[i]; // Data for this image 168 if (!data) { 169 continue; 170 } 171 psImage *rejected = psPixelsToMask(NULL, data->pixels, 172 psRegionSet(0, data->readout->image->numCols - 1, 173 0, data->readout->image->numRows - 1), 174 maskBlank); 175 psString name = NULL; // Name of image 176 psStringAppend(&name, "reject_%03d_%03d.fits", sectionNum, i); 177 psFits *fits = psFitsOpen(name, "w"); 178 psFree(name); 179 psFitsWriteImage(fits, NULL, rejected, 0, NULL); 180 psFree(rejected); 181 psFitsClose(fits); 182 } 183 #endif 184 185 if (!pmStackCombine(outRO, stack, maskBad, maskBlank, kernelSize, 0, combineRej, useVariance, false)) { 219 if (sectionNum == 0) { 220 for (int i = 0; i < stack->n; i++) { 221 pmStackData *data = stack->data[i]; // Data for this image 222 if (!data) { 223 continue; 224 } 225 psImage *reject = psPixelsToMask(NULL, data->pixels, 226 psRegionSet(0, outRO->image->numCols - 1, 227 0, outRO->image->numRows - 1), 228 maskBlank); 229 psString name = NULL; // Name of image 230 psStringAppend(&name, "reject_%03d.fits", i); 231 psFits *fits = psFitsOpen(name, "w"); 232 psFree(name); 233 psFitsWriteImage(fits, NULL, reject, 0, NULL); 234 psFree(reject); 235 psFitsClose(fits); 236 } 237 } 238 #endif 239 240 if (!pmStackCombine(outRO, stack, maskBad, maskBlank, 0, 0, NAN, useVariance, false)) { 186 241 psError(PS_ERR_UNKNOWN, false, "Unable to combine input readouts."); 187 242 psFree(fpaList); … … 194 249 { 195 250 psString name = NULL; // Name of image 196 psStringAppend(&name, "combined 2_%03d.fits", sectionNum);251 psStringAppend(&name, "combined_final_%03d.fits", sectionNum); 197 252 psFits *fits = psFitsOpen(name, "w"); 198 253 psFree(name); … … 219 274 psFree(stack); 220 275 221 sectionNum++;222 223 276 return true; 224 277 }
Note:
See TracChangeset
for help on using the changeset viewer.
