Changeset 24283 for trunk/magic/remove/src/streaksremove.c
- Timestamp:
- May 30, 2009, 11:06:34 AM (17 years ago)
- File:
-
- 1 edited
-
trunk/magic/remove/src/streaksremove.c (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/magic/remove/src/streaksremove.c
r23965 r24283 1 /* 2 * streaksremove 3 * 4 * Convert satellite streak detctions into masks and remove the covered pixels from the 5 * input images. 6 * Optionally swap the inputs with the outputs so that subsequent references to the original 7 * images access the destreaked versions. 8 */ 9 1 10 #include "streaksremove.h" 2 11 … … 23 32 } 24 33 25 psU32 maskStreak = 0; 26 psU32 maskMask = 0; 34 // Values to set for masked pixels 35 psU32 maskStreak = 0; // for the image and weight (usually NAN, MAXINT for integer images) 36 psU32 maskMask = 0; // value looked up for MASK.STREAK 27 37 28 38 psString streaksFileName = psMetadataLookupStr(NULL, config->arguments, "STREAKS"); 29 39 40 // call Paul Sydney's code to parse the streaks file that DetectStreaks produced 30 41 Streaks *streaks = readStreaksFile(streaksFileName); 31 42 if (!streaks) { … … 34 45 } 35 46 47 // open all of the input and output files, save their descriptions in the streakFiles struct 36 48 streakFiles *sfiles = openFiles(config, true, argv[0]); 37 49 setupAstrometry(sfiles); 38 50 51 // Optionally we can set pixels that are masked to NAN since they couldn't have been 52 // examined for streaks. Usually this is done by the distribution system just prior 53 // to release 39 54 bool nanForRelease = psMetadataLookupBool(&status, config->arguments, "NAN_FOR_RELEASE"); 40 55 if (nanForRelease && (sfiles->inMask == NULL)) { … … 52 67 53 68 if (checkNonWarpedPixels ) { 54 // From ICD:69 // From magic ICD: 55 70 // In the raw and detrended images, the pixels which were not 56 71 // included in any of the streak-processed warps must also be masked. … … 69 84 70 85 if (sfiles->stage == IPP_STAGE_RAW) { 71 // copy PHU to output files 86 // Except for raw stage, all of our (GPC1) files have one image extension. 87 // Raw files have a phu and multiple extensions, one per chip 88 // Since this is a raw file, copy it's PHU to output files 72 89 copyPHU(sfiles, true); 73 90 … … 82 99 int totalStreakPixels = 0; 83 100 84 // Iterate through each component of the input ( there is only one except for raw images)101 // Iterate through each component of the input (except for raw images there is only one) 85 102 do { 86 103 bool exciseImageCube = false; … … 110 127 psTimerStart("GET_STREAK_PIXELS"); 111 128 112 StreakPixels *pixels = streak_on_component (streaks, sfiles->astrom,113 sfiles->inImage->numCols, sfiles->inImage->numRows);114 129 // call Paul Sydney's code to compute the set of pixels that are covered by the detected streaks 130 StreakPixels *pixels = streak_on_component(streaks, sfiles->astrom, sfiles->inImage->numCols, 131 sfiles->inImage->numRows); 115 132 psLogMsg("streaksremove", PS_LOG_INFO, "time to get streak pixels: %f\n", psTimerClear("GET_STREAK_PIXELS")); 116 117 133 134 // if this extension contained an image, excise the streaked pixels. 135 // otherwise it contained an image cube (video cell) which is handled in the if block 118 136 if (sfiles->inImage->image) { 119 137 if (checkNonWarpedPixels) { … … 126 144 psLogMsg("streaksremove", PS_LOG_INFO, "time to excise non warped pixels: %f\n", psTimerClear("EXCISE_NON_WARPED")); 127 145 } 146 128 147 totalStreakPixels += psArrayLength(pixels); 148 129 149 psTimerStart("REMOVE_STREAKS"); 150 151 // for each pixel covered by the streak 130 152 for (int i = 0; i < psArrayLength (pixels); ++i) { 131 153 PixelPos *pixelPos = psArrayGet (pixels, i); 132 154 155 // if this pixel was not part of the warp, skip because it has already been 156 // excised (unless we weren't asked to check) 133 157 if (!checkNonWarpedPixels || warpedPixel(sfiles, pixelPos)) { 134 158 … … 140 164 } 141 165 } 166 142 167 psLogMsg("streaksremove", PS_LOG_INFO, "time to remove streak pixels: %f\n", psTimerClear("REMOVE_STREAKS")); 143 168 144 169 if (nanForRelease) { 170 // set any pixels that were masked, to NAN (unless they are already NAN) 145 171 setMaskedToNAN(sfiles, maskMask, true); 146 172 } 147 173 148 174 } else { 149 // this component contains an image cube, excise it completely 175 // this component contains an image cube 176 // For now excise it completely 150 177 exciseImageCube = true; 151 178 } … … 155 182 156 183 if (sfiles->stage == IPP_STAGE_CHIP) { 184 // as a convience to the user of the output, replace the bogus WCS transform in the 185 // chip processed files with the data calcuated by psastro at the camera stage 186 // (actually we use a linear approximation) 157 187 updateAstrometry(sfiles); 158 188 } 159 189 160 // write out the destreaked temporaryimages and the recovery images190 // write the destreaked "temporary" images and the recovery images 161 191 writeImages(sfiles, exciseImageCube); 162 192 … … 168 198 psLogMsg("streaksremove", PS_LOG_INFO, "pixels: %ld streak pixels: %ld %4.2f%%\n", totalPixels, totalStreakPixels, 100. * totalStreakPixels / totalPixels); 169 199 200 // all done close the files. This is where the files are written so it can take a long time. 201 170 202 psTimerStart("CLOSE_IMAGES"); 171 // close all files 203 172 204 closeImages(sfiles); 205 173 206 psLogMsg("streaksremove", PS_LOG_INFO, "time to close images: %f\n", psTimerClear("CLOSE_IMAGES")); 174 207 175 // NOTE: from here on we can't just quit if something goes wrong.176 // especially if we're working at the raw stage177 208 178 209 if (!replicateOutputs(sfiles)) { … … 182 213 } 183 214 215 // NOTE: from here on we can't just quit if something goes wrong. 216 // especially if we're working at the raw stage 217 184 218 if (psMetadataLookupBool(&status, config->arguments, "REPLACE")) { 185 219 // swap the instances for the input and output 186 // Note this is a database operation. No file I/O is performed220 // Note this is a nebulous database operation. No file I/O is performed 187 221 if (!swapOutputsToInputs(sfiles)) { 188 222 psError(PS_ERR_UNKNOWN, false, "failed to swap files"); … … 192 226 193 227 psErrorStackPrint(stderr, ""); 228 229 // XXX: pick a specific error code for this failure 194 230 exit(PS_EXIT_UNKNOWN_ERROR); 195 231 } 196 232 233 #ifdef notdef 234 // XXX: we've decided to not do the remove step here 235 // Instead we leave the backup images (the original images) in place and remove them 236 // later on 197 237 if (psMetadataLookupBool(&status, config->arguments, "REMOVE")) { 198 238 // delete the temporary storage objects (which now points to the original image(s) … … 210 250 } 211 251 } 212 } 252 #endif 253 254 } 255 // all done. Clean up to look for memory leaks. 213 256 214 257 psFree(sfiles); … … 425 468 } 426 469 470 #ifdef notdef 471 // This parameter is no longer supported 427 472 if ((argnum = psArgumentGet(argc, argv, "-remove"))) { 428 473 if (!gotReplace) { … … 434 479 true); 435 480 } 481 #endif 436 482 437 483 if (argc != 1) { … … 451 497 updateAstrometry(streakFiles *sf) 452 498 { 499 // XXX: why do I check this here? Shouldn't it be just around the call to linearizeTransforms? 453 500 if (sf->bilevelAstrometry) { 454 501 … … 501 548 } 502 549 } 503 sf->outImage->header = (psMetadata*)psMemIncrRefCounter(sf->inImage->header);550 sf->outImage->header = psMemIncrRefCounter(sf->inImage->header); 504 551 if (sf->recImage) { 505 sf->recImage->header = (psMetadata*) psMemIncrRefCounter(sf->inImage->header); 506 } 552 sf->recImage->header = psMetadataCopy(NULL, sf->inImage->header); 553 addRecoveryKeyword(sf->recImage->header); 554 } 555 addDestreakKeyword(sf->outImage->header); 507 556 508 557 if (!SFILE_IS_IMAGE(sf->inImage)) { … … 539 588 sf->outMask->header = (psMetadata*) psMemIncrRefCounter(sf->inMask->header); 540 589 if (sf->recMask) { 541 sf->recMask->header = (psMetadata*) psMemIncrRefCounter(sf->inMask->header); 542 } 590 sf->recMask->header = psMetadataCopy(NULL, sf->outMask->header); 591 addRecoveryKeyword(sf->recMask->header); 592 } 593 addDestreakKeyword(sf->outMask->header); 543 594 if (updateAstrometry) { 544 595 pmAstromWriteWCS(sf->outMask->header, sf->inAstrom->fpa, sf->chip, 0.001); … … 576 627 sf->outWeight->header = (psMetadata*) psMemIncrRefCounter(sf->inWeight->header); 577 628 if (sf->recWeight) { 578 sf->recWeight->header = (psMetadata*) psMemIncrRefCounter(sf->inWeight->header); 579 } 629 sf->recWeight->header = psMetadataCopy(NULL, sf->outWeight->header); 630 addRecoveryKeyword(sf->recWeight->header); 631 } 632 addDestreakKeyword(sf->outWeight->header); 580 633 if (updateAstrometry) { 581 634 pmAstromWriteWCS(sf->inWeight->header, sf->inAstrom->fpa, sf->chip, 0.001); … … 597 650 return true; 598 651 } 599 600 601 652 602 653 static void
Note:
See TracChangeset
for help on using the changeset viewer.
