LSST Applications  21.0.0+04719a4bac,21.0.0-1-ga51b5d4+4b710797af,21.0.0-1-gfc31b0f+3b24369756,21.0.0-10-g2408eff+50e97f2f47,21.0.0-10-g560fb7b+0803ad37c5,21.0.0-10-g5daeb2b+f9b8dc6d5a,21.0.0-10-g8d1d15d+77a6b82ebf,21.0.0-10-gcf60f90+c961be884d,21.0.0-11-g25eff31+7692554667,21.0.0-17-g6590b197+a14a01c114,21.0.0-2-g103fe59+b79afc2051,21.0.0-2-g1367e85+1003a3501c,21.0.0-2-g45278ab+04719a4bac,21.0.0-2-g5242d73+1003a3501c,21.0.0-2-g7f82c8f+c2a1919b98,21.0.0-2-g8f08a60+fd0b970de5,21.0.0-2-ga326454+c2a1919b98,21.0.0-2-gde069b7+ca45a81b40,21.0.0-2-gecfae73+afcaaec585,21.0.0-2-gfc62afb+1003a3501c,21.0.0-21-g5d80ea29e+5e3c9a3766,21.0.0-3-g357aad2+c67f36f878,21.0.0-3-g4be5c26+1003a3501c,21.0.0-3-g65f322c+02b1f88459,21.0.0-3-g7d9da8d+3b24369756,21.0.0-3-ge02ed75+a423c2ae7a,21.0.0-4-g591bb35+a423c2ae7a,21.0.0-4-g65b4814+0803ad37c5,21.0.0-4-g88306b8+199c7497e5,21.0.0-4-gccdca77+a631590478,21.0.0-4-ge8a399c+b923ff878e,21.0.0-5-gd00fb1e+d8b1e95daa,21.0.0-53-ge728e5d5+3cb64fea8e,21.0.0-6-g2d4f3f3+04719a4bac,21.0.0-7-g04766d7+8d320c19d5,21.0.0-7-g98eecf7+205433fbda,21.0.0-9-g39e06b5+a423c2ae7a,master-gac4afde19b+a423c2ae7a,w.2021.11
LSST Data Management Base Package
exposureInfo.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 
29 #include "lsst/afw/detection/Psf.h"
31 #include "lsst/afw/geom/SkyWcs.h"
35 #include "lsst/afw/image/Filter.h"
41 
42 namespace py = pybind11;
43 using namespace py::literals;
44 
45 namespace lsst {
46 namespace afw {
47 namespace image {
48 namespace {
49 
50 using PyExposureInfo = py::class_<ExposureInfo, std::shared_ptr<ExposureInfo>>;
51 
52 // Template methods where we can use pybind11's overload resolution (T is input)
53 template <class T>
54 void declareGenericMethods(PyExposureInfo &cls) {
55  using Class = PyExposureInfo::type;
56  cls.def(
57  "setComponent",
58  [](PyExposureInfo::type &self, std::string const &key, T const &object) {
59  self.setComponent(typehandling::makeKey<T>(key), object);
60  },
61  "key"_a, "object"_a);
62 }
63 // Template methods where we need to provide a unified interface (T is not input)
64 void declareGenericMethodsMerged(PyExposureInfo &cls) {
65  using typehandling::Storable;
66  using Class = PyExposureInfo::type;
67  cls.def(
68  "hasComponent",
69  [](Class const &self, std::string const &key) {
70  return self.hasComponent(typehandling::makeKey<std::shared_ptr<Storable const>>(key));
71  },
72  "key"_a);
73  cls.def(
74  "getComponent",
75  [](Class const &self, std::string const &key) -> py::object {
76  auto sharedKey = typehandling::makeKey<std::shared_ptr<Storable const>>(key);
77  // Cascading if-elses to support other types in the future
78  if (self.hasComponent(sharedKey)) {
79  return py::cast(self.getComponent(sharedKey));
80  } else {
81  return py::none();
82  }
83  },
84  "key"_a);
85  cls.def(
86  "removeComponent",
87  [](Class &self, std::string const &key) {
89  },
90  "key"_a);
91 }
92 
93 void wrapExposureInfo(lsst::utils::python::WrapperCollection &wrappers) {
94  wrappers.wrapType(PyExposureInfo(wrappers.module, "ExposureInfo"), [](auto &mod, auto &cls) {
95  /* Constructors */
96  cls.def(py::init<std::shared_ptr<geom::SkyWcs const> const &,
97  std::shared_ptr<detection::Psf const> const &,
98  std::shared_ptr<PhotoCalib const> const &,
99  std::shared_ptr<cameraGeom::Detector const> const &,
100  std::shared_ptr<geom::polygon::Polygon const> const &, Filter const &,
101  std::shared_ptr<daf::base::PropertySet> const &,
102  std::shared_ptr<CoaddInputs> const &, std::shared_ptr<ApCorrMap> const &,
103  std::shared_ptr<VisitInfo const> const &,
104  std::shared_ptr<TransmissionCurve const> const &>(),
105  "wcs"_a = std::shared_ptr<geom::SkyWcs const>(),
106  "psf"_a = std::shared_ptr<detection::Psf const>(),
107  "photoCalib"_a = std::shared_ptr<PhotoCalib const>(),
108  "detector"_a = std::shared_ptr<cameraGeom::Detector const>(),
109  "polygon"_a = std::shared_ptr<geom::polygon::Polygon const>(), "filter"_a = Filter(),
110  "metadata"_a = std::shared_ptr<daf::base::PropertySet>(),
111  "coaddInputs"_a = std::shared_ptr<CoaddInputs>(),
112  "apCorrMap"_a = std::shared_ptr<ApCorrMap>(),
113  "visitInfo"_a = std::shared_ptr<VisitInfo const>(), "transmissionCurve"_a = nullptr);
114  cls.def(py::init<>());
115  cls.def(py::init<ExposureInfo>(), "other"_a);
116  cls.def(py::init<ExposureInfo, bool>(), "other"_a, "copyMetadata"_a);
117 
118  /* Members */
119  cls.attr("KEY_WCS") = ExposureInfo::KEY_WCS.getId();
120  cls.def("hasWcs", &ExposureInfo::hasWcs);
121  cls.def("getWcs", (std::shared_ptr<geom::SkyWcs>(ExposureInfo::*)()) & ExposureInfo::getWcs);
122  cls.def("setWcs", &ExposureInfo::setWcs, "wcs"_a);
123 
124  cls.attr("KEY_DETECTOR") = ExposureInfo::KEY_DETECTOR.getId();
125  cls.def("hasDetector", &ExposureInfo::hasDetector);
126  cls.def("getDetector", &ExposureInfo::getDetector);
127  cls.def(
128  "setDetector",
129  [](ExposureInfo &self, py::object detector) {
130  if (detector.is(py::none())) {
131  self.setDetector(nullptr);
132  } else {
133  self.setDetector(py::cast<std::shared_ptr<afw::cameraGeom::Detector>>(detector));
134  }
135  },
136  "detector"_a);
137 
138  cls.def("getFilter", &ExposureInfo::getFilter);
139  cls.def("setFilter", &ExposureInfo::setFilter, "filter"_a);
140 
141  cls.attr("KEY_FILTER") = ExposureInfo::KEY_FILTER.getId();
142  cls.def("hasFilterLabel", &ExposureInfo::hasFilterLabel);
143  cls.def("getFilterLabel", &ExposureInfo::getFilterLabel);
144  cls.def("setFilterLabel", &ExposureInfo::setFilterLabel, "filterLabel"_a);
145 
146  declareGenericMethods<std::shared_ptr<typehandling::Storable const>>(cls);
147  declareGenericMethodsMerged(cls);
148 
149  cls.attr("KEY_PHOTO_CALIB") = ExposureInfo::KEY_PHOTO_CALIB.getId();
150  cls.def("hasPhotoCalib", &ExposureInfo::hasPhotoCalib);
151  cls.def("getPhotoCalib", &ExposureInfo::getPhotoCalib);
152  cls.def("setPhotoCalib", &ExposureInfo::setPhotoCalib, "photoCalib"_a);
153 
154  cls.def("getMetadata", &ExposureInfo::getMetadata);
155  cls.def("setMetadata", &ExposureInfo::setMetadata, "metadata"_a);
156 
157  cls.attr("KEY_PSF") = ExposureInfo::KEY_PSF.getId();
158  cls.def("hasPsf", &ExposureInfo::hasPsf);
159  cls.def("getPsf", &ExposureInfo::getPsf);
160  cls.def(
161  "setPsf",
162  [](ExposureInfo &self, py::object psf) {
163  if (psf.is(py::none())) {
164  self.setPsf(nullptr);
165  } else {
166  self.setPsf(py::cast<std::shared_ptr<afw::detection::Psf>>(psf));
167  }
168  },
169  "psf"_a);
170 
171  cls.attr("KEY_VALID_POLYGON") = ExposureInfo::KEY_VALID_POLYGON.getId();
172  cls.def("hasValidPolygon", &ExposureInfo::hasValidPolygon);
173  cls.def("getValidPolygon", &ExposureInfo::getValidPolygon);
174  cls.def(
175  "setValidPolygon",
176  [](ExposureInfo &self, py::object polygon) {
177  if (polygon.is(py::none())) {
178  self.setValidPolygon(nullptr);
179  } else {
180  self.setValidPolygon(py::cast<std::shared_ptr<afw::geom::polygon::Polygon>>(polygon));
181  }
182  },
183  "polygon"_a);
184 
185  cls.attr("KEY_AP_CORR_MAP") = ExposureInfo::KEY_AP_CORR_MAP.getId();
186  cls.def("hasApCorrMap", &ExposureInfo::hasApCorrMap);
187  cls.def("getApCorrMap", (std::shared_ptr<ApCorrMap>(ExposureInfo::*)()) & ExposureInfo::getApCorrMap);
188  cls.def("setApCorrMap", &ExposureInfo::setApCorrMap, "apCorrMap"_a);
189  cls.def("initApCorrMap", &ExposureInfo::initApCorrMap);
190 
191  cls.attr("KEY_COADD_INPUTS") = ExposureInfo::KEY_COADD_INPUTS.getId();
192  cls.def("hasCoaddInputs", &ExposureInfo::hasCoaddInputs);
193  cls.def("getCoaddInputs", &ExposureInfo::getCoaddInputs);
194  cls.def("setCoaddInputs", &ExposureInfo::setCoaddInputs, "coaddInputs"_a);
195 
196  cls.def("hasVisitInfo", &ExposureInfo::hasVisitInfo);
197  cls.def("getVisitInfo", &ExposureInfo::getVisitInfo);
198  cls.def("setVisitInfo", &ExposureInfo::setVisitInfo, "visitInfo"_a);
199 
200  cls.attr("KEY_TRANSMISSION_CURVE") = ExposureInfo::KEY_TRANSMISSION_CURVE.getId();
201  cls.def("hasTransmissionCurve", &ExposureInfo::hasTransmissionCurve);
202  cls.def("getTransmissionCurve", &ExposureInfo::getTransmissionCurve);
203  cls.def("setTransmissionCurve", &ExposureInfo::setTransmissionCurve, "transmissionCurve"_a);
204  });
205 }
206 PYBIND11_MODULE(exposureInfo, mod) {
207  lsst::utils::python::WrapperCollection wrappers(mod, "lsst.afw.image.exposureInfo");
208  wrappers.addSignatureDependency("lsst.daf.base");
209  wrappers.addSignatureDependency("lsst.afw.geom");
210  wrappers.addSignatureDependency("lsst.afw.cameraGeom.detector");
211  wrappers.addSignatureDependency("lsst.afw.detection"); // For Psf
212  wrappers.addSignatureDependency("lsst.afw.image.photoCalib");
213  wrappers.addSignatureDependency("lsst.afw.image.apCorrMap");
214  wrappers.addSignatureDependency("lsst.afw.image.coaddInputs");
215  wrappers.addSignatureDependency("lsst.afw.image.filter");
216  wrappers.addSignatureDependency("lsst.afw.image.filterLabel");
217  wrappers.addSignatureDependency("lsst.afw.image.visitInfo");
218  wrapExposureInfo(wrappers);
219  wrappers.finish();
220 }
221 } // namespace
222 } // namespace image
223 } // namespace afw
224 } // namespace lsst
Implementation of the Photometric Calibration class.
Key< U > key
Definition: Schema.cc:281
A helper class for subdividing pybind11 module across multiple translation units (i....
Definition: python.h:242
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
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
void addSignatureDependency(std::string const &name)
Indicate an external module that provides a type used in function/method signatures.
Definition: python.h:357
PYBIND11_MODULE(imageUtils, mod)
Definition: imageUtils.cc:33
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
constexpr Key< K, V > makeKey(K const &id)
Factory function for Key, to enable type parameter inference.
Definition: Key.h:173
A base class for image defects.
table::Key< int > type
Definition: Detector.cc:163
Key< int > psf
Definition: Exposure.cc:65