IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 14, 2009, 3:58:07 PM (17 years ago)
Author:
Paul Price
Message:

Fix streaksremove so that output CMF files have PHU called ext.hdr and table called ext.psf. Turned on -Wall -Werror and fixed a host of little problems.

File:
1 edited

Legend:

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

    r25001 r25082  
    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);
    804         streaksExit("", PS_EXIT_DATA_ERROR);
    805     }
    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);
     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(in->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        psMetadata *header = psFitsReadHeader(NULL, in->fits);
     827        if (!header) {
     828            psError(PS_ERR_IO, false, "failed to read header from %s", in->resolved_name);
     829            streaksExit("", PS_EXIT_DATA_ERROR);
     830        }
     831        psString extname = psMetadataLookupStr(NULL, header, "EXTNAME");
     832        if (!extname) {
     833            psError(PS_ERR_IO, false, "failed to find extname in header of %s", in->resolved_name);
     834            streaksExit("", PS_EXIT_DATA_ERROR);
     835        }
     836
     837        psArray *inTable = psFitsReadTable(in->fits);
     838        if (!inTable->n) {
     839            psError(PS_ERR_IO, false, "table in %s is empty", in->resolved_name);
     840            streaksExit("", PS_EXIT_DATA_ERROR);
     841        }
     842
     843        psArray *outTable = psArrayAllocEmpty(inTable->n);
     844        int j = 0;
     845        int numCensored = 0;
     846        for (int i = 0 ; i < inTable->n; i++) {
     847            psMetadata *row = inTable->data[i];
     848
     849            psF32 x = psMetadataLookupF32(NULL, row, "X_PSF");
     850            psF32 y = psMetadataLookupF32(NULL, row, "Y_PSF");
     851
     852            psU32 mask = psImageGet(maskImage, x, y);
     853
     854            // Key the source if the center pixel is not masked with maskStreak
     855            if (!(mask & maskStreak) ) {
     856                psArraySet(outTable, j++, row);
     857            } else {
     858                numCensored++;
     859            }
     860        }
     861
     862        // get rid of unused elements (don't know if this is necessary)
     863        psArrayRealloc(outTable, j);
     864
     865        addDestreakKeyword(header);
     866        if (psArrayLength(outTable) > 0) {
     867            printf("Censored %d sources\n", numCensored);
     868            if (! psFitsWriteTable(out->fits, header, outTable, extname)) {
     869                psError(PS_ERR_IO, false, "failed to write table to %s", out->resolved_name);
     870                streaksExit("", PS_EXIT_DATA_ERROR);
     871            }
    834872        } 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     }
     873            printf("Censored ALL %d sources\n", numCensored);
     874            if (! psFitsWriteTableEmpty(out->fits, header, inTable->data[0], extname)) {
     875                psError(PS_ERR_IO, false, "failed to write empty table to %s", out->resolved_name);
     876                streaksExit("", PS_EXIT_DATA_ERROR);
     877            }
     878        }
     879        psFree(header);
     880        psFree(outTable);
     881        psFree(inTable);
     882    }
     883
     884    // XXX Will need to update to handle extension with extended sources, etc.
    856885
    857886    if (!psFitsClose(out->fits)) {
Note: See TracChangeset for help on using the changeset viewer.