2 #ifndef LSST_AFW_fitsCompression_h_INCLUDED 3 #define LSST_AFW_fitsCompression_h_INCLUDED 8 #include "boost/cstdfloat.hpp" 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;
104 _pixels(array.getData()),
105 _manager(array.getManager()) {}
110 template <
typename U>
112 auto mem = ndarray::SimpleManager<U>::allocate(getNumElements());
113 _manager = mem.first;
114 _pixels = mem.second;
121 void const*
getData()
const override {
return _pixels; }
125 ndarray::Manager::Ptr _manager;
133 template <
typename T>
137 return std::make_shared<PixelArray<T>>(array);
139 return std::make_shared<PixelArray<std::uint8_t>>(array);
141 return std::make_shared<PixelArray<std::int16_t>>(array);
143 return std::make_shared<PixelArray<std::int32_t>>(array);
145 return std::make_shared<PixelArray<std::int64_t>>(array);
147 return std::make_shared<PixelArray<boost::float32_t>>(array);
149 return std::make_shared<PixelArray<boost::float64_t>>(array);
152 os <<
"Unrecognized bitpix: " << bitpix;
194 typedef ndarray::Array<long, 1, 1>
Tiles;
202 float quantizeLevel_ = 0.0)
203 : algorithm(algorithm_), tiles(
ndarray::copy(tiles_)), quantizeLevel(quantizeLevel_) {}
206 float quantizeLevel_ = 0.0)
207 : algorithm(algorithm_), tiles(
ndarray::allocate(tiles_.size())), quantizeLevel(quantizeLevel_) {
217 float quantizeLevel_ = 0.0);
223 template <
typename T>
225 : ImageCompressionOptions(image.getBBox().getArea() > 0 ? NONE : NONE) {}
226 template <
typename T>
228 : ImageCompressionOptions(mask.getBBox().getArea() > 0 ? NONE : NONE) {}
232 : ImageCompressionOptions(NONE) {}
235 : ImageCompressionOptions(NONE) {}
237 : ImageCompressionOptions(NONE) {}
279 bzero(
std::
floor(bzero_ / bscale_ + 0.5) * bscale_),
280 blank(bitpix > 0 ? (bitpix == 8 ? 255 : (1L << (bitpix - 1)) - 1) : 0) {}
292 template <
typename T>
294 ndarray::Array<T const, 2, 2>
const&
image,
bool forceNonfiniteRemoval,
bool fuzz =
true,
295 ndarray::Array<long, 1>
const& tiles = ndarray::Array<long, 1, 1>(),
int seed = 1)
const;
302 template <
typename T>
303 ndarray::Array<T, 2, 2> fromFits(ndarray::Array<T, 2, 2>
const& image)
const;
395 float quantizeLevel_ = 4.0,
float quantizePad_ = 5.0,
bool fuzz_ =
true,
396 double bscale_ = 1.0,
double bzero_ = 0.0);
407 template <
typename T>
418 template <
typename T,
int N>
420 ndarray::Array<bool, N, N>
const&
mask)
const;
425 template <
typename T>
429 if (mask && image.
getDimensions() != mask->getDimensions()) {
431 os <<
"Size mismatch between image and mask: ";
434 os << mask->getWidth() <<
"x" << mask->getHeight();
437 ndarray::Array<T const, 2, 2> imageArray = ndarray::dynamic_dimension_cast<2>(image.
getArray());
438 if (imageArray.empty()) imageArray = ndarray::copy(image.
getArray());
439 ndarray::Array<bool, 2, 2> maskArray = ndarray::allocate(imageArray.getShape());
441 maskArray.deep() = (mask->getArray() & mask->getPlaneBitMask(maskPlanes));
443 maskArray.deep() =
false;
454 template <
typename T,
int N>
455 ImageScale determineFromRange(ndarray::Array<T const, N, N>
const& image,
456 ndarray::Array<bool, N, N>
const& mask,
bool isUnsigned =
false,
457 bool cfitsioPadding =
true)
const;
465 template <
typename T,
int N>
466 ImageScale determineFromStdev(ndarray::Array<T const, N, N>
const& image,
467 ndarray::Array<bool, N, N>
const& mask,
bool isUnsigned =
false,
468 bool cfitsioPadding =
true)
const;
481 #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.
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 getHeight() const
Return the number of rows in the image.
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.
std::size_t getNumElements() const
Return the number of pixels.
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.
PixelArrayBase(std::size_t num)
ImageCompressionOptions(image::Mask< T > const &mask)
ImageCompressionOptions(image::Image< std::uint64_t > const &image)
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.
A base class for image defects.
float quantizeLevel
Divisor of the standard deviation for STDEV_* scaling.
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.
double bscale
Manually specified BSCALE (for MANUAL scaling)
ImageCompressionOptions(image::Image< T > const &image)
Default compression for a particular style of 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)
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
void const * getData() const override
Return a void* array of the pixels.
Abstract base class for an array of pixel values.
int getWidth() const
Return the number of columns in the image.
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 BZERO (for MANUAL scaling)
ImageScale(int bitpix_, double bscale_, double bzero_)
Constructor.
virtual ~PixelArrayBase()
Reports invalid arguments.
CompressionAlgorithm algorithm
Compresion algorithm to use.
ImageCompressionOptions::CompressionAlgorithm compressionAlgorithmFromCfitsio(int cfitsio)
Convert compression algorithm from cfitsio to ImageCompressionOptions::CompressionAlgorithm.
ImageScale determine(image::ImageBase< T > const &image, std::shared_ptr< image::Mask< image::MaskPixel > const > mask=nullptr) const
Determine the scaling for a particular image.
Extent< int, N > floor(Extent< double, N > const &input) noexcept
Return the component-wise floor (round towards more negative).
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?
lsst::geom::Extent2I getDimensions() const
Return the image's size; useful for passing to constructors.
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects...
std::vector< std::string > maskPlanes
Mask planes to ignore when doing statistics.
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)