LSST Applications g04e9c324dd+8c5ae1fdc5,g134cb467dc+1b3060144d,g18429d2f64+f642bf4753,g199a45376c+0ba108daf9,g1fd858c14a+2dcf163641,g262e1987ae+7b8c96d2ca,g29ae962dfc+3bd6ecb08a,g2cef7863aa+aef1011c0b,g35bb328faa+8c5ae1fdc5,g3fd5ace14f+53e1a9e7c5,g4595892280+fef73a337f,g47891489e3+2efcf17695,g4d44eb3520+642b70b07e,g53246c7159+8c5ae1fdc5,g67b6fd64d1+2efcf17695,g67fd3c3899+b70e05ef52,g74acd417e5+317eb4c7d4,g786e29fd12+668abc6043,g87389fa792+8856018cbb,g89139ef638+2efcf17695,g8d7436a09f+3be3c13596,g8ea07a8fe4+9f5ccc88ac,g90f42f885a+a4e7b16d9b,g97be763408+ad77d7208f,g9dd6db0277+b70e05ef52,ga681d05dcb+a3f46e7fff,gabf8522325+735880ea63,gac2eed3f23+2efcf17695,gb89ab40317+2efcf17695,gbf99507273+8c5ae1fdc5,gd8ff7fe66e+b70e05ef52,gdab6d2f7ff+317eb4c7d4,gdc713202bf+b70e05ef52,gdfd2d52018+b10e285e0f,ge365c994fd+310e8507c4,ge410e46f29+2efcf17695,geaed405ab2+562b3308c0,gffca2db377+8c5ae1fdc5,w.2025.35
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::classh<DetectorBase, typehandling::Storable>;
52using PyDetector = py::classh<Detector, DetectorBase>;
53using PyDetectorBuilder = py::classh<Detector::Builder, DetectorBase>;
54using PyDetectorPartialRebuilder = py::classh<Detector::PartialRebuilder, Detector::Builder>;
55using PyDetectorInCameraBuilder = py::classh<Detector::InCameraBuilder, Detector::Builder>;
56
57// Declare Detector methods overloaded on one coordinate system class
58template <typename SysT, typename PyClass>
59void declare1SysMethods(PyClass &cls) {
60 cls.def("getCorners",
61 (std::vector<lsst::geom::Point2D>(Detector::*)(SysT const &) const) & Detector::getCorners,
62 "cameraSys"_a);
63 cls.def("getCenter", (lsst::geom::Point2D(Detector::*)(SysT const &) const) & Detector::getCenter,
64 "cameraSys"_a);
65 cls.def("hasTransform", (bool (Detector::*)(SysT const &) const) & Detector::hasTransform, "cameraSys"_a);
66}
67
68// Declare Detector methods templated on two coordinate system classes
69template <typename FromSysT, typename ToSysT, typename PyClass>
70void declare2SysMethods(PyClass &cls) {
71 cls.def("getTransform",
72 (std::shared_ptr<geom::TransformPoint2ToPoint2>(Detector::*)(FromSysT const &, ToSysT const &)
73 const) &
75 "fromSys"_a, "toSys"_a);
76 cls.def("transform",
77 (lsst::geom::Point2D(Detector::*)(lsst::geom::Point2D const &, FromSysT const &, ToSysT const &)
78 const) &
80 "point"_a, "fromSys"_a, "toSys"_a);
81 cls.def("transform",
82 (std::vector<lsst::geom::Point2D>(Detector::*)(std::vector<lsst::geom::Point2D> const &,
83 FromSysT const &, ToSysT const &) const) &
85 "points"_a, "fromSys"_a, "toSys"_a);
86}
87
88void declareDetectorBase(lsst::cpputils::python::WrapperCollection &wrappers) {
89 wrappers.wrapType(PyDetectorBase(wrappers.module, "DetectorBase"), [](auto &mod, auto &cls) {
90 cls.def("getName", &DetectorBase::getName);
91 cls.def("getId", &DetectorBase::getId);
92 cls.def("getType", &DetectorBase::getType);
93 cls.def("getPhysicalType", &DetectorBase::getPhysicalType);
94 cls.def("getSerial", &DetectorBase::getSerial);
95 cls.def("getBBox", &DetectorBase::getBBox);
96 cls.def("getOrientation", &DetectorBase::getOrientation);
97 cls.def("getPixelSize", &DetectorBase::getPixelSize);
98 cls.def("hasCrosstalk", &DetectorBase::hasCrosstalk);
99 cls.def("getCrosstalk", &DetectorBase::getCrosstalk);
100 cls.def("getNativeCoordSys", &DetectorBase::getNativeCoordSys);
101 cls.def("makeCameraSys",
102 py::overload_cast<CameraSys const &>(&DetectorBase::makeCameraSys, py::const_),
103 "cameraSys"_a);
104 cls.def("makeCameraSys",
105 py::overload_cast<CameraSysPrefix const &>(&DetectorBase::makeCameraSys, py::const_),
106 "cameraSysPrefix"_a);
107 });
108}
109
110void declareDetectorBuilder(PyDetector &parent);
111void declareDetectorPartialRebuilder(PyDetector &parent);
112void declareDetectorInCameraBuilder(PyDetector &parent);
113
114void declareDetector(lsst::cpputils::python::WrapperCollection &wrappers) {
115 wrappers.wrapType(PyDetector(wrappers.module, "Detector"), [](auto &mod, auto &cls) {
116 declareDetectorBuilder(cls);
117 declareDetectorPartialRebuilder(cls);
118 declareDetectorInCameraBuilder(cls);
119 cls.def("rebuild", &Detector::rebuild);
120 declare1SysMethods<CameraSys>(cls);
121 declare1SysMethods<CameraSysPrefix>(cls);
122 declare2SysMethods<CameraSys, CameraSys>(cls);
123 declare2SysMethods<CameraSys, CameraSysPrefix>(cls);
124 declare2SysMethods<CameraSysPrefix, CameraSys>(cls);
125 declare2SysMethods<CameraSysPrefix, CameraSysPrefix>(cls);
126 cls.def("getTransformMap", &Detector::getTransformMap);
127 cls.def("getAmplifiers", &Detector::getAmplifiers);
128 // __iter__ defined in pure-Python extension
129 cls.def(
130 "__getitem__",
131 [](Detector const &self, std::ptrdiff_t i) {
132 return self[cpputils::python::cppIndex(self.size(), i)];
133 },
134 "i"_a);
135 cls.def("__getitem__", py::overload_cast<std::string const &>(&Detector::operator[], py::const_),
136 "name"_a);
137 cls.def("__len__", &Detector::size);
139 });
140}
141
142void declareDetectorBuilder(PyDetector &parent) {
143 PyDetectorBuilder cls(parent, "Builder");
144 cls.def("setBBox", &Detector::Builder::setBBox);
145 cls.def("setType", &Detector::Builder::setType);
146 cls.def("setSerial", &Detector::Builder::setSerial);
147 cls.def("setPhysicalType", &Detector::Builder::setPhysicalType);
148 cls.def("setCrosstalk", &Detector::Builder::setCrosstalk);
149 cls.def("unsetCrosstalk", &Detector::Builder::unsetCrosstalk);
150 cls.def("getAmplifiers", &Detector::Builder::getAmplifiers);
151 cls.def(
152 "__getitem__",
153 [](Detector::Builder const &self, std::ptrdiff_t i) {
154 return self[cpputils::python::cppIndex(self.size(), i)];
155 },
156 "i"_a);
157 cls.def("__getitem__", py::overload_cast<std::string const &>(&Detector::Builder::operator[], py::const_),
158 "name"_a);
159 cls.def("append", &Detector::Builder::append);
160 cls.def("clear", &Detector::Builder::clear);
161 cls.def("__len__", &Detector::Builder::size);
162}
163
164void declareDetectorPartialRebuilder(PyDetector &parent) {
165 PyDetectorPartialRebuilder cls(parent, "PartialRebuilder");
166 cls.def(py::init<Detector const &>(), "detector"_a);
167 cls.def("finish", &Detector::PartialRebuilder::finish);
168}
169
170void declareDetectorInCameraBuilder(PyDetector &parent) {
171 PyDetectorInCameraBuilder cls(parent, "InCameraBuilder");
172 cls.def("setOrientation", &Detector::InCameraBuilder::setOrientation);
173 cls.def("setPixelSize", &Detector::InCameraBuilder::setPixelSize);
174 cls.def("setTransformFromPixelsTo",
175 py::overload_cast<CameraSysPrefix const &,
176 std::shared_ptr<afw::geom::TransformPoint2ToPoint2 const>>(
178 "toSys"_a, "transform"_a);
179 cls.def("setTransformFromPixelsTo",
180 py::overload_cast<CameraSys const &, std::shared_ptr<afw::geom::TransformPoint2ToPoint2 const>>(
182 "toSys"_a, "transform"_a);
183 cls.def("discardTransformFromPixelsTo",
184 py::overload_cast<CameraSysPrefix const &>(
186 "toSys"_a);
187 cls.def("discardTransformFromPixelsTo",
188 py::overload_cast<CameraSys const &>(&Detector::InCameraBuilder::discardTransformFromPixelsTo),
189 "toSys"_a);
190}
191} // namespace
193 wrappers.addInheritanceDependency("lsst.afw.typehandling");
194 wrappers.wrapType(py::enum_<DetectorType>(wrappers.module, "DetectorType"), [](auto &mod, auto &enm) {
195 enm.value("SCIENCE", DetectorType::SCIENCE);
196 enm.value("FOCUS", DetectorType::FOCUS);
197 enm.value("GUIDER", DetectorType::GUIDER);
198 enm.value("WAVEFRONT", DetectorType::WAVEFRONT);
199 });
200 declareDetectorBase(wrappers);
201 declareDetector(wrappers);
202}
203} // namespace cameraGeom
204} // namespace afw
205} // namespace lsst
Camera coordinate system; used as a key in in TransformMap.
Definition CameraSys.h:83
Camera coordinate system prefix.
Definition CameraSys.h:44
A helper class for Detector that allows amplifiers and most fields to be modified.
Definition Detector.h:361
void setSerial(std::string const &serial)
Set the detector serial "number".
Definition Detector.h:380
void setBBox(lsst::geom::Box2I const &bbox)
Set the bounding box.
Definition Detector.h:374
void setPhysicalType(std::string const &physicalType)
Set the detector's physical type.
Definition Detector.h:387
void setCrosstalk(CrosstalkMatrix const &crosstalk)
Set the crosstalk coefficients.
Definition Detector.h:399
std::vector< std::shared_ptr< Amplifier::Builder > > const & getAmplifiers() const
Return the sequence of Amplifier::Builders directly.
Definition Detector.h:417
void setType(DetectorType type)
Set the purpose of this detector.
Definition Detector.h:377
void unsetCrosstalk()
Remove the crosstalk coefficient matrix.
Definition Detector.h:402
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:450
void clear()
Remove all amplifiers.
Definition Detector.h:447
void setOrientation(Orientation const &orientation)
Set the orientation of the detector in the focal plane.
Definition Detector.h:560
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:565
std::shared_ptr< Detector const > finish() const
Construct a new Detector from the current state of the Builder.
Definition Detector.cc:413
A representation of a detector in a mosaic camera.
Definition Detector.h:184
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:298
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
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
pybind11::module module
The module object passed to the PYBIND11_MODULE block that contains this WrapperCollection.
Definition python.h:448
void wrapDetector(lsst::cpputils::python::WrapperCollection &)
Definition _detector.cc:192
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