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
_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("getFocalPlaneParity", &Camera::getFocalPlaneParity);
54 cls.def("findDetectors", &Camera::findDetectors, "point"_a, "cameraSys"_a);
55 cls.def("findDetectorsList", &Camera::findDetectorsList, "pointList"_a, "cameraSys"_a);
56 // transform methods are wrapped with lambdas that translate exceptions for backwards compatibility
57 cls.def(
58 "getTransform",
59 [](Camera const &self, CameraSys const &fromSys, CameraSys const &toSys) {
60 try {
61 return self.getTransform(fromSys, toSys);
62 } catch (pex::exceptions::NotFoundError &err) {
63 PyErr_SetString(PyExc_KeyError, err.what());
64 throw py::error_already_set();
65 }
66 },
67 "fromSys"_a, "toSys"_a);
68 cls.def("getTransformMap", &Camera::getTransformMap);
69 cls.def(
70 "transform",
71 [](Camera const &self, lsst::geom::Point2D const &point, CameraSys const &fromSys,
72 CameraSys const &toSys) {
73 try {
74 return self.transform(point, fromSys, toSys);
75 } catch (pex::exceptions::NotFoundError &err) {
76 PyErr_SetString(PyExc_KeyError, err.what());
77 throw py::error_already_set();
78 }
79 },
80 "point"_a, "fromSys"_a, "toSys"_a);
81 cls.def(
82 "transform",
83 [](Camera const &self, std::vector<lsst::geom::Point2D> const &points,
84 CameraSys const &fromSys, CameraSys const &toSys) {
85 try {
86 return self.transform(points, fromSys, toSys);
87 } catch (pex::exceptions::NotFoundError &err) {
88 PyErr_SetString(PyExc_KeyError, err.what());
89 throw py::error_already_set();
90 }
91 },
92 "points"_a, "fromSys"_a, "toSys"_a);
94 });
95 wrappers.wrapType(PyCameraBuilder(camera, "Builder"), [](auto &mod, auto &cls) {
96 cls.def(py::init<std::string const &>(), "name"_a);
97 cls.def(py::init<Camera const &>(), "camera"_a);
98 cls.def("finish", &Camera::Builder::finish);
99 cls.def("getName", &Camera::Builder::getName);
100 cls.def("setName", &Camera::Builder::setName);
101 cls.def("getPupilFactoryName", &Camera::Builder::getPupilFactoryName);
102 cls.def("setPupilFactoryName", &Camera::Builder::setPupilFactoryName);
103 cls.def("setPupilFactoryClass", [](Camera::Builder &self, py::object pupilFactoryClass) {
104 std::string pupilFactoryName = "lsst.afw.cameraGeom.pupil.PupilFactory";
105 if (!pupilFactoryClass.is(py::none())) {
106 pupilFactoryName = py::str("{}.{}").format(pupilFactoryClass.attr("__module__"),
107 pupilFactoryClass.attr("__name__"));
108 }
109 self.setPupilFactoryName(pupilFactoryName);
110 });
111 cls.def("getFocalPlaneParity", &Camera::Builder::getFocalPlaneParity);
112 cls.def("setFocalPlaneParity", &Camera::Builder::setFocalPlaneParity);
113 cls.def("setTransformFromFocalPlaneTo", &Camera::Builder::setTransformFromFocalPlaneTo, "toSys"_a,
114 "transform"_a);
115 cls.def("discardTransformFromFocalPlaneTo", &Camera::Builder::discardTransformFromFocalPlaneTo);
116 cls.def("add", &Camera::Builder::add);
117 cls.def("__delitem__", py::overload_cast<int>(&Camera::Builder::remove));
118 cls.def("__delitem__", py::overload_cast<std::string const &>(&Camera::Builder::remove));
119 });
120}
121
122} // namespace cameraGeom
123} // namespace afw
124} // 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:241
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:306
std::string getName() const
Return the name of the camera.
Definition Camera.h:232
void setFocalPlaneParity(bool flipX)
Set whether an x-axis flip should be included in the FOCAL_PLANE to FIELD_ANGLE transform.
Definition Camera.cc:234
std::string getPupilFactoryName() const
Return the fully-qualified name of the Python class that provides this Camera's PupilFactory.
Definition Camera.h:238
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:331
void remove(std::string const &name)
Remove the detector with the given name or ID.
Definition Camera.h:304
bool discardTransformFromFocalPlaneTo(CameraSys const &toSys)
Remove any transformation from FOCAL_PLANE to the given coordinate system.
Definition Camera.cc:322
bool getFocalPlaneParity() const noexcept
Return True if there is an x-axis flip from FOCAL_PLANE to FIELD_ANGLE, False otherwise.
Definition Camera.h:244
void setName(std::string const &name)
Set the name of the camera.
Definition Camera.h:235
std::shared_ptr< Camera const > finish() const
Construct a new Camera from the state of the Builder.
Definition Camera.cc:236
An immutable representation of a camera.
Definition Camera.h:42
std::shared_ptr< TransformMap const > getTransformMap() const noexcept
Obtain the transform registry.
Definition Camera.h:127
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:87
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