- Timestamp:
- Sep 15, 2009, 4:02:42 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/20090715/pstamp/src/ppstampMakeStamp.c
r21403 r25406 17 17 18 18 static void skyToChip(pmAstromObj *pt, pmFPA *fpa, pmChip *chip); 19 static bool setMaskedToNAN(pmConfig *config, psImage *image, psImage *mask, psImage *variance); 19 20 20 21 // convert the input chip's transforms to the output … … 173 174 static psImage *extractStamp(psImage *image, psRegion region, double value) 174 175 { 175 int width = region.x1 - region.x0 ;176 int height = region.y1 - region.y0 ;176 int width = region.x1 - region.x0 + 0.5; 177 int height = region.y1 - region.y0 + 0.5; 177 178 178 179 if (width < 0) { … … 251 252 // Build the postage stamp output file 252 253 253 static boolmakeStamp(pmConfig *config, ppstampOptions *options, pmFPAfile *input,254 static int makeStamp(pmConfig *config, ppstampOptions *options, pmFPAfile *input, 254 255 pmChip *inChip, pmFPAview *view) 255 256 { … … 259 260 if (!output) { 260 261 psError(PS_ERR_UNKNOWN, false, "Can't find output data\n"); 261 return false;262 return PS_EXIT_DATA_ERROR; 262 263 } 263 264 char *fpaName = psMetadataLookupStr(NULL, input->fpa->concepts, "FPA.OBS"); // Name of FPA … … 283 284 pmFPAfile *mosaic = ppstampBuildMosaic(config, input, view); 284 285 if (mosaic == NULL) { 285 return false;286 return PS_EXIT_UNKNOWN_ERROR; 286 287 } 287 288 srcFile = mosaic; … … 325 326 break; 326 327 } 328 if (readout->variance) { 329 outReadout->variance = extractStamp(readout->variance, extractRegion, 0); 330 if (!outReadout->variance) { 331 psError(PS_ERR_UNKNOWN, false, "failed to create postage stamp weight image\n"); 332 status = false; 333 break; 334 } 335 } 327 336 if (readout->mask) { 328 337 outReadout->mask = extractStamp(readout->mask, extractRegion, 0); … … 332 341 break; 333 342 } 334 } 335 if (readout->variance) { 336 outReadout->variance = extractStamp(readout->variance, extractRegion, 0); 337 if (!outReadout->variance) { 338 psError(PS_ERR_UNKNOWN, false, "failed to create postage stamp weight image\n"); 339 status = false; 340 break; 343 344 if (!setMaskedToNAN(config, outReadout->image, outReadout->mask, outReadout->variance)) { 345 psError(PS_ERR_UNKNOWN, false, "failed to create postage stamp mask image\n"); 346 status = false; 347 break; 341 348 } 342 349 } … … 355 362 status = copyMetadata(output, input, inChip, options); 356 363 } 357 return status ;364 return status ? PS_EXIT_SUCCESS : PS_EXIT_UNKNOWN_ERROR; 358 365 } 359 366 … … 567 574 } 568 575 569 boolppstampMakeStamp (pmConfig *config, ppstampOptions *options)576 int ppstampMakeStamp (pmConfig *config, ppstampOptions *options) 570 577 { 571 578 bool status = false; 572 bool returnval = false;;579 int returnval = PS_EXIT_SUCCESS;; 573 580 bool foundOverlap = false; 574 581 … … 576 583 if (!status) { 577 584 psError(PS_ERR_UNKNOWN, true, "Can't find input file!\n"); 578 return false;585 return PS_EXIT_DATA_ERROR; 579 586 } 580 587 … … 584 591 } else if (astrom->camera != input->camera) { 585 592 psError(PS_ERR_UNKNOWN, true, "Input camera and astrometry camera do not match"); 586 return false;593 return PS_EXIT_CONFIG_ERROR; 587 594 } 588 595 … … 593 600 psError(PS_ERR_UNKNOWN, false, "Failed to load input."); 594 601 psFree (view); 595 return false;602 return PS_EXIT_DATA_ERROR; 596 603 } 597 604 bool bilevelAstrometry = false; … … 607 614 psError(PS_ERR_UNKNOWN, false, "Unable to read bilevel mosaic astrometry for input FPA."); 608 615 psFree(view); 609 return false;616 return PS_EXIT_DATA_ERROR; 610 617 } 611 618 } … … 640 647 break; 641 648 case PSTAMP_ERROR: 642 returnval = false;649 returnval = PS_EXIT_UNKNOWN_ERROR; 643 650 allDone = true; 644 651 break; … … 660 667 psFree(view); 661 668 662 if (!foundOverlap ) {669 if (!foundOverlap && (returnval == PS_EXIT_SUCCESS)) { 663 670 fprintf(stderr, "ROI not found in input\n"); 671 returnval = PSTAMP_NO_OVERLAP; 664 672 } 665 673 … … 668 676 669 677 678 static bool setMaskedToNAN(pmConfig *config, psImage *image, psImage *mask, psImage *variance) 679 { 680 bool status; 681 psMetadata *masks = psMetadataLookupMetadata(&status, config->recipes, "MASKS"); 682 if (!status) { 683 psError(PM_ERR_CONFIG, false, "failed to lookup MASKS in recipes\n"); 684 return false; 685 } 686 // we set anything masked to NAN except if CONV.POOR is the only bit set 687 // First check the old value 688 psU32 convPoor = psMetadataLookupU32(&status, masks, "POOR.WARP"); 689 if (!status) { 690 convPoor = psMetadataLookupU32(&status, masks, "CONV.POOR"); 691 if (!status) { 692 psError(PM_ERR_CONFIG, false, "failed to lookup mask value for CONV.POOR in recipes\n"); 693 return false; 694 } 695 } 696 psU32 maskMask = ~convPoor; 697 698 double exciseValue; 699 if (image->type.type == PS_TYPE_U16) { 700 exciseValue = 0xffff; 701 } else if (image->type.type == PS_TYPE_F32) { 702 exciseValue = NAN; 703 } else { 704 psError(PS_ERR_PROGRAMMING, true, "unexpected image type: %d\n", image->type.type); 705 return false; 706 } 707 long numExcised = 0; 708 for (int y=0; y<image->numRows; y++) { 709 for (int x=0; x<image->numCols; x++) { 710 psU16 maskVal = psImageGet(mask, x, y); 711 if (maskVal & maskMask) { 712 numExcised++; 713 psImageSet(image, x, y, exciseValue); 714 if (variance) { 715 psImageSet(variance, x, y, exciseValue); 716 } 717 } 718 } 719 } 720 fprintf(stderr, "excised %ld masked pixels\n", numExcised); 721 722 return true; 723 }
Note:
See TracChangeset
for help on using the changeset viewer.
