LSST Applications g070148d5b3+33e5256705,g0d53e28543+25c8b88941,g0da5cf3356+2dd1178308,g1081da9e2a+62d12e78cb,g17e5ecfddb+7e422d6136,g1c76d35bf8+ede3a706f7,g295839609d+225697d880,g2e2c1a68ba+cc1f6f037e,g2ffcdf413f+853cd4dcde,g38293774b4+62d12e78cb,g3b44f30a73+d953f1ac34,g48ccf36440+885b902d19,g4b2f1765b6+7dedbde6d2,g5320a0a9f6+0c5d6105b6,g56b687f8c9+ede3a706f7,g5c4744a4d9+ef6ac23297,g5ffd174ac0+0c5d6105b6,g6075d09f38+66af417445,g667d525e37+2ced63db88,g670421136f+2ced63db88,g71f27ac40c+2ced63db88,g774830318a+463cbe8d1f,g7876bc68e5+1d137996f1,g7985c39107+62d12e78cb,g7fdac2220c+0fd8241c05,g96f01af41f+368e6903a7,g9ca82378b8+2ced63db88,g9d27549199+ef6ac23297,gabe93b2c52+e3573e3735,gb065e2a02a+3dfbe639da,gbc3249ced9+0c5d6105b6,gbec6a3398f+0c5d6105b6,gc9534b9d65+35b9f25267,gd01420fc67+0c5d6105b6,geee7ff78d7+a14128c129,gf63283c776+ede3a706f7,gfed783d017+0c5d6105b6,w.2022.47
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 cls.def("initApCorrMap", &ExposureInfo::initApCorrMap);
208
209 cls.attr("KEY_COADD_INPUTS") = ExposureInfo::KEY_COADD_INPUTS.getId();
210 cls.def("hasCoaddInputs", &ExposureInfo::hasCoaddInputs);
211 cls.def("getCoaddInputs", &ExposureInfo::getCoaddInputs);
212 cls.def("setCoaddInputs", &ExposureInfo::setCoaddInputs, "coaddInputs"_a);
213
214 cls.def("hasVisitInfo", &ExposureInfo::hasVisitInfo);
215 cls.def("getVisitInfo", &ExposureInfo::getVisitInfo);
216 cls.def("setVisitInfo", &ExposureInfo::setVisitInfo, "visitInfo"_a);
217
218 cls.attr("KEY_TRANSMISSION_CURVE") = ExposureInfo::KEY_TRANSMISSION_CURVE.getId();
219 cls.def("hasTransmissionCurve", &ExposureInfo::hasTransmissionCurve);
220 cls.def("getTransmissionCurve", &ExposureInfo::getTransmissionCurve);
221 cls.def("setTransmissionCurve", &ExposureInfo::setTransmissionCurve, "transmissionCurve"_a);
222 });
223}
224} // namespace
225void wrapExposureInfo(lsst::utils::python::WrapperCollection &wrappers) {
226 wrappers.addSignatureDependency("lsst.daf.base");
227 wrappers.addSignatureDependency("lsst.afw.geom");
228 wrappers.addSignatureDependency("lsst.afw.cameraGeom");
229 wrappers.addSignatureDependency("lsst.afw.detection"); // For Psf
230 declareExposureInfo(wrappers);
231}
232} // namespace image
233} // namespace afw
234} // 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?
Definition: ExposureInfo.cc:61
void setVisitInfo(std::shared_ptr< image::VisitInfo const > const visitInfo)
Set the exposure's visit info.
Definition: ExposureInfo.h:239
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())
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.
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:186
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:236
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:183
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:233
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.
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
Key< int > psf
Definition: Exposure.cc:65