IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 16, 2009, 12:22:44 PM (16 years ago)
Author:
bills
Message:

switch to using auto tools

Location:
trunk/magic/remove
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/magic/remove

    • Property svn:ignore set to
      configure
      Makefile.in
      Doxyfile
      config.log
      depcomp
      config.status
      config.guess
      ltmain.sh
      config.sub
      autom4te.cache
      libtool
      missing
      Makefile
      aclocal.m4
      install-sh

  • trunk/magic/remove/src

    • Property svn:ignore
      •  

        old new  
        44streakscompare
        55streaksrelease
        6 makefile
         6Makefile
         7Makefile.in
         8config.h
         9.deps
         10streaksVersionDefinitions.h
         11config.h.in
  • trunk/magic/remove/src/streaksremove.c

    r26408 r26438  
    1212static pmConfig *parseArguments(int argc, char **argv);
    1313static bool readAndCopyToOutput(streakFiles *sf, bool exciseAll);
    14 static void exciseNonWarpedPixels(streakFiles *sfiles, psImageMaskType newMaskValue);
    15 static bool warpedPixel(streakFiles *sfiles, int x, int y);
     14static void exciseNonDiffedPixels(streakFiles *sfiles, psImageMaskType newMaskValue);
     15static bool diffedPixel(streakFiles *sfiles, int x, int y);
    1616static void excisePixel(streakFiles *sfiles, unsigned int x, unsigned int y, bool streak, psImageMaskType newMaskValue);
    1717static void writeImages(streakFiles *sf, bool exciseImageCube);
    1818static void updateAstrometry(streakFiles *sfiles);
    1919static void censorSources(streakFiles *sfiles, psImageMaskType maskStreak);
    20 static long censorPixels(streakFiles *sfiles, psImage * pixels, bool checkNonWarpedPixels, psU16 maskStreak);
    21 
     20static long censorPixels(streakFiles *sfiles, psImage * pixels, bool checkNonDiffedPixels, psU16 maskStreak);
     21
     22// Note: For clarity the flow of this program is in main().
     23// There is not a lot of error checking is done in main.
     24// Until the end, where we might be doing Nebulous operations, called functions exit when an error
     25// is encountered.
    2226int
    2327main(int argc, char *argv[])
     
    2630
    2731    psLibInit(NULL);
    28     psTimerStart("STREAKSREMOVE");
     32    psTimerStart("TOTAL_TIME");
    2933
    3034    pmConfig *config = parseArguments(argc, argv);
     
    4650    streakFiles *sfiles = openFiles(config, true, argv[0]);
    4751    setupAstrometry(sfiles);
     52    sfiles->stats = psMetadataAlloc();
    4853
    4954    // Optionally we can set pixels that are masked to NAN since they couldn't have been
     
    5762
    5863    bool exciseAll = false;
    59     // --keepnonwarped is a test and debug mode
    60     bool keepNonWarpedPixels = psMetadataLookupBool(&status, config->arguments, "KEEP_NON_WARPED");
    61 
    62     // we need to check for non warped pixels unless we've been asked not to or the stage is diff
    63     // (By definition pixels in diff images were included in a diff)
    64     bool checkNonWarpedPixels = ! (keepNonWarpedPixels || (sfiles->stage == IPP_STAGE_DIFF) );
    65 
    66     if (checkNonWarpedPixels ) {
     64    // --keepnondiffed is a test and debug mode
     65    bool keepNonDiffedPixels = psMetadataLookupBool(&status, config->arguments, "KEEP_NON_DIFFED");
     66
     67    // we need to check for non diffed pixels unless we've been asked not to or the stage is diff
     68    // (By definition pixels in diff images were included in the difference images)
     69    bool checkNonDiffedPixels = ! (keepNonDiffedPixels || (sfiles->stage == IPP_STAGE_DIFF) );
     70
     71    if (checkNonDiffedPixels ) {
    6772        // From magic ICD:
    6873        // In the raw and detrended images, the pixels which were not
     
    7277        // if no skycells are provided sfiles->exciseAll is set to true
    7378
    74         psTimerStart("COMPUTE_WARPED_PIXELS");
    75         if (! computeWarpedPixels(sfiles) ) {
     79        psTimerStart("COMPUTE_DIFFED_PIXELS");
     80        if (! computeDiffedPixels(sfiles) ) {
    7681            // we have no choice to excise all pixels
    7782            exciseAll = true;
    7883        }
    79         psF64 cwp_t = psTimerClear("COMPUTE_WARPED_PIXELS");
    80         psLogMsg("streaksremove", PS_LOG_INFO, "time to compute warped pixels: %f\n", cwp_t);
     84        psF64 cdp_t = psTimerClear("COMPUTE_DIFFED_PIXELS");
     85        psMetadataAddF64(sfiles->stats, PS_LIST_TAIL, "COMPUTE_UNDIFFED_PIXELS", PS_META_REPLACE, "time to compute non-diffedpixels", cdp_t);
     86        psLogMsg("streaksremove", PS_LOG_INFO, "time to compute diffed pixels: %f\n", cdp_t);
    8187    }
    8288
     
    97103    long totalStreakPixels = 0;
    98104
     105    // accumulators for the various timers
     106    psF64 gsp_t = 0;
     107    psF64 enw_t = 0;
     108    psF64 rms_t = 0;
     109    psF64 cs_t = 0;
     110    psF64 wi_t = 0;
    99111    // Iterate through each component of the input (except for raw images there is only one)
    100112    do {
     
    126138            StreakPixels *pixels = streak_on_component(streaks, sfiles->astrom, sfiles->inImage->numCols,
    127139                                                        sfiles->inImage->numRows);
     140            gsp_t +=  psTimerClear("GET_STREAK_PIXELS");
     141            psMetadataAddF64(sfiles->stats, PS_LIST_TAIL, "GET_STREAK_PIXELS", PS_META_REPLACE, "", gsp_t);
    128142            psLogMsg("streaksremove", PS_LOG_INFO, "time to get streak pixels: %f\n", psTimerClear("GET_STREAK_PIXELS"));
    129143
     
    131145            // otherwise it contained an image cube (video cell) which is handled in the if block
    132146            if (sfiles->inImage->image) {
    133                 if (checkNonWarpedPixels) {
    134                     psTimerStart("EXCISE_NON_WARPED");
    135 
    136                     // set non-warped pixels and variance to NAN, mask to maskStreak (since the pixel
     147                if (checkNonDiffedPixels) {
     148                    psTimerStart("EXCISE_NON_DIFFED");
     149
     150                    // set non-diffed pixels and variance to NAN, mask to maskStreak (since the pixel
    137151                    // is excised as part of the destreaking process)
    138                     exciseNonWarpedPixels(sfiles, sfiles->maskStreak);
    139 
    140                     psLogMsg("streaksremove", PS_LOG_INFO, "time to excise non warped pixels: %f\n", psTimerClear("EXCISE_NON_WARPED"));
     152                    exciseNonDiffedPixels(sfiles, sfiles->maskStreak);
     153
     154                    enw_t +=  psTimerClear("EXCISE_NON_DIFFED");
     155                    psMetadataAddF64(sfiles->stats, PS_LIST_TAIL, "EXCISE_NON_DIFFED", PS_META_REPLACE, "", enw_t);
     156                    psLogMsg("streaksremove", PS_LOG_INFO, "time to excise non diffed pixels: %f\n", enw_t);
    141157                }
    142158
    143159                psTimerStart("REMOVE_STREAKS");
    144160
    145                 totalStreakPixels += censorPixels(sfiles, pixels, checkNonWarpedPixels, sfiles->maskStreak);
    146 
    147                 psLogMsg("streaksremove", PS_LOG_INFO, "time to remove streak pixels: %f\n", psTimerClear("REMOVE_STREAKS"));
     161                totalStreakPixels += censorPixels(sfiles, pixels, checkNonDiffedPixels, sfiles->maskStreak);
     162
     163                rms_t += psTimerClear("REMOVE_STREAKS");
     164                psMetadataAddF64(sfiles->stats, PS_LIST_TAIL, "REMOVE_STREAKS", PS_META_REPLACE, "", enw_t);
     165                psLogMsg("streaksremove", PS_LOG_INFO, "time to remove streak pixels: %f\n", rms_t);
    148166
    149167                if (nanForRelease) {
     
    167185        }
    168186
     187        psTimerStart("CENSOR_SOURCES");
    169188        censorSources(sfiles, sfiles->maskStreak);
     189        cs_t += psTimerClear("CENSOR_SOURCES");
     190        psMetadataAddF64(sfiles->stats, PS_LIST_TAIL, "CENSOR_SOURCES", PS_META_REPLACE, "", cs_t);
     191
    170192
    171193        // write the destreaked "temporary" images and the recovery images
     194        psTimerStart("WRITE_IMAGES");
    172195        writeImages(sfiles, exciseImageCube);
    173 
     196        wi_t += psTimerClear("WRITE_IMAGES");
     197        psMetadataAddF64(sfiles->stats, PS_LIST_TAIL, "WRITE_IMAGES", PS_META_REPLACE, "", wi_t);
    174198
    175199        psLogMsg("streaksremove", PS_LOG_INFO, "time to process component %d: %f\n", sfiles->extnum, psTimerClear("PROCESS_COMPONENT"));
     
    179203    psFree(streaks);
    180204
    181     psLogMsg("streaksremove", PS_LOG_INFO, "pixels: %ld streak pixels: %ld %4.2f%%\n", totalPixels, totalStreakPixels, 100. * totalStreakPixels / totalPixels);
     205    if (exciseAll) {
     206        totalStreakPixels = totalPixels;
     207    }
     208
     209    psF64 maskedFraction = totalStreakPixels / totalPixels;
     210    psLogMsg("streaksremove", PS_LOG_INFO, "pixels: %ld streak pixels: %ld %4.2f%%\n", totalPixels, totalStreakPixels, maskedFraction * 100);
     211    psMetadataAddF64(sfiles->stats, PS_LIST_TAIL, "MASKED_FRACTION", PS_META_REPLACE, "", maskedFraction);
    182212
    183213    // check the weight and mask files for extra extensions that might be in files
     
    188218
    189219    psTimerStart("CLOSE_IMAGES");
    190 
    191220    closeImages(sfiles);
    192 
    193     psLogMsg("streaksremove", PS_LOG_INFO, "time to close images: %f\n", psTimerClear("CLOSE_IMAGES"));
    194 
    195 
     221    psF64 ci_t = psTimerClear("CLOSE_IMAGES");
     222    psMetadataAddF64(sfiles->stats, PS_LIST_TAIL, "CLOSE_IMAGES", PS_META_REPLACE, "", ci_t);
     223
     224    psLogMsg("streaksremove", PS_LOG_INFO, "time to close images: %f\n", ci_t);
     225
     226    psTimerStart("REPLICATE_OUTPUTS");
    196227    if (!replicateOutputs(sfiles)) {
    197228        psErrorStackPrint(stderr, "failed to replicate output files");
     
    199230        exit(PS_EXIT_UNKNOWN_ERROR);
    200231    }
     232    psF64 ro_t = psTimerClear("REPLICATE_OUTPUTS");
     233    psMetadataAddF64(sfiles->stats, PS_LIST_TAIL, "REPLICATE_OUTPUTS", PS_META_REPLACE, "", ro_t);
    201234
    202235    // NOTE: from here on we can't just quit if something goes wrong.
     
    208241        //     swap the instances for the input and output
    209242        //     Note this is a nebulous database operation. No file I/O is performed
     243        psTimerStart("SWAP_INSTANCES");
    210244        if (!swapOutputsToInputs(sfiles)) {
    211             // XXX: Now what?
    212245            // It is up to the program that reverts failed destreak runs to insure that
    213             // any input files that have been swapped are restored and that the de-streaked
    214             // versions are deleted
     246            // any original non-destreaked input files that have been swapped are restored and that the de-streaked
     247            // versions are deleted.
    215248
    216249            psErrorStackPrint(stderr, "failed to swap files");
     
    218251            // XXX: pick a specific error code for this failure
    219252            exit(PS_EXIT_UNKNOWN_ERROR);
     253        }
     254        psF64 si_t = psTimerClear("SWAP_INSTANCES");
     255        psMetadataAddF64(sfiles->stats, PS_LIST_TAIL, "SWAP_INSTANCES", PS_META_REPLACE, "", si_t);
     256    }
     257
     258    psF64 total_time = psTimerClear("TOTAL_TIME");
     259    psMetadataAddF64(sfiles->stats, PS_LIST_TAIL, "TOTAL_TIME", PS_META_REPLACE, "", total_time);
     260    psLogMsg("streaksremove", PS_LOG_INFO, "time to run streaksremove: %f\n", total_time);
     261
     262    if (sfiles->statsFile) {
     263        const char *statsMDC = psMetadataConfigFormat(sfiles->stats);
     264        if (!statsMDC || strlen(statsMDC) == 0) {
     265            psError(PS_ERR_IO, false, "Unable to get statistics MDC file.\n");
     266        } else {
     267            fprintf(sfiles->statsFile, "%s", statsMDC);
     268            psFree((void *)statsMDC);
     269            fclose(sfiles->statsFile);
     270            sfiles->statsFile = NULL;
     271            psFree(sfiles->stats);
     272            sfiles->stats = NULL;
    220273        }
    221274    }
     
    228281    streaksNebulousCleanup();
    229282    pmConfigDone();
    230     psLogMsg("streaksremove", PS_LOG_INFO, "time to run streaksremove: %f\n", psTimerClear("STREAKSREMOVE"));
    231283    psLibFinalize();
    232284
     
    237289
    238290static long
    239 censorPixels(streakFiles *sfiles, psImage *pixels, bool checkNonWarpedPixels, psU16 maskStreak)
     291censorPixels(streakFiles *sfiles, psImage *pixels, bool checkNonDiffedPixels, psU16 maskStreak)
    240292{
    241293    long streakPixels = 0;
     
    245297            if (psImageGet(pixels, x, y)) {
    246298                ++streakPixels;
    247                 if (!checkNonWarpedPixels || warpedPixel(sfiles, x, y)) {
     299                if (!checkNonDiffedPixels || diffedPixel(sfiles, x, y)) {
    248300
    249301                    excisePixel(sfiles, x, y, true, maskStreak);
     
    251303                } else {
    252304                    // This pixel was not included in any warp and has thus already excised
    253                     // by exciseNonWarpedPixels
     305                    // by exciseNonDiffedPixels
    254306                }
    255307            }
     
    268320    fprintf(stderr, "\t-weight WEIGHT.fits: weight file to de-streak\n");
    269321    fprintf(stderr, "\t-replace: replace the input images with the output\n");
    270     fprintf(stderr, "\t-keepnonwarped: do not exise pixels that were not part of difference processing\n");
     322    fprintf(stderr, "\t-keepnondiffed: do not exise pixels that were not part of difference processing\n");
    271323    fprintf(stderr, "\t-transparent val: instead of setting excicsed pixel to NAN add val\n");
    272324    fprintf(stderr, "\t-chip_mask MASK.fits: name of mask for chip stage (camera stage mask is passed tih -mask)\n");
     
    359411    }
    360412
    361     if ((argnum = psArgumentGet(argc, argv, "-keepnonwarped"))) {
    362         psArgumentRemove(argnum, &argc, argv);
    363         psMetadataAddBool(config->arguments, PS_LIST_TAIL, "KEEP_NON_WARPED", 0,
    364             "skip excising of non warped pixels", true);
     413    if ((argnum = psArgumentGet(argc, argv, "-keepnondiffed"))) {
     414        psArgumentRemove(argnum, &argc, argv);
     415        psMetadataAddBool(config->arguments, PS_LIST_TAIL, "KEEP_NON_DIFFED", 0,
     416            "skip excising of non diffed pixels", true);
    365417    }
    366418
     
    377429    }
    378430
    379     // if skycells are not provided then we have to execise all pixels  unless -keepnonwarped
     431    // if skycells are not provided then we have to execise all pixels  unless -keepnondiffed
    380432    pmConfigFileSetsMD(config->arguments, &argc, argv, "SKYCELLS", "-skycell", "-skycelllist");
    381433
     
    440492        psMetadataAddStr(config->arguments, PS_LIST_TAIL, "SOURCES", 0,
    441493                "name of input sources file", argv[argnum]);
     494        psArgumentRemove(argnum, &argc, argv);
     495    }
     496
     497    if ((argnum = psArgumentGet(argc, argv, "-stats"))) {
     498        psArgumentRemove(argnum, &argc, argv);
     499        psMetadataAddStr(config->arguments, PS_LIST_TAIL, "STATS", 0,
     500                "name of input stats file", argv[argnum]);
    442501        psArgumentRemove(argnum, &argc, argv);
    443502    }
     
    589648                strkGetMaskValues(sf);
    590649               
     650                // add the STREAK bit to the mask image pixels
    591651                setStreakBits(sf->inMask->image, sf->maskStreak);
    592652            }
     
    721781                sfiles->inMask->image->data.PS_TYPE_IMAGE_MASK_DATA[y][x];
    722782        }
    723         sfiles->outMask->image->data.PS_TYPE_IMAGE_MASK_DATA[y][x] =
    724             sfiles->inMask->image->data.PS_TYPE_IMAGE_MASK_DATA[y][x] | newMaskValue;
     783        sfiles->outMask->image->data.PS_TYPE_IMAGE_MASK_DATA[y][x] |= newMaskValue;
    725784    }
    726785}
    727786
    728787static void
    729 exciseNonWarpedPixels(streakFiles *sfiles, psImageMaskType newMaskValue)
     788exciseNonDiffedPixels(streakFiles *sfiles, psImageMaskType newMaskValue)
    730789{
    731790    int cell_x0 = sfiles->astrom->cell_x0;
     
    749808        }
    750809
    751         psU8 *pixels = sfiles->warpedPixels->data.U8[yChip];
     810        psU8 *pixels = sfiles->diffedPixels->data.U8[yChip];
    752811
    753812        if (xParity == 1) {
     
    772831
    773832static bool
    774 warpedPixel(streakFiles *sfiles, int x, int y)
     833diffedPixel(streakFiles *sfiles, int x, int y)
    775834{
    776835    PixelPos chipCoord;
    777836
    778837    if (!CHIP_LEVEL_INPUT(sfiles->stage)) {
    779         // if we're here on a skycell image by definition this pixel was warped
     838        // if we're here on a skycell image by definition this pixel was diffed
    780839        return true;
    781840    }
     
    790849    cellToChipInt(&chipCoord.x, &chipCoord.y, sfiles->astrom, x, y);
    791850
    792     if (chipCoord.x < 0 || chipCoord.x >= sfiles->warpedPixels->numCols) {
     851    if (chipCoord.x < 0 || chipCoord.x >= sfiles->diffedPixels->numCols) {
    793852        return false;
    794853    }
    795     if (chipCoord.y < 0 || chipCoord.y >= sfiles->warpedPixels->numRows) {
     854    if (chipCoord.y < 0 || chipCoord.y >= sfiles->diffedPixels->numRows) {
    796855        return false;
    797856    }
    798857
    799     return psImageGet(sfiles->warpedPixels, chipCoord.x, chipCoord.y) ? true : false;
     858    return psImageGet(sfiles->diffedPixels, chipCoord.x, chipCoord.y) ? true : false;
    800859}
    801860
Note: See TracChangeset for help on using the changeset viewer.