LSST Applications g0f08755f38+82efc23009,g12f32b3c4e+e7bdf1200e,g1653933729+a8ce1bb630,g1a0ca8cf93+50eff2b06f,g28da252d5a+52db39f6a5,g2bbee38e9b+37c5a29d61,g2bc492864f+37c5a29d61,g2cdde0e794+c05ff076ad,g3156d2b45e+41e33cbcdc,g347aa1857d+37c5a29d61,g35bb328faa+a8ce1bb630,g3a166c0a6a+37c5a29d61,g3e281a1b8c+fb992f5633,g414038480c+7f03dfc1b0,g41af890bb2+11b950c980,g5fbc88fb19+17cd334064,g6b1c1869cb+12dd639c9a,g781aacb6e4+a8ce1bb630,g80478fca09+72e9651da0,g82479be7b0+04c31367b4,g858d7b2824+82efc23009,g9125e01d80+a8ce1bb630,g9726552aa6+8047e3811d,ga5288a1d22+e532dc0a0b,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc28159a63d+37c5a29d61,gcf0d15dbbd+2acd6d4d48,gd7358e8bfb+778a810b6e,gda3e153d99+82efc23009,gda6a2b7d83+2acd6d4d48,gdaeeff99f8+1711a396fd,ge2409df99d+6b12de1076,ge79ae78c31+37c5a29d61,gf0baf85859+d0a5978c5a,gf3967379c6+4954f8c433,gfb92a5be7c+82efc23009,gfec2e1e490+2aaed99252,w.2024.46
LSST Data Management Base Package
Loading...
Searching...
No Matches
_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"
29
30#include "pybind11/stl.h"
31
32#include "ndarray/pybind11.h"
33
36#include "lsst/geom.h"
41
42namespace py = pybind11;
43using namespace py::literals;
44
45namespace lsst {
46namespace afw {
47namespace cameraGeom {
48
49namespace {
50
51using PyDetectorBase = py::class_<DetectorBase, std::shared_ptr<DetectorBase>>;
52using PyDetector = py::class_<Detector, DetectorBase, std::shared_ptr<Detector>, typehandling::Storable>;
53using PyDetectorBuilder = py::class_<Detector::Builder, DetectorBase, std::shared_ptr<Detector::Builder>>;
54using PyDetectorPartialRebuilder = py::class_<Detector::PartialRebuilder, Detector::Builder,
56using PyDetectorInCameraBuilder =
57 py::class_<Detector::InCameraBuilder, Detector::Builder, std::shared_ptr<Detector::InCameraBuilder>>;
58
59// Declare Detector methods overloaded on one coordinate system class
60template <typename SysT, typename PyClass>
61void declare1SysMethods(PyClass &cls) {
62 cls.def("getCorners",
63 (std::vector<lsst::geom::Point2D>(Detector::*)(SysT const &) const) & Detector::getCorners,
64 "cameraSys"_a);
65 cls.def("getCenter", (lsst::geom::Point2D(Detector::*)(SysT const &) const) & Detector::getCenter,
66 "cameraSys"_a);
67 cls.def("hasTransform", (bool (Detector::*)(SysT const &) const) & Detector::hasTransform, "cameraSys"_a);
68}
69
70// Declare Detector methods templated on two coordinate system classes
71template <typename FromSysT, typename ToSysT, typename PyClass>
72void declare2SysMethods(PyClass &cls) {
73 cls.def("getTransform",
74 (std::shared_ptr<geom::TransformPoint2ToPoint2>(Detector::*)(FromSysT const &, ToSysT const &)
75 const) &
76 Detector::getTransform,
77 "fromSys"_a, "toSys"_a);
78 cls.def("transform",
79 (lsst::geom::Point2D(Detector::*)(lsst::geom::Point2D const &, FromSysT const &, ToSysT const &)
80 const) &
81 Detector::transform,
82 "point"_a, "fromSys"_a, "toSys"_a);
83 cls.def("transform",
84 (std::vector<lsst::geom::Point2D>(Detector::*)(std::vector<lsst::geom::Point2D> const &,
85 FromSysT const &, ToSysT const &) const) &
86 Detector::transform,
87 "points"_a, "fromSys"_a, "toSys"_a);
88}
89
90void declareDetectorBase(lsst::cpputils::python::WrapperCollection &wrappers) {
91 wrappers.wrapType(PyDetectorBase(wrappers.module, "DetectorBase"), [](auto &mod, auto &cls) {
92 cls.def("getName", &DetectorBase::getName);
93 cls.def("getId", &DetectorBase::getId);
94 cls.def("getType", &DetectorBase::getType);
95 cls.def("getPhysicalType", &DetectorBase::getPhysicalType);
96 cls.def("getSerial", &DetectorBase::getSerial);
97 cls.def("getBBox", &DetectorBase::getBBox);
98 cls.def("getOrientation", &DetectorBase::getOrientation);
99 cls.def("getPixelSize", &DetectorBase::getPixelSize);
100 cls.def("hasCrosstalk", &DetectorBase::hasCrosstalk);
101 cls.def("getCrosstalk", &DetectorBase::getCrosstalk);
102 cls.def("getNativeCoordSys", &DetectorBase::getNativeCoordSys);
103 cls.def("makeCameraSys",
104 py::overload_cast<CameraSys const &>(&DetectorBase::makeCameraSys, py::const_),
105 "cameraSys"_a);
106 cls.def("makeCameraSys",
107 py::overload_cast<CameraSysPrefix const &>(&DetectorBase::makeCameraSys, py::const_),
108 "cameraSysPrefix"_a);
109 });
110}
111
112void declareDetectorBuilder(PyDetector &parent);
113void declareDetectorPartialRebuilder(PyDetector &parent);
114void declareDetectorInCameraBuilder(PyDetector &parent);
115
116void declareDetector(lsst::cpputils::python::WrapperCollection &wrappers) {
117 wrappers.wrapType(PyDetector(wrappers.module, "Detector"), [](auto &mod, auto &cls) {
118 declareDetectorBuilder(cls);
119 declareDetectorPartialRebuilder(cls);
120 declareDetectorInCameraBuilder(cls);
121 cls.def("rebuild", &Detector::rebuild);
122 declare1SysMethods<CameraSys>(cls);
123 declare1SysMethods<CameraSysPrefix>(cls);
124 declare2SysMethods<CameraSys, CameraSys>(cls);
125 declare2SysMethods<CameraSys, CameraSysPrefix>(cls);
126 declare2SysMethods<CameraSysPrefix, CameraSys>(cls);
127 declare2SysMethods<CameraSysPrefix, CameraSysPrefix>(cls);
128 cls.def("getTransformMap", &Detector::getTransformMap);
129 cls.def("getAmplifiers", &Detector::getAmplifiers);
130 // __iter__ defined in pure-Python extension
131 cls.def(
132 "__getitem__",
133 [](Detector const &self, std::ptrdiff_t i) {
134 return self[cpputils::python::cppIndex(self.size(), i)];
135 },
136 "i"_a);
137 cls.def("__getitem__", py::overload_cast<std::string const &>(&Detector::operator[], py::const_),
138 "name"_a);
139 cls.def("__len__", &Detector::size);
141 });
142}
143
144void declareDetectorBuilder(PyDetector &parent) {
145 PyDetectorBuilder cls(parent, "Builder");
146 cls.def("setBBox", &Detector::Builder::setBBox);
147 cls.def("setType", &Detector::Builder::setType);
148 cls.def("setSerial", &Detector::Builder::setSerial);
149 cls.def("setPhysicalType", &Detector::Builder::setPhysicalType);
150 cls.def("setCrosstalk", &Detector::Builder::setCrosstalk);
151 cls.def("unsetCrosstalk", &Detector::Builder::unsetCrosstalk);
152 cls.def("getAmplifiers", &Detector::Builder::getAmplifiers);
153 cls.def(
154 "__getitem__",
155 [](Detector::Builder const &self, std::ptrdiff_t i) {
156 return self[cpputils::python::cppIndex(self.size(), i)];
157 },
158 "i"_a);
159 cls.def("__getitem__", py::overload_cast<std::string const &>(&Detector::Builder::operator[], py::const_),
160 "name"_a);
161 cls.def("append", &Detector::Builder::append);
162 cls.def("clear", &Detector::Builder::clear);
163 cls.def("__len__", &Detector::Builder::size);
164}
165
166void declareDetectorPartialRebuilder(PyDetector &parent) {
167 PyDetectorPartialRebuilder cls(parent, "PartialRebuilder");
168 cls.def(py::init<Detector const &>(), "detector"_a);
169 cls.def("finish", &Detector::PartialRebuilder::finish);
170}
171
172void declareDetectorInCameraBuilder(PyDetector &parent) {
173 PyDetectorInCameraBuilder cls(parent, "InCameraBuilder");
174 cls.def("setOrientation", &Detector::InCameraBuilder::setOrientation);
175 cls.def("setPixelSize", &Detector::InCameraBuilder::setPixelSize);
176 cls.def("setTransformFromPixelsTo",
177 py::overload_cast<CameraSysPrefix const &,
180 "toSys"_a, "transform"_a);
181 cls.def("setTransformFromPixelsTo",
182 py::overload_cast<CameraSys const &, std::shared_ptr<afw::geom::TransformPoint2ToPoint2 const>>(
184 "toSys"_a, "transform"_a);
185 cls.def("discardTransformFromPixelsTo",
186 py::overload_cast<CameraSysPrefix const &>(
188 "toSys"_a);
189 cls.def("discardTransformFromPixelsTo",
190 py::overload_cast<CameraSys const &>(&Detector::InCameraBuilder::discardTransformFromPixelsTo),
191 "toSys"_a);
192}
193} // namespace
195 wrappers.addInheritanceDependency("lsst.afw.typehandling");
196 wrappers.wrapType(py::enum_<DetectorType>(wrappers.module, "DetectorType"), [](auto &mod, auto &enm) {
197 enm.value("SCIENCE", DetectorType::SCIENCE);
198 enm.value("FOCUS", DetectorType::FOCUS);
199 enm.value("GUIDER", DetectorType::GUIDER);
200 enm.value("WAVEFRONT", DetectorType::WAVEFRONT);
201 });
202 declareDetectorBase(wrappers);
203 declareDetector(wrappers);
204}
205} // namespace cameraGeom
206} // namespace afw
207} // namespace lsst
table::Key< int > transform
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:376
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:438
bool discardTransformFromPixelsTo(CameraSysPrefix const &toSys)
Remove any transformation from PIXELS to the given coordinate system.
Definition Detector.cc:466
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:413
std::size_t size() const
Get the number of amplifiers.
Definition Detector.h:299
A helper class for subdividing pybind11 module across multiple translation units (i....
Definition python.h:242
void addInheritanceDependency(std::string const &name)
Indicate an external module that provides a base class for a subsequent addType call.
Definition python.h:343
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 wrapDetector(lsst::cpputils::python::WrapperCollection &)
Definition _detector.cc:194
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
Point< double, 2 > Point2D
Definition Point.h:324
STL namespace.