23 #include "pybind11/pybind11.h"
33 using namespace pybind11::literals;
40 template <
typename PixelT>
50 template <
typename FromPixelT,
typename ToPixelT>
51 void declareCastConstructor(PyExposure<ToPixelT> &
cls) {
52 cls.def(
py::init<Exposure<FromPixelT>
const &,
bool const>(),
"src"_a,
"deep"_a);
55 template <
typename PixelT>
57 using ExposureT = Exposure<PixelT>;
58 using MaskedImageT =
typename ExposureT::MaskedImageT;
60 PyExposure<PixelT>
cls(mod, (
"Exposure" + suffix).c_str());
62 mod.def(
"makeExposure", &makeExposure<PixelT, MaskPixel, VariancePixel>,
"maskedImage"_a,
75 cls.def(py::init<std::string const &, lsst::geom::Box2I const &, ImageOrigin, bool, bool>(),
"fileName"_a,
77 "allowUnsafe"_a =
false);
78 cls.def(py::init<fits::MemFileManager &, lsst::geom::Box2I const &, ImageOrigin, bool, bool>(),
80 "allowUnsafe"_a =
false);
81 cls.def(py::init<ExposureT const &, bool>(),
"other"_a,
"deep"_a =
false);
82 cls.def(py::init<ExposureT const &, lsst::geom::Box2I const &, ImageOrigin, bool>(),
"other"_a,
"bbox"_a,
83 "origin"_a =
PARENT,
"deep"_a =
false);
86 cls.def(
"getMaskedImage", (MaskedImageT(ExposureT::*)()) & ExposureT::getMaskedImage);
87 cls.def(
"setMaskedImage", &ExposureT::setMaskedImage,
"maskedImage"_a);
88 cls.def_property(
"maskedImage", (MaskedImageT(ExposureT::*)()) & ExposureT::getMaskedImage,
89 &ExposureT::setMaskedImage);
90 cls.def(
"getMetadata", &ExposureT::getMetadata);
91 cls.def(
"setMetadata", &ExposureT::setMetadata,
"metadata"_a);
92 cls.def(
"getWidth", &ExposureT::getWidth);
93 cls.def(
"getHeight", &ExposureT::getHeight);
94 cls.def(
"getDimensions", &ExposureT::getDimensions);
95 cls.def(
"getX0", &ExposureT::getX0);
96 cls.def(
"getY0", &ExposureT::getY0);
97 cls.def(
"getXY0", &ExposureT::getXY0);
98 cls.def(
"setXY0", &ExposureT::setXY0,
"xy0"_a);
99 cls.def(
"getBBox", &ExposureT::getBBox,
"origin"_a =
PARENT);
101 cls.def(
"setWcs", &ExposureT::setWcs,
"wcs"_a);
102 cls.def(
"hasWcs", &ExposureT::hasWcs);
103 cls.def(
"getDetector", &ExposureT::getDetector);
104 cls.def(
"setDetector", &ExposureT::setDetector,
"detector"_a);
105 cls.def(
"getFilter", &ExposureT::getFilter);
106 cls.def(
"setFilter", &ExposureT::setFilter,
"filter"_a);
108 cls.def(
"getPhotoCalib", &ExposureT::getPhotoCalib);
109 cls.def(
"setPhotoCalib", &ExposureT::setPhotoCalib,
"photoCalib"_a);
111 cls.def(
"setPsf", &ExposureT::setPsf,
"psf"_a);
112 cls.def(
"hasPsf", &ExposureT::hasPsf);
114 cls.def(
"setInfo", &ExposureT::setInfo,
"exposureInfo"_a);
116 cls.def(
"subset", &ExposureT::subset,
"bbox"_a,
"origin"_a =
PARENT);
118 cls.def(
"writeFits", (
void (ExposureT::*)(
std::string const &)
const) & ExposureT::writeFits);
119 cls.def(
"writeFits", (
void (ExposureT::*)(fits::MemFileManager &)
const) & ExposureT::writeFits);
120 cls.def(
"writeFits", [](ExposureT &
self, fits::Fits &
fits) {
self.writeFits(
fits); });
123 [](ExposureT &
self,
std::string const &filename, fits::ImageWriteOptions
const &imageOptions,
124 fits::ImageWriteOptions
const &maskOptions, fits::ImageWriteOptions
const &varianceOptions) {
125 self.writeFits(filename, imageOptions, maskOptions, varianceOptions);
127 "filename"_a,
"imageOptions"_a,
"maskOptions"_a,
"varianceOptions"_a);
129 [](ExposureT &
self, fits::MemFileManager &manager, fits::ImageWriteOptions
const &imageOptions,
130 fits::ImageWriteOptions
const &maskOptions, fits::ImageWriteOptions
const &varianceOptions) {
131 self.writeFits(manager, imageOptions, maskOptions, varianceOptions);
133 "manager"_a,
"imageOptions"_a,
"maskOptions"_a,
"varianceOptions"_a);
135 [](ExposureT &
self, fits::Fits &
fits, fits::ImageWriteOptions
const &imageOptions,
136 fits::ImageWriteOptions
const &maskOptions, fits::ImageWriteOptions
const &varianceOptions) {
137 self.writeFits(
fits, imageOptions, maskOptions, varianceOptions);
139 "fits"_a,
"imageOptions"_a,
"maskOptions"_a,
"varianceOptions"_a);
141 cls.def_static(
"readFits", (ExposureT(*)(
std::string const &))ExposureT::readFits);
142 cls.def_static(
"readFits", (ExposureT(*)(fits::MemFileManager &))ExposureT::readFits);
144 cls.def(
"getCutout", &ExposureT::getCutout,
"center"_a,
"size"_a);
150 py::module::import(
"lsst.afw.image.exposureInfo");
151 py::module::import(
"lsst.afw.image.maskedImage");
153 auto clsExposureF = declareExposure<float>(mod,
"F");
154 auto clsExposureD = declareExposure<double>(mod,
"D");
155 declareExposure<int>(mod,
"I");
156 declareExposure<std::uint16_t>(mod,
"U");
157 declareExposure<std::uint64_t>(mod,
"L");
161 declareCastConstructor<int, float>(clsExposureF);
162 declareCastConstructor<int, double>(clsExposureD);
164 declareCastConstructor<float, double>(clsExposureD);
166 declareCastConstructor<double, float>(clsExposureF);
168 declareCastConstructor<std::uint16_t, float>(clsExposureF);
169 declareCastConstructor<std::uint16_t, double>(clsExposureD);
171 declareCastConstructor<std::uint64_t, float>(clsExposureF);
172 declareCastConstructor<std::uint64_t, double>(clsExposureD);