LSST Applications 27.0.0,g0265f82a02+469cd937ee,g02d81e74bb+21ad69e7e1,g1470d8bcf6+cbe83ee85a,g2079a07aa2+e67c6346a6,g212a7c68fe+04a9158687,g2305ad1205+94392ce272,g295015adf3+81dd352a9d,g2bbee38e9b+469cd937ee,g337abbeb29+469cd937ee,g3939d97d7f+72a9f7b576,g487adcacf7+71499e7cba,g50ff169b8f+5929b3527e,g52b1c1532d+a6fc98d2e7,g591dd9f2cf+df404f777f,g5a732f18d5+be83d3ecdb,g64a986408d+21ad69e7e1,g858d7b2824+21ad69e7e1,g8a8a8dda67+a6fc98d2e7,g99cad8db69+f62e5b0af5,g9ddcbc5298+d4bad12328,ga1e77700b3+9c366c4306,ga8c6da7877+71e4819109,gb0e22166c9+25ba2f69a1,gb6a65358fc+469cd937ee,gbb8dafda3b+69d3c0e320,gc07e1c2157+a98bf949bb,gc120e1dc64+615ec43309,gc28159a63d+469cd937ee,gcf0d15dbbd+72a9f7b576,gdaeeff99f8+a38ce5ea23,ge6526c86ff+3a7c1ac5f1,ge79ae78c31+469cd937ee,gee10cc3b42+a6fc98d2e7,gf1cff7945b+21ad69e7e1,gfbcc870c63+9a11dc8c8f
LSST Data Management Base Package
Loading...
Searching...
No Matches
_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
40
41namespace py = pybind11;
42using namespace py::literals;
43
44namespace lsst {
45namespace afw {
46namespace image {
47namespace {
48
49using PyExposureInfo = py::class_<ExposureInfo, std::shared_ptr<ExposureInfo>>;
50
51// Template methods where we can use pybind11's overload resolution (T is input)
52template <class T>
53void declareGenericMethods(PyExposureInfo &cls) {
54 using Class = PyExposureInfo::type;
55 cls.def(
56 "setComponent",
57 [](PyExposureInfo::type &self, std::string const &key, T const &object) {
58 self.setComponent(typehandling::makeKey<T>(key), object);
59 },
60 "key"_a, "object"_a);
61}
62// Template methods where we need to provide a unified interface (T is not input)
63void declareGenericMethodsMerged(PyExposureInfo &cls) {
64 using typehandling::Storable;
65 using Class = PyExposureInfo::type;
66 cls.def(
67 "hasComponent",
68 [](Class const &self, std::string const &key) {
69 return self.hasComponent(typehandling::makeKey<std::shared_ptr<Storable const>>(key));
70 },
71 "key"_a);
72 cls.def(
73 "getComponent",
74 [](Class const &self, std::string const &key) -> py::object {
75 auto sharedKey = typehandling::makeKey<std::shared_ptr<Storable const>>(key);
76 // Cascading if-elses to support other types in the future
77 if (self.hasComponent(sharedKey)) {
78 return py::cast(self.getComponent(sharedKey));
79 } else {
80 return py::none();
81 }
82 },
83 "key"_a);
84 cls.def(
85 "removeComponent",
86 [](Class &self, std::string const &key) {
88 },
89 "key"_a);
90}
91
92void declareExposureInfo(lsst::utils::python::WrapperCollection &wrappers) {
93 wrappers.wrapType(PyExposureInfo(wrappers.module, "ExposureInfo"), [](auto &mod, auto &cls) {
94 /* Constructors */
95 cls.def(py::init<std::shared_ptr<geom::SkyWcs const> const &,
96 std::shared_ptr<detection::Psf const> const &,
97 std::shared_ptr<PhotoCalib const> const &,
98 std::shared_ptr<cameraGeom::Detector const> const &,
99 std::shared_ptr<geom::polygon::Polygon const> const &,
100 std::shared_ptr<daf::base::PropertySet> const &,
101 std::shared_ptr<CoaddInputs> const &, std::shared_ptr<ApCorrMap> const &,
102 std::shared_ptr<VisitInfo const> const &,
103 std::shared_ptr<TransmissionCurve const> const &>(),
104 "wcs"_a = std::shared_ptr<geom::SkyWcs const>(),
105 "psf"_a = std::shared_ptr<detection::Psf const>(),
106 "photoCalib"_a = std::shared_ptr<PhotoCalib const>(),
107 "detector"_a = std::shared_ptr<cameraGeom::Detector const>(),
108 "polygon"_a = std::shared_ptr<geom::polygon::Polygon const>(),
109 "metadata"_a = std::shared_ptr<daf::base::PropertySet>(),
110 "coaddInputs"_a = std::shared_ptr<CoaddInputs>(),
111 "apCorrMap"_a = std::shared_ptr<ApCorrMap>(),
112 "visitInfo"_a = std::shared_ptr<VisitInfo const>(), "transmissionCurve"_a = nullptr);
113 cls.def(py::init<>());
114 cls.def(py::init<ExposureInfo>(), "other"_a);
115 cls.def(py::init<ExposureInfo, bool>(), "other"_a, "copyMetadata"_a);
116
117 /* Members */
118 cls.attr("KEY_WCS") = ExposureInfo::KEY_WCS.getId();
119 cls.def("hasWcs", &ExposureInfo::hasWcs);
120 cls.def("getWcs", (std::shared_ptr<geom::SkyWcs>(ExposureInfo::*)()) & ExposureInfo::getWcs);
121 cls.def("setWcs", &ExposureInfo::setWcs, "wcs"_a);
122
123 cls.attr("KEY_DETECTOR") = ExposureInfo::KEY_DETECTOR.getId();
124 cls.def("hasDetector", &ExposureInfo::hasDetector);
125 cls.def("getDetector", &ExposureInfo::getDetector);
126 cls.def(
127 "setDetector",
128 [](ExposureInfo &self, py::object detector) {
129 if (detector.is(py::none())) {
130 self.setDetector(nullptr);
131 } else {
132 self.setDetector(py::cast<std::shared_ptr<afw::cameraGeom::Detector>>(detector));
133 }
134 },
135 "detector"_a);
136
137 cls.attr("KEY_FILTER") = ExposureInfo::KEY_FILTER.getId();
138 cls.def("hasFilter", &ExposureInfo::hasFilter);
139 cls.def("getFilter", &ExposureInfo::getFilter);
140 cls.def("setFilter", &ExposureInfo::setFilter, "filterLabel"_a);
141
142 declareGenericMethods<std::shared_ptr<typehandling::Storable const>>(cls);
143 declareGenericMethodsMerged(cls);
144
145 cls.attr("KEY_PHOTO_CALIB") = ExposureInfo::KEY_PHOTO_CALIB.getId();
146 cls.def("hasPhotoCalib", &ExposureInfo::hasPhotoCalib);
147 cls.def("getPhotoCalib", &ExposureInfo::getPhotoCalib);
148 cls.def("setPhotoCalib", &ExposureInfo::setPhotoCalib, "photoCalib"_a);
149
150 cls.def("hasId", &ExposureInfo::hasId);
151 // Use exception handler to avoid overhead of calling hasId twice, and
152 // because asking for a nonexistent ID should be rare.
153 auto getId = [](ExposureInfo const &self) -> py::object {
154 try {
155 return py::cast(self.getId());
156 } catch (pex::exceptions::NotFoundError const &) {
157 return py::none();
158 }
159 };
160 auto setId = [](ExposureInfo &self, py::object id) {
161 if (id.is_none()) {
162 self.clearId();
163 } else {
164 self.setId(id.cast<table::RecordId>());
165 }
166 };
167 cls.def("getId", getId);
168 cls.def("setId", setId, "id"_a);
169 cls.def("clearId", &ExposureInfo::clearId);
170 cls.def_property("id", getId, setId);
171
172 cls.def("getMetadata", &ExposureInfo::getMetadata);
173 cls.def("setMetadata", &ExposureInfo::setMetadata, "metadata"_a);
174
175 cls.attr("KEY_PSF") = ExposureInfo::KEY_PSF.getId();
176 cls.def("hasPsf", &ExposureInfo::hasPsf);
177 cls.def("getPsf", &ExposureInfo::getPsf);
178 cls.def(
179 "setPsf",
180 [](ExposureInfo &self, py::object psf) {
181 if (psf.is(py::none())) {
182 self.setPsf(nullptr);
183 } else {
184 self.setPsf(py::cast<std::shared_ptr<afw::detection::Psf>>(psf));
185 }
186 },
187 "psf"_a);
188
189 cls.attr("KEY_VALID_POLYGON") = ExposureInfo::KEY_VALID_POLYGON.getId();
190 cls.def("hasValidPolygon", &ExposureInfo::hasValidPolygon);
191 cls.def("getValidPolygon", &ExposureInfo::getValidPolygon);
192 cls.def(
193 "setValidPolygon",
194 [](ExposureInfo &self, py::object polygon) {
195 if (polygon.is(py::none())) {
196 self.setValidPolygon(nullptr);
197 } else {
198 self.setValidPolygon(py::cast<std::shared_ptr<afw::geom::polygon::Polygon>>(polygon));
199 }
200 },
201 "polygon"_a);
202
203 cls.attr("KEY_AP_CORR_MAP") = ExposureInfo::KEY_AP_CORR_MAP.getId();
204 cls.def("hasApCorrMap", &ExposureInfo::hasApCorrMap);
205 cls.def("getApCorrMap", (std::shared_ptr<ApCorrMap>(ExposureInfo::*)()) & ExposureInfo::getApCorrMap);
206 cls.def("setApCorrMap", &ExposureInfo::setApCorrMap, "apCorrMap"_a);
207
208 cls.attr("KEY_COADD_INPUTS") = ExposureInfo::KEY_COADD_INPUTS.getId();
209 cls.def("hasCoaddInputs", &ExposureInfo::hasCoaddInputs);
210 cls.def("getCoaddInputs", &ExposureInfo::getCoaddInputs);
211 cls.def("setCoaddInputs", &ExposureInfo::setCoaddInputs, "coaddInputs"_a);
212
213 cls.def("hasVisitInfo", &ExposureInfo::hasVisitInfo);
214 cls.def("getVisitInfo", &ExposureInfo::getVisitInfo);
215 cls.def("setVisitInfo", &ExposureInfo::setVisitInfo, "visitInfo"_a);
216
217 cls.attr("KEY_TRANSMISSION_CURVE") = ExposureInfo::KEY_TRANSMISSION_CURVE.getId();
218 cls.def("hasTransmissionCurve", &ExposureInfo::hasTransmissionCurve);
219 cls.def("getTransmissionCurve", &ExposureInfo::getTransmissionCurve);
220 cls.def("setTransmissionCurve", &ExposureInfo::setTransmissionCurve, "transmissionCurve"_a);
221 });
222}
223} // namespace
224void wrapExposureInfo(lsst::utils::python::WrapperCollection &wrappers) {
225 wrappers.addSignatureDependency("lsst.daf.base");
226 wrappers.addSignatureDependency("lsst.afw.geom");
227 wrappers.addSignatureDependency("lsst.afw.cameraGeom");
228 wrappers.addSignatureDependency("lsst.afw.detection"); // For Psf
229 declareExposureInfo(wrappers);
230}
231} // namespace image
232} // namespace afw
233} // namespace lsst
table::Key< int > id
Definition Detector.cc:162
Implementation of the Photometric Calibration class.
bool hasCoaddInputs() const
Does this exposure have coadd provenance catalogs?
bool hasTransmissionCurve() const
Does this exposure have a transmission curve?
bool hasPsf() const
Does this exposure have a Psf?
void setVisitInfo(std::shared_ptr< image::VisitInfo const > const visitInfo)
Set the exposure's visit info.
bool hasPhotoCalib() const
Does this exposure have a photometric calibration?
bool hasApCorrMap() const
Return true if the exposure has an aperture correction map.
std::shared_ptr< PhotoCalib const > getPhotoCalib() const
Return the exposure's photometric calibration.
void setApCorrMap(std::shared_ptr< ApCorrMap const > apCorrMap)
Set the exposure's aperture correction map (null pointer if !hasApCorrMap())
void setPhotoCalib(std::shared_ptr< PhotoCalib const > photoCalib)
Set the Exposure's PhotoCalib object.
static typehandling::Key< std::string, std::shared_ptr< geom::polygon::Polygon const > > const KEY_VALID_POLYGON
Standard key for looking up the valid polygon.
bool hasValidPolygon() const
Does this exposure have a valid Polygon.
std::shared_ptr< FilterLabel const > getFilter() const
Return the exposure's filter information.
static typehandling::Key< std::string, std::shared_ptr< PhotoCalib const > > const KEY_PHOTO_CALIB
Standard key for looking up the photometric calibration.
void setCoaddInputs(std::shared_ptr< CoaddInputs const > coaddInputs)
Set the exposure's coadd provenance catalogs.
void clearId() noexcept
Unset the exposure ID, if any.
void setMetadata(std::shared_ptr< daf::base::PropertySet > metadata)
Set the flexible metadata.
void setFilter(std::shared_ptr< FilterLabel const > filter)
Set the exposure's filter information.
bool hasVisitInfo() const
Does this exposure have visit info?
static typehandling::Key< std::string, std::shared_ptr< TransmissionCurve const > > const KEY_TRANSMISSION_CURVE
Standard key for looking up the transmission curve.
static typehandling::Key< std::string, std::shared_ptr< CoaddInputs const > > const KEY_COADD_INPUTS
Standard key for looking up coadd provenance catalogs.
static typehandling::Key< std::string, std::shared_ptr< detection::Psf const > > const KEY_PSF
Standard key for looking up the point-spread function.
std::shared_ptr< CoaddInputs const > getCoaddInputs() const
Return a pair of catalogs that record the inputs, if this Exposure is a coadd (otherwise null).
bool hasFilter() const
Does this exposure have filter information?
std::shared_ptr< geom::polygon::Polygon const > getValidPolygon() const
Return the valid Polygon.
std::shared_ptr< daf::base::PropertySet > getMetadata() const
Return flexible metadata.
static typehandling::Key< std::string, std::shared_ptr< ApCorrMap const > > const KEY_AP_CORR_MAP
Standard key for looking up the aperture correction map.
std::shared_ptr< image::VisitInfo const > getVisitInfo() const
Return the exposure's visit info.
static typehandling::Key< std::string, std::shared_ptr< FilterLabel const > > const KEY_FILTER
Standard key for looking up filter information.
bool hasId() const noexcept
Does this Exposure have an exposure id?
void setTransmissionCurve(std::shared_ptr< TransmissionCurve const > tc)
Set the exposure's transmission curve.
std::shared_ptr< detection::Psf const > getPsf() const
Return the exposure's point-spread function.
std::shared_ptr< TransmissionCurve const > getTransmissionCurve() const
Return the exposure's transmission curve.
void wrapExposureInfo(lsst::utils::python::WrapperCollection &wrappers)
constexpr Key< K, V > makeKey(K const &id)
Factory function for Key, to enable type parameter inference.
Definition Key.h:173