IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 25082


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.

Location:
trunk/magic
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/magic/Makefile.in

    r24938 r25082  
    1212
    1313update:
    14         # get the source code (replace this with SVN interactions)
     14# get the source code (replace this with SVN interactions)
    1515        tar xvzf ~/magic.tgz
    1616        tar xvzf ~/ssa-core-cpp.tgz
  • trunk/magic/remove/src/Line.c

    r25001 r25082  
    3636    // If the current line is not vertical, check to see if the point
    3737    // is inside the two endpoints independent of direction
    38    
     38
    3939    if (line->begin.x != line->end.x)
    4040    {
     
    5959    ux = line->end.x - line->begin.x;
    6060    uy = line->end.y - line->begin.y;
    61    
     61
    6262    vx = x - line->begin.x;
    6363    vy = y - line->begin.y;
    64    
     64
    6565    double u_u = ux * ux + uy * uy;                         // (u . u)
    6666    double u_v = ux * vx + uy * vy;                         // (u . v)
    67    
     67
    6868    if (u_v <= 0) return vx * vx + vy * vy;                 // (v . v)
    6969    if (u_u <= u_v)
     
    7373        return wx * wx + wy * wy;                           // (w . w)
    7474    }
    75    
     75
    7676    // Compute P(b) is the base of the perpendicular dropped from tuple to
    7777    // the line
    78    
     78
    7979    b = u_v / u_u;
    8080    px = vx - b * ux;
     
    109109    double wx  = first->begin.x - second->begin.x;
    110110    double wy  = first->begin.y - second->begin.y;
    111    
     111
    112112    // Calculate the perpendicular product, dt
    113    
     113
    114114    double dt = dx1 * dy2 - dy1 * dx2;
    115    
     115
    116116    // Are the lines parallel?
    117    
     117
    118118    if (fabs (dt) <= 1e-8)
    119119    {
    120120        // Check to see if they are overlap
    121        
     121
    122122        if (dx1 * wy - dy1 * wx != 0 || dx2 * wy - dy2 * wx != 0) return 0;
    123        
     123
    124124        // The line are coplanar, so check to see if they are degenerate
    125        
     125
    126126        len1 = dx1 * dx1 + dy1 * dy1;
    127127        len2 = dx2 * dx2 + dy2 * dy2;
    128        
     128
    129129        // First, check to see if both lines are points and if they are
    130130        // distinct tuples
    131        
     131
    132132        if (len1 == 0 && len2 == 0)
    133133        {
     
    137137            return 1;
    138138        }
    139        
     139
    140140        // Check to see if the first line is a point and is inside the
    141141        // second line
    142        
     142
    143143        if (len1 == 0)
    144144        {
     
    148148                return 0;
    149149        }
    150        
     150
    151151        // Check to see if the second line is a point and is inside the
    152152        // first line
    153        
     153
    154154        if (len2 == 0)
    155155        {
     
    159159                return 0;
    160160        }
    161        
     161
    162162        // Since both lines are coplanar and have length, search for
    163163        // overlap tuples
    164        
     164
    165165        w2x = first->end.x - second->begin.x;
    166166        w2y = first->end.y - second->begin.y;
    167        
     167
    168168        t0 = (dx2 != 0) ? wx  / dx2 : wy  / dy2;
    169169        t1 = (dx2 != 0) ? w2x / dx2 : w2y / dy2;
    170        
     170
    171171        if (t0 > t1) SwapDouble (&t0, &t1);
    172172        if ((inFirstSegment || inSecondSegment) && (t0 > 1 || t1 < 0))
     
    176176        t0 = (t0 < 0) ? 0 : t0;             // Clip to min 0
    177177        t1 = (t1 > 1) ? 1 : t1;             // Clip to max 1
    178        
     178
    179179        // Set the first tuple of intersection
    180        
     180
    181181        tuple1->x = second->begin.x + t0 * dx2;
    182182        tuple1->y = second->begin.y + t0 * dy2;
    183        
     183
    184184        // Check to see if the intersection is a single tuple
    185        
     185
    186186        if (t0 == t1) return 1;
    187        
     187
    188188        // Otherwise, set the second tuple of intersection as well
    189        
     189
    190190        tuple2->x = second->begin.x + t1 * dx2;
    191191        tuple2->y = second->begin.y + t1 * dy2;
    192192        return 2;
    193193    }
    194    
     194
    195195    // The segments are skew and may intersect in a tuple.
    196196    // Get the intersect parameter for the first line
    197    
     197
    198198    double i1 = (dx2 * wy - dy2 * wx) / dt;
    199199    if (inFirstSegment && (i1 < 0 || i1 > 1)) return 0;
    200    
     200
    201201    // Get the intersect parameter for the second line
    202202
     
    226226    vertices[3].x = 0;       vertices[3].y = numRows;
    227227
     228    clipLine.begin.x = 0;
     229    clipLine.begin.y = 0;
     230    clipLine.end.x = 0;
     231    clipLine.end.y = 0;
     232
    228233    for (i = 0; i < 4 && found < 2; ++i)
    229234    {
     
    237242                ++found;
    238243            }
    239             else if (tuple1.x != clipLine.begin.x || 
     244            else if (tuple1.x != clipLine.begin.x ||
    240245                     tuple1.y != clipLine.begin.y)
    241246            {
     
    245250        }
    246251    }
    247    
     252
    248253    // If two endpoints are found, clip the line
    249    
     254
    250255    if (found > 1)
    251256    {
     
    283288    vertices[3].x = minX; vertices[3].y = maxY;
    284289
     290    clipLine.begin.x = 0;
     291    clipLine.begin.y = 0;
     292    clipLine.end.x = 0;
     293    clipLine.end.y = 0;
     294
    285295    for (i = 0; i < 4 && found < 2; ++i)
    286296    {
     
    294304                ++found;
    295305            }
    296             else if (tuple1.x != clipLine.begin.x || 
     306            else if (tuple1.x != clipLine.begin.x ||
    297307                     tuple1.y != clipLine.begin.y)
    298308            {
     
    302312        }
    303313    }
    304    
     314
    305315    // If two endpoints are found, clip the line
    306    
     316
    307317    if (found > 1)
    308318    {
     
    360370    @param[out] pixels list of PixelPos pointers corresponding
    361371                       based on the line settings
    362     @param[in] line Line to map to pixels   
     372    @param[in] line Line to map to pixels
    363373    @param[in] numCols maximum X (columns) for the line
    364374    @param[in] numRows maximum Y (rows) for the line            */
     
    367377{
    368378    Line offsetLine;
    369     PixelPos *pixel;
    370379    double slope, xOffset, yOffset, xMid, yMid;
    371380    int x, y, xBegin = numCols, yBegin = numRows, xEnd = 0, yEnd = 0;
    372381
    373382    // Extract the endpoints
    374    
     383
    375384    double x1 = line->begin.x;
    376385    double y1 = line->begin.y;
    377386    double x2 = line->end.x;
    378387    double y2 = line->end.y;
    379    
     388
    380389    // Determine the width and height of the line
    381    
     390
    382391    double dx = x2 - x1;
    383392    double dy = y2 - y1;
     
    403412
    404413    // Step point by point based on the dominate axis
    405    
     414
    406415    if (fabs (dx) > fabs (dy))
    407416    {
     
    411420        // If line is back to front, reorder endpoints and recompute
    412421        // the line width and height
    413        
     422
    414423        if (x1 > x2)
    415424        {
     
    421430
    422431        // Compute the slope of the line
    423        
     432
    424433        slope = dy / dx;
    425        
     434
    426435        // Compute the x and y offsets for the line width extent
    427436
    428         if (xBegin > xEnd) 
     437        if (xBegin > xEnd)
    429438            SwapInt (&xBegin, &xEnd);
    430439        else
     
    451460    }
    452461    else
    453     {       
     462    {
    454463        // -------------------
    455464        // vertical(ish) lines
     
    457466        // If line is back to front, reorder endpoints and recompute
    458467        // the line width and height
    459        
     468
    460469        if (y1 > y2)
    461470        {
     
    465474            dy = y2 - y1;
    466475        }
    467        
     476
    468477        // Compute the slope of the line
    469        
     478
    470479        slope = dx / dy;
    471        
     480
    472481        // Compute the x and y offsets for the line width extent
    473482
     
    481490        xMid = x1 + slope * (yBegin - y1);
    482491        xOffset = fabs (halfWidth * dr / dy);
    483        
     492
    484493        for (y = yBegin; y != yEnd; ++y)
    485494        {
  • trunk/magic/remove/src/Makefile.simple

    r24761 r25082  
    3636
    3737STREAKSFLAGS=-DSTREAKS_COMPRESS_OUTPUT=1
    38 OPTFLAGS= -g -O2
     38OPTFLAGS= -g -O2 -Wall -Werror
    3939#OPTFLAGS= -g
    40 CFLAGS=`psmodules-config --cflags` -std=gnu99 ${OPTFLAGS} ${STREAKSFLAGS}
    41 #CFLAGS=`psmodules-config --cflags` -std=gnu99 ${OPTFLAGS}
    42 LDFLAGS=`psmodules-config --libs`
     40CFLAGS=`psmodules-config --cflags` `pslib-config --cflags` -std=gnu99 ${OPTFLAGS} ${STREAKSFLAGS}
     41#CFLAGS=`psmodules-config --cflags` `pslib-config --cflags` -std=gnu99 ${OPTFLAGS}
     42LDFLAGS=`psmodules-config --libs` `pslib-config --libs`
    4343
    4444PROGRAMS= streaksremove streaksreplace streakscompare streaksrelease isdestreaked
  • trunk/magic/remove/src/isdestreaked.c

    r24715 r25082  
    1818    psFits *fits = psFitsOpen(fileName, "r");
    1919    if (!fits) {
    20         psError(PS_ERR_UNKNOWN, false, "failed to open fits file: %s\n", fileName);
    21         psErrorStackPrint(stderr, "");
     20        psErrorStackPrint(stderr, "failed to open fits file: %s\n", fileName);
    2221        exit(PS_EXIT_DATA_ERROR);
    2322    }
     
    2524    psMetadata *header = psFitsReadHeader(NULL, fits);
    2625    if (!header) {
    27         psError(PS_ERR_IO, false, "failed to read header for: %s", fileName);
    28         psErrorStackPrint(stderr, "");
     26        psErrorStackPrint(stderr, "failed to read header for: %s", fileName);
    2927        exit(PS_EXIT_DATA_ERROR);
    3028    }
  • trunk/magic/remove/src/streaksastrom.c

    r24716 r25082  
    9393    // since the transform already accounts for the chip parity we just use the cell parity
    9494    astrom->xParity = (double) xParityCell;
    95     astrom->yParity = (double) yParityCell; 
     95    astrom->yParity = (double) yParityCell;
    9696
    9797    astrom->numCols = numCols;
     
    135135
    136136void
    137 cellToChipInt(int *xChip, int *yChip, strkAstrom *astrom, int xCell, int yCell)
     137cellToChipInt(unsigned int *xChip, unsigned int *yChip, strkAstrom *astrom, int xCell, int yCell)
    138138{
    139139    if (astrom->xParity > 0) {
     
    148148    }
    149149}
    150  
     150
    151151bool
    152152SkyToLocal(strkPt *outPt, strkAstrom *astrom, double ra, double dec)
     
    156156
    157157    pmFPA *fpa   = (pmFPA *) astrom->fpa;
    158     pmChip *chip = (pmChip *) astrom->chip;
    159158
    160159    // find the RA,DEC coords of the 0,0 pixel for this chip:
     
    183182
    184183    pmFPA *fpa   = (pmFPA *) astrom->fpa;
    185     pmChip *chip = (pmChip *) astrom->chip;
    186184
    187185    // find the RA,DEC coords of the 0,0 pixel for this chip:
     
    251249    pmChip *chip = (pmChip *) astrom->chip;
    252250    pmAstromObj *pt = (pmAstromObj *) astrom->pt;
    253    
     251
    254252    pt->sky->r = ra;
    255253    pt->sky->d = dec;
     
    276274    pmChip *chip = (pmChip *) astrom->chip;
    277275    pmAstromObj *pt = (pmAstromObj *) astrom->pt;
    278    
     276
    279277    cellToChip(&pt->chip->x, &pt->chip->y, astrom, x, y);
    280278
     
    294292}
    295293
    296  
     294
    297295static bool
    298296readAstrometry(streakFiles *sf)
     
    362360            break;
    363361        }
    364     } 
     362    }
    365363    if (!sf->chip) {
    366364        psError(PS_ERR_UNKNOWN, true, "Failed to find chip with data.");
  • trunk/magic/remove/src/streakscompare.c

    r21156 r25082  
    55int main(int argc, char *argv[])
    66{
    7     long i;
    87    bool status;
    98
     
    3534    int numErrors = 0;
    3635    for (int component = 0; component < ncomponents; component++) {
    37         if (component && !(psFitsMoveExtNum(file1->fits, 1, true) 
     36        if (component && !(psFitsMoveExtNum(file1->fits, 1, true)
    3837                           && psFitsMoveExtNum(file2->fits, 1, true))) {
    3938            streaksExit("failed to advance to next extesion\n", PS_EXIT_DATA_ERROR);
     
    4544        psImage *image2 = file2->image;
    4645
    47         // TODO: do more sanity checking. For example check that extname's  (if any) match 
     46        // TODO: do more sanity checking. For example check that extname's  (if any) match
    4847        // check for matching image cubes
    4948        if (image1 && image2) {
     
    6867                        error = ! isnan(value1) && isnan(value2);
    6968                    }
    70                    
     69
    7170                    if (error) {
    7271                        numErrors++;
  • trunk/magic/remove/src/streaksextern.h

    r25001 r25082  
    5454            pixels
    5555*/
    56    
     56
    5757extern StreakPixels *streak_on_component(Streaks *streaks, strkAstrom *astrom,
    5858                                         int numCols, int numRows);
  • trunk/magic/remove/src/streaksio.c

    r24853 r25082  
    1212// Assumptions about the file structure of non-raw files
    1313// The 'image' for each file (image, mask weight) is contained in the first
    14 // extension. 
     14// extension.
    1515
    1616
     
    625625        streaksExit("", PS_EXIT_DATA_ERROR);
    626626    }
    627  
     627
    628628    bool status;
    629629    in->extname = psMetadataLookupStr(&status, in->header, "EXTNAME");
     
    654654            streaksExit("", PS_EXIT_DATA_ERROR);
    655655        }
    656         psImage *image = (psImage *) (in->imagecube->data[0]);
    657656    }
    658657    setDataExtent(stage, in, (stage == IPP_STAGE_RAW) && !isMask);
     
    925924replicateOutputs(streakFiles *sfiles)
    926925{
    927     bool status = false;
    928 
    929926    if (!replicate(sfiles->outImage, sfiles->inImage)) {
    930927        psError(PM_ERR_SYS, false, "failed to replicate outImage.");
     
    973970
    974971        if (!nebSwap(server, in->name, out->name)) {
    975             psError(PM_ERR_SYS, true, "failed to swap files for: %s.",
     972            psError(PM_ERR_SYS, true, "failed to swap files for %s: %s.",
    976973                in->name, nebErr(server));
    977974            return false;
     
    10971094setMaskedToNAN(streakFiles *sfiles, psU32 maskMask, bool printCounts)
    10981095{
    1099         int maskedPixels = 0;
    1100         int nandPixels = 0;
    1101         int nandWeights = 0;
     1096        long maskedPixels = 0;
     1097        long nandPixels = 0;
     1098        long nandWeights = 0;
    11021099
    11031100        psImage *image = sfiles->outImage->image;
     
    11201117                psU32 maskVal;
    11211118                if (sfiles->stage == IPP_STAGE_RAW) {
    1122                     int xChip, yChip;
     1119                    unsigned int xChip, yChip;
    11231120                    cellToChipInt(&xChip, &yChip, sfiles->astrom, x, y);
    11241121                    maskVal = psImageGet(mask, xChip, yChip);
     
    11441141        if (printCounts) {
    11451142            psLogMsg(sfiles->program_name, PS_LOG_INFO, "time to NAN mask pixels: %f\n", psTimerClear("NAN_MASKED"));
    1146             int totalPixels = image->numRows * image->numCols;
     1143            long totalPixels = image->numRows * image->numCols;
    11471144            psLogMsg(sfiles->program_name, PS_LOG_INFO, "pixels:        %10ld\n", totalPixels);
    11481145            psLogMsg(sfiles->program_name, PS_LOG_INFO, "masked pixels: %10ld %4.2f%%\n", maskedPixels, 100. * maskedPixels / totalPixels);
  • trunk/magic/remove/src/streaksrelease.c

    r24853 r25082  
    33static pmConfig *parseArguments(int argc, char **argv);
    44static bool readAndCopyToOutput(streakFiles *sf, bool exciseAll);
    5 static StreakPixels * getStreakPixels(streakFiles *sfiles, Streaks *streaks);
    6 static void exciseNonWarpedPixels(streakFiles *sfiles, double newMaskValue);
    7 static bool warpedPixel(streakFiles *sfiles, PixelPos *cellCoord);
    8 static void excisePixel(streakFiles *sfiles, unsigned int x, unsigned int y, bool streak, double newMaskValue);
    95static void writeImages(streakFiles *sf, bool exciseImageCube);
    106
     
    128main(int argc, char *argv[])
    139{
    14     bool status;
    15 
    1610    psLibInit(NULL);
    1711    psTimerStart("STREAKSREMOVE");
     
    2519    // Values to set for masked pixels
    2620    psU32 maskStreak = 0;           // for the image and weight (usually NAN, MAXINT for integer images)
    27     psU32 maskMask = 0;             // value looked up for MASK.STREAK 
     21    psU32 maskMask = 0;             // value looked up for MASK.STREAK
    2822
    2923    // Does true work here?
     
    216210        // image data directly from psFits
    217211        readImage(sf->inImage, sf->extnum, sf->stage, false);
    218        
     212
    219213        // astrom struct is only needed for raw stage, and only the chip to cell parameters are used
    220214        sf->astrom = streakSetAstrometry(sf->astrom, sf->stage, NULL, NULL, false,
     
    304298            initValue = NAN;
    305299        } else {
    306             // otherwise write it to the output 
     300            // otherwise write it to the output
    307301            writeImageCube(sf->outImage, sf->inImage->imagecube, extname, sf->extnum);
    308302            initValue = 0;
  • 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)) {
  • trunk/magic/remove/src/streaksremove.h

    r24691 r25082  
    8484// can't declare this in streaksastrom due to header file ordering
    8585extern void cellToChip(double *xChip, double *yChip, strkAstrom *astrom, double xCell, double yCell);
    86 extern void cellToChipInt(int *xChip, int *yChip, strkAstrom *astrom, int xCell, int yCell);
     86extern void cellToChipInt(unsigned int *xChip, unsigned int *yChip, strkAstrom *astrom, int xCell, int yCell);
    8787
    8888extern bool computeWarpedPixels(streakFiles *sf);
  • trunk/magic/remove/src/streaksreplace.c

    r24556 r25082  
    88int main(int argc, char *argv[])
    99{
    10     long i;
    1110    bool status;
    12     StreakPixels *pixels;
    13     PixelPos *pixelPos;
    1411
    1512    psLibInit(NULL);
     
    9289
    9390    if (!replicateOutputs(sfiles)) {
    94         psError(PS_ERR_UNKNOWN, false, "failed to replicate output files");
    95         psErrorStackPrint(stderr, "");
     91        psErrorStackPrint(stderr, "failed to replicate output files");
    9692        exit(PS_EXIT_UNKNOWN_ERROR);
    9793    }
     
    172168            true);
    173169    }
    174    
     170
    175171    bool gotMask = false;
    176172    if ((argnum = psArgumentGet(argc, argv, "-mask"))) {
     
    353349        // we have an image cube
    354350        double initValue;
    355         // otherwise write it to the output 
     351        // otherwise write it to the output
    356352        writeImageCube(sf->outImage, sf->recImage->imagecube, extname, sf->extnum);
    357353
  • trunk/magic/remove/src/streaksutil.c

    r24556 r25082  
    4444// we just bail out
    4545void streaksExit(psString str, int exitCode) {
    46     psErrorStackPrint(stderr, str);
     46    psErrorStackPrint(stderr, "%s", str);
    4747    if (ourStreakFiles) {
    4848        deleteTemps(ourStreakFiles);
  • trunk/magic/remove/src/warpedpixels.c

    r21438 r25082  
    2323
    2424    psRegion     *bounds = pmChipPixels(sf->chip);
    25    
     25
    2626    int width  = bounds->x1 - bounds->x0;
    2727    int height = bounds->y1 - bounds->y0;
     
    8383
    8484    /* now set up our wrapper to the chip astrometry to apply to the whole chip */
    85     sf->astrom = streakSetAstrometry(sf->astrom, sf->stage, sf->inAstrom->fpa, sf->chip, false, NULL, 
     85    sf->astrom = streakSetAstrometry(sf->astrom, sf->stage, sf->inAstrom->fpa, sf->chip, false, NULL,
    8686        sf->warpedPixels->numCols, sf->warpedPixels->numRows);
    8787
     
    106106        // convert corner of skycell to sky coordinates
    107107        if (!pmAstromWCStoSky(&sky, wcs, &pt[i])) {
    108             psError(PS_ERR_IO, false, "failed to convert pt %d of %s to sky coords: %s", fileName);
     108            psErrorStackPrint(stderr, "failed to convert pt %d of %s to sky coords", i, fileName);
    109109            streaksExit("", PS_EXIT_DATA_ERROR);
    110110        }
     
    112112        // convert to chip coordinates
    113113        if (!skyToCell(&p, sf->astrom, sky.r, sky.d)) {
    114             psError(PS_ERR_IO, false, "failed to convert pt %d of %s to sky coords: %s", fileName);
     114            psErrorStackPrint(stderr, "failed to convert pt %d of %s to sky coords", i, fileName);
    115115            streaksExit("", PS_EXIT_DATA_ERROR);
    116116        }
     
    171171}
    172172
    173 // x as a function of y for the line between two points 
     173// x as a function of y for the line between two points
    174174// Note: the caller guarentees that the y's of the two points are different
    175175static double xOfY(psPlane *pI, psPlane *pJ, int y)
     
    212212 * To compute the overlap of a quadrilateral with a set of
    213213 * points we transform the 4 corners to image coordinates
    214  * and name the 4 points of the quad 
     214 * and name the 4 points of the quad
    215215            pt 0 is left most (bottom most corner)
    216216            pt 1 is bottom most (right most corner)
     
    238238
    239239                3
    240                  C       
     240                 C
    241241         ---------------2           left boundary:  line 0_1 y < pt0.y
    242242                 B                                  line 0_3 y >= pt0.y
     
    249249              C
    250250        0----------------
    251               B     
     251              B
    252252      ----------------2
    253253              A
     
    258258
    259259        3       2
    260            
     260
    261261            B
    262262
     
    265265(region A and C are empty in the case where the points form a rectangle)
    266266*/
    267            
     267
    268268/*
    269269    Name the corners
    270     The following algorithm works for points that form a quadrilateral 
     270    The following algorithm works for points that form a quadrilateral
    271271    I think it also works for the situation where 3 points are co-linear
    272272    and we have a triangle, but that isn't important for our purposes
     
    313313        pt[i] = pt[i+1];
    314314    }
    315            
     315
    316316    // now find the right most (top most) of the remaining 2 points
    317317    if ((pt[0].x > pt[1].x) ||
Note: See TracChangeset for help on using the changeset viewer.