IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 30119


Ignore:
Timestamp:
Dec 20, 2010, 4:25:10 PM (15 years ago)
Author:
watersc1
Message:

log(flux) compressed image work.

Location:
branches/czw_branch/20101203
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/20101203

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/czw_branch/20101203/ippconfig/recipes/fitstypes.mdc

    r29021 r30119  
    9898        NOISE           S32     8
    9999END
     100# Compressed log flux image for stacks.
     101COMP_STACK     METADATA
     102        BITPIX          S32     16
     103        SCALING         STR     LOG_STDEV_POSITIVE
     104        STDEV.BITS      S32     4
     105        STDEV.NUM       F32     10
     106        COMPRESSION     STR     RICE
     107        TILE.X          S32     0
     108        TILE.Y          S32     1
     109        TILE.Z          S32     1
     110        NOISE           S32     8
     111END
    100112
    101113# Compressed exposure image
  • branches/czw_branch/20101203/psLib/src/fits/psFits.h

    r25383 r30119  
    5050    PS_FITS_SCALE_STDEV_NEGATIVE,       ///< Auto-scale to sample stdev, place mean at upper limit
    5151    PS_FITS_SCALE_STDEV_BOTH,           ///< Auto-scale to sample stdev, place mean at middle
     52    PS_FITS_SCALE_LOG_RANGE,            ///< Take logarithm, Auto-scale to preserve dynamic range
     53    PS_FITS_SCALE_LOG_STDEV_POSITIVE,   ///< Take logarithm, Auto-scale to sample stdev, place mean at lower limit
     54    PS_FITS_SCALE_LOG_STDEV_NEGATIVE,   ///< Take logarithm, Auto-scale to sample stdev, place mean at upper limit
     55    PS_FITS_SCALE_LOG_STDEV_BOTH,       ///< Take logarithm, Auto-scale to sample stdev, place mean at middle
     56
    5257    PS_FITS_SCALE_MANUAL                ///< Manual scaling (use specified BSCALE and BZERO)
    5358} psFitsScaling;
  • branches/czw_branch/20101203/psLib/src/fits/psFitsScale.c

    r27417 r30119  
    100100}
    101101
     102   
    102103// Determine appropriate BSCALE and BZERO for an image, mapping the standard deviation to the nominated number
    103104// of bits
     
    237238}
    238239
     240
     241static bool logscaleStdev(double *bscale, // Scaling, to return
     242                          double *bzero, // Zero point, to return
     243                          const psImage *image, // Image to scale
     244                          const psImage *mask, // Mask image
     245                          psImageMaskType maskVal, // Value to mask
     246                          const psFitsOptions *options // FITS options
     247    )
     248{
     249    psAssert(bscale, "impossible");
     250    psAssert(bzero, "impossible");
     251    psAssert(image, "impossible");
     252    psAssert(options, "impossible");
     253
     254    psTrace("psLib.fits", 3, "Scaling image by logarithm statistics");
     255    int numCols = image->numCols, numRows = image->numRows; // Size of image
     256   
     257    double offset = 99e99;
     258
     259    // Determine the minimum value on this image.
     260    switch (image->type.type) {
     261    case PS_TYPE_F32:
     262      for (int y = 0; y < numRows; y++) {
     263        for (int x = 0; x < numCols; x++) {
     264          psF32 value = image->data.F32[y][x];
     265          if (!isfinite(value)) {
     266            if (value < offset) {
     267              offset = value;
     268            }
     269          }
     270        }
     271      }
     272      break;
     273    case PS_TYPE_F64:
     274      for (int y = 0; y < numRows; y++) {
     275        for (int x = 0; x < numCols; x++) {
     276          psF64 value = image->data.F64[y][x];
     277          if (!isfinite(value)) {
     278            if (value < offset) {
     279              offset = value;
     280            }
     281          }
     282        }
     283      }
     284      break;
     285    default:
     286      psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Target type is not a float: %d",image->type.type);
     287      return NULL;
     288      break;
     289    }
     290    // We only need to offset images that go negative.
     291    if (offset > 0.0) {
     292      offset = 0.0;
     293    }
     294    // Write offset to header
     295    // How?
     296    //    psMetadataAddF32(header,PS_LIST_TAIL,"LOGZERO",0,"Flux offset subtracted before taking logarithm.",offset);
     297    // Take the logarithm of the image, applying the offset
     298    switch (image->type.type) {
     299    case PS_TYPE_F32:
     300      for (int y = 0; y < numRows; y++) {
     301        for (int x = 0; x < numCols; x++) {
     302          image->data.F32[y][x] = (log10( image->data.F32[y][x] - offset));
     303        }
     304      }
     305      break;
     306    case PS_TYPE_F64:
     307        for (int y = 0; y < numRows; y++) {
     308          for (int x = 0; x < numCols; x++) {
     309            image->data.F64[y][x] = (log10( image->data.F64[y][x] - offset));
     310          }
     311        }
     312      break;
     313    default:
     314      psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Target type is not a float: %d",image->type.type);
     315      return NULL;
     316      break;
     317    }
     318     
     319    // Do regular scaling on the logarithm image
     320    if (!scaleStdev(bscale, bzero, image, mask, maskVal, options)) {
     321      psError(PS_ERR_UNKNOWN, false, "Unable to set BSCALE and BZERO from stdev");
     322      return false;
     323    }
     324    return true;
     325}
     326
     327static bool logscaleRange(double *bscale, // Scaling, to return
     328                          double *bzero, // Zero point, to return
     329                          const psImage *image, // Image to scale
     330                          const psFitsOptions *options // FITS options
     331    )
     332{
     333    psAssert(bscale, "impossible");
     334    psAssert(bzero, "impossible");
     335    psAssert(image, "impossible");
     336    psAssert(options, "impossible");
     337
     338    psTrace("psLib.fits", 3, "Scaling image by logarithm statistics");
     339    int numCols = image->numCols, numRows = image->numRows; // Size of image
     340   
     341    double offset = 99e99;
     342
     343    // Determine the minimum value on this image.
     344    switch (image->type.type) {
     345    case PS_TYPE_F32:
     346      for (int y = 0; y < numRows; y++) {
     347        for (int x = 0; x < numCols; x++) {
     348          psF32 value = image->data.F32[y][x];
     349          if (!isfinite(value)) {
     350            if (value < offset) {
     351              offset = value;
     352            }
     353          }
     354        }
     355      }
     356      break;
     357    case PS_TYPE_F64:
     358      for (int y = 0; y < numRows; y++) {
     359        for (int x = 0; x < numCols; x++) {
     360          psF64 value = image->data.F64[y][x];
     361          if (!isfinite(value)) {
     362            if (value < offset) {
     363              offset = value;
     364            }
     365          }
     366        }
     367      }
     368      break;
     369    default:
     370      psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Target type is not a float: %d",image->type.type);
     371      return NULL;
     372      break;
     373    }
     374    // We only need to offset images that go negative.
     375    if (offset > 0.0) {
     376      offset = 0.0;
     377    }
     378    // Write offset to header
     379    // How?
     380    //    psMetadataAddF32(header,PS_LIST_TAIL,"LOGZERO",0,"Flux offset subtracted before taking logarithm.",offset);
     381    // Take the logarithm of the image, applying the offset
     382    switch (image->type.type) {
     383    case PS_TYPE_F32:
     384      for (int y = 0; y < numRows; y++) {
     385        for (int x = 0; x < numCols; x++) {
     386          image->data.F32[y][x] = (log10( image->data.F32[y][x] - offset));
     387        }
     388      }
     389      break;
     390    case PS_TYPE_F64:
     391        for (int y = 0; y < numRows; y++) {
     392          for (int x = 0; x < numCols; x++) {
     393            image->data.F64[y][x] = (log10( image->data.F64[y][x] - offset));
     394          }
     395        }
     396      break;
     397    default:
     398      psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Target type is not a float: %d",image->type.type);
     399      return NULL;
     400      break;
     401    }
     402     
     403    // Do regular scaling on the logarithm image
     404    if (!scaleRange(bscale, bzero, image, options)) {
     405      psError(PS_ERR_UNKNOWN, false, "Unable to set BSCALE and BZERO from stdev");
     406      return false;
     407    }
     408    return true;
     409}
     410
     411
    239412//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    240413// Public functions
     
    295468      case PS_FITS_SCALE_STDEV_BOTH:
    296469        if (!scaleStdev(bscale, bzero, image, mask, maskVal, options)) {
     470            psError(PS_ERR_UNKNOWN, false, "Unable to set BSCALE and BZERO from stdev");
     471            return false;
     472        }
     473        break;
     474    case PS_FITS_SCALE_LOG_RANGE:
     475      if (!logscaleRange(bscale,bzero,image,options)) {
     476        psError(PS_ERR_UNKNOWN, false, "Unable to set BSCALE and BZERO from range");
     477        return false;
     478      }
     479      break;
     480    case PS_FITS_SCALE_LOG_STDEV_POSITIVE:
     481    case PS_FITS_SCALE_LOG_STDEV_NEGATIVE:
     482    case PS_FITS_SCALE_LOG_STDEV_BOTH:
     483      if (!logscaleStdev(bscale, bzero, image, mask, maskVal, options)) {
    297484            psError(PS_ERR_UNKNOWN, false, "Unable to set BSCALE and BZERO from stdev");
    298485            return false;
  • branches/czw_branch/20101203/psLib/src/imageops

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/czw_branch/20101203/psLib/test/math

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/czw_branch/20101203/psModules/src/config/pmConfig.c

    r29004 r30119  
    897897            psMetadataAddMetadata(filerules, PS_LIST_TAIL, old, PS_META_REPLACE,
    898898                                  "Original replaced by -F option", newRule);
     899        }
     900        psFree(camerasIter);
     901    }
     902
     903    // Look for command-line options for files to replace
     904    while ((argNum = psArgumentGet(*argc, argv, "-R")) > 0) {
     905        psArgumentRemove(argNum, argc, argv);
     906        if (argNum + 2 >= *argc) {
     907            psError(PM_ERR_CONFIG, true,
     908                    "Filerule element switch (-R) provided without filerule element and value.");
     909            psFree(config);
     910            return NULL;
     911        }
     912
     913        const char *rulename = argv[argNum]; // The filerule, to be modified
     914        psArgumentRemove(argNum, argc, argv);
     915        const char *element  = argv[argNum]; // The element, to be modified
     916        psArgumentRemove(argNum, argc, argv);
     917        const char *value    = argv[argNum]; // The value, to be set
     918        psArgumentRemove(argNum, argc, argv);
     919
     920        psMetadata *cameras = psMetadataLookupMetadata(NULL, config->system, "CAMERAS"); // List of cameras
     921        if (!cameras) {
     922            psError(PM_ERR_CONFIG, false, "Unable to find CAMERAS in the site configuration.\n");
     923            return false;
     924        }
     925
     926        psMetadataIterator *camerasIter = psMetadataIteratorAlloc(cameras, PS_LIST_HEAD, NULL); // Iterator
     927        psMetadataItem *cameraItem;     // Item from iteration
     928        while ((cameraItem = psMetadataGetAndIncrement(camerasIter))) {
     929            // Silently ignore problems --- they will be caught later, because if the user wants the nominated
     930            // file and it's not available for that camera, then they will know.
     931
     932            if (cameraItem->type != PS_DATA_METADATA) {
     933                psTrace("psModules.config", 2,
     934                        "Entry %s in CAMERAS is not of type METADATA --- ignored.", cameraItem->name);
     935                continue;
     936            }
     937            psMetadata *camera = cameraItem->data.md; // Camera configuration
     938
     939            psMetadata *newRule = pmConfigFileRule(config, camera, rulename); // The rule of interest
     940            if (!newRule) {
     941                psTrace("psModules.config", 2,
     942                        "Unable to find filerule %s in camera %s --- ignored.", rulename, cameraItem->name);
     943                continue;
     944            }
     945
     946            // By calling pmConfigFileRule, we've assured that the FILERULES is now a metadata
     947            psMetadata *filerules = psMetadataLookupMetadata(NULL, camera, "FILERULES"); // File rules
     948            if (!filerules) {
     949                psTrace("psModules.config", 2,
     950                        "Can't find FILERULES of type METADATA in camera %s --- ignored.", cameraItem->name);
     951                continue;
     952            }
     953
     954            // Convert newRule to have the element value requested.
     955            if (!psMetadataLookupStr(NULL,newRule,element)) {
     956              psTrace("psModules.config", 2,
     957                      "Unable to find filerule element %s in filerule %s in camera %s --- ignored.",
     958                      element,rulename,cameraItem->name);
     959              continue;
     960            }
     961            psMetadataAddStr(newRule, PS_LIST_TAIL, element, PS_META_REPLACE,
     962                             "Original replaced by -R option", value);
     963           
     964            psMetadataAddMetadata(filerules, PS_LIST_TAIL, rulename, PS_META_REPLACE,
     965                                  "Original replaced by -R option", newRule);
    899966        }
    900967        psFree(camerasIter);
  • branches/czw_branch/20101203/psModules/src/objects

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/czw_branch/20101203/psphot/src/psphotApResid.c

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/czw_branch/20101203/psphot/src/psphotMakeFluxScale.c

    • Property svn:mergeinfo changed (with no actual effect on merging)
Note: See TracChangeset for help on using the changeset viewer.