IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 24691


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

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippScripts/scripts/magic_destreak.pl

    r24687 r24691  
    194194    }
    195195
    196     my ($image, $mask, $ch_mask, $weight, $astrom);
     196    my ($image, $mask, $ch_mask, $weight, $astrom, $sources);
    197197
    198198    if ($stage eq "raw") {
     
    211211        $mask   = $ipprc->filename("PSWARP.OUTPUT.MASK", $path_base);
    212212        $weight = $ipprc->filename("PSWARP.OUTPUT.VARIANCE", $path_base);
     213        $sources    = $ipprc->filename("PSWARP.OUTPUT.SOURCES", $path_base);
    213214    } elsif ($stage eq "diff") {
    214215        my $name = $inverse ? "PPSUB.INVERSE" : "PPSUB.OUTPUT"; # Base name for images
     
    216217        $mask   = $ipprc->filename("$name.MASK", $path_base);
    217218        $weight = $ipprc->filename("$name.VARIANCE", $path_base);
     219        $sources    = $ipprc->filename("PPSUB.OUTPUT.SOURCES", $path_base);
    218220    }
    219221
     
    227229        $command .= " -chip_mask $ch_mask" if defined $ch_mask;
    228230        $command .= " -weight $weight" if defined $weight;
     231        $command .= " -sources $sources" if defined $sources;
    229232        $command .= " -skycelllist $skycell_list" if defined $skycell_list;
    230233        $command .= " -replace" if $replace;
  • trunk/magic/remove/src/streaksio.c

    r24556 r24691  
    2020    memset(sf, 0, sizeof(*sf));
    2121
     22    sf->config = config;
     23    sf->program_name = basename(program_name);
     24
    2225    if (remove) {
    2326        // remember pointer so that streaksExit can delete temps
     
    2528    }
    2629
    27     sf->config = config;
    28     sf->program_name = basename(program_name);
    2930
    3031    // error checking is done by sFileOpen. If a file can't be opened we just exit
     
    8081        } else {
    8182            sf->recWeight = sFileOpen(config, stage, "RECOVERY.WEIGHT", NULL, true);
     83        }
     84    }
     85    if (remove) {
     86        sf->inSources = sFileOpen(config, stage, "SOURCES", NULL, false);
     87        if (sf->inSources) {
     88            inputBasename = basename(sf->inSources->name);
     89            sf->outSources = sFileOpen(config, stage, "OUTPUT", inputBasename, true);
    8290        }
    8391    }
     
    607615        streaksExit("", PS_EXIT_DATA_ERROR);
    608616    }
    609 
     617 
    610618    bool status;
    611619    in->extname = psMetadataLookupStr(&status, in->header, "EXTNAME");
     
    929937        if (!replicate(sfiles->outWeight, sfiles->inWeight)) {
    930938            psError(PM_ERR_SYS, false, "failed to replicate outImage.");
     939            return false;
     940        }
     941    }
     942
     943    if (sfiles->outSources) {
     944        if (!replicate(sfiles->outSources, sfiles->inSources)) {
     945            psError(PM_ERR_SYS, false, "failed to replicate outSources.");
    931946            return false;
    932947        }
     
    9971012    }
    9981013
     1014    if (sfiles->outSources) {
     1015        if (!swapOutputToInput(sfiles->inSources, sfiles->outSources)) {
     1016            psError(PM_ERR_SYS, false, "failed to swap instances for sources.");
     1017            return false;
     1018        }
     1019    }
     1020
    9991021    if (!swapOutputToInput(sfiles->inImage, sfiles->outImage)) {
    10001022        psError(PM_ERR_SYS, false, "failed to swap instances for Image.");
    10011023        return false;
    10021024    }
     1025
    10031026
    10041027    return true;
     
    10421065    if (sfiles->outImage) {
    10431066        deleteFile(sfiles->outImage);
     1067    }
     1068
     1069    if (sfiles->outSources) {
     1070        deleteFile(sfiles->outSources);
    10441071    }
    10451072
  • 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}
  • trunk/magic/remove/src/streaksremove.h

    r24556 r24691  
    6262    sFile *outChMask;
    6363    sFile *recChMask;
     64    sFile *inSources;
     65    sFile *outSources;
    6466    psString class_id;
    6567    pmFPAfile  *inAstrom;
Note: See TracChangeset for help on using the changeset viewer.