LSST Applications g0fba68d861+5616995c1c,g1ebb85f214+2420ccdea7,g1fd858c14a+44c57a1f81,g21d47ad084+8e51fce9ac,g262e1987ae+1a7d68eb3b,g2cef7863aa+3bd8df3d95,g35bb328faa+fcb1d3bbc8,g36ff55ed5b+2420ccdea7,g47891489e3+5c6313fe9a,g53246c7159+fcb1d3bbc8,g646c943bdb+dbb9921566,g67b6fd64d1+5c6313fe9a,g6bd32b75b5+2420ccdea7,g74acd417e5+37fc0c974d,g786e29fd12+cf7ec2a62a,g86c591e316+6e13bcb9e9,g87389fa792+1e0a283bba,g89139ef638+5c6313fe9a,g90f42f885a+fce05a46d3,g9125e01d80+fcb1d3bbc8,g93e38de9ac+5345a64125,g95a1e89356+47d08a1cc6,g97be763408+bba861c665,ga9e4eb89a6+85210110a1,gb0b61e0e8e+1f27f70249,gb58c049af0+f03b321e39,gb89ab40317+5c6313fe9a,gc4e39d7843+4e09c98c3d,gd16ba4ae74+5402bcf54a,gd8ff7fe66e+2420ccdea7,gd9a9a58781+fcb1d3bbc8,gdab6d2f7ff+37fc0c974d,gde280f09ee+604b327636,ge278dab8ac+50e2446c94,ge410e46f29+5c6313fe9a,gef3c2e6661+6b480e0fb7,gf67bdafdda+5c6313fe9a,gffca2db377+fcb1d3bbc8,v29.2.0.rc1
LSST Data Management Base Package
Loading...
Searching...
No Matches
_camera.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
27#include "pybind11/stl.h"
28
31
32namespace py = pybind11;
33using namespace py::literals;
34
35namespace lsst {
36namespace afw {
37namespace cameraGeom {
38
39using PyCamera = py::classh<Camera, DetectorCollection>;
40using PyCameraBuilder = py::classh<Camera::Builder, DetectorCollectionBase<Detector::InCameraBuilder>>;
41
42// Bindings here are ordered to match the order of the declarations in
43// Camera.h to the greatest extent possible; modifications to this file should
44// attempt to preserve this.
45
47 wrappers.addInheritanceDependency("lsst.afw.table.io");
48 wrappers.addSignatureDependency("lsst.afw.cameraGeom");
49 auto camera = wrappers.wrapType(PyCamera(wrappers.module, "Camera"), [](auto &mod, auto &cls) {
50 cls.def("rebuild", &Camera::rebuild);
51 cls.def("getName", &Camera::getName);
52 cls.def("getPupilFactoryName", &Camera::getPupilFactoryName);
53 cls.def("findDetectors", &Camera::findDetectors, "point"_a, "cameraSys"_a);
54 cls.def("findDetectorsList", &Camera::findDetectorsList, "pointList"_a, "cameraSys"_a);
55 // transform methods are wrapped with lambdas that translate exceptions for backwards compatibility
56 cls.def(
57 "getTransform",
58 [](Camera const &self, CameraSys const &fromSys, CameraSys const &toSys) {
59 try {
60 return self.getTransform(fromSys, toSys);
61 } catch (pex::exceptions::NotFoundError &err) {
62 PyErr_SetString(PyExc_KeyError, err.what());
63 throw py::error_already_set();
64 }
65 },
66 "fromSys"_a, "toSys"_a);
67 cls.def("getTransformMap", &Camera::getTransformMap);
68 cls.def(
69 "transform",
70 [](Camera const &self, lsst::geom::Point2D const &point, CameraSys const &fromSys,
71 CameraSys const &toSys) {
72 try {
73 return self.transform(point, fromSys, toSys);
74 } catch (pex::exceptions::NotFoundError &err) {
75 PyErr_SetString(PyExc_KeyError, err.what());
76 throw py::error_already_set();
77 }
78 },
79 "point"_a, "fromSys"_a, "toSys"_a);
80 cls.def(
81 "transform",
82 [](Camera const &self, std::vector<lsst::geom::Point2D> const &points,
83 CameraSys const &fromSys, CameraSys const &toSys) {
84 try {
85 return self.transform(points, fromSys, toSys);
86 } catch (pex::exceptions::NotFoundError &err) {
87 PyErr_SetString(PyExc_KeyError, err.what());
88 throw py::error_already_set();
89 }
90 },
91 "points"_a, "fromSys"_a, "toSys"_a);
93 });
94 wrappers.wrapType(PyCameraBuilder(camera, "Builder"), [](auto &mod, auto &cls) {
95 cls.def(py::init<std::string const &>(), "name"_a);
96 cls.def(py::init<Camera const &>(), "camera"_a);
97 cls.def("finish", &Camera::Builder::finish);
98 cls.def("getName", &Camera::Builder::getName);
99 cls.def("setName", &Camera::Builder::setName);
100 cls.def("getPupilFactoryName", &Camera::Builder::getPupilFactoryName);
101 cls.def("setPupilFactoryName", &Camera::Builder::setPupilFactoryName);
102 cls.def("setPupilFactoryClass", [](Camera::Builder &self, py::object pupilFactoryClass) {
103 std::string pupilFactoryName = "lsst.afw.cameraGeom.pupil.PupilFactory";
104 if (!pupilFactoryClass.is(py::none())) {
105 pupilFactoryName = py::str("{}.{}").format(pupilFactoryClass.attr("__module__"),
106 pupilFactoryClass.attr("__name__"));
107 }
108 self.setPupilFactoryName(pupilFactoryName);
109 });
110 cls.def("setTransformFromFocalPlaneTo", &Camera::Builder::setTransformFromFocalPlaneTo, "toSys"_a,
111 "transform"_a);
112 cls.def("discardTransformFromFocalPlaneTo", &Camera::Builder::discardTransformFromFocalPlaneTo);
113 cls.def("add", &Camera::Builder::add);
114 cls.def("__delitem__", py::overload_cast<int>(&Camera::Builder::remove));
115 cls.def("__delitem__", py::overload_cast<std::string const &>(&Camera::Builder::remove));
116 });
117}
118
119} // namespace cameraGeom
120} // namespace afw
121} // namespace lsst
void setPupilFactoryName(std::string const &pupilFactoryName)
Set the fully-qualified name of the Python class that provides this Camera's PupilFactory.
Definition Camera.h:239
void setTransformFromFocalPlaneTo(CameraSys const &toSys, std::shared_ptr< afw::geom::TransformPoint2ToPoint2 const > transform)
Set the transformation from FOCAL_PLANE to the given coordinate system.
Definition Camera.cc:311
std::string getName() const
Return the name of the camera.
Definition Camera.h:230
std::string getPupilFactoryName() const
Return the fully-qualified name of the Python class that provides this Camera's PupilFactory.
Definition Camera.h:236
std::shared_ptr< Detector::InCameraBuilder > add(std::string const &name, int id)
Add a new Detector with the given name and ID.
Definition Camera.cc:341
void remove(std::string const &name)
Remove the detector with the given name or ID.
Definition Camera.h:283
bool discardTransformFromFocalPlaneTo(CameraSys const &toSys)
Remove any transformation from FOCAL_PLANE to the given coordinate system.
Definition Camera.cc:332
void setName(std::string const &name)
Set the name of the camera.
Definition Camera.h:233
std::shared_ptr< Camera const > finish() const
Construct a new Camera from the state of the Builder.
Definition Camera.cc:246
An immutable representation of a camera.
Definition Camera.h:43
std::shared_ptr< TransformMap const > getTransformMap() const noexcept
Obtain the transform registry.
Definition Camera.h:120
lsst::geom::Point2D transform(lsst::geom::Point2D const &point, CameraSys const &fromSys, CameraSys const &toSys) const
Transform a point from one camera coordinate system to another.
Definition Camera.cc:83
Camera coordinate system; used as a key in in TransformMap.
Definition CameraSys.h:83
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
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
virtual char const * what(void) const noexcept
Return a character string summarizing this exception.
Definition Exception.cc:99
Reports attempts to access elements using an invalid key.
Definition Runtime.h:151
void wrapCamera(lsst::cpputils::python::WrapperCollection &wrappers)
Definition _camera.cc:46
py::classh< Camera::Builder, DetectorCollectionBase< Detector::InCameraBuilder > > PyCameraBuilder
Definition _camera.cc:40
py::classh< Camera, DetectorCollection > PyCamera
Definition _camera.cc:39
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
Point< double, 2 > Point2D
Definition Point.h:324