2 #ifndef LSST_AFW_fitsCompression_h_INCLUDED
3 #define LSST_AFW_fitsCompression_h_INCLUDED
8 #include "boost/cstdfloat.hpp"
10 #include "lsst/pex/exceptions.h"
11 #include "lsst/daf/base.h"
13 #include "ndarray/eigen.h"
33 static int const value = 8;
37 static int const value = 16;
41 static int const value = 32;
45 static int const value = 64;
49 static int const value = 16;
53 static int const value = 32;
57 static int const value = 64;
61 static int const value = -32;
65 static int const value = -64;
80 virtual void const*
getData()
const = 0;
108 template <
typename U>
112 _manager = mem.first;
113 _pixels = mem.second;
114 std::copy(array.begin(), array.end(),
115 const_cast<typename std::remove_const<T>::type *
>(
reinterpret_cast<T const*
>(_pixels)));
120 void const*
getData()
const override {
return _pixels; }
124 ndarray::Manager::Ptr _manager;
132 template <
typename T>
135 ndarray::Array<T, 1, 1>
const& array
138 case 0:
return std::make_shared<PixelArray<T>>(array);
139 case 8:
return std::make_shared<PixelArray<std::uint8_t>>(array);
140 case 16:
return std::make_shared<PixelArray<std::int16_t>>(array);
141 case 32:
return std::make_shared<PixelArray<std::int32_t>>(array);
142 case 64:
return std::make_shared<PixelArray<std::int64_t>>(array);
143 case -32:
return std::make_shared<PixelArray<boost::float32_t>>(array);
144 case -64:
return std::make_shared<PixelArray<boost::float64_t>>(array);
146 std::ostringstream os;
147 os <<
"Unrecognized bitpix: " << bitpix;
148 throw LSST_EXCEPT(pex::exceptions::InvalidParameterError, os.str());
190 typedef ndarray::Array<long, 1, 1>
Tiles;
200 float quantizeLevel_=0.0
205 std::vector<long> tiles_,
206 float quantizeLevel_=0.0
208 std::copy(tiles_.cbegin(), tiles_.cend(),
tiles.begin());
219 float quantizeLevel_=0.0
226 template <
typename T>
229 template <
typename T>
295 template <
typename T>
296 std::shared_ptr<detail::PixelArrayBase>
toFits(
297 ndarray::Array<T const, 2, 2>
const&
image,
298 bool forceNonfiniteRemoval,
300 ndarray::Array<long, 1>
const& tiles=ndarray::Array<long, 1, 1>(),
309 template <
typename T>
310 ndarray::Array<T, 2, 2>
fromFits(ndarray::Array<T, 2, 2>
const& image)
const;
387 std::numeric_limits<double>::quiet_NaN()) {}
403 std::vector<std::string>
const& maskPlanes_={},
405 float quantizeLevel_=4.0,
406 float quantizePad_=5.0,
425 template <
typename T>
426 ImageScale determine(
430 auto const arrays = _toArray(image,
mask);
431 return determine(arrays.first, arrays.second);
434 template <
typename T,
int N>
435 ImageScale determine(
436 ndarray::Array<T const, N, N>
const&
image,
437 ndarray::Array<bool, N, N>
const&
mask
443 template <
typename T>
444 std::pair<ndarray::Array<T const, 2, 2>, ndarray::Array<bool, 2, 2>> _toArray(
449 std::ostringstream os;
450 os <<
"Size mismatch between image and mask: ";
453 os <<
mask->getWidth() <<
"x" <<
mask->getHeight();
454 throw LSST_EXCEPT(pex::exceptions::InvalidParameterError, os.str());
456 ndarray::Array<T const, 2, 2> imageArray = ndarray::dynamic_dimension_cast<2>(image.
getArray());
457 if (imageArray.empty()) imageArray = ndarray::copy(image.
getArray());
458 ndarray::Array<bool, 2, 2> maskArray = ndarray::allocate(imageArray.getShape());
462 maskArray.deep() =
false;
464 return std::make_pair(imageArray, maskArray);
473 template <
typename T,
int N>
474 ImageScale determineFromRange(
475 ndarray::Array<T const, N, N>
const& image,
476 ndarray::Array<bool, N, N>
const&
mask,
477 bool isUnsigned=
false,
478 bool cfitsioPadding=
true
487 template <
typename T,
int N>
488 ImageScale determineFromStdev(
489 ndarray::Array<T const, N, N>
const& image,
490 ndarray::Array<bool, N, N>
const&
mask,
491 bool isUnsigned=
false,
492 bool cfitsioPadding=
true
505 #endif // ifndef LSST_AFW_fitsCompression_h_INCLUDED
ImageCompressionOptions(image::Mask< std::uint64_t > const &mask)
ImageScalingOptions()
Default Ctor.
int bitpix
Bits per pixel (0, 8,16,32,64,-32,-64)
std::shared_ptr< PixelArrayBase > makePixelArray(int bitpix, ndarray::Array< T, 1, 1 > const &array)
Create a PixelArray suitable for an image with the nominated BITPIX.
ndarray::Array< T, 2, 2 > fromFits(ndarray::Array< T, 2, 2 > const &image) const
Convert to an array.
Scale to preserve dynamic range.
int compressionAlgorithmToCfitsio(ImageCompressionOptions::CompressionAlgorithm algorithm)
Convert ImageCompressionOptions::CompressionAlgorithm to cfitsio.
long blank
Value for integer images indicating non-finite values.
int bitpix
Bits per pixel; negative means floating-point: 8,16,32,64,-32,-64.
PixelArray(ndarray::Array< T, 1, 1 > const &array)
Construct from an ndarray::Array of the same type.
ImageCompressionOptions(image::Mask< std::int64_t > const &mask)
PixelArray(ndarray::Array< U, 1, 1 > const &array)
Construct from an ndarray::Array of different type.
CompressionAlgorithm
Compression algorithms.
The base class for all image classed (Image, Mask, MaskedImage, ...)
Typed array of pixel values.
FITS BITPIX header value by C++ type.
int seed
Seed for random number generator when fuzzing.
std::size_t getNumElements() const
Return the number of pixels.
PixelArrayBase(std::size_t num)
ImageCompressionOptions(image::Mask< T > const &mask)
ImageCompressionOptions(image::Image< std::uint64_t > const &image)
Extent< int, N > floor(Extent< double, N > const &input)
Return the component-wise floor (round towards more negative).
Tiles tiles
Tile size; a dimension with 0 means infinite (e.g., to specify one row: 0,1)
ImageCompressionOptions(CompressionAlgorithm algorithm_, Tiles tiles_, float quantizeLevel_=0.0)
Custom compression.
Options for tile compression of image pixels.
float quantizeLevel
Divisor of the standard deviation for STDEV_* scaling.
geom::Extent2I getDimensions() const
Return the image's size; useful for passing to constructors.
Represent a 2-dimensional array of bitmask pixels.
double bzero
Zero-point to apply when reading from FITS.
ImageCompressionOptions::CompressionAlgorithm compressionAlgorithmFromString(std::string const &name)
Interpret compression algorithm expressed in string.
std::shared_ptr< detail::PixelArrayBase > toFits(ndarray::Array< T const, 2, 2 > const &image, bool forceNonfiniteRemoval, bool fuzz=true, ndarray::Array< long, 1 > const &tiles=ndarray::Array< long, 1, 1 >(), int seed=1) const
Convert to an array of pixel values to write to FITS.
table::Key< std::string > name
ImageCompressionOptions(image::Image< T > const &image)
Default compression for a particular style of image.
int getHeight() const
Return the number of rows in the image.
ndarray::Array< long, 1, 1 > Tiles
Options for scaling image pixels.
double bscale
Scale to apply when reading from FITS.
std::string scalingAlgorithmToString(ImageScalingOptions::ScalingAlgorithm algorithm)
Provide string version of compression algorithm.
std::string compressionAlgorithmToString(ImageCompressionOptions::CompressionAlgorithm algorithm)
Provide string version of compression algorithm.
ImageCompressionOptions(image::Image< std::int64_t > const &image)
void const * getData() const override
Return a void* array of the pixels.
Abstract base class for an array of pixel values.
Standard GZIP compression.
float quantizeLevel
quantization level: 0.0 = none requires use of GZIP or GZIP_SHUFFLE
Scale based on the standard deviation, dynamic range negative.
double bzero
Manually specified BSCALE and BZERO (for MANUAL scaling)
ImageScale(int bitpix_, double bscale_, double bzero_)
Constructor.
virtual ~PixelArrayBase()
CompressionAlgorithm algorithm
Compresion algorithm to use.
ImageCompressionOptions::CompressionAlgorithm compressionAlgorithmFromCfitsio(int cfitsio)
Convert compression algorithm from cfitsio to ImageCompressionOptions::CompressionAlgorithm.
ScalingAlgorithm algorithm
Scaling algorithm to use.
Scale based on the standard deviation, dynamic range positive+negative.
float quantizePad
Number of stdev to allow on the low/high side (for STDEV_POSITIVE/NEGATIVE)
ImageCompressionOptions(CompressionAlgorithm algorithm_, std::vector< long > tiles_, float quantizeLevel_=0.0)
bool fuzz
Fuzz the values when quantising floating-point values?
virtual void const * getData() const =0
Return a void* array of the pixels.
std::vector< std::string > maskPlanes
Mask planes to ignore when doing statistics.
int getWidth() const
Return the number of columns in the image.
A class to represent a 2-dimensional array of pixels.
Scale based on the standard deviation. dynamic range positive.
ImageScalingOptions(int bitpix_, double bscale_=1.0, double bzero_=0.0)
Manual scaling Ctor.
ImageScalingOptions::ScalingAlgorithm scalingAlgorithmFromString(std::string const &name)
Interpret scaling algorithm expressed in string.
GZIP compression with shuffle (most-significant byte first)