24 #include "pybind11/pybind11.h"
36 using namespace pybind11::literals;
43 template <
typename PixelT>
53 template <
typename FromPixelT,
typename ToPixelT>
54 void declareCastConstructor(PyExposure<ToPixelT> &cls) {
55 cls.def(
py::init<Exposure<FromPixelT>
const &,
bool const>(),
"src"_a,
"deep"_a);
58 template <
typename PixelT>
61 using ExposureT = Exposure<PixelT>;
62 using MaskedImageT =
typename ExposureT::MaskedImageT;
63 wrappers.
wrap([](
auto &mod) {
64 mod.def(
"makeExposure", &makeExposure<PixelT, MaskPixel, VariancePixel>,
"maskedImage"_a,
68 PyExposure<PixelT>(wrappers.
module, (
"Exposure" + suffix).c_str()), [](
auto &mod,
auto &cls) {
70 cls.def(py::init<unsigned int, unsigned int, std::shared_ptr<geom::SkyWcs const>>(),
71 "width"_a,
"height"_a,
"wcs"_a = std::shared_ptr<geom::SkyWcs const>());
72 cls.def(py::init<lsst::geom::Extent2I const &, std::shared_ptr<geom::SkyWcs const>>(),
73 "dimensions"_a = lsst::geom::Extent2I(),
74 "wcs"_a = std::shared_ptr<geom::SkyWcs const>());
75 cls.def(py::init<lsst::geom::Box2I const &, std::shared_ptr<geom::SkyWcs const>>(),
"bbox"_a,
76 "wcs"_a = std::shared_ptr<geom::SkyWcs const>());
77 cls.def(py::init<MaskedImageT &, std::shared_ptr<geom::SkyWcs const>>(),
"maskedImage"_a,
78 "wcs"_a = std::shared_ptr<geom::SkyWcs const>());
79 cls.def(py::init<MaskedImageT &, std::shared_ptr<ExposureInfo>>(),
"maskedImage"_a,
81 cls.def(py::init<std::string const &, lsst::geom::Box2I const &, ImageOrigin, bool, bool>(),
82 "fileName"_a,
"bbox"_a = lsst::geom::Box2I(),
"origin"_a = PARENT,
83 "conformMasks"_a = false,
"allowUnsafe"_a = false);
84 cls.def(py::init<fits::MemFileManager &, lsst::geom::Box2I const &, ImageOrigin, bool,
86 "manager"_a,
"bbox"_a = lsst::geom::Box2I(),
"origin"_a = PARENT,
87 "conformMasks"_a = false,
"allowUnsafe"_a = false);
88 cls.def(py::init<ExposureT const &, bool>(),
"other"_a,
"deep"_a = false);
89 cls.def(py::init<ExposureT const &, lsst::geom::Box2I const &, ImageOrigin, bool>(),
90 "other"_a,
"bbox"_a,
"origin"_a = PARENT,
"deep"_a = false);
93 cls.def(
"getMaskedImage", (MaskedImageT(ExposureT::*)()) & ExposureT::getMaskedImage);
94 cls.def(
"setMaskedImage", &ExposureT::setMaskedImage,
"maskedImage"_a);
95 cls.def_property(
"maskedImage", (MaskedImageT(ExposureT::*)()) & ExposureT::getMaskedImage,
96 &ExposureT::setMaskedImage);
97 cls.def(
"getMetadata", &ExposureT::getMetadata);
98 cls.def(
"setMetadata", &ExposureT::setMetadata,
"metadata"_a);
99 cls.def(
"getWidth", &ExposureT::getWidth);
100 cls.def(
"getHeight", &ExposureT::getHeight);
101 cls.def(
"getDimensions", &ExposureT::getDimensions);
102 cls.def(
"getX0", &ExposureT::getX0);
103 cls.def(
"getY0", &ExposureT::getY0);
104 cls.def(
"getXY0", &ExposureT::getXY0);
105 cls.def(
"setXY0", &ExposureT::setXY0,
"xy0"_a);
106 cls.def(
"getBBox", &ExposureT::getBBox,
"origin"_a = PARENT);
107 cls.def(
"getWcs", (std::shared_ptr<geom::SkyWcs>(ExposureT::*)()) & ExposureT::getWcs);
108 cls.def(
"setWcs", &ExposureT::setWcs,
"wcs"_a);
109 cls.def(
"hasWcs", &ExposureT::hasWcs);
110 cls.def(
"getDetector", &ExposureT::getDetector);
111 cls.def(
"setDetector", &ExposureT::setDetector,
"detector"_a);
112 cls.def(
"getFilter", &ExposureT::getFilter);
113 cls.def(
"setFilter", &ExposureT::setFilter,
"filter"_a);
114 cls.def(
"getFilterLabel", &ExposureT::getFilterLabel);
115 cls.def(
"setFilterLabel", &ExposureT::setFilterLabel,
"filterLabel"_a);
117 cls.def(
"getPhotoCalib", &ExposureT::getPhotoCalib);
118 cls.def(
"setPhotoCalib", &ExposureT::setPhotoCalib,
"photoCalib"_a);
119 cls.def(
"getPsf", (std::shared_ptr<detection::Psf>(ExposureT::*)()) & ExposureT::getPsf);
120 cls.def(
"setPsf", &ExposureT::setPsf,
"psf"_a);
121 cls.def(
"hasPsf", &ExposureT::hasPsf);
122 cls.def(
"getInfo", (std::shared_ptr<ExposureInfo>(ExposureT::*)()) & ExposureT::getInfo);
123 cls.def(
"setInfo", &ExposureT::setInfo,
"exposureInfo"_a);
125 cls.def(
"subset", &ExposureT::subset,
"bbox"_a,
"origin"_a = PARENT);
127 cls.def(
"writeFits", (void (ExposureT::*)(std::string const &) const) & ExposureT::writeFits);
129 (void (ExposureT::*)(fits::MemFileManager &) const) & ExposureT::writeFits);
130 cls.def(
"writeFits", [](ExposureT &self, fits::Fits &fits) { self.writeFits(fits); });
135 fits::ImageWriteOptions
const &imageOptions,
136 fits::ImageWriteOptions
const &maskOptions,
137 fits::ImageWriteOptions
const &varianceOptions) {
138 self.writeFits(filename, imageOptions, maskOptions, varianceOptions);
140 "filename"_a,
"imageOptions"_a,
"maskOptions"_a,
"varianceOptions"_a);
143 [](ExposureT &
self, fits::MemFileManager &manager,
144 fits::ImageWriteOptions
const &imageOptions,
145 fits::ImageWriteOptions
const &maskOptions,
146 fits::ImageWriteOptions
const &varianceOptions) {
147 self.writeFits(manager, imageOptions, maskOptions, varianceOptions);
149 "manager"_a,
"imageOptions"_a,
"maskOptions"_a,
"varianceOptions"_a);
152 [](ExposureT &
self, fits::Fits &
fits, fits::ImageWriteOptions
const &imageOptions,
153 fits::ImageWriteOptions
const &maskOptions,
154 fits::ImageWriteOptions
const &varianceOptions) {
155 self.writeFits(
fits, imageOptions, maskOptions, varianceOptions);
157 "fits"_a,
"imageOptions"_a,
"maskOptions"_a,
"varianceOptions"_a);
159 cls.def_static(
"readFits", (ExposureT(*)(
std::string const &))ExposureT::readFits);
160 cls.def_static(
"readFits", (ExposureT(*)(fits::MemFileManager &))ExposureT::readFits);
162 cls.def(
"getCutout", &ExposureT::getCutout,
"center"_a,
"size"_a);
173 auto clsExposureF = declareExposure<float>(wrappers,
"F");
174 auto clsExposureD = declareExposure<double>(wrappers,
"D");
175 declareExposure<int>(wrappers,
"I");
176 declareExposure<std::uint16_t>(wrappers,
"U");
177 declareExposure<std::uint64_t>(wrappers,
"L");
181 declareCastConstructor<int, float>(clsExposureF);
182 declareCastConstructor<int, double>(clsExposureD);
184 declareCastConstructor<float, double>(clsExposureD);
185 declareCastConstructor<double, float>(clsExposureF);
187 declareCastConstructor<std::uint16_t, float>(clsExposureF);
188 declareCastConstructor<std::uint16_t, double>(clsExposureD);
190 declareCastConstructor<std::uint64_t, float>(clsExposureF);
191 declareCastConstructor<std::uint64_t, double>(clsExposureD);
Implementation of the Photometric Calibration class.
A helper class for subdividing pybind11 module across multiple translation units (i....
pybind11::module module
The module object passed to the PYBIND11_MODULE block that contains this WrapperCollection.
void finish()
Invoke all deferred wrapper-declaring callables.
PyType wrapType(PyType cls, ClassWrapperCallback function, bool setModuleName=true)
Add a type (class or enum) wrapper, deferring method and other attribute definitions until finish() i...
void wrap(WrapperCallback function)
Add a set of wrappers without defining a class.
void addSignatureDependency(std::string const &name)
Indicate an external module that provides a type used in function/method signatures.
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
PYBIND11_MODULE(_exposure, mod)
A base class for image defects.