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
_detector.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 <memory>
25#include <string>
26
27#include "pybind11/pybind11.h"
28#include <lsst/utils/python.h>
29
30#include "pybind11/stl.h"
31
32#include "ndarray/pybind11.h"
33
34#include "lsst/utils/python.h"
37#include "lsst/geom.h"
42
43namespace py = pybind11;
44using namespace py::literals;
45
46namespace lsst {
47namespace afw {
48namespace cameraGeom {
49
50namespace {
51
52using PyDetectorBase = py::class_<DetectorBase, std::shared_ptr<DetectorBase>>;
53using PyDetector = py::class_<Detector, DetectorBase, std::shared_ptr<Detector>, typehandling::Storable>;
54using PyDetectorBuilder = py::class_<Detector::Builder, DetectorBase, std::shared_ptr<Detector::Builder>>;
55using PyDetectorPartialRebuilder = py::class_<Detector::PartialRebuilder, Detector::Builder,
57using PyDetectorInCameraBuilder =
58 py::class_<Detector::InCameraBuilder, Detector::Builder, std::shared_ptr<Detector::InCameraBuilder>>;
59
60// Declare Detector methods overloaded on one coordinate system class
61template <typename SysT, typename PyClass>
62void declare1SysMethods(PyClass &cls) {
63 cls.def("getCorners",
64 (std::vector<lsst::geom::Point2D>(Detector::*)(SysT const &) const) & Detector::getCorners,
65 "cameraSys"_a);
66 cls.def("getCenter", (lsst::geom::Point2D(Detector::*)(SysT const &) const) & Detector::getCenter,
67 "cameraSys"_a);
68 cls.def("hasTransform", (bool (Detector::*)(SysT const &) const) & Detector::hasTransform, "cameraSys"_a);
69}
70
71// Declare Detector methods templated on two coordinate system classes
72template <typename FromSysT, typename ToSysT, typename PyClass>
73void declare2SysMethods(PyClass &cls) {
74 cls.def("getTransform",
75 (std::shared_ptr<geom::TransformPoint2ToPoint2>(Detector::*)(FromSysT const &, ToSysT const &)
76 const) &
78 "fromSys"_a, "toSys"_a);
79 cls.def("transform",
80 (lsst::geom::Point2D(Detector::*)(lsst::geom::Point2D const &, FromSysT const &, ToSysT const &)
81 const) &
83 "point"_a, "fromSys"_a, "toSys"_a);
84 cls.def("transform",
86 FromSysT const &, ToSysT const &) const) &
88 "points"_a, "fromSys"_a, "toSys"_a);
89}
90
91void declareDetectorBase(lsst::utils::python::WrapperCollection &wrappers) {
92 wrappers.wrapType(PyDetectorBase(wrappers.module, "DetectorBase"), [](auto &mod, auto &cls) {
93 cls.def("getName", &DetectorBase::getName);
94 cls.def("getId", &DetectorBase::getId);
95 cls.def("getType", &DetectorBase::getType);
96 cls.def("getPhysicalType", &DetectorBase::getPhysicalType);
97 cls.def("getSerial", &DetectorBase::getSerial);
98 cls.def("getBBox", &DetectorBase::getBBox);
99 cls.def("getOrientation", &DetectorBase::getOrientation);
100 cls.def("getPixelSize", &DetectorBase::getPixelSize);
101 cls.def("hasCrosstalk", &DetectorBase::hasCrosstalk);
102 cls.def("getCrosstalk", &DetectorBase::getCrosstalk);
103 cls.def("getNativeCoordSys", &DetectorBase::getNativeCoordSys);
104 cls.def("makeCameraSys",
105 py::overload_cast<CameraSys const &>(&DetectorBase::makeCameraSys, py::const_),
106 "cameraSys"_a);
107 cls.def("makeCameraSys",
108 py::overload_cast<CameraSysPrefix const &>(&DetectorBase::makeCameraSys, py::const_),
109 "cameraSysPrefix"_a);
110 });
111}
112
113void declareDetectorBuilder(PyDetector &parent);
114void declareDetectorPartialRebuilder(PyDetector &parent);
115void declareDetectorInCameraBuilder(PyDetector &parent);
116
117void declareDetector(lsst::utils::python::WrapperCollection &wrappers) {
118 wrappers.wrapType(PyDetector(wrappers.module, "Detector"), [](auto &mod, auto &cls) {
119 declareDetectorBuilder(cls);
120 declareDetectorPartialRebuilder(cls);
121 declareDetectorInCameraBuilder(cls);
122 cls.def("rebuild", &Detector::rebuild);
123 declare1SysMethods<CameraSys>(cls);
124 declare1SysMethods<CameraSysPrefix>(cls);
125 declare2SysMethods<CameraSys, CameraSys>(cls);
126 declare2SysMethods<CameraSys, CameraSysPrefix>(cls);
127 declare2SysMethods<CameraSysPrefix, CameraSys>(cls);
128 declare2SysMethods<CameraSysPrefix, CameraSysPrefix>(cls);
129 cls.def("getTransformMap", &Detector::getTransformMap);
130 cls.def("getAmplifiers", &Detector::getAmplifiers);
131 // __iter__ defined in pure-Python extension
132 cls.def(
133 "__getitem__",
134 [](Detector const &self, std::ptrdiff_t i) {
135 return self[utils::python::cppIndex(self.size(), i)];
136 },
137 "i"_a);
138 cls.def("__getitem__", py::overload_cast<std::string const &>(&Detector::operator[], py::const_),
139 "name"_a);
140 cls.def("__len__", &Detector::size);
142 });
143}
144
145void declareDetectorBuilder(PyDetector &parent) {
146 PyDetectorBuilder cls(parent, "Builder");
147 cls.def("setBBox", &Detector::Builder::setBBox);
148 cls.def("setType", &Detector::Builder::setType);
149 cls.def("setSerial", &Detector::Builder::setSerial);
150 cls.def("setPhysicalType", &Detector::Builder::setPhysicalType);
151 cls.def("setCrosstalk", &Detector::Builder::setCrosstalk);
152 cls.def("unsetCrosstalk", &Detector::Builder::unsetCrosstalk);
153 cls.def("getAmplifiers", &Detector::Builder::getAmplifiers);
154 cls.def(
155 "__getitem__",
156 [](Detector::Builder const &self, std::ptrdiff_t i) {
157 return self[utils::python::cppIndex(self.size(), i)];
158 },
159 "i"_a);
160 cls.def("__getitem__", py::overload_cast<std::string const &>(&Detector::Builder::operator[], py::const_),
161 "name"_a);
162 cls.def("append", &Detector::Builder::append);
163 cls.def("clear", &Detector::Builder::clear);
164 cls.def("__len__", &Detector::Builder::size);
165}
166
167void declareDetectorPartialRebuilder(PyDetector &parent) {
168 PyDetectorPartialRebuilder cls(parent, "PartialRebuilder");
169 cls.def(py::init<Detector const &>(), "detector"_a);
170 cls.def("finish", &Detector::PartialRebuilder::finish);
171}
172
173void declareDetectorInCameraBuilder(PyDetector &parent) {
174 PyDetectorInCameraBuilder cls(parent, "InCameraBuilder");
175 cls.def("setOrientation", &Detector::InCameraBuilder::setOrientation);
176 cls.def("setPixelSize", &Detector::InCameraBuilder::setPixelSize);
177 cls.def("setTransformFromPixelsTo",
178 py::overload_cast<CameraSysPrefix const &,
181 "toSys"_a, "transform"_a);
182 cls.def("setTransformFromPixelsTo",
183 py::overload_cast<CameraSys const &, std::shared_ptr<afw::geom::TransformPoint2ToPoint2 const>>(
185 "toSys"_a, "transform"_a);
186 cls.def("discardTransformFromPixelsTo",
187 py::overload_cast<CameraSysPrefix const &>(
189 "toSys"_a);
190 cls.def("discardTransformFromPixelsTo",
191 py::overload_cast<CameraSys const &>(&Detector::InCameraBuilder::discardTransformFromPixelsTo),
192 "toSys"_a);
193}
194} // namespace
195void wrapDetector(lsst::utils::python::WrapperCollection &wrappers) {
196 wrappers.addInheritanceDependency("lsst.afw.typehandling");
197 wrappers.wrapType(py::enum_<DetectorType>(wrappers.module, "DetectorType"), [](auto &mod, auto &enm) {
198 enm.value("SCIENCE", DetectorType::SCIENCE);
199 enm.value("FOCUS", DetectorType::FOCUS);
200 enm.value("GUIDER", DetectorType::GUIDER);
201 enm.value("WAVEFRONT", DetectorType::WAVEFRONT);
202 });
203 declareDetectorBase(wrappers);
204 declareDetector(wrappers);
205}
206} // namespace cameraGeom
207} // namespace afw
208} // namespace lsst
void setSerial(std::string const &serial)
Set the detector serial "number".
Definition: Detector.h:381
void setBBox(lsst::geom::Box2I const &bbox)
Set the bounding box.
Definition: Detector.h:375
void setPhysicalType(std::string const &physicalType)
Set the detector's physical type.
Definition: Detector.h:388
void setCrosstalk(CrosstalkMatrix const &crosstalk)
Set the crosstalk coefficients.
Definition: Detector.h:400
std::vector< std::shared_ptr< Amplifier::Builder > > const & getAmplifiers() const
Return the sequence of Amplifier::Builders directly.
Definition: Detector.h:418
void setType(DetectorType type)
Set the purpose of this detector.
Definition: Detector.h:378
void unsetCrosstalk()
Remove the crosstalk coefficient matrix.
Definition: Detector.h:403
void append(std::shared_ptr< Amplifier::Builder > builder)
Append a new amplifier.
Definition: Detector.cc:351
std::size_t size() const
Return the number of amplifiers (renamed to len in Python).
Definition: Detector.h:451
void clear()
Remove all amplifiers.
Definition: Detector.h:448
void setOrientation(Orientation const &orientation)
Set the orientation of the detector in the focal plane.
Definition: Detector.h:561
void setTransformFromPixelsTo(CameraSysPrefix const &toSys, std::shared_ptr< afw::geom::TransformPoint2ToPoint2 const > transform)
Set the transformation from PIXELS to the given coordinate system.
Definition: Detector.cc:413
bool discardTransformFromPixelsTo(CameraSysPrefix const &toSys)
Remove any transformation from PIXELS to the given coordinate system.
Definition: Detector.cc:441
void setPixelSize(lsst::geom::Extent2D const &pixelSize)
Set the pixel size (in mm).
Definition: Detector.h:566
std::shared_ptr< Detector const > finish() const
Construct a new Detector from the current state of the Builder.
Definition: Detector.cc:388
bool hasTransform(CameraSys const &cameraSys) const
Can this object convert between PIXELS and the specified camera coordinate system?
Definition: Detector.cc:82
std::shared_ptr< afw::geom::TransformPoint2ToPoint2 > getTransform(FromSysT const &fromSys, ToSysT const &toSys) const
Get a Transform from one camera coordinate system, or camera coordinate system prefix,...
std::size_t size() const
Get the number of amplifiers.
Definition: Detector.h:299
lsst::geom::Point2D transform(lsst::geom::Point2D const &point, FromSysT const &fromSys, ToSysT const &toSys) const
Transform a point from one camera system to another.
Definition: Detector.cc:95
std::vector< lsst::geom::Point2D > getCorners(CameraSys const &cameraSys) const
Get the corners of the detector in the specified camera coordinate system.
Definition: Detector.cc:62
lsst::geom::Point2D getCenter(CameraSys const &cameraSys) const
Get the center of the detector in the specified camera coordinate system.
Definition: Detector.cc:72
void wrapDetector(lsst::utils::python::WrapperCollection &)
Definition: _detector.cc:195
py::class_< PixelAreaBoundedField, std::shared_ptr< PixelAreaBoundedField >, BoundedField > PyClass
void addPersistableMethods(pybind11::class_< Class, Args... > &cls)
Add table::io::Persistable and PersistableFacade methods to the pybind11 wrapper for a class.
Definition: python.h:56
std::size_t cppIndex(std::ptrdiff_t size, std::ptrdiff_t i)
Compute a C++ index from a Python index (negative values count from the end) and range-check.
Definition: python.h:124
A base class for image defects.