LSST Applications g0b6bd0c080+a72a5dd7e6,g1182afd7b4+2a019aa3bb,g17e5ecfddb+2b8207f7de,g1d67935e3f+06cf436103,g38293774b4+ac198e9f13,g396055baef+6a2097e274,g3b44f30a73+6611e0205b,g480783c3b1+98f8679e14,g48ccf36440+89c08d0516,g4b93dc025c+98f8679e14,g5c4744a4d9+a302e8c7f0,g613e996a0d+e1c447f2e0,g6c8d09e9e7+25247a063c,g7271f0639c+98f8679e14,g7a9cd813b8+124095ede6,g9d27549199+a302e8c7f0,ga1cf026fa3+ac198e9f13,ga32aa97882+7403ac30ac,ga786bb30fb+7a139211af,gaa63f70f4e+9994eb9896,gabf319e997+ade567573c,gba47b54d5d+94dc90c3ea,gbec6a3398f+06cf436103,gc6308e37c7+07dd123edb,gc655b1545f+ade567573c,gcc9029db3c+ab229f5caf,gd01420fc67+06cf436103,gd877ba84e5+06cf436103,gdb4cecd868+6f279b5b48,ge2d134c3d5+cc4dbb2e3f,ge448b5faa6+86d1ceac1d,gecc7e12556+98f8679e14,gf3ee170dca+25247a063c,gf4ac96e456+ade567573c,gf9f5ea5b4d+ac198e9f13,gff490e6085+8c2580be5c,w.2022.27
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
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("hasFilterLabel", &ExposureInfo::hasFilterLabel);
139 cls.def("getFilterLabel", &ExposureInfo::getFilterLabel);
140 cls.def("setFilterLabel", &ExposureInfo::setFilterLabel, "filterLabel"_a);
141 cls.def("hasFilter", &ExposureInfo::hasFilter);
142 cls.def("getFilter", &ExposureInfo::getFilter);
143 cls.def("setFilter", &ExposureInfo::setFilter, "filterLabel"_a);
144
145 declareGenericMethods<std::shared_ptr<typehandling::Storable const>>(cls);
146 declareGenericMethodsMerged(cls);
147
148 cls.attr("KEY_PHOTO_CALIB") = ExposureInfo::KEY_PHOTO_CALIB.getId();
149 cls.def("hasPhotoCalib", &ExposureInfo::hasPhotoCalib);
150 cls.def("getPhotoCalib", &ExposureInfo::getPhotoCalib);
151 cls.def("setPhotoCalib", &ExposureInfo::setPhotoCalib, "photoCalib"_a);
152
153 cls.def("hasId", &ExposureInfo::hasId);
154 // Use exception handler to avoid overhead of calling hasId twice, and
155 // because asking for a nonexistent ID should be rare.
156 auto getId = [](ExposureInfo const &self) -> py::object {
157 try {
158 return py::cast(self.getId());
159 } catch (pex::exceptions::NotFoundError const &) {
160 return py::none();
161 }
162 };
163 auto setId = [](ExposureInfo &self, py::object id) {
164 if (id.is_none()) {
165 self.clearId();
166 } else {
167 self.setId(id.cast<table::RecordId>());
168 }
169 };
170 cls.def("getId", getId);
171 cls.def("setId", setId, "id"_a);
172 cls.def("clearId", &ExposureInfo::clearId);
173 cls.def_property("id", getId, setId);
174
175 cls.def("getMetadata", &ExposureInfo::getMetadata);
176 cls.def("setMetadata", &ExposureInfo::setMetadata, "metadata"_a);
177
178 cls.attr("KEY_PSF") = ExposureInfo::KEY_PSF.getId();
179 cls.def("hasPsf", &ExposureInfo::hasPsf);
180 cls.def("getPsf", &ExposureInfo::getPsf);
181 cls.def(
182 "setPsf",
183 [](ExposureInfo &self, py::object psf) {
184 if (psf.is(py::none())) {
185 self.setPsf(nullptr);
186 } else {
187 self.setPsf(py::cast<std::shared_ptr<afw::detection::Psf>>(psf));
188 }
189 },
190 "psf"_a);
191
192 cls.attr("KEY_VALID_POLYGON") = ExposureInfo::KEY_VALID_POLYGON.getId();
193 cls.def("hasValidPolygon", &ExposureInfo::hasValidPolygon);
194 cls.def("getValidPolygon", &ExposureInfo::getValidPolygon);
195 cls.def(
196 "setValidPolygon",
197 [](ExposureInfo &self, py::object polygon) {
198 if (polygon.is(py::none())) {
199 self.setValidPolygon(nullptr);
200 } else {
201 self.setValidPolygon(py::cast<std::shared_ptr<afw::geom::polygon::Polygon>>(polygon));
202 }
203 },
204 "polygon"_a);
205
206 cls.attr("KEY_AP_CORR_MAP") = ExposureInfo::KEY_AP_CORR_MAP.getId();
207 cls.def("hasApCorrMap", &ExposureInfo::hasApCorrMap);
208 cls.def("getApCorrMap", (std::shared_ptr<ApCorrMap>(ExposureInfo::*)()) & ExposureInfo::getApCorrMap);
209 cls.def("setApCorrMap", &ExposureInfo::setApCorrMap, "apCorrMap"_a);
210 cls.def("initApCorrMap", &ExposureInfo::initApCorrMap);
211
212 cls.attr("KEY_COADD_INPUTS") = ExposureInfo::KEY_COADD_INPUTS.getId();
213 cls.def("hasCoaddInputs", &ExposureInfo::hasCoaddInputs);
214 cls.def("getCoaddInputs", &ExposureInfo::getCoaddInputs);
215 cls.def("setCoaddInputs", &ExposureInfo::setCoaddInputs, "coaddInputs"_a);
216
217 cls.def("hasVisitInfo", &ExposureInfo::hasVisitInfo);
218 cls.def("getVisitInfo", &ExposureInfo::getVisitInfo);
219 cls.def("setVisitInfo", &ExposureInfo::setVisitInfo, "visitInfo"_a);
220
221 cls.attr("KEY_TRANSMISSION_CURVE") = ExposureInfo::KEY_TRANSMISSION_CURVE.getId();
222 cls.def("hasTransmissionCurve", &ExposureInfo::hasTransmissionCurve);
223 cls.def("getTransmissionCurve", &ExposureInfo::getTransmissionCurve);
224 cls.def("setTransmissionCurve", &ExposureInfo::setTransmissionCurve, "transmissionCurve"_a);
225 });
226}
227} // namespace
228void wrapExposureInfo(lsst::utils::python::WrapperCollection &wrappers) {
229 wrappers.addSignatureDependency("lsst.daf.base");
230 wrappers.addSignatureDependency("lsst.afw.geom");
231 wrappers.addSignatureDependency("lsst.afw.cameraGeom");
232 wrappers.addSignatureDependency("lsst.afw.detection"); // For Psf
233 declareExposureInfo(wrappers);
234}
235} // namespace image
236} // namespace afw
237} // namespace lsst
table::Key< int > id
Definition: Detector.cc:162
table::Key< int > type
Definition: Detector.cc:163
Implementation of the Photometric Calibration class.
bool hasCoaddInputs() const
Does this exposure have coadd provenance catalogs?
void setFilterLabel(std::shared_ptr< FilterLabel const > filterLabel)
Set the exposure's filter information.
bool hasTransmissionCurve() const
Does this exposure have a transmission curve?
bool hasPsf() const
Does this exposure have a Psf?
Definition: ExposureInfo.cc:61
void setVisitInfo(std::shared_ptr< image::VisitInfo const > const visitInfo)
Set the exposure's visit info.
Definition: ExposureInfo.h:254
bool hasPhotoCalib() const
Does this exposure have a photometric calibration?
Definition: ExposureInfo.cc:68
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.
Definition: ExposureInfo.cc:69
std::shared_ptr< ApCorrMap const > getApCorrMap() const
Return the exposure's aperture correction map (null pointer if !hasApCorrMap())
std::shared_ptr< FilterLabel const > getFilterLabel() const
Return the exposure's filter information.
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.
Definition: ExposureInfo.cc:72
static typehandling::Key< std::string, std::shared_ptr< geom::polygon::Polygon const > > const KEY_VALID_POLYGON
Standard key for looking up the valid polygon.
Definition: ExposureInfo.h:100
bool hasValidPolygon() const
Does this exposure have a valid Polygon.
Definition: ExposureInfo.cc:91
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.
Definition: ExposureInfo.h:95
void setCoaddInputs(std::shared_ptr< CoaddInputs const > coaddInputs)
Set the exposure's coadd provenance catalogs.
bool hasFilterLabel() const
Does this exposure have filter information?
void clearId() noexcept
Unset the exposure ID, if any.
void setMetadata(std::shared_ptr< daf::base::PropertySet > metadata)
Set the flexible metadata.
Definition: ExposureInfo.h:201
void setFilter(std::shared_ptr< FilterLabel const > filter)
Set the exposure's filter information.
bool hasVisitInfo() const
Does this exposure have visit info?
Definition: ExposureInfo.h:251
static typehandling::Key< std::string, std::shared_ptr< TransmissionCurve const > > const KEY_TRANSMISSION_CURVE
Standard key for looking up the transmission curve.
Definition: ExposureInfo.h:107
void initApCorrMap()
Set the exposure's aperture correction map to a new, empty map.
static typehandling::Key< std::string, std::shared_ptr< CoaddInputs const > > const KEY_COADD_INPUTS
Standard key for looking up coadd provenance catalogs.
Definition: ExposureInfo.h:102
static typehandling::Key< std::string, std::shared_ptr< detection::Psf const > > const KEY_PSF
Standard key for looking up the point-spread function.
Definition: ExposureInfo.h:93
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.
Definition: ExposureInfo.cc:92
std::shared_ptr< daf::base::PropertySet > getMetadata() const
Return flexible metadata.
Definition: ExposureInfo.h:198
static typehandling::Key< std::string, std::shared_ptr< ApCorrMap const > > const KEY_AP_CORR_MAP
Standard key for looking up the aperture correction map.
Definition: ExposureInfo.h:104
std::shared_ptr< image::VisitInfo const > getVisitInfo() const
Return the exposure's visit info.
Definition: ExposureInfo.h:248
static typehandling::Key< std::string, std::shared_ptr< FilterLabel const > > const KEY_FILTER
Standard key for looking up filter information.
Definition: ExposureInfo.h:109
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.
Definition: ExposureInfo.cc:62
std::shared_ptr< TransmissionCurve const > getTransmissionCurve() const
Return the exposure's transmission curve.
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
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
A base class for image defects.
Key< int > psf
Definition: Exposure.cc:65