Changeset 30636 for trunk/psLib/src/fits/psFitsImage.c
- Timestamp:
- Feb 14, 2011, 2:58:01 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
psLib/src/fits/psFitsImage.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/czw_branch/20101203 merged: 30118-30119,30255,30331,30419,30586-30587,30631
- Property svn:mergeinfo changed
-
trunk/psLib/src/fits/psFitsImage.c
r29931 r30636 54 54 int fitsDatatype; // cfitsio data type 55 55 int psDatatype; // psLib data type 56 bool is_logscaled; // is this image log scaled using BOFFSET? 56 57 } p_psFitsReadInfo; 57 58 … … 128 129 129 130 // Check scale and zero 130 double bscale = 0.0, bzero = 0.0 ; // Scale and zero point131 double bscale = 0.0, bzero = 0.0, boffset = NAN; // Scale and zero point 131 132 if (fits_read_key_dbl(fits->fd, "BSCALE", &bscale, NULL, &status) && status != KEY_NO_EXIST) { 132 133 psFitsError(status, true, "Unable to read header."); … … 137 138 psFitsError(status, true, "Unable to read header."); 138 139 goto bad; 140 } 141 status = 0; 142 if (fits_read_key_dbl(fits->fd, "BOFFSET", &boffset, NULL, &status) && status != KEY_NO_EXIST) { 143 psFitsError(status, true, "Unable to read header."); 144 goto bad; 145 } 146 if (status == KEY_NO_EXIST) { 147 info->is_logscaled = false; 148 } 149 else if (isfinite(boffset)) { 150 info->is_logscaled = true; 151 } 152 else { 153 info->is_logscaled = false; 139 154 } 140 155 status = 0; … … 246 261 static psImage *imageToDiskRepresentation(double *bscale, // Scaling applied 247 262 double *bzero, // Zero point applied 263 double *boffset, // Log offset applied 248 264 long *blank, // Blank value (integer data) 249 265 psFitsFloat *floatType, // Type of custom floating-point … … 258 274 psAssert(bscale, "impossible"); 259 275 psAssert(bzero, "impossible"); 276 psAssert(boffset, "impossible"); 260 277 psAssert(floatType, "impossible"); 261 278 psAssert(fits, "impossible"); … … 305 322 if (newScaleZero) { 306 323 // Choose an appropriate BSCALE and BZERO 307 if (!psFitsScaleDetermine(bscale, bzero, blank, image, mask, maskVal, fits)) {324 if (!psFitsScaleDetermine(bscale, bzero, boffset, blank, image, mask, maskVal, fits)) { 308 325 // We can't have the write dying for this reason --- try to save it somehow! 309 326 psWarning("Unable to determine BSCALE and BZERO for image --- refusing to quantise."); … … 331 348 } 332 349 333 return psFitsScaleForDisk(image, fits, *bscale, *bzero, rng);350 return psFitsScaleForDisk(image, fits, *bscale, *bzero, *boffset, rng); 334 351 } 335 352 … … 459 476 return NULL; 460 477 } 461 psFree(info);462 478 463 479 if (floatType != PS_FITS_FLOAT_NONE) { 464 480 outImage = psFitsFloatImageFromDisk(outImage, inImage, floatType); 465 481 } 482 483 // Need to apply BOFFSET if info->is_logscaled is true 484 if (info->is_logscaled) { 485 double boffset; 486 int status; 487 fits_read_key_dbl(fits->fd, "BOFFSET", &boffset, NULL, &status); 488 outImage = psFitsScaleFromDisk(outImage,boffset); 489 } 490 psFree(info); 491 466 492 psFree(inImage); 467 493 … … 572 598 573 599 double bscale = NAN, bzero = NAN; // Scale and zero point to put in header 600 double boffset = NAN; // Log offset to put into header. 574 601 long blank = 0; // Blank (undefined) value for image 575 602 psFitsFloat floatType; // Custom floating-point convention type 576 psImage *diskImage = imageToDiskRepresentation(&bscale, &bzero, &b lank, &floatType, fits, image,603 psImage *diskImage = imageToDiskRepresentation(&bscale, &bzero, &boffset, &blank, &floatType, fits, image, 577 604 mask, maskVal, NULL, true); // Image to write out 578 605 if (!diskImage) { … … 610 637 611 638 psFitsOptions *options = fits->options; // FITS I/O options 639 /* if (options) { */ 640 /* if (options->scaling == PS_FITS_SCALE_LOG_RANGE) { */ 641 /* fprintf(stderr,"it has the scaling I expect\n"); */ 642 /* } */ 643 /* else { */ 644 /* fprintf(stderr,"it does nto have the scaling I expect\n"); */ 645 /* } */ 646 /* } */ 647 /* else { */ 648 /* fprintf(stderr,"options is null, apparently? \n"); */ 649 /* } */ 650 612 651 psAssert(!useRequestedScale || !options || bitPix == options->bitpix || options->bitpix == 0, 613 652 "Something's not consistent"); … … 651 690 } 652 691 692 // Remove any BOFFSET values that exist in the header if we are not using that scaling anymore 693 if (options&&(!((options->scaling == PS_FITS_SCALE_LOG_RANGE)|| 694 (options->scaling == PS_FITS_SCALE_LOG_MANUAL)|| 695 (options->scaling == PS_FITS_SCALE_LOG_STDEV_POSITIVE)|| 696 (options->scaling == PS_FITS_SCALE_LOG_STDEV_NEGATIVE)|| 697 (options->scaling == PS_FITS_SCALE_LOG_STDEV_BOTH)))) { 698 if (psMetadataLookup(header,"BOFFSET")) { 699 psMetadataRemoveKey(header,"BOFFSET"); 700 } 701 } 702 653 703 // write the header, if any. 654 704 if (header && !psFitsWriteHeaderImage(fits, header, createPHU)) { … … 668 718 fits_write_key_dbl(fits->fd, "BSCALE", bscale, 12, 669 719 "Scaling: TRUE = BZERO + BSCALE * DISK", &status); 720 if (options&&(((options->scaling == PS_FITS_SCALE_LOG_RANGE)|| 721 (options->scaling == PS_FITS_SCALE_LOG_MANUAL)|| 722 (options->scaling == PS_FITS_SCALE_LOG_STDEV_POSITIVE)|| 723 (options->scaling == PS_FITS_SCALE_LOG_STDEV_NEGATIVE)|| 724 (options->scaling == PS_FITS_SCALE_LOG_STDEV_BOTH)))) { 725 fits_write_key_dbl(fits->fd, "BOFFSET", boffset, 12, 726 "Scaling: TRUE = BZERO + BSCALE * 10**(DISK) + BOFFSET)", &status); 727 } 670 728 if (psFitsError(status, true, "Could not write BSCALE/BZERO headers to file.")) { 671 729 success = false; … … 769 827 bool success = true; // Successful update? 770 828 double bscale = NAN, bzero = NAN; // Scale and zero point to put in header 829 double boffset = NAN; // Log offset to put in header 771 830 long blank = 0; // Blank (undefined) value for image 772 831 psFitsFloat floatType; // Custom floating-point convention type 773 psImage *diskImage = imageToDiskRepresentation(&bscale, &bzero, &b lank, &floatType, fits, input,832 psImage *diskImage = imageToDiskRepresentation(&bscale, &bzero, &boffset, &blank, &floatType, fits, input, 774 833 mask, maskVal, NULL, false); // Image to write out 775 834 if (!diskImage) {
Note:
See TracChangeset
for help on using the changeset viewer.
