23 #include "pybind11/pybind11.h"
34 using namespace pybind11::literals;
41 template <
typename PixelT>
51 template <
typename FromPixelT,
typename ToPixelT>
52 void declareCastConstructor(PyExposure<ToPixelT> &
cls) {
53 cls.def(
py::init<Exposure<FromPixelT>
const &,
bool const>(),
"src"_a,
"deep"_a);
56 template <
typename PixelT>
58 using ExposureT = Exposure<PixelT>;
59 using MaskedImageT =
typename ExposureT::MaskedImageT;
61 PyExposure<PixelT>
cls(mod, (
"Exposure" + suffix).c_str());
63 mod.def(
"makeExposure", &makeExposure<PixelT, MaskPixel, VariancePixel>,
"maskedImage"_a,
76 cls.def(py::init<std::string const &, lsst::geom::Box2I const &, ImageOrigin, bool, bool>(),
"fileName"_a,
78 "allowUnsafe"_a =
false);
79 cls.def(py::init<fits::MemFileManager &, lsst::geom::Box2I const &, ImageOrigin, bool, bool>(),
81 "allowUnsafe"_a =
false);
82 cls.def(py::init<ExposureT const &, bool>(),
"other"_a,
"deep"_a =
false);
83 cls.def(py::init<ExposureT const &, lsst::geom::Box2I const &, ImageOrigin, bool>(),
"other"_a,
"bbox"_a,
84 "origin"_a =
PARENT,
"deep"_a =
false);
87 cls.def(
"getMaskedImage", (MaskedImageT(ExposureT::*)()) & ExposureT::getMaskedImage);
88 cls.def(
"setMaskedImage", &ExposureT::setMaskedImage,
"maskedImage"_a);
89 cls.def_property(
"maskedImage", (MaskedImageT(ExposureT::*)()) & ExposureT::getMaskedImage,
90 &ExposureT::setMaskedImage);
91 cls.def(
"getMetadata", &ExposureT::getMetadata);
92 cls.def(
"setMetadata", &ExposureT::setMetadata,
"metadata"_a);
93 cls.def(
"getWidth", &ExposureT::getWidth);
94 cls.def(
"getHeight", &ExposureT::getHeight);
95 cls.def(
"getDimensions", &ExposureT::getDimensions);
96 cls.def(
"getX0", &ExposureT::getX0);
97 cls.def(
"getY0", &ExposureT::getY0);
98 cls.def(
"getXY0", &ExposureT::getXY0);
99 cls.def(
"setXY0", &ExposureT::setXY0,
"xy0"_a);
100 cls.def(
"getBBox", &ExposureT::getBBox,
"origin"_a =
PARENT);
102 cls.def(
"setWcs", &ExposureT::setWcs,
"wcs"_a);
103 cls.def(
"hasWcs", &ExposureT::hasWcs);
104 cls.def(
"getDetector", &ExposureT::getDetector);
105 cls.def(
"setDetector", &ExposureT::setDetector,
"detector"_a);
106 cls.def(
"getFilter", &ExposureT::getFilter);
107 cls.def(
"setFilter", &ExposureT::setFilter,
"filter"_a);
108 cls.def(
"getFilterLabel", &ExposureT::getFilterLabel);
109 cls.def(
"setFilterLabel", &ExposureT::setFilterLabel,
"filterLabel"_a);
111 cls.def(
"getPhotoCalib", &ExposureT::getPhotoCalib);
112 cls.def(
"setPhotoCalib", &ExposureT::setPhotoCalib,
"photoCalib"_a);
114 cls.def(
"setPsf", &ExposureT::setPsf,
"psf"_a);
115 cls.def(
"hasPsf", &ExposureT::hasPsf);
117 cls.def(
"setInfo", &ExposureT::setInfo,
"exposureInfo"_a);
119 cls.def(
"subset", &ExposureT::subset,
"bbox"_a,
"origin"_a =
PARENT);
123 cls.def(
"writeFits", [](ExposureT &
self, fits::Fits &
fits) {
self.writeFits(
fits); });
126 [](ExposureT &
self,
std::string const &filename, fits::ImageWriteOptions
const &imageOptions,
127 fits::ImageWriteOptions
const &maskOptions, fits::ImageWriteOptions
const &varianceOptions) {
128 self.writeFits(filename, imageOptions, maskOptions, varianceOptions);
130 "filename"_a,
"imageOptions"_a,
"maskOptions"_a,
"varianceOptions"_a);
132 [](ExposureT &
self, fits::MemFileManager &manager, fits::ImageWriteOptions
const &imageOptions,
133 fits::ImageWriteOptions
const &maskOptions, fits::ImageWriteOptions
const &varianceOptions) {
134 self.writeFits(manager, imageOptions, maskOptions, varianceOptions);
136 "manager"_a,
"imageOptions"_a,
"maskOptions"_a,
"varianceOptions"_a);
138 [](ExposureT &
self, fits::Fits &
fits, fits::ImageWriteOptions
const &imageOptions,
139 fits::ImageWriteOptions
const &maskOptions, fits::ImageWriteOptions
const &varianceOptions) {
140 self.writeFits(
fits, imageOptions, maskOptions, varianceOptions);
142 "fits"_a,
"imageOptions"_a,
"maskOptions"_a,
"varianceOptions"_a);
144 cls.def_static(
"readFits", (ExposureT(*)(
std::string const &))ExposureT::readFits);
145 cls.def_static(
"readFits", (ExposureT(*)(fits::MemFileManager &))ExposureT::readFits);
147 cls.def(
"getCutout", &ExposureT::getCutout,
"center"_a,
"size"_a);
153 py::module::import(
"lsst.afw.image.exposureInfo");
154 py::module::import(
"lsst.afw.image.maskedImage");
156 auto clsExposureF = declareExposure<float>(mod,
"F");
157 auto clsExposureD = declareExposure<double>(mod,
"D");
158 declareExposure<int>(mod,
"I");
159 declareExposure<std::uint16_t>(mod,
"U");
160 declareExposure<std::uint64_t>(mod,
"L");
164 declareCastConstructor<int, float>(clsExposureF);
165 declareCastConstructor<int, double>(clsExposureD);
167 declareCastConstructor<float, double>(clsExposureD);
169 declareCastConstructor<double, float>(clsExposureF);
171 declareCastConstructor<std::uint16_t, float>(clsExposureF);
172 declareCastConstructor<std::uint16_t, double>(clsExposureD);
174 declareCastConstructor<std::uint64_t, float>(clsExposureF);
175 declareCastConstructor<std::uint64_t, double>(clsExposureD);