IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 30, 2009, 11:06:34 AM (17 years ago)
Author:
bills
Message:

add keywords to the headers indicating that an output image is
destreaked or a recovery image

File:
1 edited

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
    110#include "streaksremove.h"
    211
     
    2332    }
    2433
    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
    2737
    2838    psString streaksFileName = psMetadataLookupStr(NULL, config->arguments, "STREAKS");
    2939
     40    // call Paul Sydney's code to parse the streaks file that DetectStreaks produced
    3041    Streaks *streaks = readStreaksFile(streaksFileName);
    3142    if (!streaks) {
     
    3445    }
    3546
     47    // open all of the input and output files, save their descriptions in the streakFiles struct
    3648    streakFiles *sfiles = openFiles(config, true, argv[0]);
    3749    setupAstrometry(sfiles);
    3850
     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
    3954    bool nanForRelease = psMetadataLookupBool(&status, config->arguments, "NAN_FOR_RELEASE");
    4055    if (nanForRelease && (sfiles->inMask == NULL)) {
     
    5267
    5368    if (checkNonWarpedPixels ) {
    54         // From ICD:
     69        // From magic ICD:
    5570        // In the raw and detrended images, the pixels which were not
    5671        // included in any of the streak-processed warps must also be masked.
     
    6984   
    7085    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
    7289        copyPHU(sfiles, true);
    7390
     
    8299    int totalStreakPixels = 0;
    83100
    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)
    85102    do {
    86103        bool exciseImageCube = false;
     
    110127            psTimerStart("GET_STREAK_PIXELS");
    111128
    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);
    115132            psLogMsg("streaksremove", PS_LOG_INFO, "time to get streak pixels: %f\n", psTimerClear("GET_STREAK_PIXELS"));
    116 
    117133           
     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
    118136            if (sfiles->inImage->image) {
    119137                if (checkNonWarpedPixels) {
     
    126144                    psLogMsg("streaksremove", PS_LOG_INFO, "time to excise non warped pixels: %f\n", psTimerClear("EXCISE_NON_WARPED"));
    127145                }
     146
    128147                totalStreakPixels +=  psArrayLength(pixels);
     148
    129149                psTimerStart("REMOVE_STREAKS");
     150
     151                // for each pixel covered by the streak
    130152                for (int i = 0; i < psArrayLength (pixels); ++i) {
    131153                    PixelPos *pixelPos = psArrayGet (pixels, i);
    132154
     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)
    133157                    if (!checkNonWarpedPixels || warpedPixel(sfiles, pixelPos)) {
    134158
     
    140164                    }
    141165                }
     166
    142167                psLogMsg("streaksremove", PS_LOG_INFO, "time to remove streak pixels: %f\n", psTimerClear("REMOVE_STREAKS"));
    143168
    144169                if (nanForRelease) {
     170                    // set any pixels that were masked, to NAN (unless they are already NAN)
    145171                    setMaskedToNAN(sfiles, maskMask, true);
    146172                }
    147173
    148174            } else {
    149                 // this component contains an image cube, excise it completely
     175                // this component contains an image cube
     176                // For now excise it completely
    150177                exciseImageCube = true;
    151178            }
     
    155182
    156183        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)
    157187            updateAstrometry(sfiles);
    158188        }
    159189
    160         // write out the destreaked temporary images and the recovery images
     190        // write the destreaked "temporary" images and the recovery images
    161191        writeImages(sfiles, exciseImageCube);
    162192
     
    168198    psLogMsg("streaksremove", PS_LOG_INFO, "pixels: %ld streak pixels: %ld %4.2f%%\n", totalPixels, totalStreakPixels, 100. * totalStreakPixels / totalPixels);
    169199
     200    // all done close the files. This is where the files are written so it can take a long time.
     201
    170202    psTimerStart("CLOSE_IMAGES");
    171     // close all files
     203
    172204    closeImages(sfiles);
     205
    173206    psLogMsg("streaksremove", PS_LOG_INFO, "time to close images: %f\n", psTimerClear("CLOSE_IMAGES"));
    174207
    175     // NOTE: from here on we can't just quit if something goes wrong.
    176     // especially if we're working at the raw stage
    177208
    178209    if (!replicateOutputs(sfiles)) {
     
    182213    }
    183214
     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
    184218    if (psMetadataLookupBool(&status, config->arguments, "REPLACE")) {
    185219        //     swap the instances for the input and output
    186         //     Note this is a database operation. No file I/O is performed
     220        //     Note this is a nebulous database operation. No file I/O is performed
    187221        if (!swapOutputsToInputs(sfiles)) {
    188222            psError(PS_ERR_UNKNOWN, false, "failed to swap files");
     
    192226
    193227            psErrorStackPrint(stderr, "");
     228
     229            // XXX: pick a specific error code for this failure
    194230            exit(PS_EXIT_UNKNOWN_ERROR);
    195231        }
    196232
     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
    197237        if (psMetadataLookupBool(&status, config->arguments, "REMOVE")) {
    198238            //      delete the temporary storage objects (which now points to the original image(s)
     
    210250            }
    211251        }
    212     }
     252#endif
     253
     254    }
     255    // all done. Clean up to look for memory leaks.
    213256
    214257    psFree(sfiles);
     
    425468    }
    426469
     470#ifdef notdef
     471    // This parameter is no longer supported
    427472    if ((argnum = psArgumentGet(argc, argv, "-remove"))) {
    428473        if (!gotReplace) {
     
    434479            true);
    435480    }
     481#endif
    436482
    437483    if (argc != 1) {
     
    451497updateAstrometry(streakFiles *sf)
    452498{
     499    // XXX: why do I check this here? Shouldn't it be just around the call to linearizeTransforms?
    453500    if (sf->bilevelAstrometry) {
    454501
     
    501548        }
    502549    }
    503     sf->outImage->header = (psMetadata*) psMemIncrRefCounter(sf->inImage->header);
     550    sf->outImage->header = psMemIncrRefCounter(sf->inImage->header);
    504551    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);
    507556
    508557    if (!SFILE_IS_IMAGE(sf->inImage)) {
     
    539588            sf->outMask->header = (psMetadata*) psMemIncrRefCounter(sf->inMask->header);
    540589            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);
    543594            if (updateAstrometry) {
    544595                pmAstromWriteWCS(sf->outMask->header, sf->inAstrom->fpa, sf->chip, 0.001);
     
    576627        sf->outWeight->header = (psMetadata*) psMemIncrRefCounter(sf->inWeight->header);
    577628        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);
    580633        if (updateAstrometry) {
    581634            pmAstromWriteWCS(sf->inWeight->header, sf->inAstrom->fpa, sf->chip, 0.001);
     
    597650    return true;
    598651}
    599 
    600 
    601652
    602653static void
Note: See TracChangeset for help on using the changeset viewer.