IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 20, 2009, 12:42:13 PM (17 years ago)
Author:
watersc1
Message:

More merging

Location:
branches/czw_branch/cleanup
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/cleanup

  • branches/czw_branch/cleanup/magic/remove/src/streaksremove.c

    r25051 r25158  
    3535    // Values to set for masked pixels
    3636    psU32 maskStreak = 0;           // for the image and weight (usually NAN, MAXINT for integer images)
    37     psU32 maskMask = 0;             // value looked up for MASK.STREAK 
     37    psU32 maskMask = 0;             // value looked up for MASK.STREAK
    3838
    3939    psString streaksFileName = psMetadataLookupStr(NULL, config->arguments, "STREAKS");
     
    4242    Streaks *streaks = readStreaksFile(streaksFileName);
    4343    if (!streaks) {
    44         psError(PS_ERR_UNKNOWN, "failed to read streaks file: %s", streaksFileName);
     44        psError(PS_ERR_UNKNOWN, false, "failed to read streaks file: %s", streaksFileName);
    4545        streaksExit("", PS_EXIT_PROG_ERROR);
    4646    }
     
    8383        psLogMsg("streaksremove", PS_LOG_INFO, "time to compute warped pixels: %f\n", cwp_t);
    8484    }
    85    
     85
    8686    if (sfiles->stage == IPP_STAGE_RAW) {
    8787        // Except for raw stage, all of our (GPC1) files have one image extension.
     
    9797    }
    9898
    99     int totalPixels = 0;
    100     int totalStreakPixels = 0;
     99    long totalPixels = 0;
     100    long totalStreakPixels = 0;
    101101
    102102    // Iterate through each component of the input (except for raw images there is only one)
     
    132132                                                        sfiles->inImage->numRows);
    133133            psLogMsg("streaksremove", PS_LOG_INFO, "time to get streak pixels: %f\n", psTimerClear("GET_STREAK_PIXELS"));
    134            
     134
    135135            // if this extension contained an image, excise the streaked pixels.
    136136            // otherwise it contained an image cube (video cell) which is handled in the if block
     
    172172                }
    173173
    174             } else { 
     174            } else {
    175175                // this component contains an image cube
    176176                // For now excise it completely
     
    215215
    216216    if (!replicateOutputs(sfiles)) {
    217         psError(PS_ERR_UNKNOWN, false, "failed to replicate output files");
     217        psErrorStackPrint(stderr, "failed to replicate output files");
    218218        deleteTemps(sfiles);
    219         psErrorStackPrint(stderr, "");
    220219        exit(PS_EXIT_UNKNOWN_ERROR);
    221220    }
     
    247246    pmConceptsDone();
    248247    pmModelClassCleanup();
    249     streaksNebulousCleanup(); 
     248    streaksNebulousCleanup();
    250249    pmConfigDone();
    251250    psLogMsg("streaksremove", PS_LOG_INFO, "time to run streaksremove: %f\n", psTimerClear("STREAKSREMOVE"));
     
    356355            true);
    357356    }
    358    
     357
    359358    if ((argnum = psArgumentGet(argc, argv, "-keepnonwarped"))) {
    360359        psArgumentRemove(argnum, &argc, argv);
     
    374373        psArgumentRemove(argnum, &argc, argv);
    375374    }
    376        
     375
    377376    // if skycells are not provided then we have to execise all pixels  unless -keepnonwarped
    378377    pmConfigFileSetsMD(config->arguments, &argc, argv, "SKYCELLS", "-skycell", "-skycelllist");
     
    628627            initValue = NAN;
    629628        } else {
    630             // otherwise write it to the output 
     629            // otherwise write it to the output
    631630            writeImageCube(sf->outImage, sf->inImage->imagecube, extname, sf->extnum);
    632631            initValue = 0;
     
    799798    sFile *out = sfiles->outSources;
    800799
    801     in->header = psFitsReadHeader(NULL, in->fits);
    802     if (!in->header) {
    803         psError(PS_ERR_IO, false, "failed to read header from %s", in->resolved_name);
     800
     801    // Primary header, should be "something.hdr"
     802    {
     803        psMetadata *header = psFitsReadHeader(NULL, in->fits);
     804        if (!header) {
     805            psError(PS_ERR_IO, false, "failed to read header from %s", in->resolved_name);
     806            streaksExit("", PS_EXIT_DATA_ERROR);
     807        }
     808
     809        bool status;
     810        psString extname = psMetadataLookupStr(&status, header, "EXTNAME");
     811        if (!extname) {
     812            psError(PS_ERR_IO, false, "failed to find extname in header of %s", in->resolved_name);
     813            streaksExit("", PS_EXIT_DATA_ERROR);
     814        }
     815        addDestreakKeyword(header);
     816
     817        if (!psFitsWriteBlank(out->fits, header, extname)) {
     818            psError(PS_ERR_IO, false, "failed to write blank in header of %s", in->resolved_name);
     819            streaksExit("", PS_EXIT_DATA_ERROR);
     820        }
     821        psFree(header);
     822    }
     823
     824    // Extension with PSF fits, should be "something.psf"
     825    {
     826        if (!psFitsMoveExtNum(in->fits, 1, true)) {
     827            psErrorStackPrint(stderr, "failed to read header from %s", in->resolved_name);
     828            streaksExit("", PS_EXIT_DATA_ERROR);
     829        }
     830
     831        psMetadata *header = psFitsReadHeader(NULL, in->fits);
     832        if (!header) {
     833            psErrorStackPrint(stderr, "failed to read header from %s", in->resolved_name);
     834            streaksExit("", PS_EXIT_DATA_ERROR);
     835        }
     836        psString extname = psMetadataLookupStr(NULL, header, "EXTNAME");
     837        if (!extname) {
     838            psError(PS_ERR_IO, false, "failed to find extname in header of %s", in->resolved_name);
     839            streaksExit("", PS_EXIT_DATA_ERROR);
     840        }
     841
     842        psArray *inTable = psFitsReadTable(in->fits);
     843        if (!inTable->n) {
     844            psErrorStackPrint(stderr, "table in %s is empty", in->resolved_name);
     845            streaksExit("", PS_EXIT_DATA_ERROR);
     846        }
     847
     848        psArray *outTable = psArrayAllocEmpty(inTable->n);
     849        int j = 0;
     850        int numCensored = 0;
     851        for (int i = 0 ; i < inTable->n; i++) {
     852            psMetadata *row = inTable->data[i];
     853
     854            psF32 x = psMetadataLookupF32(NULL, row, "X_PSF");
     855            psF32 y = psMetadataLookupF32(NULL, row, "Y_PSF");
     856
     857            psU32 mask = psImageGet(maskImage, x, y);
     858
     859            // Key the source if the center pixel is not masked with maskStreak
     860            if (!(mask & maskStreak) ) {
     861                psArraySet(outTable, j++, row);
     862            } else {
     863                numCensored++;
     864            }
     865        }
     866
     867        // get rid of unused elements (don't know if this is necessary)
     868        psArrayRealloc(outTable, j);
     869
     870        addDestreakKeyword(header);
     871        if (psArrayLength(outTable) > 0) {
     872            printf("Censored %d sources\n", numCensored);
     873            if (! psFitsWriteTable(out->fits, header, outTable, extname)) {
     874                psErrorStackPrint(stderr, "failed to write table to %s", out->resolved_name);
     875                streaksExit("", PS_EXIT_DATA_ERROR);
     876            }
     877        } else {
     878            printf("Censored ALL %d sources\n", numCensored);
     879            if (! psFitsWriteTableEmpty(out->fits, header, inTable->data[0], extname)) {
     880                psErrorStackPrint(stderr, "failed to write empty table to %s", out->resolved_name);
     881                streaksExit("", PS_EXIT_DATA_ERROR);
     882            }
     883        }
     884        psFree(header);
     885        psFree(outTable);
     886        psFree(inTable);
     887    }
     888
     889    // XXX Will need to update to handle extension with extended sources, etc.
     890
     891    if (!psFitsClose(out->fits)) {
     892        psErrorStackPrint(stderr, "failed to close table %s", out->resolved_name);
    804893        streaksExit("", PS_EXIT_DATA_ERROR);
    805894    }
    806 
    807     bool status;
    808     psString extname = psMetadataLookupStr(&status, in->header, "EXTNAME");
    809     if (!extname) {
    810         psError(PS_ERR_IO, false, "failed to find extname in header of %s", in->resolved_name);
    811         streaksExit("", PS_EXIT_DATA_ERROR);
    812     }
    813 
    814     psArray *inTable = psFitsReadTable(in->fits);
    815     if (!inTable->n) {
    816         psError(PS_ERR_IO, false, "table in %s is empty", in->resolved_name);
    817         streaksExit("", PS_EXIT_DATA_ERROR);
    818     }
    819 
    820     psArray *outTable = psArrayAllocEmpty(inTable->n);
    821     int j = 0;
    822     int numCensored = 0;
    823     for (int i = 0 ; i < inTable->n; i++) {
    824         psMetadata *row = inTable->data[i];
    825 
    826         psF32 x = psMetadataLookupF32 (&status, row, "X_PSF");
    827         psF32 y = psMetadataLookupF32 (&status, row, "Y_PSF");
    828        
    829         psU32 mask = psImageGet(maskImage, x, y);
    830 
    831         // Key the source if the center pixel is not masked with maskStreak
    832         if (! (mask & maskStreak) ) {
    833             psArraySet(outTable, j++, row);
    834         } else {
    835             numCensored++;
    836         }
    837     }
    838 
    839     // get rid of unused elements (don't know if this is necessary)
    840     psArrayRealloc(outTable, j);
    841 
    842     addDestreakKeyword(in->header);
    843     if (psArrayLength(outTable) > 0) {
    844         printf("Censored %d sources\n", numCensored);
    845         if (! psFitsWriteTable(out->fits, in->header, outTable, extname)) {
    846             psError(PS_ERR_IO, false, "failed to write table to %s", out->resolved_name);
    847             streaksExit("", PS_EXIT_DATA_ERROR);
    848         }
    849     } else {
    850         printf("Censored ALL %d sources\n", numCensored);
    851         if (! psFitsWriteTableEmpty(out->fits, in->header, inTable->data[0], extname)) {
    852             psError(PS_ERR_IO, false, "failed to write empty table to %s", out->resolved_name);
    853             streaksExit("", PS_EXIT_DATA_ERROR);
    854         }
    855     }
    856 
    857     if (!psFitsClose(out->fits)) {
    858         psError(PS_ERR_IO, false, "failed to close table %s", out->resolved_name);
    859         streaksExit("", PS_EXIT_DATA_ERROR);
    860     }
    861 }
     895}
Note: See TracChangeset for help on using the changeset viewer.