LSST Applications g180d380827+78227d2bc4,g2079a07aa2+86d27d4dc4,g2305ad1205+bdd7851fe3,g2bbee38e9b+c6a8a0fb72,g337abbeb29+c6a8a0fb72,g33d1c0ed96+c6a8a0fb72,g3a166c0a6a+c6a8a0fb72,g3d1719c13e+260d7c3927,g3ddfee87b4+723a6db5f3,g487adcacf7+29e55ea757,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+9443c4b912,g62aa8f1a4b+7e2ea9cd42,g858d7b2824+260d7c3927,g864b0138d7+8498d97249,g95921f966b+dffe86973d,g991b906543+260d7c3927,g99cad8db69+4809d78dd9,g9c22b2923f+e2510deafe,g9ddcbc5298+9a081db1e4,ga1e77700b3+03d07e1c1f,gb0e22166c9+60f28cb32d,gb23b769143+260d7c3927,gba4ed39666+c2a2e4ac27,gbb8dafda3b+e22341fd87,gbd998247f1+585e252eca,gc120e1dc64+713f94b854,gc28159a63d+c6a8a0fb72,gc3e9b769f7+385ea95214,gcf0d15dbbd+723a6db5f3,gdaeeff99f8+f9a426f77a,ge6526c86ff+fde82a80b9,ge79ae78c31+c6a8a0fb72,gee10cc3b42+585e252eca,w.2024.18
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