IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 21, 2011, 6:44:31 PM (15 years ago)
Author:
eugene
Message:

merge from trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20110505/psLib/src/fits/psFitsImage.c

    r31608 r31656  
    5555    int psDatatype;                     // psLib data type
    5656    bool is_logscaled;                  // is this image log scaled using BOFFSET?
     57    bool is_asinh;                      // is this image asinh scaled using BSOFTEN?
    5758} p_psFitsReadInfo;
    5859
     
    129130
    130131    // Check scale and zero
    131     double bscale = 0.0, bzero = 0.0, boffset = NAN;    // Scale and zero point
     132    double bscale = 0.0, bzero = 0.0, boffset = NAN, bsoften = NAN;    // Scale and zero point
    132133    if (fits_read_key_dbl(fits->fd, "BSCALE", &bscale, NULL, &status) && status != KEY_NO_EXIST) {
    133134        psFitsError(status, true, "Unable to read header.");
     
    153154      info->is_logscaled = false;
    154155    }
     156    status = 0;
     157    if (fits_read_key_dbl(fits->fd, "BSOFTEN", &bsoften, NULL, &status) && status != KEY_NO_EXIST) {
     158        psFitsError(status, true, "Unable to read header.");
     159        goto bad;
     160    }
     161    if (status == KEY_NO_EXIST) {
     162      info->is_asinh = false;
     163    }
     164    else if (isfinite(bsoften)) {
     165      info->is_asinh = true;
     166      info->is_logscaled = false;
     167    }
     168    else {
     169      info->is_asinh = false;
     170    }
     171
    155172    status = 0;
    156173
     
    262279                                          double *bzero, // Zero point applied
    263280                                          double *boffset, // Log offset applied
     281                                          double *bsoften, // asinh offset applied
    264282                                          long *blank, // Blank value (integer data)
    265283                                          psFitsFloat *floatType, // Type of custom floating-point
     
    275293    psAssert(bzero, "impossible");
    276294    psAssert(boffset, "impossible");
     295    psAssert(bsoften, "impossible");
    277296    psAssert(floatType, "impossible");
    278297    psAssert(fits, "impossible");
     
    322341        if (newScaleZero) {
    323342            // Choose an appropriate BSCALE and BZERO
    324           if (!psFitsScaleDetermine(bscale, bzero, boffset, blank, image, mask, maskVal, fits)) {
     343          if (!psFitsScaleDetermine(bscale, bzero, boffset, bsoften, blank, image, mask, maskVal, fits)) {
    325344                // We can't have the write dying for this reason --- try to save it somehow!
    326345                psWarning("Unable to determine BSCALE and BZERO for image --- refusing to quantise.");
     
    348367        }
    349368
    350         return psFitsScaleForDisk(image, fits, *bscale, *bzero, *boffset, rng);
     369        return psFitsScaleForDisk(image, fits, *bscale, *bzero, *boffset, *bsoften, rng);
    351370    }
    352371
     
    480499        outImage = psFitsFloatImageFromDisk(outImage, inImage, floatType);
    481500    }
    482 
    483501    // Need to apply BOFFSET if info->is_logscaled is true
     502
    484503    if (info->is_logscaled) {
    485504      double boffset;
     
    487506      status = 0;
    488507      fits_read_key_dbl(fits->fd, "BOFFSET", &boffset, NULL, &status);
    489       psImage *newImage = psFitsScaleFromDisk(outImage,boffset);
     508      psImage *newImage = psFitsScaleFromDisk(outImage,boffset,0.0);
     509      psFree (outImage);
     510      outImage = newImage;
     511    }
     512    else if (info->is_asinh) {
     513      double bsoften,boffset;
     514      int status;
     515      status = 0;
     516      fits_read_key_dbl(fits->fd, "BSOFTEN", &bsoften, NULL, &status);
     517      fits_read_key_dbl(fits->fd, "BOFFSET", &boffset, NULL, &status);
     518      psImage *newImage = psFitsScaleFromDisk(outImage,boffset,bsoften);
    490519      psFree (outImage);
    491520      outImage = newImage;
     
    602631    double bscale = NAN, bzero = NAN;   // Scale and zero point to put in header
    603632    double boffset = NAN;               // Log offset to put into header.
     633    double bsoften = NAN;               // Asinh softening parameter to put into header
    604634    long blank = 0;                     // Blank (undefined) value for image
    605635    psFitsFloat floatType;              // Custom floating-point convention type
    606     psImage *diskImage = imageToDiskRepresentation(&bscale, &bzero, &boffset, &blank, &floatType, fits, image,
     636    psImage *diskImage = imageToDiskRepresentation(&bscale, &bzero, &boffset, &bsoften, &blank, &floatType, fits, image,
    607637                                                   mask, maskVal, NULL, true); // Image to write out
    608638    if (!diskImage) {
     
    696726    if (options&&(!((options->scaling == PS_FITS_SCALE_LOG_RANGE)||
    697727                    (options->scaling == PS_FITS_SCALE_LOG_MANUAL)||
    698                    (options->scaling == PS_FITS_SCALE_LOG_STDEV_POSITIVE)||
    699                    (options->scaling == PS_FITS_SCALE_LOG_STDEV_NEGATIVE)||
    700                    (options->scaling == PS_FITS_SCALE_LOG_STDEV_BOTH)))) {
     728                    (options->scaling == PS_FITS_SCALE_LOG_STDEV_POSITIVE)||
     729                    (options->scaling == PS_FITS_SCALE_LOG_STDEV_NEGATIVE)||
     730                    (options->scaling == PS_FITS_SCALE_LOG_STDEV_BOTH)||
     731                    (options->scaling == PS_FITS_SCALE_ASINH_RANGE)||
     732                    (options->scaling == PS_FITS_SCALE_ASINH_MANUAL)||
     733                    (options->scaling == PS_FITS_SCALE_ASINH_STDEV_POSITIVE)||
     734                    (options->scaling == PS_FITS_SCALE_ASINH_STDEV_NEGATIVE)||
     735                    (options->scaling == PS_FITS_SCALE_ASINH_STDEV_BOTH)))) {
    701736      if (psMetadataLookup(header,"BOFFSET")) {
    702737        psMetadataRemoveKey(header,"BOFFSET");
     738      }
     739    }   
     740    // Remove any BSOFTENvalues that exist in the header if we are not using that scaling anymore
     741    if (options&&(!((options->scaling == PS_FITS_SCALE_ASINH_RANGE)||
     742                    (options->scaling == PS_FITS_SCALE_ASINH_MANUAL)||
     743                    (options->scaling == PS_FITS_SCALE_ASINH_STDEV_POSITIVE)||
     744                    (options->scaling == PS_FITS_SCALE_ASINH_STDEV_NEGATIVE)||
     745                    (options->scaling == PS_FITS_SCALE_ASINH_STDEV_BOTH)))) {
     746      if (psMetadataLookup(header,"BSOFTEN")) {
     747        psMetadataRemoveKey(header,"BSOFTEN");
    703748      }
    704749    }   
     
    727772                       (options->scaling == PS_FITS_SCALE_LOG_STDEV_BOTH)))) {
    728773          fits_write_key_dbl(fits->fd, "BOFFSET", boffset, 12,
    729                              "Scaling: TRUE = BZERO + BSCALE * 10**(DISK) + BOFFSET)", &status);
     774                             "Scaling: ORIGINAL = 10**(TRUE) + BOFFSET)", &status);
    730775        }       
     776        if (options&&(((options->scaling == PS_FITS_SCALE_ASINH_RANGE)||
     777                       (options->scaling == PS_FITS_SCALE_ASINH_MANUAL)||
     778                       (options->scaling == PS_FITS_SCALE_ASINH_STDEV_POSITIVE)||
     779                       (options->scaling == PS_FITS_SCALE_ASINH_STDEV_NEGATIVE)||
     780                       (options->scaling == PS_FITS_SCALE_ASINH_STDEV_BOTH)))) {
     781          fits_write_key_dbl(fits->fd, "BOFFSET", boffset, 12,
     782                             "Scaling: NORM = DISK + BOFFSET", &status);
     783          fits_write_key_dbl(fits->fd, "BSOFTEN", bsoften, 12,
     784                             "Scaling: TRUE = 2 * BSOFTEN * sinh(NORM/a)",&status);
     785
     786
     787        }       
     788
    731789        if (psFitsError(status, true, "Could not write BSCALE/BZERO headers to file.")) {
    732790            success = false;
     
    831889    double bscale = NAN, bzero = NAN;   // Scale and zero point to put in header
    832890    double boffset = NAN;               // Log offset to put in header
     891    double bsoften = NAN;               // Asinh softening parameter to put in header
    833892    long blank = 0;                     // Blank (undefined) value for image
    834893    psFitsFloat floatType;              // Custom floating-point convention type
    835     psImage *diskImage = imageToDiskRepresentation(&bscale, &bzero, &boffset, &blank, &floatType, fits, input,
     894    psImage *diskImage = imageToDiskRepresentation(&bscale, &bzero, &boffset, &bsoften, &blank, &floatType, fits, input,
    836895                                                   mask, maskVal, NULL, false); // Image to write out
    837896    if (!diskImage) {
Note: See TracChangeset for help on using the changeset viewer.