LSSTApplications  17.0+11,17.0+34,17.0+56,17.0+57,17.0+59,17.0+7,17.0-1-g377950a+33,17.0.1-1-g114240f+2,17.0.1-1-g4d4fbc4+28,17.0.1-1-g55520dc+49,17.0.1-1-g5f4ed7e+52,17.0.1-1-g6dd7d69+17,17.0.1-1-g8de6c91+11,17.0.1-1-gb9095d2+7,17.0.1-1-ge9fec5e+5,17.0.1-1-gf4e0155+55,17.0.1-1-gfc65f5f+50,17.0.1-1-gfc6fb1f+20,17.0.1-10-g87f9f3f+1,17.0.1-11-ge9de802+16,17.0.1-16-ga14f7d5c+4,17.0.1-17-gc79d625+1,17.0.1-17-gdae4c4a+8,17.0.1-2-g26618f5+29,17.0.1-2-g54f2ebc+9,17.0.1-2-gf403422+1,17.0.1-20-g2ca2f74+6,17.0.1-23-gf3eadeb7+1,17.0.1-3-g7e86b59+39,17.0.1-3-gb5ca14a,17.0.1-3-gd08d533+40,17.0.1-30-g596af8797,17.0.1-4-g59d126d+4,17.0.1-4-gc69c472+5,17.0.1-6-g5afd9b9+4,17.0.1-7-g35889ee+1,17.0.1-7-gc7c8782+18,17.0.1-9-gc4bbfb2+3,w.2019.22
LSSTDataManagementBasePackage
camera.cc
Go to the documentation of this file.
1 /*
2  * Developed for the LSST Data Management System.
3  * This product includes software developed by the LSST Project
4  * (https://www.lsst.org).
5  * See the COPYRIGHT file at the top-level directory of this distribution
6  * for details of code ownership.
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
22 #include "pybind11/pybind11.h"
23 #include "pybind11/stl.h"
26 
27 namespace py = pybind11;
28 using namespace py::literals;
29 
30 namespace lsst {
31 namespace afw {
32 namespace cameraGeom {
33 
34 PYBIND11_MODULE(camera, mod){
35  py::module::import("lsst.afw.cameraGeom.detectorCollection");
36  py::module::import("lsst.afw.cameraGeom.transformMap");
37 
38  py::class_<Camera, DetectorCollection, std::shared_ptr<Camera>> cls(mod, "Camera");
39 
40  cls.def(py::init<std::string const &, Camera::DetectorList const &,
42  "name"_a, "detectorList"_a, "transformMap"_a, "pupilFactoryName"_a);
43  // Python-only constructor that takes a PupilFactory type object for
44  // backwards compatibility.
45  cls.def(
46  py::init(
47  [](
48  std::string const & name,
49  Camera::DetectorList const & detectorList,
51  py::object pupilFactoryClass
52  ) {
53  std::string pupilFactoryName = "lsst.afw.cameraGeom.pupil.PupilFactory";
54  if (!pupilFactoryClass.is(py::none())) {
55  pupilFactoryName = py::str("{}.{}").format(
56  pupilFactoryClass.attr("__module__"),
57  pupilFactoryClass.attr("__name__")
58  );
59  }
60  return std::make_shared<Camera>(name, detectorList, transformMap, pupilFactoryName);
61  }
62  ),
63  "name"_a,
64  "detectorList"_a,
65  "transformMap"_a,
66  "pupilFactoryClass"_a=py::none()
67  );
68  cls.def("getName", &Camera::getName);
69  cls.def("getPupilFactoryName", &Camera::getPupilFactoryName);
70  cls.def("findDetectors", &Camera::findDetectors, "point"_a, "cameraSys"_a);
71  cls.def("findDetectorsList", &Camera::findDetectorsList, "pointList"_a, "cameraSys"_a);
72  cls.def("getTransformMap", &Camera::getTransformMap);
73  // transform methods are wrapped with lambdas that translate exceptions for backwards compatibility
74  cls.def(
75  "getTransform",
76  [](Camera const & self, CameraSys const & fromSys, CameraSys const & toSys) {
77  try {
78  return self.getTransform(fromSys, toSys);
79  } catch (pex::exceptions::NotFoundError & err) {
80  PyErr_SetString(PyExc_KeyError, err.what());
81  throw py::error_already_set();
82  }
83  },
84  "fromSys"_a, "toSys"_a
85  );
86  cls.def(
87  "transform",
88  [](
89  Camera const & self,
90  lsst::geom::Point2D const & point,
91  CameraSys const & fromSys,
92  CameraSys const & toSys
93  ) {
94  try {
95  return self.transform(point, fromSys, toSys);
96  } catch (pex::exceptions::NotFoundError & err) {
97  PyErr_SetString(PyExc_KeyError, err.what());
98  throw py::error_already_set();
99  }
100  },
101  "point"_a, "fromSys"_a, "toSys"_a
102  );
103  cls.def(
104  "transform",
105  [](
106  Camera const & self,
107  std::vector<lsst::geom::Point2D> const & points,
108  CameraSys const & fromSys,
109  CameraSys const & toSys
110  ) {
111  try {
112  return self.transform(points, fromSys, toSys);
113  } catch (pex::exceptions::NotFoundError & err) {
114  PyErr_SetString(PyExc_KeyError, err.what());
115  throw py::error_already_set();
116  }
117  },
118  "points"_a, "fromSys"_a, "toSys"_a
119  );
120 
122 }
123 
124 } // cameraGeom
125 } // afw
126 } // lsst
Camera coordinate system; used as a key in in TransformMap.
Definition: CameraSys.h:83
def init()
Definition: tests.py:75
PYBIND11_MODULE(camera, mod)
Definition: camera.cc:34
A collection of Detectors plus additional coordinate system support.
Definition: Camera.h:43
void addPersistableMethods(pybind11::class_< Class, Args... > &cls)
Add table::io::Persistable and PersistableFacade methods to the pybind11 wrapper for a class...
Definition: python.h:88
STL class.
Reports attempts to access elements using an invalid key.
Definition: Runtime.h:151
virtual char const * what(void) const noexcept
Return a character string summarizing this exception.
Definition: Exception.cc:99
A base class for image defects.
table::Key< int > transformMap
Definition: Camera.cc:164
STL class.
table::Key< std::string > pupilFactoryName
Definition: Camera.cc:163