LSSTApplications  16.0-1-gce273f5+15,16.0-1-gf77f410+8,16.0-10-g230e10e+8,16.0-10-g5a5abec+4,16.0-10-gc1446dd+8,16.0-11-g5cf5345,16.0-12-g1dc09ba+2,16.0-12-g726f8f3+6,16.0-13-g4c33ca5+8,16.0-13-g5f6c0b1+8,16.0-13-gd9b1b71+8,16.0-14-g71e547a+4,16.0-17-g0bdc215,16.0-17-g6a7bfb3b+8,16.0-18-g95848a16+2,16.0-2-g0febb12+12,16.0-2-g839ba83+46,16.0-2-g9d5294e+35,16.0-3-g404ea43+7,16.0-3-gbc759ec+6,16.0-3-gcfd6c53+33,16.0-4-g03cf288+24,16.0-4-g13a27c5+10,16.0-4-g2cc461c+3,16.0-4-g5f3a788+11,16.0-4-g8a0f11a+30,16.0-4-ga3eb747+1,16.0-43-gaa65a4573+4,16.0-5-g1991253+8,16.0-5-g865efd9+8,16.0-5-gb3f8a4b+40,16.0-5-gd0f1235+4,16.0-6-g316b399+8,16.0-6-gf0acd13+27,16.0-6-gf9cb114+9,16.0-7-ga8e1655+4,16.0-8-g23bbf3f+1,16.0-8-g4dec96c+21,16.0-8-gfd407c0,w.2018.39
LSSTDataManagementBasePackage
spherePoint.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"
24 
25 #include <memory>
26 
27 #include "lsst/utils/python.h"
28 
29 #include "lsst/utils/python.h"
31 #include "lsst/sphgeom/Vector3d.h"
32 #include "lsst/sphgeom/LonLat.h"
33 #include "lsst/geom/Angle.h"
34 #include "lsst/geom/Point.h"
35 #include "lsst/geom/SpherePoint.h"
36 
37 namespace py = pybind11;
38 using namespace py::literals;
39 
40 namespace lsst {
41 namespace geom {
42 namespace {
43 
44 using PySpherePoint = py::class_<SpherePoint, std::shared_ptr<SpherePoint>>;
45 
46 PYBIND11_MODULE(spherePoint, mod) {
47  py::module::import("lsst.sphgeom");
48  py::module::import("lsst.geom.angle");
49  py::module::import("lsst.geom.coordinates");
50 
51  /* Module level */
52  mod.def("averageSpherePoint", averageSpherePoint);
53  PySpherePoint cls(mod, "SpherePoint");
54 
55  /* Constructors */
56  cls.def(py::init<>());
57  cls.def(py::init<Angle const &, Angle const &>(), "longitude"_a, "latitude"_a);
58  cls.def(py::init<double, double, AngleUnit>(), "longitude"_a, "latitude"_a, "units"_a);
59  cls.def(py::init<sphgeom::Vector3d const &>(), "vector"_a);
60  cls.def(py::init<sphgeom::UnitVector3d const &>(), "unitVector"_a);
61  cls.def(py::init<sphgeom::LonLat const &>(), "lonLat"_a);
62  cls.def(py::init<SpherePoint const &>(), "other"_a);
63 
64  py::implicitly_convertible<SpherePoint, sphgeom::LonLat>();
65  py::implicitly_convertible<sphgeom::LonLat, SpherePoint>();
66 
67  /* Operators */
68  cls.def("__getitem__",
69  [](SpherePoint const &self, std::ptrdiff_t i) { return self[utils::python::cppIndex(2, i)]; });
70  cls.def("__eq__", &SpherePoint::operator==, py::is_operator());
71  cls.def("__ne__", &SpherePoint::operator!=, py::is_operator());
72 
73  /* Members */
74  cls.def("getLongitude", &SpherePoint::getLongitude);
75  cls.def("getLatitude", &SpherePoint::getLatitude);
76  cls.def("getRa", &SpherePoint::getRa);
77  cls.def("getDec", &SpherePoint::getDec);
78  cls.def("getVector", &SpherePoint::getVector);
79  cls.def("getPosition", &SpherePoint::getPosition, "units"_a);
80  cls.def("atPole", &SpherePoint::atPole);
81  cls.def("isFinite", &SpherePoint::isFinite);
82  cls.def("bearingTo", &SpherePoint::bearingTo, "other"_a);
83  cls.def("separation", &SpherePoint::separation, "other"_a);
84  cls.def("rotated", &SpherePoint::rotated, "axis"_a, "amount"_a);
85  cls.def("offset", &SpherePoint::offset, "bearing"_a, "amount"_a);
86  cls.def("getTangentPlaneOffset", &SpherePoint::getTangentPlaneOffset, "other"_a);
87  utils::python::addOutputOp(cls, "__str__");
88  cls.def("__len__", [](SpherePoint const &) { return 2; });
89  cls.def("__reduce__", [cls](SpherePoint const &self) {
90  return py::make_tuple(cls,
91  py::make_tuple(py::cast(self.getLongitude()), py::cast(self.getLatitude())));
92  });
93 }
94 
95 } // namespace
96 } // namespace geom
97 } // namespace lsst
void addOutputOp(PyClass &cls, std::string const &method)
Add __str__ or __repr__ method implemented by operator<<.
Definition: python.h:82
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:119
This file declares a class for representing vectors in ℝ³.
This file declares a class for representing unit vectors in ℝ³.
A base class for image defects.
Definition: cameraGeom.dox:3
PYBIND11_MODULE(cameraSys, mod)
Definition: cameraSys.cc:62
lsst::geom::SpherePoint SpherePoint
Definition: misc.h:35
This file contains a class representing spherical coordinates.
SpherePoint averageSpherePoint(std::vector< SpherePoint > const &coords)
Return the average of a list of coordinates.
Definition: SpherePoint.cc:229