IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 6, 2009, 4:24:20 PM (17 years ago)
Author:
bills
Message:

when destreaking warp and diff skyfiles, censor any sources whose coordinates are masked

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/magic/remove/src/streaksremove.c

    r24684 r24691  
    1717static void writeImages(streakFiles *sf, bool exciseImageCube);
    1818static void updateAstrometry(streakFiles *sfiles);
     19static void censorSources(streakFiles *sfiles, psU32 maskStreak);
    1920
    2021int
     
    188189        }
    189190
     191        censorSources(sfiles, maskStreak);
     192
    190193        // write the destreaked "temporary" images and the recovery images
    191194        writeImages(sfiles, exciseImageCube);
     195
    192196
    193197        psLogMsg("streaksremove", PS_LOG_INFO, "time to process component %d: %f\n", sfiles->extnum, psTimerClear("PROCESS_COMPONENT"));
     
    259263    fprintf(stderr, "\t-weight WEIGHT.fits: weight file to de-streak\n");
    260264    fprintf(stderr, "\t-replace: replace the input images with the output\n");
    261     fprintf(stderr, "\t-remove: remove the original image after processing (requires -replace)\n");
    262265    fprintf(stderr, "\t-keepnonwarped: do not exise pixels that were not part of difference processing\n");
    263266    fprintf(stderr, "\t-transparent val: instead of setting excicsed pixel to NAN add val\n");
     
    335338    bool gotReplace = false;
    336339    if ((argnum = psArgumentGet(argc, argv, "-replace"))) {
     340        if (!nebulousImage) {
     341            psError(PS_ERR_UNKNOWN, true, "replace is only supported for nebulous files");
     342            usage();
     343        }
    337344        gotReplace = true;
    338345        psArgumentRemove(argnum, &argc, argv);
     
    416423        psMetadataAddStr(config->arguments, PS_LIST_TAIL, "INPUT.WEIGHT", 0,
    417424                "name of input weight image", argv[argnum]);
     425        psArgumentRemove(argnum, &argc, argv);
     426    }
     427    if ((argnum = psArgumentGet(argc, argv, "-sources"))) {
     428        psArgumentRemove(argnum, &argc, argv);
     429        bool nebulousSources = IN_NEBULOUS(argv[argnum]);
     430        if (nebulousSources != nebulousImage) {
     431            psError(PS_ERR_UNKNOWN, true, "sources file must have %snebulous path with %s image path\n",
     432                nebulousImage ? "" : "non ", nebulousImage ? "nebulous" : "regular");
     433            usage();
     434        }
     435        psMetadataAddStr(config->arguments, PS_LIST_TAIL, "SOURCES", 0,
     436                "name of input sources file", argv[argnum]);
    418437        psArgumentRemove(argnum, &argc, argv);
    419438    }
     
    757776}
    758777
     778// read a sources file (.cmf) and remove any rows whose coordinate is convered by a
     779// streak mask
     780static void
     781censorSources(streakFiles *sfiles, psU32 maskStreak)
     782{
     783    if ((!sfiles->inSources) || (!sfiles->outMask)) {
     784        return;
     785    }
     786    psImage *maskImage = sfiles->outMask->image;
     787    if (!maskImage) {
     788        psError(PS_ERR_IO, false, "maskImage is null!");
     789        streaksExit("", PS_EXIT_PROG_ERROR);
     790    }
     791
     792    sFile *in = sfiles->inSources;
     793    sFile *out = sfiles->outSources;
     794
     795    in->header = psFitsReadHeader(NULL, in->fits);
     796    if (!in->header) {
     797        psError(PS_ERR_IO, false, "failed to read header from %s", in->resolved_name);
     798        streaksExit("", PS_EXIT_DATA_ERROR);
     799    }
     800
     801    bool status;
     802    psString extname = psMetadataLookupStr(&status, in->header, "EXTNAME");
     803    if (!extname) {
     804        psError(PS_ERR_IO, false, "failed to find extname in header of %s", in->resolved_name);
     805        streaksExit("", PS_EXIT_DATA_ERROR);
     806    }
     807
     808    psArray *inTable = psFitsReadTable(in->fits);
     809    if (!inTable->n) {
     810        psError(PS_ERR_IO, false, "table in %s is empty", in->resolved_name);
     811        streaksExit("", PS_EXIT_DATA_ERROR);
     812    }
     813
     814    psArray *outTable = psArrayAllocEmpty(inTable->n);
     815    int j = 0;
     816    int numCensored = 0;
     817    for (int i = 0 ; i < inTable->n; i++) {
     818        psMetadata *row = inTable->data[i];
     819
     820        psF32 x = psMetadataLookupF32 (&status, row, "X_PSF");
     821        psF32 y = psMetadataLookupF32 (&status, row, "Y_PSF");
     822       
     823        psU32 mask = psImageGet(maskImage, x, y);
     824
     825        // Key the source if the center pixel is not masked with maskStreak
     826        if (! (mask & maskStreak) ) {
     827            psArraySet(outTable, j++, row);
     828        } else {
     829            numCensored++;
     830        }
     831    }
     832
     833    printf("Censored %d sources\n", numCensored);
     834
     835    // get rid of unused elements (don't know if this is necessary)
     836    psArrayRealloc(outTable, j);
     837
     838    addDestreakKeyword(in->header);
     839    if (! psFitsWriteTable(out->fits, in->header, outTable, extname)) {
     840        psError(PS_ERR_IO, false, "failed to write table to %s", out->resolved_name);
     841        streaksExit("", PS_EXIT_DATA_ERROR);
     842    }
     843
     844    if (!psFitsClose(out->fits)) {
     845        psError(PS_ERR_IO, false, "failed to close table %s", out->resolved_name);
     846        streaksExit("", PS_EXIT_DATA_ERROR);
     847    }
     848}
Note: See TracChangeset for help on using the changeset viewer.