23 #include <pybind11/pybind11.h> 24 #include <pybind11/stl.h> 26 #include "ndarray/pybind11.h" 44 py::class_<ImageCompressionOptions>
cls(mod,
"ImageCompressionOptions");
46 py::enum_<ImageCompressionOptions::CompressionAlgorithm>(
cls,
"CompressionAlgorithm").
47 value(
"NONE", ImageCompressionOptions::CompressionAlgorithm::NONE).
48 value(
"GZIP", ImageCompressionOptions::CompressionAlgorithm::GZIP).
49 value(
"GZIP_SHUFFLE", ImageCompressionOptions::CompressionAlgorithm::GZIP_SHUFFLE).
50 value(
"RICE", ImageCompressionOptions::CompressionAlgorithm::RICE).
51 value(
"PLIO", ImageCompressionOptions::CompressionAlgorithm::PLIO).
54 cls.def(py::init<ImageCompressionOptions::CompressionAlgorithm, ImageCompressionOptions::Tiles, float>(),
55 "algorithm"_a,
"tiles"_a,
"quantizeLevel"_a=0.0);
56 cls.def(py::init<ImageCompressionOptions::CompressionAlgorithm, int, float>(),
"algorithm"_a,
"rows"_a=1,
57 "quantizeLevel"_a=0.0);
81 cls.def(
"determine", &ImageScalingOptions::determine<T>);
85 py::class_<ImageScalingOptions>
cls(mod,
"ImageScalingOptions");
86 py::enum_<ImageScalingOptions::ScalingAlgorithm>(
cls,
"ScalingAlgorithm").
87 value(
"NONE", ImageScalingOptions::ScalingAlgorithm::NONE).
88 value(
"RANGE", ImageScalingOptions::ScalingAlgorithm::RANGE).
89 value(
"STDEV_POSITIVE", ImageScalingOptions::ScalingAlgorithm::STDEV_POSITIVE).
90 value(
"STDEV_NEGATIVE", ImageScalingOptions::ScalingAlgorithm::STDEV_NEGATIVE).
91 value(
"STDEV_BOTH", ImageScalingOptions::ScalingAlgorithm::STDEV_BOTH).
92 value(
"MANUAL", ImageScalingOptions::ScalingAlgorithm::MANUAL).
95 cls.def(py::init<>());
97 unsigned long,
float,
float,
bool,
double,
double>(),
99 "quantizeLevel"_a=4.0,
"quantizePad"_a=5.0,
"fuzz"_a=
true,
"bscale"_a=1.0,
"bzero"_a=0.0);
111 declareImageScalingOptionsTemplates<float>(
cls);
112 declareImageScalingOptionsTemplates<double>(
cls);
115 template <
typename T>
117 cls.def(
"toFits", &ImageScale::toFits<T>,
"image"_a,
"forceNonfiniteRemoval"_a=
false,
"fuzz"_a=
true,
118 "tiles"_a=ndarray::Array<long, 1, 1>(),
"seed"_a=1);
119 cls.def(
"fromFits", &ImageScale::fromFits<T>);
123 py::class_<ImageScale>
cls(mod,
"ImageScale");
124 cls.def(py::init<int, double, double>(),
"bitpix"_a,
"bscale"_a,
"bzero"_a);
130 declareImageScaleTemplates<float>(
cls,
"F");
131 declareImageScaleTemplates<double>(
cls,
"D");
135 py::class_<ImageWriteOptions>
cls(mod,
"ImageWriteOptions");
145 cls.def(py::init<ImageCompressionOptions const&, ImageScalingOptions const&>(),
147 cls.def(py::init<ImageScalingOptions const&>());
149 cls.def(py::init<lsst::daf::base::PropertySet const&>());
162 py::class_<Fits>
cls(mod,
"Fits");
164 cls.def(py::init<std::string const&, std::string const&, int>(),
"filename"_a,
"mode"_a,
166 cls.def(py::init<MemFileManager &, std::string const&, int>(),
"manager"_a,
"mode"_a,
172 cls.def(
"setHdu", &
Fits::setHdu,
"hdu"_a,
"relative"_a=
false);
180 cls.def(
"gotoFirstHdu", [](
Fits &
self) {
self.setHdu(
DEFAULT_HDU); });
191 py::class_<MemFileManager> clsMemFileManager(mod,
"MemFileManager");
193 py::module::import(
"lsst.pex.exceptions");
195 lsst::pex::exceptions::python::declareException<FitsError, lsst::pex::exceptions::IoError>(
196 mod,
"FitsError",
"IoError");
200 clsMemFileManager.def(py::init<>());
201 clsMemFileManager.def(py::init<size_t>());
211 memcpy(m.
getData(), PyBytes_AsString(d.ptr()), size);
213 clsMemFileManager.def(
"readMetadata",
228 mod.def(
"readMetadata",
231 },
"fileName"_a,
"hdu"_a=
DEFAULT_HDU,
"strip"_a=
false);
std::shared_ptr< daf::base::PropertyList > combineMetadata(std::shared_ptr< const daf::base::PropertyList > first, std::shared_ptr< const daf::base::PropertyList > second)
Combine two sets of metadata in a FITS-appropriate fashion.
std::string getFileName() const
Return the file name associated with the FITS object or "<unknown>" if there is none.
int bitpix
Bits per pixel (0, 8,16,32,64,-32,-64)
ImageCompressionOptions getImageCompression()
Return the current image compression settings.
ImageCompressionOptions compression
Options controlling compression.
void writeMetadata(daf::base::PropertySet const &metadata)
Read a FITS header into a PropertySet or PropertyList.
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.
void declareImageWriteOptions(py::module &mod)
PYBIND11_MODULE(fits, mod)
void declareImageScalingOptionsTemplates(py::class_< ImageScalingOptions > &cls)
void declareImageScale(py::module &mod)
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
void closeFile()
Close a FITS file.
int seed
Seed for random number generator when fuzzing.
void createEmpty()
Create an empty image HDU with NAXIS=0 at the end of the file.
void declareImageScalingOptions(py::module &mod)
Tiles tiles
Tile size; a dimension with 0 means infinite (e.g., to specify one row: 0,1)
float quantizeLevel
Divisor of the standard deviation for STDEV_* scaling.
Represent a 2-dimensional array of bitmask pixels.
Lifetime-management for memory that goes into FITS memory files.
double bzero
Zero-point to apply when reading from FITS.
void declareImageScaleTemplates(py::class_< ImageScale > &cls, std::string const &suffix)
void * getData() const
Return the buffer.
ImageCompressionOptions::CompressionAlgorithm compressionAlgorithmFromString(std::string const &name)
Interpret compression algorithm expressed in string.
double bscale
Manually specified BSCALE (for MANUAL scaling)
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.
void declareImageCompression(py::module &mod)
void setHdu(int hdu, bool relative=false)
Set the current HDU.
ImageScalingOptions scaling
Options controlling scaling.
static std::shared_ptr< daf::base::PropertySet > validate(daf::base::PropertySet const &config)
Validate a PropertySet.
bool checkCompressedImagePhu()
Go to the first image header in the FITS file.
std::size_t getLength() const
Return the buffer length.
void setAllowImageCompression(bool allow)
float quantizeLevel
quantization level: 0.0 = none requires use of GZIP or GZIP_SHUFFLE
double bzero
Manually specified BZERO (for MANUAL scaling)
CompressionAlgorithm algorithm
Compresion algorithm to use.
void setImageCompression(ImageCompressionOptions const &options)
Set compression options for writing FITS images.
ScalingAlgorithm algorithm
Scaling algorithm to use.
float quantizePad
Number of stdev to allow on the low/high side (for STDEV_POSITIVE/NEGATIVE)
bool fuzz
Fuzz the values when quantising floating-point values?
bool getAllowImageCompression()
int getHdu()
Return the current HDU (0-indexed; 0 is the Primary HDU).
std::vector< std::string > maskPlanes
Mask planes to ignore when doing statistics.
A class to represent a 2-dimensional array of pixels.
ImageScalingOptions::ScalingAlgorithm scalingAlgorithmFromString(std::string const &name)
Interpret scaling algorithm expressed in string.
std::string makeLimitedFitsHeader(lsst::daf::base::PropertySet const &metadata, std::set< std::string > const &excludeNames={})
Format a PropertySet into an FITS header string in a simplistic fashion.
void declareFits(py::module &mod)
const int DEFAULT_HDU
Specify that the default HDU should be read.
std::shared_ptr< daf::base::PropertyList > readMetadata(std::string const &fileName, int hdu=DEFAULT_HDU, bool strip=false)
Read FITS header.
int countHdus()
Return the number of HDUs in the file.