24#include "pybind11/pybind11.h"
35using namespace pybind11::literals;
42template <
typename PixelT>
52template <
typename FromPixelT,
typename ToPixelT>
53void declareCastConstructor(PyExposure<ToPixelT> &cls) {
54 cls.def(py::init<Exposure<FromPixelT>
const &,
bool const>(),
"src"_a,
"deep"_a);
57template <
typename PixelT>
58PyExposure<PixelT> declareExposure(lsst::utils::python::WrapperCollection &wrappers,
60 using ExposureT = Exposure<PixelT>;
61 using MaskedImageT =
typename ExposureT::MaskedImageT;
62 wrappers.wrap([](
auto &mod) {
63 mod.def(
"makeExposure", &makeExposure<PixelT, MaskPixel, VariancePixel>,
"maskedImage"_a,
66 return wrappers.wrapType(
67 PyExposure<PixelT>(wrappers.module, (
"Exposure" + suffix).c_str()), [](
auto &mod,
auto &cls) {
69 cls.def(py::init<unsigned int, unsigned int, std::shared_ptr<geom::SkyWcs const>>(),
70 "width"_a,
"height"_a,
"wcs"_a = std::shared_ptr<geom::SkyWcs const>());
71 cls.def(py::init<lsst::geom::Extent2I const &, std::shared_ptr<geom::SkyWcs const>>(),
72 "dimensions"_a = lsst::geom::Extent2I(),
73 "wcs"_a = std::shared_ptr<geom::SkyWcs const>());
74 cls.def(py::init<lsst::geom::Box2I const &, std::shared_ptr<geom::SkyWcs const>>(),
"bbox"_a,
75 "wcs"_a = std::shared_ptr<geom::SkyWcs const>());
76 cls.def(py::init<MaskedImageT &, std::shared_ptr<geom::SkyWcs const>>(),
"maskedImage"_a,
77 "wcs"_a = std::shared_ptr<geom::SkyWcs const>());
78 cls.def(py::init<MaskedImageT &, std::shared_ptr<ExposureInfo>>(),
"maskedImage"_a,
80 cls.def(py::init<std::string const &, lsst::geom::Box2I const &, ImageOrigin, bool, bool>(),
81 "fileName"_a,
"bbox"_a = lsst::geom::Box2I(),
"origin"_a = PARENT,
82 "conformMasks"_a = false,
"allowUnsafe"_a = false);
83 cls.def(py::init<fits::MemFileManager &, lsst::geom::Box2I const &, ImageOrigin, bool,
85 "manager"_a,
"bbox"_a = lsst::geom::Box2I(),
"origin"_a = PARENT,
86 "conformMasks"_a = false,
"allowUnsafe"_a = false);
87 cls.def(py::init<ExposureT const &, bool>(),
"other"_a,
"deep"_a = false);
88 cls.def(py::init<ExposureT const &, lsst::geom::Box2I const &, ImageOrigin, bool>(),
89 "other"_a,
"bbox"_a,
"origin"_a = PARENT,
"deep"_a = false);
92 cls.def(
"getMaskedImage", (MaskedImageT(ExposureT::*)()) & ExposureT::getMaskedImage);
93 cls.def(
"setMaskedImage", &ExposureT::setMaskedImage,
"maskedImage"_a);
94 cls.def_property(
"maskedImage", (MaskedImageT(ExposureT::*)()) & ExposureT::getMaskedImage,
95 &ExposureT::setMaskedImage);
96 cls.def(
"getMetadata", &ExposureT::getMetadata);
97 cls.def(
"setMetadata", &ExposureT::setMetadata,
"metadata"_a);
98 cls.def(
"getWidth", &ExposureT::getWidth);
99 cls.def(
"getHeight", &ExposureT::getHeight);
100 cls.def_property_readonly(
"width", &ExposureT::getWidth);
101 cls.def_property_readonly(
"height", &ExposureT::getHeight);
102 cls.def(
"getDimensions", &ExposureT::getDimensions);
103 cls.def(
"getX0", &ExposureT::getX0);
104 cls.def(
"getY0", &ExposureT::getY0);
105 cls.def_property_readonly(
"x0", &ExposureT::getX0);
106 cls.def_property_readonly(
"y0", &ExposureT::getY0);
107 cls.def(
"getXY0", &ExposureT::getXY0);
108 cls.def(
"setXY0", &ExposureT::setXY0,
"xy0"_a);
109 cls.def(
"getBBox", &ExposureT::getBBox,
"origin"_a = PARENT);
110 cls.def(
"getWcs", (std::shared_ptr<geom::SkyWcs>(ExposureT::*)()) & ExposureT::getWcs);
111 cls.def_property_readonly(
112 "wcs", (std::shared_ptr<geom::SkyWcs>(ExposureT::*)()) & ExposureT::getWcs);
113 cls.def(
"setWcs", &ExposureT::setWcs,
"wcs"_a);
114 cls.def(
"hasWcs", &ExposureT::hasWcs);
115 cls.def(
"getDetector", &ExposureT::getDetector);
116 cls.def_property_readonly(
"detector", &ExposureT::getDetector);
117 cls.def(
"setDetector", &ExposureT::setDetector,
"detector"_a);
118 cls.def(
"getFilterLabel", &ExposureT::getFilterLabel);
119 cls.def_property_readonly(
"filterLabel", &ExposureT::getFilterLabel);
120 cls.def(
"setFilterLabel", &ExposureT::setFilterLabel,
"filterLabel"_a);
121 cls.def(
"getFilter", &ExposureT::getFilter);
122 cls.def_property_readonly(
"filter", &ExposureT::getFilter);
123 cls.def(
"setFilter", &ExposureT::setFilter,
"filterLabel"_a);
125 cls.def(
"getPhotoCalib", &ExposureT::getPhotoCalib);
126 cls.def_property_readonly(
"photoCalib", &ExposureT::getPhotoCalib);
127 cls.def(
"setPhotoCalib", &ExposureT::setPhotoCalib,
"photoCalib"_a);
128 cls.def(
"getPsf", (std::shared_ptr<detection::Psf>(ExposureT::*)()) & ExposureT::getPsf);
129 cls.def_property_readonly(
130 "psf", (std::shared_ptr<detection::Psf>(ExposureT::*)()) & ExposureT::getPsf);
131 cls.def(
"setPsf", &ExposureT::setPsf,
"psf"_a);
132 cls.def(
"hasPsf", &ExposureT::hasPsf);
133 cls.def(
"getInfo", (std::shared_ptr<ExposureInfo>(ExposureT::*)()) & ExposureT::getInfo);
134 cls.def_property_readonly(
135 "info", (std::shared_ptr<ExposureInfo>(ExposureT::*)()) & ExposureT::getInfo);
136 cls.def(
"setInfo", &ExposureT::setInfo,
"exposureInfo"_a);
138 cls.def_property_readonly(
"visitInfo",
139 [](ExposureT &self) { return self.getInfo()->getVisitInfo(); });
141 cls.def(
"subset", &ExposureT::subset,
"bbox"_a,
"origin"_a =
PARENT);
146 cls.def(
"writeFits", [](ExposureT &
self, fits::Fits &
fits) {
self.writeFits(
fits); });
151 fits::ImageWriteOptions
const &imageOptions,
152 fits::ImageWriteOptions
const &maskOptions,
153 fits::ImageWriteOptions
const &varianceOptions) {
154 self.writeFits(filename, imageOptions, maskOptions, varianceOptions);
156 "filename"_a,
"imageOptions"_a,
"maskOptions"_a,
"varianceOptions"_a);
159 [](ExposureT &
self, fits::MemFileManager &manager,
160 fits::ImageWriteOptions
const &imageOptions,
161 fits::ImageWriteOptions
const &maskOptions,
162 fits::ImageWriteOptions
const &varianceOptions) {
163 self.writeFits(manager, imageOptions, maskOptions, varianceOptions);
165 "manager"_a,
"imageOptions"_a,
"maskOptions"_a,
"varianceOptions"_a);
168 [](ExposureT &
self, fits::Fits &
fits, fits::ImageWriteOptions
const &imageOptions,
169 fits::ImageWriteOptions
const &maskOptions,
170 fits::ImageWriteOptions
const &varianceOptions) {
171 self.writeFits(
fits, imageOptions, maskOptions, varianceOptions);
173 "fits"_a,
"imageOptions"_a,
"maskOptions"_a,
"varianceOptions"_a);
175 cls.def_static(
"readFits", (ExposureT(*)(
std::string const &))ExposureT::readFits);
176 cls.def_static(
"readFits", (ExposureT(*)(fits::MemFileManager &))ExposureT::readFits);
178 cls.def(
"getCutout", &ExposureT::getCutout,
"center"_a,
"size"_a);
183 lsst::utils::python::WrapperCollection wrappers(mod,
"lsst.afw.image.exposure");
184 wrappers.addSignatureDependency(
"lsst.afw.image.apCorrMap");
185 wrappers.addSignatureDependency(
"lsst.afw.geom");
186 wrappers.addSignatureDependency(
"lsst.afw.detection");
187 wrappers.addSignatureDependency(
"lsst.afw.image.maskedImage");
189 auto clsExposureF = declareExposure<float>(wrappers,
"F");
190 auto clsExposureD = declareExposure<double>(wrappers,
"D");
191 declareExposure<int>(wrappers,
"I");
192 declareExposure<std::uint16_t>(wrappers,
"U");
193 declareExposure<std::uint64_t>(wrappers,
"L");
197 declareCastConstructor<int, float>(clsExposureF);
198 declareCastConstructor<int, double>(clsExposureD);
200 declareCastConstructor<float, double>(clsExposureD);
201 declareCastConstructor<double, float>(clsExposureF);
203 declareCastConstructor<std::uint16_t, float>(clsExposureF);
204 declareCastConstructor<std::uint16_t, double>(clsExposureD);
206 declareCastConstructor<std::uint64_t, float>(clsExposureF);
207 declareCastConstructor<std::uint64_t, double>(clsExposureD);
Implementation of the Photometric Calibration class.
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
PYBIND11_MODULE(_exposure, mod)
def writeFits(filename, stamps, metadata, type_name, write_mask, write_variance, write_archive=False)
A base class for image defects.