LSST Applications g00d0e8bbd7+edbf708997,g03191d30f7+9ce8016dbd,g1955dfad08+0bd186d245,g199a45376c+5137f08352,g1fd858c14a+a888a50aa2,g262e1987ae+45f9aba685,g29ae962dfc+1c7d47a24f,g2cef7863aa+73c82f25e4,g35bb328faa+edbf708997,g3fd5ace14f+eed17d2c67,g47891489e3+6dc8069a4c,g53246c7159+edbf708997,g64539dfbff+c4107e45b5,g67b6fd64d1+6dc8069a4c,g74acd417e5+f452e9c21a,g786e29fd12+af89c03590,g7ae74a0b1c+a25e60b391,g7aefaa3e3d+2025e9ce17,g7cc15d900a+2d158402f9,g87389fa792+a4172ec7da,g89139ef638+6dc8069a4c,g8d4809ba88+c4107e45b5,g8d7436a09f+e96c132b44,g8ea07a8fe4+db21c37724,g98df359435+aae6d409c1,ga2180abaac+edbf708997,gac66b60396+966efe6077,gb632fb1845+88945a90f8,gbaa8f7a6c5+38b34f4976,gbf99507273+edbf708997,gca7fc764a6+6dc8069a4c,gd7ef33dd92+6dc8069a4c,gda68eeecaf+7d1e613a8d,gdab6d2f7ff+f452e9c21a,gdbb4c4dda9+c4107e45b5,ge410e46f29+6dc8069a4c,ge41e95a9f2+c4107e45b5,geaed405ab2+e194be0d2b,w.2025.47
LSST Data Management Base Package
Loading...
Searching...
No Matches
_exposure.cc
Go to the documentation of this file.
1/*
2 * This file is part of afw.
3 *
4 * Developed for the LSST Data Management System.
5 * This product includes software developed by the LSST Project
6 * (https://www.lsst.org).
7 * See the COPYRIGHT file at the top-level directory of this distribution
8 * for details of code ownership.
9 *
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24#include "pybind11/pybind11.h"
26
34
35namespace py = pybind11;
36using namespace pybind11::literals;
37
38namespace lsst {
39namespace afw {
40namespace image {
41namespace {
42
43template <typename PixelT>
44using PyExposure = py::classh<Exposure<PixelT>>;
45
46/*
47Declare a constructor that takes an Exposure of FromPixelT and returns an Exposure cast to ToPixelT
48
49The mask and variance must be of the standard types.
50
51@param[in] cls The pybind11 class to which add the constructor
52*/
53template <typename FromPixelT, typename ToPixelT>
54void declareCastConstructor(PyExposure<ToPixelT> &cls) {
55 cls.def(py::init<Exposure<FromPixelT> const &, bool const>(), "src"_a, "deep"_a);
56}
57
58template <typename PixelT> // only the image type varies; mask and variance are fixed to default tparams
59PyExposure<PixelT> declareExposure(lsst::cpputils::python::WrapperCollection &wrappers,
60 const std::string &suffix) {
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,
65 "wcs"_a = std::shared_ptr<geom::SkyWcs const>());
66 });
67 return wrappers.wrapType(
68 PyExposure<PixelT>(wrappers.module, ("Exposure" + suffix).c_str()), [](auto &mod, auto &cls) {
69 /* Constructors */
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,
80 "exposureInfo"_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,
85 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);
91
92 /* Members */
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_property("metadata", &ExposureT::getMetadata, &ExposureT::setMetadata);
100 cls.def("getWidth", &ExposureT::getWidth);
101 cls.def("getHeight", &ExposureT::getHeight);
102 cls.def_property_readonly("width", &ExposureT::getWidth);
103 cls.def_property_readonly("height", &ExposureT::getHeight);
104 cls.def("getDimensions", &ExposureT::getDimensions);
105 cls.def("getX0", &ExposureT::getX0);
106 cls.def("getY0", &ExposureT::getY0);
107 cls.def_property_readonly("x0", &ExposureT::getX0);
108 cls.def_property_readonly("y0", &ExposureT::getY0);
109 cls.def("getXY0", &ExposureT::getXY0);
110 cls.def("setXY0", &ExposureT::setXY0, "xy0"_a);
111 cls.def("getBBox", &ExposureT::getBBox, "origin"_a = PARENT);
112 cls.def("getWcs", (std::shared_ptr<geom::SkyWcs>(ExposureT::*)()) & ExposureT::getWcs);
113 cls.def_property_readonly(
114 "wcs", (std::shared_ptr<geom::SkyWcs>(ExposureT::*)()) & ExposureT::getWcs);
115 cls.def("setWcs", &ExposureT::setWcs, "wcs"_a);
116 cls.def("hasWcs", &ExposureT::hasWcs);
117 cls.def("getDetector", &ExposureT::getDetector);
118 cls.def_property_readonly("detector", &ExposureT::getDetector);
119 cls.def("setDetector", &ExposureT::setDetector, "detector"_a);
120 cls.def("getFilter", &ExposureT::getFilter);
121 cls.def_property_readonly("filter", &ExposureT::getFilter);
122 cls.def("setFilter", &ExposureT::setFilter, "filterLabel"_a);
123
124 cls.def("getPhotoCalib", &ExposureT::getPhotoCalib);
125 cls.def_property_readonly("photoCalib", &ExposureT::getPhotoCalib);
126 cls.def("setPhotoCalib", &ExposureT::setPhotoCalib, "photoCalib"_a);
127 cls.def("getPsf", (std::shared_ptr<detection::Psf>(ExposureT::*)()) & ExposureT::getPsf);
128 cls.def_property_readonly(
129 "psf", (std::shared_ptr<detection::Psf>(ExposureT::*)()) & ExposureT::getPsf);
130 cls.def("setPsf", &ExposureT::setPsf, "psf"_a);
131 cls.def("hasPsf", &ExposureT::hasPsf);
132 cls.def("getInfo", (std::shared_ptr<ExposureInfo>(ExposureT::*)()) & ExposureT::getInfo);
133 cls.def_property_readonly(
134 "info", (std::shared_ptr<ExposureInfo>(ExposureT::*)()) & ExposureT::getInfo);
135 cls.def("setInfo", &ExposureT::setInfo, "exposureInfo"_a);
136
137 cls.def_property_readonly("visitInfo",
138 [](ExposureT &self) { return self.getInfo()->getVisitInfo(); });
139
140 cls.def("setApCorrMap", &ExposureT::setApCorrMap, "apCorrMap"_a);
141 cls.def_property_readonly("apCorrMap", [](ExposureT &self) { return self.getApCorrMap(); });
142
143 cls.def("subset", &ExposureT::subset, "bbox"_a, "origin"_a = PARENT);
144
145 cls.def(
146 "writeFits",
147 [](ExposureT &self, std::string const &filename,
148 fits::CompressionOptions const *imageOptions,
149 fits::CompressionOptions const *maskOptions,
150 fits::CompressionOptions const *varianceOptions) {
151 self.writeFits(filename, imageOptions, maskOptions, varianceOptions);
152 },
153 "filename"_a, "imageOptions"_a=py::none(),
154 "maskOptions"_a=py::none(), "varianceOptions"_a=py::none());
155 cls.def(
156 "writeFits",
157 [](ExposureT &self, fits::MemFileManager &manager,
158 fits::CompressionOptions const *imageOptions,
159 fits::CompressionOptions const *maskOptions,
160 fits::CompressionOptions const *varianceOptions) {
161 self.writeFits(manager, imageOptions, maskOptions, varianceOptions);
162 },
163 "manager"_a, "imageOptions"_a=py::none(),
164 "maskOptions"_a=py::none(), "varianceOptions"_a=py::none());
165 cls.def(
166 "writeFits",
167 [](ExposureT &self, fits::Fits &fits, fits::CompressionOptions const *imageOptions,
168 fits::CompressionOptions const *maskOptions,
169 fits::CompressionOptions const *varianceOptions) {
170 self.writeFits(fits, imageOptions, maskOptions, varianceOptions);
171 },
172 "fits"_a, "imageOptions"_a=py::none(),
173 "maskOptions"_a=py::none(), "varianceOptions"_a=py::none());
174
175 cls.def_static("readFits", (ExposureT(*)(std::string const &))ExposureT::readFits);
176 cls.def_static("readFits", (ExposureT(*)(fits::MemFileManager &))ExposureT::readFits);
177
178 cls.def("getCutout",
179 py::overload_cast<lsst::geom::SpherePoint const &, lsst::geom::Extent2I const &>(
180 &ExposureT::getCutout, py::const_),
181 "center"_a, "size"_a);
182 cls.def("getCutout",
183 py::overload_cast<lsst::geom::Point2D const &, lsst::geom::Extent2I const &>(
184 &ExposureT::getCutout, py::const_),
185 "center"_a, "size"_a);
186 cls.def("getCutout",
187 py::overload_cast<lsst::geom::Box2I const &>(&ExposureT::getCutout, py::const_),
188 "box"_a);
189 });
190}
191} // namespace
193 lsst::cpputils::python::WrapperCollection wrappers(mod, "lsst.afw.image._exposure");
194 wrappers.addSignatureDependency("lsst.afw.image._apCorrMap");
195 wrappers.addSignatureDependency("lsst.afw.geom");
196 wrappers.addSignatureDependency("lsst.afw.detection");
197 wrappers.addSignatureDependency("lsst.afw.image._maskedImage");
198
199 auto clsExposureF = declareExposure<float>(wrappers, "F");
200 auto clsExposureD = declareExposure<double>(wrappers, "D");
201 declareExposure<int>(wrappers, "I");
202 declareExposure<std::uint16_t>(wrappers, "U");
203 declareExposure<std::uint64_t>(wrappers, "L");
204
205 // Declare constructors for casting all exposure types to to float and double
206 // (the only two types of casts that Python supports)
207 declareCastConstructor<int, float>(clsExposureF);
208 declareCastConstructor<int, double>(clsExposureD);
209
210 declareCastConstructor<float, double>(clsExposureD);
211 declareCastConstructor<double, float>(clsExposureF);
212
213 declareCastConstructor<std::uint16_t, float>(clsExposureF);
214 declareCastConstructor<std::uint16_t, double>(clsExposureD);
215
216 declareCastConstructor<std::uint64_t, float>(clsExposureF);
217 declareCastConstructor<std::uint64_t, double>(clsExposureD);
218
219 wrappers.finish();
220}
221} // namespace image
222} // namespace afw
223} // namespace lsst
Implementation of the Photometric Calibration class.
A class to contain the data, WCS, and other information needed to describe an image of the sky.
Definition Exposure.h:72
A helper class for subdividing pybind11 module across multiple translation units (i....
Definition python.h:242
void addSignatureDependency(std::string const &name)
Indicate an external module that provides a type used in function/method signatures.
Definition python.h:357
void wrap(WrapperCallback function)
Add a set of wrappers without defining a class.
Definition python.h:369
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...
Definition python.h:391
pybind11::module module
The module object passed to the PYBIND11_MODULE block that contains this WrapperCollection.
Definition python.h:448
void finish()
Invoke all deferred wrapper-declaring callables.
Definition python.h:435
PYBIND11_MODULE(_gauss2d, m)
Definition pybind11.cc:31
std::shared_ptr< Exposure< ImagePixelT, MaskPixelT, VariancePixelT > > makeExposure(MaskedImage< ImagePixelT, MaskPixelT, VariancePixelT > &mimage, std::shared_ptr< geom::SkyWcs const > wcs=std::shared_ptr< geom::SkyWcs const >())
A function to return an Exposure of the correct type (cf.
Definition Exposure.h:459