Changeset 24557 for branches/eam_branches/20090522/magic/remove/src
- Timestamp:
- Jun 25, 2009, 2:00:56 PM (17 years ago)
- Location:
- branches/eam_branches/20090522
- Files:
-
- 15 edited
- 1 copied
-
. (modified) (1 prop)
-
magic/remove/src (modified) (1 prop)
-
magic/remove/src/Line.c (modified) (5 diffs)
-
magic/remove/src/Line.h (modified) (2 diffs)
-
magic/remove/src/Makefile.simple (modified) (4 diffs)
-
magic/remove/src/isdestreaked.c (copied) (copied from trunk/magic/remove/src/isdestreaked.c )
-
magic/remove/src/streaksastrom.c (modified) (1 diff)
-
magic/remove/src/streaksastrom.h (modified) (1 diff)
-
magic/remove/src/streaksextern.c (modified) (2 diffs)
-
magic/remove/src/streaksio.c (modified) (20 diffs)
-
magic/remove/src/streaksio.h (modified) (2 diffs)
-
magic/remove/src/streaksrelease.c (modified) (6 diffs)
-
magic/remove/src/streaksremove.c (modified) (19 diffs)
-
magic/remove/src/streaksremove.h (modified) (2 diffs)
-
magic/remove/src/streaksreplace.c (modified) (4 diffs)
-
magic/remove/src/streaksutil.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/20090522
- Property svn:mergeinfo changed
-
branches/eam_branches/20090522/magic/remove/src
- Property svn:ignore
-
old new 3 3 streakscompare 4 4 streaksrelease 5 makefile
-
- Property svn:ignore
-
branches/eam_branches/20090522/magic/remove/src/Line.c
r21156 r24557 16 16 { 17 17 double temp = *first; 18 *first = *second; 19 *second = temp; 20 } 21 22 /** Internal routine to swap integer values */ 23 24 void SwapInt (int* first, int* second) 25 { 26 int temp = *first; 18 27 *first = *second; 19 28 *second = temp; … … 255 264 } 256 265 257 /** Map a line to an image for its specified width and store as a list 258 of pixel positions 266 /** Clip the line between (minX,minY) and (maxX,maxY) 267 268 @param[in,out] line line to be clipped within the bounds 269 @param[in] minX minimum X (columns) for the line 270 @param[in] minY minimum Y (rows) for the line 271 @param[in] maxX maximum X (columns) for the line 272 @param[in] maxY maximum Y (rows) for the line 273 @return true if line overlaps the clip boundaries */ 274 275 bool LineClipFull (Line *line, int minX, int minY, int maxX, int maxY) 276 { 277 unsigned int i, found = 0; 278 Line boundLine, clipLine; 279 strkPt tuple1, tuple2, vertices[4]; 280 vertices[0].x = minX; vertices[0].y = minY; 281 vertices[1].x = maxX; vertices[1].y = minY; 282 vertices[2].x = maxX; vertices[2].y = maxY; 283 vertices[3].x = minX; vertices[3].y = maxY; 284 285 for (i = 0; i < 4 && found < 2; ++i) 286 { 287 boundLine.begin = vertices[i]; 288 boundLine.end = vertices[(i + 1) % 4]; 289 if (LineIntercept (line, &boundLine, &tuple1, &tuple2, false, true)) 290 { 291 if (found == 0) 292 { 293 clipLine.begin = tuple1; 294 ++found; 295 } 296 else if (tuple1.x != clipLine.begin.x || 297 tuple1.y != clipLine.begin.y) 298 { 299 clipLine.end = tuple1; 300 ++found; 301 } 302 } 303 } 304 305 // If two endpoints are found, clip the line 306 307 if (found > 1) 308 { 309 if (clipLine.begin.x <= clipLine.end.x) 310 { 311 line->begin = clipLine.begin; 312 line->end = clipLine.end; 313 } 314 else 315 { 316 line->begin = clipLine.end; 317 line->end = clipLine.begin; 318 } 319 } 320 return found > 1; 321 } 322 323 /** Move a line by the specified X and Y offsets 324 @param[in,out] line Line to move by X and Y offsets 325 @param[in] xOffset X shift applied to both endpoints 326 @param[in] yOffset Y shift applied to both endpoints */ 327 328 void LineMove (Line *line, double xOffset, double yOffset) 329 { 330 line->begin.x += xOffset; 331 line->begin.y += yOffset; 332 line->end.x += xOffset; 333 line->end.y += yOffset; 334 } 335 336 /** Return the maximum bounds between the line endpoints and 337 current bounds 338 @param[in] line Line endpoints to compare 339 @param[in,out] xMin minimum X value to update 340 @param[in,out] xMax maximum X value to update 341 @param[in,out] yMin minimum Y value to update 342 @param[in,out] yMax maximum Y value to update */ 343 344 void MaxBounds (Line *line, int *xMin, int *xMax, int *yMin, int *yMax) 345 { 346 if (line->begin.x < *xMin) *xMin = (int) floor (line->begin.x); 347 if (line->end.x < *xMin) *xMin = (int) floor (line->end.x); 348 if (line->begin.y < *yMin) *yMin = (int) floor (line->begin.y); 349 if (line->end.y < *yMin) *yMin = (int) floor (line->end.y); 350 351 if (line->begin.x > *xMax) *xMax = (int) ceil (line->begin.x); 352 if (line->end.x > *xMax) *xMax = (int) ceil (line->end.x); 353 if (line->begin.y > *yMax) *yMax = (int) ceil (line->begin.y); 354 if (line->end.y > *yMax) *yMax = (int) ceil (line->end.y); 355 } 356 357 /** Map a line to an image for its specified width and store as 358 a list of pixel positions 259 359 260 360 @param[out] pixels list of PixelPos pointers corresponding 261 361 based on the line settings 262 @param[in] line Line to map to pixels */ 263 264 void PixelsFromLine (StreakPixels* pixels, Line *line) 265 { 362 @param[in] line Line to map to pixels 363 @param[in] numCols maximum X (columns) for the line 364 @param[in] numRows maximum Y (rows) for the line */ 365 366 void PixelsFromLine (StreakPixels* pixels, Line *line, int numCols, int numRows) 367 { 368 Line offsetLine; 266 369 PixelPos *pixel; 267 double slope, xOffset, yOffset, xMid, yMid, xBegin, yBegin, xEnd, yEnd, x, y; 370 double slope, xOffset, yOffset, xMid, yMid; 371 int x, y, xBegin = numCols, yBegin = numRows, xEnd = 0, yEnd = 0; 268 372 269 373 // Extract the endpoints … … 280 384 double dr = sqrt (dx * dx + dy * dy); 281 385 double halfWidth = line->width / 2.0; 282 double halfWidth2 = halfWidth * halfWidth;283 386 if (!dr) return; 284 387 388 // Compute the intercepts of line width bounds and determine maximum 389 // bounds in each axis 390 391 xOffset = -halfWidth * dy / dr; 392 yOffset = halfWidth * dx / dr; 393 394 offsetLine = *line; 395 LineMove (&offsetLine, xOffset, yOffset); 396 if (LineClip (&offsetLine, numCols, numRows)) 397 MaxBounds (&offsetLine, &xBegin, &xEnd, &yBegin, &yEnd); 398 399 offsetLine = *line; 400 LineMove (&offsetLine, -xOffset, -yOffset); 401 if (LineClip (&offsetLine, numCols, numRows)) 402 MaxBounds (&offsetLine, &xBegin, &xEnd, &yBegin, &yEnd); 403 285 404 // Step point by point based on the dominate axis 286 405 … … 307 426 // Compute the x and y offsets for the line width extent 308 427 309 xOffset = halfWidth * dy / dr; 310 yOffset = halfWidth * dr / dx; 311 yMid = y1 + slope * (floor (x1 - xOffset) - x1); 312 xBegin = floor (x1 - xOffset); 313 xEnd = ceil (x2 + xOffset) + 1.0; 314 315 for (x = xBegin; x < xEnd; ++x) 316 { 317 yBegin = floor (yMid - yOffset); 318 yEnd = ceil (yMid + yOffset) + 1.0; 319 for (y = yBegin; y < yEnd; ++y) 428 if (xBegin > xEnd) 429 SwapInt (&xBegin, &xEnd); 430 else 431 ++xEnd; 432 if (xBegin < 0) xBegin = 0; 433 if (xEnd > numCols) xEnd = numCols; 434 435 yMid = y1 + slope * (xBegin - x1); 436 yOffset = fabs (halfWidth * dr / dx); 437 438 for (x = xBegin; x != xEnd; ++x) 439 { 440 yBegin = (int) floor (yMid - yOffset); 441 yEnd = (int) ceil (yMid + yOffset) + 1; 442 for (y = yBegin; y != yEnd; ++y) 320 443 { 321 if ( DistanceSquared (line, x, y) <= halfWidth2)444 if (y >= 0 && y < numRows) 322 445 { 323 if (x >=0 && y >= 0) { 324 pixel = psAlloc (sizeof(PixelPos)); 325 pixel->x = (unsigned int) x; 326 pixel->y = (unsigned int) y; 327 psArrayAdd (pixels, 1024, pixel); 328 psFree (pixel); 329 } 446 pixel = psAlloc (sizeof(PixelPos)); 447 pixel->x = (unsigned int) x; 448 pixel->y = (unsigned int) y; 449 psArrayAdd (pixels, 1024, pixel); 450 psFree (pixel); 330 451 } 331 452 } … … 354 475 355 476 // Compute the x and y offsets for the line width extent 356 357 xOffset = halfWidth * dr / dy; 358 yOffset = halfWidth * dx / dr; 359 360 xMid = x1 + slope * (floor (y1 - yOffset) - y1); 361 yBegin = floor (y1 - yOffset); 362 yEnd = ceil (y2 + yOffset) + 1.0; 363 364 for (y = yBegin; y < yEnd; ++y) 365 { 366 xBegin = floor (xMid - xOffset); 367 xEnd = ceil (xMid + xOffset) + 1.0; 368 for (x = xBegin; x < xEnd; ++x) 477 478 if (yBegin > yEnd) 479 SwapInt (&yBegin, &yEnd); 480 else 481 ++yEnd; 482 if (yBegin < 0) yBegin = 0; 483 if (yEnd > numRows) yEnd = numRows; 484 485 xMid = x1 + slope * (yBegin - y1); 486 xOffset = fabs (halfWidth * dr / dy); 487 488 for (y = yBegin; y != yEnd; ++y) 489 { 490 xBegin = (int) floor (xMid - xOffset); 491 xEnd = (int) ceil (xMid + xOffset) + 1; 492 for (x = xBegin; x != xEnd; ++x) 369 493 { 370 if ( DistanceSquared (line, x, y) <= halfWidth2)494 if (x >=0 && x < numCols) 371 495 { 372 if (x >=0 && y >= 0) { 373 pixel = psAlloc (sizeof(PixelPos)); 374 pixel->x = (unsigned int) x; 375 pixel->y = (unsigned int) y; 376 psArrayAdd (pixels, 1024, pixel); 377 psFree (pixel); 378 } 496 pixel = psAlloc (sizeof(PixelPos)); 497 pixel->x = (unsigned int) x; 498 pixel->y = (unsigned int) y; 499 psArrayAdd (pixels, 1024, pixel); 500 psFree (pixel); 379 501 } 380 502 } -
branches/eam_branches/20090522/magic/remove/src/Line.h
r20308 r24557 21 21 extern bool LineClip (Line *line, int numCols, int numRows); 22 22 23 /** Clip the line between (minX,minY) and (maxX,maxY) 24 25 @param[in,out] line line to be clipped within the bounds 26 @param[in] minX minimum X (columns) for the line 27 @param[in] minY minimum Y (rows) for the line 28 @param[in] maxX maximum X (columns) for the line 29 @param[in] maxY maximum Y (rows) for the line 30 @return true if line overlaps the clip boundaries */ 31 32 extern bool LineClipFull (Line *line, int minX, int minY, int maxX, int maxY); 33 23 34 /** Map a line to an image for its specified width and append as 24 35 a list of pixel positions … … 26 37 @param[out] pixels list of PixelPos pointers corresponding 27 38 based on the line settings 28 @param[in] line Line to map to pixels */ 39 @param[in] line Line to map to pixels 40 @param[in] numCols maximum X (columns) for the line 41 @param[in] numRows maximum Y (rows) for the line */ 29 42 30 extern void PixelsFromLine (StreakPixels* pixels, Line *line); 43 extern void PixelsFromLine (StreakPixels* pixels, Line *line, 44 int numCols, int numRows); 31 45 32 46 #endif /* STREAK_LINE_H */ -
branches/eam_branches/20090522/magic/remove/src/Makefile.simple
r23910 r24557 28 28 streaksrelease.o 29 29 30 # STREAKSFLAGS=-DSTREAKS_COMPRESS_OUTPUT=1 30 ISDESTREAKED_OBJECTS= \ 31 ${COMMON_OBJECTS} \ 32 isdestreaked.o 33 34 35 HEADERS= Line.h streaksastrom.h streaksextern.h streaksio.h streaksremove.h 36 37 STREAKSFLAGS=-DSTREAKS_COMPRESS_OUTPUT=1 31 38 OPTFLAGS= -g -O2 32 39 OPTFLAGS= -g … … 35 42 LDFLAGS=`psmodules-config --libs` 36 43 37 PROGRAMS= streaksremove streaksreplace streakscompare streaksrelease 44 PROGRAMS= streaksremove streaksreplace streakscompare streaksrelease isdestreaked 45 HEADERS=Line.h streaksastrom.h streaksextern.h streaksio.h streaksremove.h 38 46 39 47 all: ${PROGRAMS} 40 48 49 ${REMOVE_OBJECTS}: ${HEADERS} 41 50 streaksremove: ${REMOVE_OBJECTS} 42 51 … … 47 56 streaksrelease: ${RELEASE_OBJECTS} 48 57 58 isdestreaked: ${ISDESTREAKED_OBJECTS} 59 60 49 61 install: ${PROGRAMS} 50 62 install -t $(PSCONFDIR)/$(PSCONFIG)/bin streaksremove … … 52 64 install -t $(PSCONFDIR)/$(PSCONFIG)/bin streakscompare 53 65 install -t $(PSCONFDIR)/$(PSCONFIG)/bin streaksrelease 66 install -t $(PSCONFDIR)/$(PSCONFIG)/bin isdestreaked 54 67 55 68 clean: -
branches/eam_branches/20090522/magic/remove/src/streaksastrom.c
r21437 r24557 150 150 151 151 bool 152 SkyToLocal(strkPt *outPt, strkAstrom *astrom, double ra, double dec) 153 { 154 // generate a local project using the RA, DEC of the 0,0 pixel of the chip as the 155 // projection center with the same plate scale as the nominal TP->Sky astrometry. 156 157 pmFPA *fpa = (pmFPA *) astrom->fpa; 158 pmChip *chip = (pmChip *) astrom->chip; 159 160 // find the RA,DEC coords of the 0,0 pixel for this chip: 161 162 psPlane ptTP; 163 psSphere ptSky; 164 165 ptSky.r = ra; 166 ptSky.d = dec; 167 ptSky.rErr = 0.0; 168 ptSky.dErr = 0.0; 169 170 psProject(&ptTP, &ptSky, fpa->toSky); 171 172 outPt->x = ptTP.x; 173 outPt->y = ptTP.y; 174 175 return true; 176 } 177 178 bool 179 LocalToSky(strkPt *outPt, strkAstrom *astrom, strkPt *inPt) 180 { 181 // generate a local project using the RA, DEC of the 0,0 pixel of the chip as the 182 // projection center with the same plate scale as the nominal TP->Sky astrometry. 183 184 pmFPA *fpa = (pmFPA *) astrom->fpa; 185 pmChip *chip = (pmChip *) astrom->chip; 186 187 // find the RA,DEC coords of the 0,0 pixel for this chip: 188 189 psPlane ptTP; 190 psSphere ptSky; 191 192 ptTP.x = inPt->x; 193 ptTP.y = inPt->y; 194 ptTP.xErr = 0.0; 195 ptTP.yErr = 0.0; 196 197 psDeproject(&ptSky, &ptTP, fpa->toSky); 198 199 outPt->x = ptSky.r; 200 outPt->y = ptSky.d; 201 202 return true; 203 } 204 205 bool 206 componentBounds(int *minX, int *minY, int *maxX, int *maxY, strkAstrom *astrom, int numCols, int numRows) 207 { 208 // find the bounds of the (padded) chip region in tangent-plane coordinates 209 210 pmFPA *fpa = (pmFPA *) astrom->fpa; 211 pmChip *chip = (pmChip *) astrom->chip; 212 213 psPlane ptCH, ptFP, TPo, TPx, TPy; 214 215 // coordinate of the chip center: 216 ptCH.x = 0.5*numCols; 217 ptCH.y = 0.5*numRows; 218 psPlaneTransformApply(&ptFP, chip->toFPA, &ptCH); 219 psPlaneTransformApply(&TPo, fpa->toTPA, &ptFP); 220 221 // coordinate of the chip center + dX/2: 222 ptCH.x = numCols; 223 ptCH.y = 0.5*numRows; 224 psPlaneTransformApply(&ptFP, chip->toFPA, &ptCH); 225 psPlaneTransformApply(&TPx, fpa->toTPA, &ptFP); 226 227 // coordinate of the chip center + dY/2: 228 ptCH.x = 0.5*numCols; 229 ptCH.y = numRows; 230 psPlaneTransformApply(&ptFP, chip->toFPA, &ptCH); 231 psPlaneTransformApply(&TPy, fpa->toTPA, &ptFP); 232 233 // half-lengths of the two sides in tangent-plane coords: 234 double xSize = hypot (TPx.x - TPo.x, TPx.y - TPo.y); 235 double ySize = hypot (TPy.x - TPo.x, TPy.y - TPo.y); 236 double radius = hypot (xSize, ySize); 237 238 // define the region encompassed by the radius with some padding: 239 *minX = TPo.x - 1.1*radius; 240 *minY = TPo.y - 1.1*radius; 241 *maxX = TPo.x + 1.1*radius; 242 *maxY = TPo.y + 1.1*radius; 243 244 return true; 245 } 246 247 bool 152 248 skyToCell(strkPt *outPt, strkAstrom *astrom, double ra, double dec) 153 249 { -
branches/eam_branches/20090522/magic/remove/src/streaksastrom.h
r21155 r24557 32 32 extern void linearizeTransforms(strkAstrom *astrom); 33 33 34 extern bool SkyToLocal(strkPt *outPt, strkAstrom *astrom, double ra, double dec); 35 extern bool LocalToSky(strkPt *outPt, strkAstrom *astrom, strkPt *inPt); 36 extern bool componentBounds(int *minX, int *minY, int *maxX, int *maxY, strkAstrom *astrom, int numCols, int numRows); 37 34 38 #endif // STREAKS_ASTROM_H -
branches/eam_branches/20090522/magic/remove/src/streaksextern.c
r21439 r24557 36 36 StreakPixels *pixels = psArrayAllocEmpty (1024); 37 37 int streaksOnComponent = 0; 38 39 int minX, minY, maxX, maxY; 40 41 // find the chip dimensions in the tangent-plane coordinates (length of hypotenuse) 42 componentBounds (&minX, &minY, &maxX, &maxY, astrom, numCols, numRows); 43 38 44 for (i = 0; i != streaks->size; ++i) 39 45 { … … 41 47 42 48 line.width = streaks->list[i].width; 43 if (skyToCell (&line.begin, astrom, 44 streaks->list[i].ra1, streaks->list[i].dec1) && 45 skyToCell (&line.end, astrom, 46 streaks->list[i].ra2, streaks->list[i].dec2) && 49 50 /* Use tangent plane coordinates to narrow down the ra,dec range of the line closer to 51 * the chip boundaries. Use these new ra,dec positions to generate the line on the 52 * chip using the full non-linear astrometry */ 53 54 // project the ends of the line using a linear projection centered on the chip center: 55 Line full; 56 SkyToLocal (&full.begin, astrom, streaks->list[i].ra1, streaks->list[i].dec1); 57 SkyToLocal (&full.end, astrom, streaks->list[i].ra2, streaks->list[i].dec2); 58 59 // clip the line to a square box with diameter = hypotenuse of the chip image centerd 60 // on the chip center in tangent-plane coordinates. skip the rest of this streak if 61 // the line does not intersect this region 62 if (!LineClipFull (&full, minX, minY, maxX, maxY)) { 63 continue; 64 } 65 66 // convert the end points back into ra, dec pairs: 67 strkPt sky1, sky2; 68 LocalToSky (&sky1, astrom, &full.begin); 69 LocalToSky (&sky2, astrom, &full.end); 70 71 if (skyToCell (&line.begin, astrom, sky1.x, sky1.y) && 72 skyToCell (&line.end, astrom, sky2.x, sky2.y) && 47 73 LineClip (&line, numCols, numRows)) 48 74 { 49 PixelsFromLine (pixels, &line );75 PixelsFromLine (pixels, &line, numCols, numRows); 50 76 streaksOnComponent++; 51 77 } -
branches/eam_branches/20090522/magic/remove/src/streaksio.c
r23965 r24557 19 19 psMemSetDeallocator(sf, (psFreeFunc) streakFilesFree); 20 20 memset(sf, 0, sizeof(*sf)); 21 22 if (remove) { 23 // remember pointer so that streaksExit can delete temps 24 setStreakFiles(sf); 25 } 21 26 22 27 sf->config = config; … … 160 165 } 161 166 167 // figure out if a nebulous instance is a non-destreaked file 168 static bool 169 nebFileIsDestreaked(sFile *sfile) 170 { 171 if (!sfile->resolved_name) { 172 psError(PS_ERR_PROGRAMMING, true, "resolved name is null"); 173 return false; 174 } 175 psFits *fits = psFitsOpen(sfile->resolved_name, "r"); 176 if (!fits) { 177 psError(PS_ERR_IO, true, "failed open %s", sfile->name); 178 // can't tell if it is a destreaked file 179 return false; 180 } 181 psMetadata *header = psFitsReadHeader(NULL, fits); 182 if (!header) { 183 psError(PS_ERR_IO, true, "failed to read header for: %s", sfile->name); 184 return false; 185 } 186 bool mdok; 187 bool isDestreaked = psMetadataLookupBool(&mdok, header, "PSDESTRK"); 188 if (mdok && isDestreaked) { 189 return true; 190 } else { 191 psError(PS_ERR_IO, false, "output file already exists and may not be de-streaked: %s", sfile->name); 192 return false; 193 } 194 } 195 162 196 static psString 163 197 resolveFilename(pmConfig *config, sFile *sfile, bool create) … … 171 205 // delete the existing file, since there may be more than one 172 206 // instance. It will get created below in pmConfigConvertFilename 173 if (nebFind(server, sfile->name)) { 207 if ((sfile->resolved_name = nebFind(server, sfile->name)) != NULL) { 208 if (!nebFileIsDestreaked(sfile)) { 209 psError(PS_ERR_IO, false, "attempting to delete file that has not been destreaked %s", sfile->name); 210 return NULL; 211 } 212 nebFree(sfile->resolved_name); 213 sfile->resolved_name = NULL; 174 214 nebDelete(server, sfile->name); 175 215 } … … 193 233 // all of the keywords in the raw image files written to the output destreaked files 194 234 195 if (! CHIP_LEVEL_INPUT(stage) && !strcmp(fileSelect, "INPUT")) {235 if (!outputFilename && !CHIP_LEVEL_INPUT(stage) && !strcmp(fileSelect, "INPUT")) { 196 236 // stage is warp or diff AND fileSelect eq "INPUT" 197 237 // get data from pmFPAfile. … … 250 290 } 251 291 252 // if outputFilename is not null name it contains the "directory" 292 // if outputFilename is not null name it contains the "directory" (perhaps with a prefix like SR_) 253 293 // and outputFilename is the basename name of the file (or nebulous key) 254 294 // and the file is to be opened for writing … … 334 374 335 375 void 376 addDestreakKeyword(psMetadata *header) 377 { 378 psMetadataAddBool(header, PS_LIST_TAIL, "PSDESTRK", PS_META_REPLACE, 379 "Have streaks been removed from image?", true); 380 } 381 382 void 383 addRecoveryKeyword(psMetadata *header) 384 { 385 psMetadataAddBool(header, PS_LIST_TAIL, "PSRECOVR", PS_META_REPLACE, 386 "Does this image contain excised streak pixels?", true); 387 } 388 389 void 336 390 copyPHU(streakFiles *sfiles, bool remove) 337 391 { … … 344 398 streaksExit("", PS_EXIT_DATA_ERROR); 345 399 } 346 347 // TODO: add keyword indicating that streaks have been removed 400 psMetadata *recHeader = NULL; 401 if (remove && sfiles->recImage) { 402 recHeader = psMetadataCopy(NULL, imageHeader); 403 addRecoveryKeyword(recHeader); 404 } 405 406 // add keyword indicating that streaks have been removed 407 addDestreakKeyword(imageHeader); 408 348 409 if (!psFitsWriteBlank(sfiles->outImage->fits, imageHeader, NULL)) { 349 410 psError(PS_ERR_IO, false, "failed to write primary header to %s", … … 351 412 streaksExit("", PS_EXIT_DATA_ERROR); 352 413 } 353 // TODO: add keyword indicating that this is the recovery image 354 if (remove && sfiles->recImage && !psFitsWriteBlank(sfiles->recImage->fits, imageHeader, NULL)) { 414 if (recHeader && !psFitsWriteBlank(sfiles->recImage->fits, recHeader, NULL)) { 355 415 psError(PS_ERR_IO, false, "failed to write primary header to %s", 356 416 sfiles->recImage->resolved_name); 357 417 streaksExit("", PS_EXIT_DATA_ERROR); 358 418 } 419 psFree(recHeader); 420 recHeader = NULL; 359 421 psFree(imageHeader); 360 422 … … 367 429 streaksExit("", 1); 368 430 } 369 // TODO: add keyword indicating that streaks have been removed 431 if (remove && sfiles->recMask) { 432 recHeader = psMetadataCopy(NULL, maskHeader); 433 // add keyword indicating that this is the recovery image 434 addRecoveryKeyword(recHeader); 435 } 436 // add keyword indicating that streaks have been removed 437 addDestreakKeyword(maskHeader); 370 438 if (!psFitsWriteBlank(sfiles->outMask->fits, maskHeader, NULL)) { 371 439 psError(PS_ERR_IO, false, "failed to write primary header to %s", … … 373 441 streaksExit("", PS_EXIT_DATA_ERROR); 374 442 } 375 // TODO: add keyword indicating that this is the recovery image 376 if (remove && sfiles->recMask && !psFitsWriteBlank(sfiles->recMask->fits, maskHeader, NULL)) { 443 if (recHeader && !psFitsWriteBlank(sfiles->recMask->fits, recHeader, NULL)) { 377 444 psError(PS_ERR_IO, false, "failed to write primary header to %s", 378 445 sfiles->recMask->resolved_name); 379 446 streaksExit("", PS_EXIT_DATA_ERROR); 380 447 } 448 psFree(recHeader); 449 recHeader = NULL; 381 450 psFree(maskHeader); 382 451 } … … 389 458 streaksExit("", 1); 390 459 } 391 // TODO: add keyword indicating that streaks have been removed 460 if (remove && sfiles->recWeight) { 461 recHeader = psMetadataCopy(NULL, weightHeader); 462 // add keyword indicating that this is a recovery image 463 addRecoveryKeyword(recHeader); 464 } 465 466 // add keyword indicating that streaks have been removed 467 addDestreakKeyword(weightHeader); 392 468 if (!psFitsWriteBlank(sfiles->outWeight->fits, weightHeader, NULL)) { 393 469 psError(PS_ERR_IO, false, "failed to write primary header to %s", … … 395 471 streaksExit("", PS_EXIT_DATA_ERROR); 396 472 } 397 // TODO: add keyword indicating that this is a recovery image 398 if (remove && sfiles->recWeight && !psFitsWriteBlank(sfiles->recWeight->fits, weightHeader, NULL)) { 473 if (recHeader && !psFitsWriteBlank(sfiles->recWeight->fits, recHeader, NULL)) { 399 474 psError(PS_ERR_IO, false, "failed to write primary header to %s", 400 475 sfiles->recWeight->resolved_name); … … 402 477 } 403 478 psFree(weightHeader); 479 psFree(recHeader); 404 480 } 405 481 } … … 566 642 567 643 static void 568 setFitsOptions(sFile *sfile, int bitpix, float bscale, float bzero) 644 setFitsOptions(sFile *sfile, int bitpix, float bscale, float bzero, psFitsCompressionType compType, 645 psVector *tiles) 569 646 { 570 647 if (!sfile) { … … 579 656 sfile->fits->options->bscale = bscale; 580 657 sfile->fits->options->bzero = bzero; 581 } 582 583 void 584 copyFitsOptions(sFile *out, sFile *rec, sFile *in) 585 { 658 659 psFitsSetCompression(sfile->fits, compType, tiles, 8, 0, 0); 660 } 661 662 void 663 copyFitsOptions(sFile *out, sFile *rec, sFile *in, psVector *tiles) 664 { 665 bool mdok; 666 psString compTypeStr = psMetadataLookupStr(&mdok, in->header, "ZCMPTYPE"); 667 psFitsCompressionType compType = psFitsCompressionTypeFromString(compTypeStr); 668 if (compType == PS_FITS_COMPRESS_NONE) { 669 return; 670 } 586 671 // Get current BITPIX, BSCALE, BZERO, EXTNAME 587 672 // Probably not necessary to look the numerical values up in this … … 610 695 611 696 #ifdef STREAKS_COMPRESS_OUTPUT 612 // Paul says that I should be able to leave this blank 613 bitpix = 0; 614 setFitsOptions(out, bitpix, bscale, bzero); 615 setFitsOptions(rec, bitpix, bscale, bzero); 697 // printf("%d %f %f\n", bitpix, bscale, bzero); 698 setFitsOptions(out, bitpix, bscale, bzero, compType, tiles); 699 setFitsOptions(rec, bitpix, bscale, bzero, compType, tiles); 616 700 #endif 617 701 } … … 790 874 791 875 bool 792 replicate(sFile * sfile, void *xattr)793 { 794 if (! sfile->inNebulous) {876 replicate(sFile *outFile, sFile *inFile) 877 { 878 if (!outFile->inNebulous) { 795 879 return true; 796 880 } 797 881 nebServer *server = getNebServer(NULL); 798 882 799 // for now just set "user.copies" to 2 800 if (!nebSetXattr(server, sfile->name, "user.copies", "2", NEB_REPLACE)) { 801 psError(PM_ERR_UNKNOWN, true, "nebSetXattr failed for %s\n%s", sfile->name, nebErr(server)); 883 char *user_copies = nebGetXattr(server, inFile->name, "user.copies"); 884 bool free_user_copies = true; 885 if (user_copies == NULL) { 886 user_copies = "2"; 887 free_user_copies = false; 888 } 889 if (!nebSetXattr(server, outFile->name, "user.copies", user_copies, NEB_REPLACE)) { 890 psError(PM_ERR_UNKNOWN, true, "nebSetXattr failed for %s\n%s", outFile->name, nebErr(server)); 802 891 return false; 803 892 } 804 if (!nebReplicate(server, sfile->name, NULL, NULL)) {805 psError(PM_ERR_UNKNOWN, true, "neb SetXattr failed for %s\n%s", sfile->name, nebErr(server));893 if (!nebReplicate(server, outFile->name, "any", NULL)) { 894 psError(PM_ERR_UNKNOWN, true, "nebReplicate failed for %s\n%s", outFile->name, nebErr(server)); 806 895 return false; 896 } 897 if (free_user_copies) { 898 nebFree(user_copies); 807 899 } 808 900 return true; … … 817 909 bool status = false; 818 910 819 // XXX: TODO: need a nebGetXatrr function, but there isn't one 820 // another option would be to take the number of copies to be 821 // created as an option. That way the system could decide 822 // whether to replicate anything other than raw Image files 823 void *xattr = NULL; 824 825 if (!replicate(sfiles->outImage, xattr)) { 911 if (!replicate(sfiles->outImage, sfiles->inImage)) { 826 912 psError(PM_ERR_SYS, false, "failed to replicate outImage."); 827 913 return false; 828 914 } 829 915 830 #ifdef notyet831 // XXX: don't replicate mask and weight images until we can look up832 // the input's xattr. There may be a perl program that can getXattr833 916 if (sfiles->outMask) { 834 // get xattr from input to see if we need to replicate 835 if (!replicate(sfiles->outMask, xattr)) { 917 if (!replicate(sfiles->outMask, sfiles->inMask)) { 836 918 psError(PM_ERR_SYS, false, "failed to replicate outImage."); 837 919 return false; 838 920 } 839 921 } 840 if (sfiles->outWeight) { 841 // get xattr from input to see if we need to replicate 842 if (!replicate(sfiles->outWeight, xattr)) { 922 if (sfiles->outChMask) { 923 if (!replicate(sfiles->outChMask, sfiles->inChMask)) { 843 924 psError(PM_ERR_SYS, false, "failed to replicate outImage."); 844 925 return false; 845 926 } 846 927 } 847 #endif 848 849 // replicate the recovery images (if in nebulous) 928 if (sfiles->outWeight) { 929 if (!replicate(sfiles->outWeight, sfiles->inWeight)) { 930 psError(PM_ERR_SYS, false, "failed to replicate outImage."); 931 return false; 932 } 933 } 934 935 // XXX: replicate the recovery images (if in nebulous) 850 936 // perhaps whether we do that or not should be configurable. 851 937 // Sounds like we need a recipe … … 904 990 } 905 991 992 if (sfiles->outChMask) { 993 if (!swapOutputToInput(sfiles->inChMask, sfiles->outChMask)) { 994 psError(PM_ERR_SYS, false, "failed to swap instances for chip mask."); 995 return false; 996 } 997 } 998 906 999 if (!swapOutputToInput(sfiles->inImage, sfiles->outImage)) { 907 1000 psError(PM_ERR_SYS, false, "failed to swap instances for Image."); … … 936 1029 { 937 1030 if (sfiles->outMask) { 938 if (!deleteFile(sfiles->outMask)) { 939 psError(PM_ERR_SYS, false, "failed to delete Mask."); 940 return false; 941 } 1031 deleteFile(sfiles->outMask); 1032 } 1033 1034 if (sfiles->outChMask) { 1035 deleteFile(sfiles->outChMask); 942 1036 } 943 1037 944 1038 if (sfiles->outWeight) { 945 if (!deleteFile(sfiles->outWeight)) { 946 psError(PM_ERR_SYS, false, "failed to delete Weight."); 947 return false; 948 } 949 } 950 951 if (!deleteFile(sfiles->outImage)) { 952 psError(PM_ERR_SYS, false, "failed to delete Image."); 953 return false; 1039 deleteFile(sfiles->outWeight); 1040 } 1041 1042 if (sfiles->outImage) { 1043 deleteFile(sfiles->outImage); 954 1044 } 955 1045 -
branches/eam_branches/20090522/magic/remove/src/streaksio.h
r23964 r24557 14 14 void copyPHU(streakFiles *sfiles, bool remove); 15 15 void copyTable(sFile *out, sFile *in, int extnum); 16 void copyFitsOptions(sFile *out, sFile *rec, sFile *in );16 void copyFitsOptions(sFile *out, sFile *rec, sFile *in, psVector *tiles); 17 17 void setupImageRefs(sFile *out, sFile *recoveryOut, sFile *in, int extnum, bool exciseAll); 18 18 void strkGetMaskValues(streakFiles *sfiles, psU32 *maskStreak, psU32 *maskMask); … … 20 20 void writeImage(sFile *sfile, psString extname, int extnum); 21 21 void writeImageCube(sFile *sfile, psArray *imagecube, psString extname, int extnum); 22 bool replicate(sFile * sfile, void *xattr);22 bool replicate(sFile *outFile, sFile *inFile); 23 23 void readImageFrom_pmFile(streakFiles *sf); 24 25 void addDestreakKeyword(psMetadata *); 26 void addRecoveryKeyword(psMetadata *); 24 27 25 28 bool streakFilesNextExtension(streakFiles *sf); -
branches/eam_branches/20090522/magic/remove/src/streaksrelease.c
r23965 r24557 23 23 } 24 24 25 psMetadata *masks = psMetadataLookupMetadata(&status, config->recipes, "MASKS"); 26 if (!status) { 27 psError(PM_ERR_CONFIG, false, "failed to lookup MASKS in recipes\n"); 28 return PS_EXIT_CONFIG_ERROR; 29 } 30 psU8 poorWarp = (double) psMetadataLookupU8(&status, masks, "POOR.WARP"); 31 if (!status) { 32 psError(PM_ERR_CONFIG, false, "failed to lookup mask value for POOR.WARP in recipes\n"); 33 return PS_EXIT_CONFIG_ERROR; 34 } 35 // we're setting pixels with any mask bits execpt POOR.WARP to NAN 36 psU8 maskMask = ~poorWarp; 25 // Values to set for masked pixels 26 psU32 maskStreak = 0; // for the image and weight (usually NAN, MAXINT for integer images) 27 psU32 maskMask = 0; // value looked up for MASK.STREAK 37 28 38 29 // Does true work here? … … 64 55 } 65 56 57 // now that we've read the input files, lookup the mask values that we read 58 if (maskStreak == 0) { 59 strkGetMaskValues(sfiles, &maskStreak, &maskMask); 60 } 61 66 62 setMaskedToNAN(sfiles, maskMask, true); 67 63 … … 77 73 printf("time to close images: %f\n", psTimerClear("CLOSE_IMAGES")); 78 74 79 #ifdef NOTYET80 if (!replicateOutputs(sfiles)) {81 psError(PS_ERR_UNKNOWN, false, "failed to replicate output files");82 psErrorStackPrint(stderr, "");83 exit(PS_EXIT_UNKNOWN_ERROR);84 }85 86 if (psMetadataLookupBool(&status, config->arguments, "REPLACE")) {87 // swap the instances for the input and output88 // Note this is a database operation. No file I/O is performed89 if (!swapOutputsToInputs(sfiles)) {90 psError(PS_ERR_UNKNOWN, false, "failed to swap files");91 92 // XXX: Now what? I guess swapOutputsToInputs will need to undo anything that93 // it has done and give a detailed report of what happened94 95 psErrorStackPrint(stderr, "");96 exit(PS_EXIT_UNKNOWN_ERROR);97 }98 99 if (psMetadataLookupBool(&status, config->arguments, "REMOVE")) {100 // delete the temporary storage objects (which now points to the original image(s)101 if (!deleteTemps(sfiles)) {102 psError(PS_ERR_UNKNOWN, false, "failed to delete temporary files");103 // XXX: Now what? At this point the output files have been swapped, so we can't104 // repeat the operation.105 106 // Returning error status here is problematic. The inputs have been streak removed107 // but they're still lying around108 // Maybe just print an error message and109 // let other system tools clean up110 psErrorStackPrint(stderr, "");111 exit(PS_EXIT_UNKNOWN_ERROR);112 }113 }114 }115 #endif // REPLACE, REMOVE116 75 printf("time to run streaksrelease: %f\n", psTimerClear("STREAKSREMOVE")); 117 76 … … 275 234 276 235 // set up the compression parameters 277 #ifdef STREAKS_COMPRESS_OUTPUT 278 // compression of the image pixels is disabled for now. Some consortium members 279 // have problems reading them 280 copyFitsOptions(sf->outImage, sf->recImage, sf->inImage); 281 282 // XXX: TODO: can we derive these values from the input header? 283 // psFitsCompressionGet(sf->inImage->image) gives compression none 284 // perhaps we should just use the definition of COMP_IMG in the configuration 285 psFitsSetCompression(sf->outImage->fits, PS_FITS_COMPRESS_RICE, sf->tiles, 8, 0, 0); 286 if (sf->recImage) { 287 psFitsSetCompression(sf->recImage->fits, PS_FITS_COMPRESS_RICE, sf->tiles, 8, 0, 0); 288 } 289 #endif 236 copyFitsOptions(sf->outImage, sf->recImage, sf->inImage, sf->tiles); 290 237 291 238 if (sf->inMask) { … … 306 253 } 307 254 308 #ifdef STREAKS_COMPRESS_OUTPUT 309 // XXX: see note above 310 copyFitsOptions(sf->outMask, sf->recMask, sf->inMask); 311 psFitsSetCompression(sf->outMask->fits, PS_FITS_COMPRESS_PLIO, sf->tiles, 8, 0, 0); 312 if (sf->recMask) { 313 psFitsSetCompression(sf->recMask->fits, PS_FITS_COMPRESS_PLIO, sf->tiles, 8, 0, 0); 314 } 255 copyFitsOptions(sf->outMask, sf->recMask, sf->inMask, sf->tiles); 315 256 if (sf->outChMask) { 316 copyFitsOptions(sf->outChMask, sf->recChMask, sf->inMask); 317 psFitsSetCompression(sf->outChMask->fits, PS_FITS_COMPRESS_PLIO, sf->tiles, 8, 0, 0); 318 if (sf->recChMask) { 319 psFitsSetCompression(sf->recChMask->fits, PS_FITS_COMPRESS_PLIO, sf->tiles, 8, 0, 0); 320 } 321 } 322 #endif 257 copyFitsOptions(sf->outChMask, sf->recChMask, sf->inMask, sf->tiles); 258 } 323 259 } 324 260 } … … 332 268 setupImageRefs(sf->outWeight, sf->recWeight, sf->inWeight, sf->extnum, exciseAll); 333 269 334 #ifdef STREAKS_COMPRESS_OUTPUT 335 copyFitsOptions(sf->outWeight, sf->recWeight, sf->inWeight); 336 // XXX: see note above 337 psFitsSetCompression(sf->outWeight->fits, PS_FITS_COMPRESS_RICE, sf->tiles, 8, 0, 0); 338 if (sf->recWeight) { 339 psFitsSetCompression(sf->recWeight->fits, PS_FITS_COMPRESS_RICE, sf->tiles, 8, 0, 0); 340 } 341 #endif 270 copyFitsOptions(sf->outWeight, sf->recWeight, sf->inWeight, sf->tiles); 342 271 } 343 272 // and for raw images, create sub images that represent the actual image -
branches/eam_branches/20090522/magic/remove/src/streaksremove.c
r23965 r24557 1 /* 2 * streaksremove 3 * 4 * Convert satellite streak detctions into masks and remove the covered pixels from the 5 * input images. 6 * Optionally swap the inputs with the outputs so that subsequent references to the original 7 * images access the destreaked versions. 8 */ 9 1 10 #include "streaksremove.h" 2 11 … … 23 32 } 24 33 25 psU32 maskStreak = 0; 26 psU32 maskMask = 0; 34 // Values to set for masked pixels 35 psU32 maskStreak = 0; // for the image and weight (usually NAN, MAXINT for integer images) 36 psU32 maskMask = 0; // value looked up for MASK.STREAK 27 37 28 38 psString streaksFileName = psMetadataLookupStr(NULL, config->arguments, "STREAKS"); 29 39 40 // call Paul Sydney's code to parse the streaks file that DetectStreaks produced 30 41 Streaks *streaks = readStreaksFile(streaksFileName); 31 42 if (!streaks) { 32 psError StackPrint(stderr, "failed to read streaks file: %s", streaksFileName);43 psError(PS_ERR_UNKNOWN, "failed to read streaks file: %s", streaksFileName); 33 44 streaksExit("", PS_EXIT_PROG_ERROR); 34 45 } 35 46 47 // open all of the input and output files, save their descriptions in the streakFiles struct 36 48 streakFiles *sfiles = openFiles(config, true, argv[0]); 37 49 setupAstrometry(sfiles); 38 50 51 // Optionally we can set pixels that are masked to NAN since they couldn't have been 52 // examined for streaks. Usually this is done by the distribution system just prior 53 // to release 39 54 bool nanForRelease = psMetadataLookupBool(&status, config->arguments, "NAN_FOR_RELEASE"); 40 55 if (nanForRelease && (sfiles->inMask == NULL)) { … … 52 67 53 68 if (checkNonWarpedPixels ) { 54 // From ICD:69 // From magic ICD: 55 70 // In the raw and detrended images, the pixels which were not 56 71 // included in any of the streak-processed warps must also be masked. … … 69 84 70 85 if (sfiles->stage == IPP_STAGE_RAW) { 71 // copy PHU to output files 86 // Except for raw stage, all of our (GPC1) files have one image extension. 87 // Raw files have a phu and multiple extensions, one per chip 88 // Since this is a raw file, copy it's PHU to output files 72 89 copyPHU(sfiles, true); 73 90 … … 82 99 int totalStreakPixels = 0; 83 100 84 // Iterate through each component of the input ( there is only one except for raw images)101 // Iterate through each component of the input (except for raw images there is only one) 85 102 do { 86 103 bool exciseImageCube = false; … … 110 127 psTimerStart("GET_STREAK_PIXELS"); 111 128 112 StreakPixels *pixels = streak_on_component (streaks, sfiles->astrom,113 sfiles->inImage->numCols, sfiles->inImage->numRows);114 129 // call Paul Sydney's code to compute the set of pixels that are covered by the detected streaks 130 StreakPixels *pixels = streak_on_component(streaks, sfiles->astrom, sfiles->inImage->numCols, 131 sfiles->inImage->numRows); 115 132 psLogMsg("streaksremove", PS_LOG_INFO, "time to get streak pixels: %f\n", psTimerClear("GET_STREAK_PIXELS")); 116 117 133 134 // if this extension contained an image, excise the streaked pixels. 135 // otherwise it contained an image cube (video cell) which is handled in the if block 118 136 if (sfiles->inImage->image) { 119 137 if (checkNonWarpedPixels) { … … 126 144 psLogMsg("streaksremove", PS_LOG_INFO, "time to excise non warped pixels: %f\n", psTimerClear("EXCISE_NON_WARPED")); 127 145 } 146 128 147 totalStreakPixels += psArrayLength(pixels); 148 129 149 psTimerStart("REMOVE_STREAKS"); 150 151 // for each pixel covered by the streak 130 152 for (int i = 0; i < psArrayLength (pixels); ++i) { 131 153 PixelPos *pixelPos = psArrayGet (pixels, i); 132 154 155 // if this pixel was not part of the warp, skip because it has already been 156 // excised (unless we weren't asked to check) 133 157 if (!checkNonWarpedPixels || warpedPixel(sfiles, pixelPos)) { 134 158 … … 140 164 } 141 165 } 166 142 167 psLogMsg("streaksremove", PS_LOG_INFO, "time to remove streak pixels: %f\n", psTimerClear("REMOVE_STREAKS")); 143 168 144 169 if (nanForRelease) { 170 // set any pixels that were masked, to NAN (unless they are already NAN) 145 171 setMaskedToNAN(sfiles, maskMask, true); 146 172 } 147 173 148 174 } else { 149 // this component contains an image cube, excise it completely 175 // this component contains an image cube 176 // For now excise it completely 150 177 exciseImageCube = true; 151 178 } … … 155 182 156 183 if (sfiles->stage == IPP_STAGE_CHIP) { 184 // as a convience to the user of the output, replace the bogus WCS transform in the 185 // chip processed files with the data calcuated by psastro at the camera stage 186 // (actually we use a linear approximation) 157 187 updateAstrometry(sfiles); 158 188 } 159 189 160 // write out the destreaked temporaryimages and the recovery images190 // write the destreaked "temporary" images and the recovery images 161 191 writeImages(sfiles, exciseImageCube); 162 192 … … 168 198 psLogMsg("streaksremove", PS_LOG_INFO, "pixels: %ld streak pixels: %ld %4.2f%%\n", totalPixels, totalStreakPixels, 100. * totalStreakPixels / totalPixels); 169 199 200 // all done close the files. This is where the files are written so it can take a long time. 201 170 202 psTimerStart("CLOSE_IMAGES"); 171 // close all files 203 172 204 closeImages(sfiles); 205 173 206 psLogMsg("streaksremove", PS_LOG_INFO, "time to close images: %f\n", psTimerClear("CLOSE_IMAGES")); 207 208 209 if (!replicateOutputs(sfiles)) { 210 psError(PS_ERR_UNKNOWN, false, "failed to replicate output files"); 211 deleteTemps(sfiles); 212 psErrorStackPrint(stderr, ""); 213 exit(PS_EXIT_UNKNOWN_ERROR); 214 } 174 215 175 216 // NOTE: from here on we can't just quit if something goes wrong. 176 217 // especially if we're working at the raw stage 177 178 if (!replicateOutputs(sfiles)) { 179 psError(PS_ERR_UNKNOWN, false, "failed to replicate output files"); 180 psErrorStackPrint(stderr, ""); 181 exit(PS_EXIT_UNKNOWN_ERROR); 182 } 218 // turn off automatic deletion of output files by streaksExit 219 setStreakFiles(NULL); 183 220 184 221 if (psMetadataLookupBool(&status, config->arguments, "REPLACE")) { 185 222 // swap the instances for the input and output 186 // Note this is a database operation. No file I/O is performed223 // Note this is a nebulous database operation. No file I/O is performed 187 224 if (!swapOutputsToInputs(sfiles)) { 188 psError(PS_ERR_UNKNOWN, false, "failed to swap files"); 189 190 // XXX: Now what? I guess swapOutputsToInputs will need to undo anything that 191 // it has done and give a detailed report of what happened 192 193 psErrorStackPrint(stderr, ""); 225 // XXX: Now what? 226 // It is up to the program that reverts failed destreak runs to insure that 227 // any input files that have been swapped are restored 228 229 psErrorStackPrint(stderr, "failed to swap files"); 230 231 // XXX: pick a specific error code for this failure 194 232 exit(PS_EXIT_UNKNOWN_ERROR); 195 233 } 196 197 if (psMetadataLookupBool(&status, config->arguments, "REMOVE")) { 198 // delete the temporary storage objects (which now points to the original image(s) 199 if (!deleteTemps(sfiles)) { 200 psError(PS_ERR_UNKNOWN, false, "failed to delete temporary files"); 201 // XXX: Now what? At this point the output files have been swapped, so we can't 202 // repeat the operation. 203 204 // Returning error status here is problematic. The inputs have been streak removed 205 // but they're still lying around 206 // Maybe just print an error message and 207 // let other system tools clean up 208 psErrorStackPrint(stderr, ""); 209 exit(PS_EXIT_UNKNOWN_ERROR); 210 } 211 } 212 } 234 } 235 // all done. Clean up to look for memory leaks. 213 236 214 237 psFree(sfiles); … … 403 426 usage(); 404 427 } 405 psString dir = pathToDirectory(argv[argnum]); 406 psMetadataAddStr(config->arguments, PS_LIST_TAIL, "OUTPUT", 0, "directory for temporary files", 407 dir); 408 psFree(dir); 428 psMetadataAddStr(config->arguments, PS_LIST_TAIL, "OUTPUT", 0, "path for (temporary if replae) output files", 429 argv[argnum]); 409 430 psArgumentRemove(argnum, &argc, argv); 410 431 } else { … … 415 436 if ((argnum = psArgumentGet(argc, argv, "-recovery"))) { 416 437 psArgumentRemove(argnum, &argc, argv); 417 psString dir = pathToDirectory(argv[argnum]); 418 psMetadataAddStr(config->arguments, PS_LIST_TAIL, "RECOVERY", 0, "directory for recovery files", 419 dir); 420 psFree(dir); 438 psMetadataAddStr(config->arguments, PS_LIST_TAIL, "RECOVERY", 0, "path for recovery files", 439 argv[argnum]); 421 440 psArgumentRemove(argnum, &argc, argv); 422 441 } else if ((stage == IPP_STAGE_RAW) && gotReplace) { 423 442 psError(PS_ERR_UNKNOWN, true, "-recovery is required for -stage raw with -replace\n"); 424 443 usage(); 425 }426 427 if ((argnum = psArgumentGet(argc, argv, "-remove"))) {428 if (!gotReplace) {429 psError(PS_ERR_UNKNOWN, true, "-replace is required with -remove\n");430 usage();431 }432 psArgumentRemove(argnum, &argc, argv);433 psMetadataAddBool(config->arguments, PS_LIST_TAIL, "REMOVE", 0, "remove original files",434 true);435 444 } 436 445 … … 451 460 updateAstrometry(streakFiles *sf) 452 461 { 462 // XXX: why do I check this here? Shouldn't it be just around the call to linearizeTransforms? 453 463 if (sf->bilevelAstrometry) { 454 464 … … 501 511 } 502 512 } 503 sf->outImage->header = (psMetadata*)psMemIncrRefCounter(sf->inImage->header);513 sf->outImage->header = psMemIncrRefCounter(sf->inImage->header); 504 514 if (sf->recImage) { 505 sf->recImage->header = (psMetadata*) psMemIncrRefCounter(sf->inImage->header); 506 } 515 sf->recImage->header = psMetadataCopy(NULL, sf->inImage->header); 516 addRecoveryKeyword(sf->recImage->header); 517 } 518 addDestreakKeyword(sf->outImage->header); 507 519 508 520 if (!SFILE_IS_IMAGE(sf->inImage)) { … … 520 532 521 533 // set up the compression parameters 522 #ifdef STREAKS_COMPRESS_OUTPUT 523 // compression of the image pixels is disabled for now. Some consortium members 524 // have problems reading them 525 copyFitsOptions(sf->outImage, sf->recImage, sf->inImage); 526 527 // XXX: TODO: can we derive these values from the input header? 528 // psFitsCompressionGet(sf->inImage->image) gives compression none 529 // perhaps we should just use the definition of COMP_IMG in the configuration 530 psFitsSetCompression(sf->outImage->fits, PS_FITS_COMPRESS_RICE, sf->tiles, 8, 0, 0); 531 if (sf->recImage) { 532 psFitsSetCompression(sf->recImage->fits, PS_FITS_COMPRESS_RICE, sf->tiles, 8, 0, 0); 533 } 534 #endif 534 copyFitsOptions(sf->outImage, sf->recImage, sf->inImage, sf->tiles); 535 535 536 536 if (sf->inMask) { … … 539 539 sf->outMask->header = (psMetadata*) psMemIncrRefCounter(sf->inMask->header); 540 540 if (sf->recMask) { 541 sf->recMask->header = (psMetadata*) psMemIncrRefCounter(sf->inMask->header); 542 } 541 sf->recMask->header = psMetadataCopy(NULL, sf->outMask->header); 542 addRecoveryKeyword(sf->recMask->header); 543 } 544 addDestreakKeyword(sf->outMask->header); 543 545 if (updateAstrometry) { 544 546 pmAstromWriteWCS(sf->outMask->header, sf->inAstrom->fpa, sf->chip, 0.001); … … 554 556 } 555 557 556 #ifdef STREAKS_COMPRESS_OUTPUT 557 // XXX: see note above 558 copyFitsOptions(sf->outMask, sf->recMask, sf->inMask); 559 psFitsSetCompression(sf->outMask->fits, PS_FITS_COMPRESS_PLIO, sf->tiles, 8, 0, 0); 560 if (sf->recMask) { 561 psFitsSetCompression(sf->recMask->fits, PS_FITS_COMPRESS_PLIO, sf->tiles, 8, 0, 0); 562 } 558 copyFitsOptions(sf->outMask, sf->recMask, sf->inMask, sf->tiles); 563 559 if (sf->outChMask) { 564 copyFitsOptions(sf->outChMask, sf->recChMask, sf->inMask); 565 psFitsSetCompression(sf->outChMask->fits, PS_FITS_COMPRESS_PLIO, sf->tiles, 8, 0, 0); 566 if (sf->recChMask) { 567 psFitsSetCompression(sf->recChMask->fits, PS_FITS_COMPRESS_PLIO, sf->tiles, 8, 0, 0); 568 } 569 } 570 #endif 560 copyFitsOptions(sf->outChMask, sf->recChMask, sf->inMask, sf->tiles); 561 } 571 562 } 572 563 } … … 576 567 sf->outWeight->header = (psMetadata*) psMemIncrRefCounter(sf->inWeight->header); 577 568 if (sf->recWeight) { 578 sf->recWeight->header = (psMetadata*) psMemIncrRefCounter(sf->inWeight->header); 579 } 569 sf->recWeight->header = psMetadataCopy(NULL, sf->outWeight->header); 570 addRecoveryKeyword(sf->recWeight->header); 571 } 572 addDestreakKeyword(sf->outWeight->header); 580 573 if (updateAstrometry) { 581 574 pmAstromWriteWCS(sf->inWeight->header, sf->inAstrom->fpa, sf->chip, 0.001); … … 583 576 setupImageRefs(sf->outWeight, sf->recWeight, sf->inWeight, sf->extnum, exciseAll); 584 577 585 #ifdef STREAKS_COMPRESS_OUTPUT 586 copyFitsOptions(sf->outWeight, sf->recWeight, sf->inWeight); 587 // XXX: see note above 588 psFitsSetCompression(sf->outWeight->fits, PS_FITS_COMPRESS_RICE, sf->tiles, 8, 0, 0); 589 if (sf->recWeight) { 590 psFitsSetCompression(sf->recWeight->fits, PS_FITS_COMPRESS_RICE, sf->tiles, 8, 0, 0); 591 } 592 #endif 593 } 594 // and for raw images, create sub images that represent the actual image 595 // area (no overscan) 578 copyFitsOptions(sf->outWeight, sf->recWeight, sf->inWeight, sf->tiles); 579 } 596 580 597 581 return true; 598 582 } 599 600 601 583 602 584 static void -
branches/eam_branches/20090522/magic/remove/src/streaksremove.h
r23963 r24557 88 88 extern ippStage parseStage(psString); 89 89 extern psString pathToDirectory(char *path); 90 extern void setStreakFiles( streakFiles *); 90 91 91 92 #define CHIP_LEVEL_INPUT(_stage) ((_stage == IPP_STAGE_RAW) || (_stage == IPP_STAGE_CHIP)) … … 95 96 #define IN_NEBULOUS(_filename) (!strncasecmp(_filename, "neb://", strlen("neb://"))) 96 97 98 97 99 #endif // STREAKS_H -
branches/eam_branches/20090522/magic/remove/src/streaksreplace.c
r23965 r24557 97 97 } 98 98 99 #ifdef NOTYET100 if (psMetadataLookupBool(&status, config->arguments, "REPLACE")) {101 // swap the instances for the input and output102 // Note this is a database operation. No file I/O is performed103 if (!swapOutputsToInputs(sfiles)) {104 psError(PS_ERR_UNKNOWN, false, "failed to swap files");105 106 // XXX: Now what? I guess swapOutputsToInputs will need to undo anything that107 // it has done and give a detailed report of what happened108 109 psErrorStackPrint(stderr, "");110 exit(PS_EXIT_UNKNOWN_ERROR);111 }112 113 if (psMetadataLookupBool(&status, config->arguments, "REMOVE")) {114 // delete the temporary storage objects (which now points to the original image(s)115 if (!deleteTemps(sfiles)) {116 psError(PS_ERR_UNKNOWN, false, "failed to delete temporary files");117 // XXX: Now what? At this point the output files have been swapped, so we can't118 // repeat the operation.119 120 // Returning error status here is problematic. The inputs have been streak removed121 // but they're still lying around122 // Maybe just print an error message and123 // let other system tools clean up124 psErrorStackPrint(stderr, "");125 exit(PS_EXIT_UNKNOWN_ERROR);126 }127 }128 }129 #endif // REPLACE, REMOVE130 99 // nebServerFree(ourNebServer); 131 100 psFree(config); … … 344 313 345 314 // set up the compression parameters 346 #ifdef STREAKS_COMPRESS_OUTPUT 347 // compression of the image pixels is disabled for now. Some consortium members 348 // have problems reading compressed images. 349 copyFitsOptions(sf->outImage, sf->recImage, sf->inImage); 350 351 // XXX: TODO: can we derive these values from the input header? 352 // psFitsCompressionGet(sf->inImage->image) gives compression none 353 // perhaps we should just use the definition of COMP_IMG in the configuration 354 psFitsSetCompression(sf->outImage->fits, PS_FITS_COMPRESS_RICE, sf->tiles, 8, 0, 0); 355 #endif 315 copyFitsOptions(sf->outImage, sf->recImage, sf->inImage, sf->tiles); 316 356 317 if (sf->inMask) { 357 318 readImage(sf->inMask, sf->extnum, sf->stage, true); … … 362 323 setupImageRefs(sf->outMask, NULL, sf->inMask, sf->extnum, false); 363 324 364 // XXX: see note above 365 copyFitsOptions(sf->outMask, NULL, sf->inMask); 366 psFitsSetCompression(sf->outMask->fits, PS_FITS_COMPRESS_PLIO, sf->tiles, 8, 0, 0); 325 copyFitsOptions(sf->outMask, NULL, sf->inMask, sf->tiles); 367 326 } 368 327 … … 374 333 setupImageRefs(sf->outMask, NULL, sf->inMask, sf->extnum, false); 375 334 376 copyFitsOptions(sf->outWeight, NULL, sf->inWeight); 377 // XXX: see note above 378 psFitsSetCompression(sf->outWeight->fits, PS_FITS_COMPRESS_RICE, sf->tiles, 8, 0, 0); 335 copyFitsOptions(sf->outWeight, NULL, sf->inWeight, sf->tiles); 379 336 } 380 337 -
branches/eam_branches/20090522/magic/remove/src/streaksutil.c
r20816 r24557 33 33 } 34 34 35 streakFiles *ourStreakFiles = NULL; 36 37 void 38 setStreakFiles(streakFiles *sfiles) 39 { 40 ourStreakFiles = sfiles; 41 } 42 35 43 // to enhance clarity in these programs we don't propagate errors up the stack 36 44 // we just bail out 37 45 void streaksExit(psString str, int exitCode) { 38 46 psErrorStackPrint(stderr, str); 47 if (ourStreakFiles) { 48 deleteTemps(ourStreakFiles); 49 } 39 50 exit(exitCode); 40 51 }
Note:
See TracChangeset
for help on using the changeset viewer.
