LSST Applications g070148d5b3+33e5256705,g0d53e28543+25c8b88941,g0da5cf3356+2dd1178308,g1081da9e2a+62d12e78cb,g17e5ecfddb+7e422d6136,g1c76d35bf8+ede3a706f7,g295839609d+225697d880,g2e2c1a68ba+cc1f6f037e,g2ffcdf413f+853cd4dcde,g38293774b4+62d12e78cb,g3b44f30a73+d953f1ac34,g48ccf36440+885b902d19,g4b2f1765b6+7dedbde6d2,g5320a0a9f6+0c5d6105b6,g56b687f8c9+ede3a706f7,g5c4744a4d9+ef6ac23297,g5ffd174ac0+0c5d6105b6,g6075d09f38+66af417445,g667d525e37+2ced63db88,g670421136f+2ced63db88,g71f27ac40c+2ced63db88,g774830318a+463cbe8d1f,g7876bc68e5+1d137996f1,g7985c39107+62d12e78cb,g7fdac2220c+0fd8241c05,g96f01af41f+368e6903a7,g9ca82378b8+2ced63db88,g9d27549199+ef6ac23297,gabe93b2c52+e3573e3735,gb065e2a02a+3dfbe639da,gbc3249ced9+0c5d6105b6,gbec6a3398f+0c5d6105b6,gc9534b9d65+35b9f25267,gd01420fc67+0c5d6105b6,geee7ff78d7+a14128c129,gf63283c776+ede3a706f7,gfed783d017+0c5d6105b6,w.2022.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"
25#include "lsst/utils/python.h"
26
33
34namespace py = pybind11;
35using namespace pybind11::literals;
36
37namespace lsst {
38namespace afw {
39namespace image {
40namespace {
41
42template <typename PixelT>
43using PyExposure = py::class_<Exposure<PixelT>, std::shared_ptr<Exposure<PixelT>>>;
44
45/*
46Declare a constructor that takes an Exposure of FromPixelT and returns an Exposure cast to ToPixelT
47
48The mask and variance must be of the standard types.
49
50@param[in] cls The pybind11 class to which add the constructor
51*/
52template <typename FromPixelT, typename ToPixelT>
53void declareCastConstructor(PyExposure<ToPixelT> &cls) {
54 cls.def(py::init<Exposure<FromPixelT> const &, bool const>(), "src"_a, "deep"_a);
55}
56
57template <typename PixelT> // only the image type varies; mask and variance are fixed to default tparams
58PyExposure<PixelT> declareExposure(lsst::utils::python::WrapperCollection &wrappers,
59 const std::string &suffix) {
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,
65 });
66 return wrappers.wrapType(
67 PyExposure<PixelT>(wrappers.module, ("Exposure" + suffix).c_str()), [](auto &mod, auto &cls) {
68 /* Constructors */
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,
79 "exposureInfo"_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,
84 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);
90
91 /* Members */
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("getFilter", &ExposureT::getFilter);
119 cls.def_property_readonly("filter", &ExposureT::getFilter);
120 cls.def("setFilter", &ExposureT::setFilter, "filterLabel"_a);
121
122 cls.def("getPhotoCalib", &ExposureT::getPhotoCalib);
123 cls.def_property_readonly("photoCalib", &ExposureT::getPhotoCalib);
124 cls.def("setPhotoCalib", &ExposureT::setPhotoCalib, "photoCalib"_a);
125 cls.def("getPsf", (std::shared_ptr<detection::Psf>(ExposureT::*)()) & ExposureT::getPsf);
126 cls.def_property_readonly(
127 "psf", (std::shared_ptr<detection::Psf>(ExposureT::*)()) & ExposureT::getPsf);
128 cls.def("setPsf", &ExposureT::setPsf, "psf"_a);
129 cls.def("hasPsf", &ExposureT::hasPsf);
130 cls.def("getInfo", (std::shared_ptr<ExposureInfo>(ExposureT::*)()) & ExposureT::getInfo);
131 cls.def_property_readonly(
132 "info", (std::shared_ptr<ExposureInfo>(ExposureT::*)()) & ExposureT::getInfo);
133 cls.def("setInfo", &ExposureT::setInfo, "exposureInfo"_a);
134
135 cls.def_property_readonly("visitInfo",
136 [](ExposureT &self) { return self.getInfo()->getVisitInfo(); });
137
138 cls.def("subset", &ExposureT::subset, "bbox"_a, "origin"_a = PARENT);
139
140 cls.def("writeFits", (void (ExposureT::*)(std::string const &) const) & ExposureT::writeFits);
141 cls.def("writeFits",
142 (void (ExposureT::*)(fits::MemFileManager &) const) & ExposureT::writeFits);
143 cls.def("writeFits", [](ExposureT &self, fits::Fits &fits) { self.writeFits(fits); });
144
145 cls.def(
146 "writeFits",
147 [](ExposureT &self, std::string const &filename,
148 fits::ImageWriteOptions const &imageOptions,
149 fits::ImageWriteOptions const &maskOptions,
150 fits::ImageWriteOptions const &varianceOptions) {
151 self.writeFits(filename, imageOptions, maskOptions, varianceOptions);
152 },
153 "filename"_a, "imageOptions"_a, "maskOptions"_a, "varianceOptions"_a);
154 cls.def(
155 "writeFits",
156 [](ExposureT &self, fits::MemFileManager &manager,
157 fits::ImageWriteOptions const &imageOptions,
158 fits::ImageWriteOptions const &maskOptions,
159 fits::ImageWriteOptions const &varianceOptions) {
160 self.writeFits(manager, imageOptions, maskOptions, varianceOptions);
161 },
162 "manager"_a, "imageOptions"_a, "maskOptions"_a, "varianceOptions"_a);
163 cls.def(
164 "writeFits",
165 [](ExposureT &self, fits::Fits &fits, fits::ImageWriteOptions const &imageOptions,
166 fits::ImageWriteOptions const &maskOptions,
167 fits::ImageWriteOptions const &varianceOptions) {
168 self.writeFits(fits, imageOptions, maskOptions, varianceOptions);
169 },
170 "fits"_a, "imageOptions"_a, "maskOptions"_a, "varianceOptions"_a);
171
172 cls.def_static("readFits", (ExposureT(*)(std::string const &))ExposureT::readFits);
173 cls.def_static("readFits", (ExposureT(*)(fits::MemFileManager &))ExposureT::readFits);
174
175 cls.def("getCutout", &ExposureT::getCutout, "center"_a, "size"_a);
176 });
177}
178} // namespace
179PYBIND11_MODULE(_exposure, mod) {
180 lsst::utils::python::WrapperCollection wrappers(mod, "lsst.afw.image.exposure");
181 wrappers.addSignatureDependency("lsst.afw.image.apCorrMap");
182 wrappers.addSignatureDependency("lsst.afw.geom");
183 wrappers.addSignatureDependency("lsst.afw.detection");
184 wrappers.addSignatureDependency("lsst.afw.image.maskedImage");
185
186 auto clsExposureF = declareExposure<float>(wrappers, "F");
187 auto clsExposureD = declareExposure<double>(wrappers, "D");
188 declareExposure<int>(wrappers, "I");
189 declareExposure<std::uint16_t>(wrappers, "U");
190 declareExposure<std::uint64_t>(wrappers, "L");
191
192 // Declare constructors for casting all exposure types to to float and double
193 // (the only two types of casts that Python supports)
194 declareCastConstructor<int, float>(clsExposureF);
195 declareCastConstructor<int, double>(clsExposureD);
196
197 declareCastConstructor<float, double>(clsExposureD);
198 declareCastConstructor<double, float>(clsExposureF);
199
200 declareCastConstructor<std::uint16_t, float>(clsExposureF);
201 declareCastConstructor<std::uint16_t, double>(clsExposureD);
202
203 declareCastConstructor<std::uint64_t, float>(clsExposureF);
204 declareCastConstructor<std::uint64_t, double>(clsExposureD);
205
206 wrappers.finish();
207}
208} // namespace image
209} // namespace afw
210} // namespace lsst
Implementation of the Photometric Calibration class.