LSSTApplications  20.0.0
LSSTDataManagementBasePackage
exposureInfo.cc
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 2008-2017 AURA/LSST.
4  *
5  * This product includes software developed by the
6  * LSST Project (http://www.lsst.org/).
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the LSST License Statement and
19  * the GNU General Public License along with this program. If not,
20  * see <https://www.lsstcorp.org/LegalNotices/>.
21  */
22 
23 #include "pybind11/pybind11.h"
24 
27 #include "lsst/afw/detection/Psf.h"
29 #include "lsst/afw/geom/SkyWcs.h"
33 #include "lsst/afw/image/Filter.h"
38 
39 namespace py = pybind11;
40 using namespace py::literals;
41 
42 namespace lsst {
43 namespace afw {
44 namespace image {
45 namespace {
46 
47 using PyExposureInfo = py::class_<ExposureInfo, std::shared_ptr<ExposureInfo>>;
48 
49 // Template methods where we can use pybind11's overload resolution (T is input)
50 template <class T>
51 void declareGenericMethods(PyExposureInfo &cls) {
52  using Class = PyExposureInfo::type;
53  cls.def("setComponent",
54  [](PyExposureInfo::type &self, std::string const &key, T const &object) {
55  self.setComponent(typehandling::makeKey<T>(key), object);
56  },
57  "key"_a, "object"_a);
58 }
59 // Template methods where we need to provide a unified interface (T is not input)
60 void declareGenericMethodsMerged(PyExposureInfo &cls) {
61  using typehandling::Storable;
62  using Class = PyExposureInfo::type;
63  cls.def("hasComponent",
64  [](Class const &self, std::string const &key) {
65  return self.hasComponent(typehandling::makeKey<std::shared_ptr<Storable const>>(key));
66  },
67  "key"_a);
68  cls.def("getComponent",
69  [](Class const &self, std::string const &key) -> py::object {
70  auto sharedKey = typehandling::makeKey<std::shared_ptr<Storable const>>(key);
71  // Cascading if-elses to support other types in the future
72  if (self.hasComponent(sharedKey)) {
73  return py::cast(self.getComponent(sharedKey));
74  } else {
75  return py::none();
76  }
77  },
78  "key"_a);
79  cls.def("removeComponent",
80  [](Class &self, std::string const &key) {
82  },
83  "key"_a);
84 }
85 
86 PYBIND11_MODULE(exposureInfo, mod) {
87  py::module::import("lsst.daf.base");
88  py::module::import("lsst.afw.geom.skyWcs");
89  py::module::import("lsst.afw.cameraGeom.detector");
90  py::module::import("lsst.afw.detection"); // For Psf
91  py::module::import("lsst.afw.image.photoCalib");
92  py::module::import("lsst.afw.image.apCorrMap");
93  py::module::import("lsst.afw.image.coaddInputs");
94  py::module::import("lsst.afw.image.filter");
95  py::module::import("lsst.afw.image.visitInfo");
96 
97  /* Module level */
98  PyExposureInfo cls(mod, "ExposureInfo");
99 
100  /* Member types and enums */
101 
102  /* Constructors */
106  std::shared_ptr<geom::polygon::Polygon const> const &, Filter const &,
112  "photoCalib"_a = std::shared_ptr<PhotoCalib const>(),
114  "polygon"_a = std::shared_ptr<geom::polygon::Polygon const>(), "filter"_a = Filter(),
116  "coaddInputs"_a = std::shared_ptr<CoaddInputs>(), "apCorrMap"_a = std::shared_ptr<ApCorrMap>(),
117  "visitInfo"_a = std::shared_ptr<VisitInfo const>(), "transmissionCurve"_a = nullptr);
118  cls.def(py::init<>());
119  cls.def(py::init<ExposureInfo>(), "other"_a);
120  cls.def(py::init<ExposureInfo, bool>(), "other"_a, "copyMetadata"_a);
121 
122  /* Members */
123  cls.attr("KEY_WCS") = ExposureInfo::KEY_WCS.getId();
124  cls.def("hasWcs", &ExposureInfo::hasWcs);
125  cls.def("getWcs", (std::shared_ptr<geom::SkyWcs>(ExposureInfo::*)()) & ExposureInfo::getWcs);
126  cls.def("setWcs", &ExposureInfo::setWcs, "wcs"_a);
127 
128  cls.attr("KEY_DETECTOR") = ExposureInfo::KEY_DETECTOR.getId();
129  cls.def("hasDetector", &ExposureInfo::hasDetector);
130  cls.def("getDetector", &ExposureInfo::getDetector);
131  cls.def("setDetector",
132  [](ExposureInfo &self, py::object detector) {
133  if (detector.is(py::none())) {
134  self.setDetector(nullptr);
135  } else {
136  self.setDetector(py::cast<std::shared_ptr<afw::cameraGeom::Detector>>(detector));
137  }
138  },
139  "detector"_a);
140 
141  cls.def("getFilter", &ExposureInfo::getFilter);
142  cls.def("setFilter", &ExposureInfo::setFilter, "filter"_a);
143 
144  declareGenericMethods<std::shared_ptr<typehandling::Storable const>>(cls);
145  declareGenericMethodsMerged(cls);
146 
147  cls.attr("KEY_PHOTO_CALIB") = ExposureInfo::KEY_PHOTO_CALIB.getId();
148  cls.def("hasPhotoCalib", &ExposureInfo::hasPhotoCalib);
149  cls.def("getPhotoCalib", &ExposureInfo::getPhotoCalib);
150  cls.def("setPhotoCalib", &ExposureInfo::setPhotoCalib, "photoCalib"_a);
151 
152  cls.def("getMetadata", &ExposureInfo::getMetadata);
153  cls.def("setMetadata", &ExposureInfo::setMetadata, "metadata"_a);
154 
155  cls.attr("KEY_PSF") = ExposureInfo::KEY_PSF.getId();
156  cls.def("hasPsf", &ExposureInfo::hasPsf);
157  cls.def("getPsf", &ExposureInfo::getPsf);
158  cls.def("setPsf",
159  [](ExposureInfo &self, py::object psf) {
160  if (psf.is(py::none())) {
161  self.setPsf(nullptr);
162  } else {
163  self.setPsf(py::cast<std::shared_ptr<afw::detection::Psf>>(psf));
164  }
165  },
166  "psf"_a);
167 
168  cls.attr("KEY_VALID_POLYGON") = ExposureInfo::KEY_VALID_POLYGON.getId();
169  cls.def("hasValidPolygon", &ExposureInfo::hasValidPolygon);
170  cls.def("getValidPolygon", &ExposureInfo::getValidPolygon);
171  cls.def("setValidPolygon",
172  [](ExposureInfo &self, py::object polygon) {
173  if (polygon.is(py::none())) {
174  self.setValidPolygon(nullptr);
175  } else {
176  self.setValidPolygon(py::cast<std::shared_ptr<afw::geom::polygon::Polygon>>(polygon));
177  }
178  },
179  "polygon"_a);
180 
181  cls.attr("KEY_AP_CORR_MAP") = ExposureInfo::KEY_AP_CORR_MAP.getId();
182  cls.def("hasApCorrMap", &ExposureInfo::hasApCorrMap);
183  cls.def("getApCorrMap", (std::shared_ptr<ApCorrMap>(ExposureInfo::*)()) & ExposureInfo::getApCorrMap);
184  cls.def("setApCorrMap", &ExposureInfo::setApCorrMap, "apCorrMap"_a);
185  cls.def("initApCorrMap", &ExposureInfo::initApCorrMap);
186 
187  cls.attr("KEY_COADD_INPUTS") = ExposureInfo::KEY_COADD_INPUTS.getId();
188  cls.def("hasCoaddInputs", &ExposureInfo::hasCoaddInputs);
189  cls.def("getCoaddInputs", &ExposureInfo::getCoaddInputs);
190  cls.def("setCoaddInputs", &ExposureInfo::setCoaddInputs, "coaddInputs"_a);
191 
192  cls.def("hasVisitInfo", &ExposureInfo::hasVisitInfo);
193  cls.def("getVisitInfo", &ExposureInfo::getVisitInfo);
194  cls.def("setVisitInfo", &ExposureInfo::setVisitInfo, "visitInfo"_a);
195 
196  cls.attr("KEY_TRANSMISSION_CURVE") = ExposureInfo::KEY_TRANSMISSION_CURVE.getId();
197  cls.def("hasTransmissionCurve", &ExposureInfo::hasTransmissionCurve);
198  cls.def("getTransmissionCurve", &ExposureInfo::getTransmissionCurve);
199  cls.def("setTransmissionCurve", &ExposureInfo::setTransmissionCurve, "transmissionCurve"_a);
200 }
201 } // namespace
202 } // namespace image
203 } // namespace afw
204 } // namespace lsst
CoaddInputs.h
lsst::afw::image
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
Definition: imageAlgorithm.dox:1
std::string
STL class.
std::shared_ptr
STL class.
lsst::afw::typehandling::makeKey
constexpr Key< K, V > makeKey(K const &id)
Factory function for Key, to enable type parameter inference.
Definition: Key.h:173
Psf.h
TransmissionCurve.h
psf
Key< int > psf
Definition: Exposure.cc:65
lsst::afw
Definition: imageAlgorithm.dox:1
SkyWcs.h
Filter.h
lsst::afw::geom.transform.transformContinued.cls
cls
Definition: transformContinued.py:33
PropertySet.h
Storable.h
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
Polygon.h
ExposureInfo.h
PhotoCalib.h
Implementation of the Photometric Calibration class.
type
table::Key< int > type
Definition: Detector.cc:163
detector
table::Key< int > detector
Definition: DetectorCollection.cc:172
key
Key< U > key
Definition: Schema.cc:281
ApCorrMap.h
pybind11
Definition: _GenericMap.cc:40
lsst::utils.tests.init
def init()
Definition: tests.py:58
lsst::afw::cameraGeom::PYBIND11_MODULE
PYBIND11_MODULE(camera, mod)
Definition: camera.cc:133
Detector.h
VisitInfo.h