LSST Applications g063fba187b+cac8b7c890,g0f08755f38+6aee506743,g1653933729+a8ce1bb630,g168dd56ebc+a8ce1bb630,g1a2382251a+b4475c5878,g1dcb35cd9c+8f9bc1652e,g20f6ffc8e0+6aee506743,g217e2c1bcf+73dee94bd0,g28da252d5a+1f19c529b9,g2bbee38e9b+3f2625acfc,g2bc492864f+3f2625acfc,g3156d2b45e+6e55a43351,g32e5bea42b+1bb94961c2,g347aa1857d+3f2625acfc,g35bb328faa+a8ce1bb630,g3a166c0a6a+3f2625acfc,g3e281a1b8c+c5dd892a6c,g3e8969e208+a8ce1bb630,g414038480c+5927e1bc1e,g41af890bb2+8a9e676b2a,g7af13505b9+809c143d88,g80478fca09+6ef8b1810f,g82479be7b0+f568feb641,g858d7b2824+6aee506743,g89c8672015+f4add4ffd5,g9125e01d80+a8ce1bb630,ga5288a1d22+2903d499ea,gb58c049af0+d64f4d3760,gc28159a63d+3f2625acfc,gcab2d0539d+b12535109e,gcf0d15dbbd+46a3f46ba9,gda6a2b7d83+46a3f46ba9,gdaeeff99f8+1711a396fd,ge79ae78c31+3f2625acfc,gef2f8181fd+0a71e47438,gf0baf85859+c1f95f4921,gfa517265be+6aee506743,gfa999e8aa5+17cd334064,w.2024.51
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"
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::cpputils::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
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.
A helper class for subdividing pybind11 module across multiple translation units (i....
Definition python.h:242
void addSignatureDependency(std::string const &name)
Indicate an external module that provides a type used in function/method signatures.
Definition python.h:357
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 wrapExposureInfo(lsst::cpputils::python::WrapperCollection &wrappers)
constexpr Key< K, V > makeKey(K const &id)
Factory function for Key, to enable type parameter inference.
Definition Key.h:173
Key< int > psf
Definition Exposure.cc:65