Changeset 25082
- Timestamp:
- Aug 14, 2009, 3:58:07 PM (17 years ago)
- Location:
- trunk/magic
- Files:
-
- 14 edited
-
Makefile.in (modified) (1 diff)
-
remove/src/Line.c (modified) (23 diffs)
-
remove/src/Makefile.simple (modified) (1 diff)
-
remove/src/isdestreaked.c (modified) (2 diffs)
-
remove/src/streaksastrom.c (modified) (9 diffs)
-
remove/src/streakscompare.c (modified) (4 diffs)
-
remove/src/streaksextern.h (modified) (1 diff)
-
remove/src/streaksio.c (modified) (8 diffs)
-
remove/src/streaksrelease.c (modified) (5 diffs)
-
remove/src/streaksremove.c (modified) (12 diffs)
-
remove/src/streaksremove.h (modified) (1 diff)
-
remove/src/streaksreplace.c (modified) (4 diffs)
-
remove/src/streaksutil.c (modified) (1 diff)
-
remove/src/warpedpixels.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/magic/Makefile.in
r24938 r25082 12 12 13 13 update: 14 # get the source code (replace this with SVN interactions)14 # get the source code (replace this with SVN interactions) 15 15 tar xvzf ~/magic.tgz 16 16 tar xvzf ~/ssa-core-cpp.tgz -
trunk/magic/remove/src/Line.c
r25001 r25082 36 36 // If the current line is not vertical, check to see if the point 37 37 // is inside the two endpoints independent of direction 38 38 39 39 if (line->begin.x != line->end.x) 40 40 { … … 59 59 ux = line->end.x - line->begin.x; 60 60 uy = line->end.y - line->begin.y; 61 61 62 62 vx = x - line->begin.x; 63 63 vy = y - line->begin.y; 64 64 65 65 double u_u = ux * ux + uy * uy; // (u . u) 66 66 double u_v = ux * vx + uy * vy; // (u . v) 67 67 68 68 if (u_v <= 0) return vx * vx + vy * vy; // (v . v) 69 69 if (u_u <= u_v) … … 73 73 return wx * wx + wy * wy; // (w . w) 74 74 } 75 75 76 76 // Compute P(b) is the base of the perpendicular dropped from tuple to 77 77 // the line 78 78 79 79 b = u_v / u_u; 80 80 px = vx - b * ux; … … 109 109 double wx = first->begin.x - second->begin.x; 110 110 double wy = first->begin.y - second->begin.y; 111 111 112 112 // Calculate the perpendicular product, dt 113 113 114 114 double dt = dx1 * dy2 - dy1 * dx2; 115 115 116 116 // Are the lines parallel? 117 117 118 118 if (fabs (dt) <= 1e-8) 119 119 { 120 120 // Check to see if they are overlap 121 121 122 122 if (dx1 * wy - dy1 * wx != 0 || dx2 * wy - dy2 * wx != 0) return 0; 123 123 124 124 // The line are coplanar, so check to see if they are degenerate 125 125 126 126 len1 = dx1 * dx1 + dy1 * dy1; 127 127 len2 = dx2 * dx2 + dy2 * dy2; 128 128 129 129 // First, check to see if both lines are points and if they are 130 130 // distinct tuples 131 131 132 132 if (len1 == 0 && len2 == 0) 133 133 { … … 137 137 return 1; 138 138 } 139 139 140 140 // Check to see if the first line is a point and is inside the 141 141 // second line 142 142 143 143 if (len1 == 0) 144 144 { … … 148 148 return 0; 149 149 } 150 150 151 151 // Check to see if the second line is a point and is inside the 152 152 // first line 153 153 154 154 if (len2 == 0) 155 155 { … … 159 159 return 0; 160 160 } 161 161 162 162 // Since both lines are coplanar and have length, search for 163 163 // overlap tuples 164 164 165 165 w2x = first->end.x - second->begin.x; 166 166 w2y = first->end.y - second->begin.y; 167 167 168 168 t0 = (dx2 != 0) ? wx / dx2 : wy / dy2; 169 169 t1 = (dx2 != 0) ? w2x / dx2 : w2y / dy2; 170 170 171 171 if (t0 > t1) SwapDouble (&t0, &t1); 172 172 if ((inFirstSegment || inSecondSegment) && (t0 > 1 || t1 < 0)) … … 176 176 t0 = (t0 < 0) ? 0 : t0; // Clip to min 0 177 177 t1 = (t1 > 1) ? 1 : t1; // Clip to max 1 178 178 179 179 // Set the first tuple of intersection 180 180 181 181 tuple1->x = second->begin.x + t0 * dx2; 182 182 tuple1->y = second->begin.y + t0 * dy2; 183 183 184 184 // Check to see if the intersection is a single tuple 185 185 186 186 if (t0 == t1) return 1; 187 187 188 188 // Otherwise, set the second tuple of intersection as well 189 189 190 190 tuple2->x = second->begin.x + t1 * dx2; 191 191 tuple2->y = second->begin.y + t1 * dy2; 192 192 return 2; 193 193 } 194 194 195 195 // The segments are skew and may intersect in a tuple. 196 196 // Get the intersect parameter for the first line 197 197 198 198 double i1 = (dx2 * wy - dy2 * wx) / dt; 199 199 if (inFirstSegment && (i1 < 0 || i1 > 1)) return 0; 200 200 201 201 // Get the intersect parameter for the second line 202 202 … … 226 226 vertices[3].x = 0; vertices[3].y = numRows; 227 227 228 clipLine.begin.x = 0; 229 clipLine.begin.y = 0; 230 clipLine.end.x = 0; 231 clipLine.end.y = 0; 232 228 233 for (i = 0; i < 4 && found < 2; ++i) 229 234 { … … 237 242 ++found; 238 243 } 239 else if (tuple1.x != clipLine.begin.x || 244 else if (tuple1.x != clipLine.begin.x || 240 245 tuple1.y != clipLine.begin.y) 241 246 { … … 245 250 } 246 251 } 247 252 248 253 // If two endpoints are found, clip the line 249 254 250 255 if (found > 1) 251 256 { … … 283 288 vertices[3].x = minX; vertices[3].y = maxY; 284 289 290 clipLine.begin.x = 0; 291 clipLine.begin.y = 0; 292 clipLine.end.x = 0; 293 clipLine.end.y = 0; 294 285 295 for (i = 0; i < 4 && found < 2; ++i) 286 296 { … … 294 304 ++found; 295 305 } 296 else if (tuple1.x != clipLine.begin.x || 306 else if (tuple1.x != clipLine.begin.x || 297 307 tuple1.y != clipLine.begin.y) 298 308 { … … 302 312 } 303 313 } 304 314 305 315 // If two endpoints are found, clip the line 306 316 307 317 if (found > 1) 308 318 { … … 360 370 @param[out] pixels list of PixelPos pointers corresponding 361 371 based on the line settings 362 @param[in] line Line to map to pixels 372 @param[in] line Line to map to pixels 363 373 @param[in] numCols maximum X (columns) for the line 364 374 @param[in] numRows maximum Y (rows) for the line */ … … 367 377 { 368 378 Line offsetLine; 369 PixelPos *pixel;370 379 double slope, xOffset, yOffset, xMid, yMid; 371 380 int x, y, xBegin = numCols, yBegin = numRows, xEnd = 0, yEnd = 0; 372 381 373 382 // Extract the endpoints 374 383 375 384 double x1 = line->begin.x; 376 385 double y1 = line->begin.y; 377 386 double x2 = line->end.x; 378 387 double y2 = line->end.y; 379 388 380 389 // Determine the width and height of the line 381 390 382 391 double dx = x2 - x1; 383 392 double dy = y2 - y1; … … 403 412 404 413 // Step point by point based on the dominate axis 405 414 406 415 if (fabs (dx) > fabs (dy)) 407 416 { … … 411 420 // If line is back to front, reorder endpoints and recompute 412 421 // the line width and height 413 422 414 423 if (x1 > x2) 415 424 { … … 421 430 422 431 // Compute the slope of the line 423 432 424 433 slope = dy / dx; 425 434 426 435 // Compute the x and y offsets for the line width extent 427 436 428 if (xBegin > xEnd) 437 if (xBegin > xEnd) 429 438 SwapInt (&xBegin, &xEnd); 430 439 else … … 451 460 } 452 461 else 453 { 462 { 454 463 // ------------------- 455 464 // vertical(ish) lines … … 457 466 // If line is back to front, reorder endpoints and recompute 458 467 // the line width and height 459 468 460 469 if (y1 > y2) 461 470 { … … 465 474 dy = y2 - y1; 466 475 } 467 476 468 477 // Compute the slope of the line 469 478 470 479 slope = dx / dy; 471 480 472 481 // Compute the x and y offsets for the line width extent 473 482 … … 481 490 xMid = x1 + slope * (yBegin - y1); 482 491 xOffset = fabs (halfWidth * dr / dy); 483 492 484 493 for (y = yBegin; y != yEnd; ++y) 485 494 { -
trunk/magic/remove/src/Makefile.simple
r24761 r25082 36 36 37 37 STREAKSFLAGS=-DSTREAKS_COMPRESS_OUTPUT=1 38 OPTFLAGS= -g -O2 38 OPTFLAGS= -g -O2 -Wall -Werror 39 39 #OPTFLAGS= -g 40 CFLAGS=`psmodules-config --cflags` -std=gnu99 ${OPTFLAGS} ${STREAKSFLAGS}41 #CFLAGS=`psmodules-config --cflags` -std=gnu99 ${OPTFLAGS}42 LDFLAGS=`psmodules-config --libs` 40 CFLAGS=`psmodules-config --cflags` `pslib-config --cflags` -std=gnu99 ${OPTFLAGS} ${STREAKSFLAGS} 41 #CFLAGS=`psmodules-config --cflags` `pslib-config --cflags` -std=gnu99 ${OPTFLAGS} 42 LDFLAGS=`psmodules-config --libs` `pslib-config --libs` 43 43 44 44 PROGRAMS= streaksremove streaksreplace streakscompare streaksrelease isdestreaked -
trunk/magic/remove/src/isdestreaked.c
r24715 r25082 18 18 psFits *fits = psFitsOpen(fileName, "r"); 19 19 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); 22 21 exit(PS_EXIT_DATA_ERROR); 23 22 } … … 25 24 psMetadata *header = psFitsReadHeader(NULL, fits); 26 25 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); 29 27 exit(PS_EXIT_DATA_ERROR); 30 28 } -
trunk/magic/remove/src/streaksastrom.c
r24716 r25082 93 93 // since the transform already accounts for the chip parity we just use the cell parity 94 94 astrom->xParity = (double) xParityCell; 95 astrom->yParity = (double) yParityCell; 95 astrom->yParity = (double) yParityCell; 96 96 97 97 astrom->numCols = numCols; … … 135 135 136 136 void 137 cellToChipInt( int *xChip,int *yChip, strkAstrom *astrom, int xCell, int yCell)137 cellToChipInt(unsigned int *xChip, unsigned int *yChip, strkAstrom *astrom, int xCell, int yCell) 138 138 { 139 139 if (astrom->xParity > 0) { … … 148 148 } 149 149 } 150 150 151 151 bool 152 152 SkyToLocal(strkPt *outPt, strkAstrom *astrom, double ra, double dec) … … 156 156 157 157 pmFPA *fpa = (pmFPA *) astrom->fpa; 158 pmChip *chip = (pmChip *) astrom->chip;159 158 160 159 // find the RA,DEC coords of the 0,0 pixel for this chip: … … 183 182 184 183 pmFPA *fpa = (pmFPA *) astrom->fpa; 185 pmChip *chip = (pmChip *) astrom->chip;186 184 187 185 // find the RA,DEC coords of the 0,0 pixel for this chip: … … 251 249 pmChip *chip = (pmChip *) astrom->chip; 252 250 pmAstromObj *pt = (pmAstromObj *) astrom->pt; 253 251 254 252 pt->sky->r = ra; 255 253 pt->sky->d = dec; … … 276 274 pmChip *chip = (pmChip *) astrom->chip; 277 275 pmAstromObj *pt = (pmAstromObj *) astrom->pt; 278 276 279 277 cellToChip(&pt->chip->x, &pt->chip->y, astrom, x, y); 280 278 … … 294 292 } 295 293 296 294 297 295 static bool 298 296 readAstrometry(streakFiles *sf) … … 362 360 break; 363 361 } 364 } 362 } 365 363 if (!sf->chip) { 366 364 psError(PS_ERR_UNKNOWN, true, "Failed to find chip with data."); -
trunk/magic/remove/src/streakscompare.c
r21156 r25082 5 5 int main(int argc, char *argv[]) 6 6 { 7 long i;8 7 bool status; 9 8 … … 35 34 int numErrors = 0; 36 35 for (int component = 0; component < ncomponents; component++) { 37 if (component && !(psFitsMoveExtNum(file1->fits, 1, true) 36 if (component && !(psFitsMoveExtNum(file1->fits, 1, true) 38 37 && psFitsMoveExtNum(file2->fits, 1, true))) { 39 38 streaksExit("failed to advance to next extesion\n", PS_EXIT_DATA_ERROR); … … 45 44 psImage *image2 = file2->image; 46 45 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 48 47 // check for matching image cubes 49 48 if (image1 && image2) { … … 68 67 error = ! isnan(value1) && isnan(value2); 69 68 } 70 69 71 70 if (error) { 72 71 numErrors++; -
trunk/magic/remove/src/streaksextern.h
r25001 r25082 54 54 pixels 55 55 */ 56 56 57 57 extern StreakPixels *streak_on_component(Streaks *streaks, strkAstrom *astrom, 58 58 int numCols, int numRows); -
trunk/magic/remove/src/streaksio.c
r24853 r25082 12 12 // Assumptions about the file structure of non-raw files 13 13 // The 'image' for each file (image, mask weight) is contained in the first 14 // extension. 14 // extension. 15 15 16 16 … … 625 625 streaksExit("", PS_EXIT_DATA_ERROR); 626 626 } 627 627 628 628 bool status; 629 629 in->extname = psMetadataLookupStr(&status, in->header, "EXTNAME"); … … 654 654 streaksExit("", PS_EXIT_DATA_ERROR); 655 655 } 656 psImage *image = (psImage *) (in->imagecube->data[0]);657 656 } 658 657 setDataExtent(stage, in, (stage == IPP_STAGE_RAW) && !isMask); … … 925 924 replicateOutputs(streakFiles *sfiles) 926 925 { 927 bool status = false;928 929 926 if (!replicate(sfiles->outImage, sfiles->inImage)) { 930 927 psError(PM_ERR_SYS, false, "failed to replicate outImage."); … … 973 970 974 971 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.", 976 973 in->name, nebErr(server)); 977 974 return false; … … 1097 1094 setMaskedToNAN(streakFiles *sfiles, psU32 maskMask, bool printCounts) 1098 1095 { 1099 intmaskedPixels = 0;1100 intnandPixels = 0;1101 intnandWeights = 0;1096 long maskedPixels = 0; 1097 long nandPixels = 0; 1098 long nandWeights = 0; 1102 1099 1103 1100 psImage *image = sfiles->outImage->image; … … 1120 1117 psU32 maskVal; 1121 1118 if (sfiles->stage == IPP_STAGE_RAW) { 1122 int xChip, yChip;1119 unsigned int xChip, yChip; 1123 1120 cellToChipInt(&xChip, &yChip, sfiles->astrom, x, y); 1124 1121 maskVal = psImageGet(mask, xChip, yChip); … … 1144 1141 if (printCounts) { 1145 1142 psLogMsg(sfiles->program_name, PS_LOG_INFO, "time to NAN mask pixels: %f\n", psTimerClear("NAN_MASKED")); 1146 inttotalPixels = image->numRows * image->numCols;1143 long totalPixels = image->numRows * image->numCols; 1147 1144 psLogMsg(sfiles->program_name, PS_LOG_INFO, "pixels: %10ld\n", totalPixels); 1148 1145 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 3 3 static pmConfig *parseArguments(int argc, char **argv); 4 4 static 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);9 5 static void writeImages(streakFiles *sf, bool exciseImageCube); 10 6 … … 12 8 main(int argc, char *argv[]) 13 9 { 14 bool status;15 16 10 psLibInit(NULL); 17 11 psTimerStart("STREAKSREMOVE"); … … 25 19 // Values to set for masked pixels 26 20 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 28 22 29 23 // Does true work here? … … 216 210 // image data directly from psFits 217 211 readImage(sf->inImage, sf->extnum, sf->stage, false); 218 212 219 213 // astrom struct is only needed for raw stage, and only the chip to cell parameters are used 220 214 sf->astrom = streakSetAstrometry(sf->astrom, sf->stage, NULL, NULL, false, … … 304 298 initValue = NAN; 305 299 } else { 306 // otherwise write it to the output 300 // otherwise write it to the output 307 301 writeImageCube(sf->outImage, sf->inImage->imagecube, extname, sf->extnum); 308 302 initValue = 0; -
trunk/magic/remove/src/streaksremove.c
r25001 r25082 35 35 // Values to set for masked pixels 36 36 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 38 38 39 39 psString streaksFileName = psMetadataLookupStr(NULL, config->arguments, "STREAKS"); … … 42 42 Streaks *streaks = readStreaksFile(streaksFileName); 43 43 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); 45 45 streaksExit("", PS_EXIT_PROG_ERROR); 46 46 } … … 83 83 psLogMsg("streaksremove", PS_LOG_INFO, "time to compute warped pixels: %f\n", cwp_t); 84 84 } 85 85 86 86 if (sfiles->stage == IPP_STAGE_RAW) { 87 87 // Except for raw stage, all of our (GPC1) files have one image extension. … … 97 97 } 98 98 99 inttotalPixels = 0;100 inttotalStreakPixels = 0;99 long totalPixels = 0; 100 long totalStreakPixels = 0; 101 101 102 102 // Iterate through each component of the input (except for raw images there is only one) … … 132 132 sfiles->inImage->numRows); 133 133 psLogMsg("streaksremove", PS_LOG_INFO, "time to get streak pixels: %f\n", psTimerClear("GET_STREAK_PIXELS")); 134 134 135 135 // if this extension contained an image, excise the streaked pixels. 136 136 // otherwise it contained an image cube (video cell) which is handled in the if block … … 172 172 } 173 173 174 } else { 174 } else { 175 175 // this component contains an image cube 176 176 // For now excise it completely … … 215 215 216 216 if (!replicateOutputs(sfiles)) { 217 psError (PS_ERR_UNKNOWN, false, "failed to replicate output files");217 psErrorStackPrint(stderr, "failed to replicate output files"); 218 218 deleteTemps(sfiles); 219 psErrorStackPrint(stderr, "");220 219 exit(PS_EXIT_UNKNOWN_ERROR); 221 220 } … … 247 246 pmConceptsDone(); 248 247 pmModelClassCleanup(); 249 streaksNebulousCleanup(); 248 streaksNebulousCleanup(); 250 249 pmConfigDone(); 251 250 psLogMsg("streaksremove", PS_LOG_INFO, "time to run streaksremove: %f\n", psTimerClear("STREAKSREMOVE")); … … 356 355 true); 357 356 } 358 357 359 358 if ((argnum = psArgumentGet(argc, argv, "-keepnonwarped"))) { 360 359 psArgumentRemove(argnum, &argc, argv); … … 374 373 psArgumentRemove(argnum, &argc, argv); 375 374 } 376 375 377 376 // if skycells are not provided then we have to execise all pixels unless -keepnonwarped 378 377 pmConfigFileSetsMD(config->arguments, &argc, argv, "SKYCELLS", "-skycell", "-skycelllist"); … … 628 627 initValue = NAN; 629 628 } else { 630 // otherwise write it to the output 629 // otherwise write it to the output 631 630 writeImageCube(sf->outImage, sf->inImage->imagecube, extname, sf->extnum); 632 631 initValue = 0; … … 799 798 sFile *out = sfiles->outSources; 800 799 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 } 834 872 } 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. 856 885 857 886 if (!psFitsClose(out->fits)) { -
trunk/magic/remove/src/streaksremove.h
r24691 r25082 84 84 // can't declare this in streaksastrom due to header file ordering 85 85 extern 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);86 extern void cellToChipInt(unsigned int *xChip, unsigned int *yChip, strkAstrom *astrom, int xCell, int yCell); 87 87 88 88 extern bool computeWarpedPixels(streakFiles *sf); -
trunk/magic/remove/src/streaksreplace.c
r24556 r25082 8 8 int main(int argc, char *argv[]) 9 9 { 10 long i;11 10 bool status; 12 StreakPixels *pixels;13 PixelPos *pixelPos;14 11 15 12 psLibInit(NULL); … … 92 89 93 90 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"); 96 92 exit(PS_EXIT_UNKNOWN_ERROR); 97 93 } … … 172 168 true); 173 169 } 174 170 175 171 bool gotMask = false; 176 172 if ((argnum = psArgumentGet(argc, argv, "-mask"))) { … … 353 349 // we have an image cube 354 350 double initValue; 355 // otherwise write it to the output 351 // otherwise write it to the output 356 352 writeImageCube(sf->outImage, sf->recImage->imagecube, extname, sf->extnum); 357 353 -
trunk/magic/remove/src/streaksutil.c
r24556 r25082 44 44 // we just bail out 45 45 void streaksExit(psString str, int exitCode) { 46 psErrorStackPrint(stderr, str);46 psErrorStackPrint(stderr, "%s", str); 47 47 if (ourStreakFiles) { 48 48 deleteTemps(ourStreakFiles); -
trunk/magic/remove/src/warpedpixels.c
r21438 r25082 23 23 24 24 psRegion *bounds = pmChipPixels(sf->chip); 25 25 26 26 int width = bounds->x1 - bounds->x0; 27 27 int height = bounds->y1 - bounds->y0; … … 83 83 84 84 /* 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, 86 86 sf->warpedPixels->numCols, sf->warpedPixels->numRows); 87 87 … … 106 106 // convert corner of skycell to sky coordinates 107 107 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); 109 109 streaksExit("", PS_EXIT_DATA_ERROR); 110 110 } … … 112 112 // convert to chip coordinates 113 113 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); 115 115 streaksExit("", PS_EXIT_DATA_ERROR); 116 116 } … … 171 171 } 172 172 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 174 174 // Note: the caller guarentees that the y's of the two points are different 175 175 static double xOfY(psPlane *pI, psPlane *pJ, int y) … … 212 212 * To compute the overlap of a quadrilateral with a set of 213 213 * 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 215 215 pt 0 is left most (bottom most corner) 216 216 pt 1 is bottom most (right most corner) … … 238 238 239 239 3 240 C 240 C 241 241 ---------------2 left boundary: line 0_1 y < pt0.y 242 242 B line 0_3 y >= pt0.y … … 249 249 C 250 250 0---------------- 251 B 251 B 252 252 ----------------2 253 253 A … … 258 258 259 259 3 2 260 260 261 261 B 262 262 … … 265 265 (region A and C are empty in the case where the points form a rectangle) 266 266 */ 267 267 268 268 /* 269 269 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 271 271 I think it also works for the situation where 3 points are co-linear 272 272 and we have a triangle, but that isn't important for our purposes … … 313 313 pt[i] = pt[i+1]; 314 314 } 315 315 316 316 // now find the right most (top most) of the remaining 2 points 317 317 if ((pt[0].x > pt[1].x) ||
Note:
See TracChangeset
for help on using the changeset viewer.
