LSSTApplications  12.1-5-gbdcc3ab+2,15.0+13,15.0+26,15.0-1-g19261fa+17,15.0-1-g60afb23+26,15.0-1-g615e0bb+18,15.0-1-g788a293+26,15.0-1-ga91101e+26,15.0-1-gae1598d+12,15.0-1-gd076f1f+24,15.0-1-gdf18595+5,15.0-1-gf4f1c34+12,15.0-11-g7db6e543+4,15.0-12-g3681e7a+4,15.0-15-gc15de322,15.0-16-g83b84f4,15.0-2-g100d730+19,15.0-2-g1f9c9cf+4,15.0-2-g8aea5f4+1,15.0-2-gf38729e+21,15.0-29-ga12a2b06e,15.0-3-g11fe1a0+14,15.0-3-g707930d+3,15.0-3-g9103c06+12,15.0-3-gd3cbb57+3,15.0-4-g2d82b59,15.0-4-g535e784+10,15.0-4-g92ca6c3+4,15.0-4-gf906033+2,15.0-5-g23e394c+14,15.0-5-g4be42a9,15.0-6-g69628aa,15.0-6-g86e3f3d+1,15.0-6-gfa9b38f+4,15.0-7-g949993c+3,15.0-8-g67a62d3+1,15.0-8-gcf05001+1,15.0-9-g1e7c341+1,w.2018.21
LSSTDataManagementBasePackage
spherePoint.cc
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 2008-2017 AURA/LSST.
4  *
5  * This product includes software developed by the
6  * LSST Project (http://www.lsst.org/).
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 LSST License Statement and
19  * the GNU General Public License along with this program. If not,
20  * see <https://www.lsstcorp.org/LegalNotices/>.
21  */
22 
23 #include "pybind11/pybind11.h"
24 #include "pybind11/stl.h"
25 
26 #include <memory>
27 
28 #include "lsst/utils/python.h"
29 
30 #include "lsst/utils/python.h"
32 #include "lsst/sphgeom/Vector3d.h"
33 #include "lsst/sphgeom/LonLat.h"
34 #include "lsst/afw/geom/Angle.h"
35 #include "lsst/afw/geom/Point.h"
37 
38 namespace py = pybind11;
39 using namespace py::literals;
40 
41 namespace lsst {
42 namespace afw {
43 namespace geom {
44 
45 using PySpherePoint = py::class_<SpherePoint, std::shared_ptr<SpherePoint>>;
46 
47 PYBIND11_PLUGIN(spherePoint) {
48  py::module mod("spherePoint");
49 
50  py::module::import("lsst.sphgeom");
51  py::module::import("lsst.afw.geom.angle");
52  py::module::import("lsst.afw.geom.coordinates");
53 
54  /* Module level */
55  mod.def("averageSpherePoint", averageSpherePoint);
56  PySpherePoint cls(mod, "SpherePoint");
57 
58  /* Constructors */
59  cls.def(py::init<>());
60  cls.def(py::init<Angle const &, Angle const &>(), "longitude"_a, "latitude"_a);
61  cls.def(py::init<double, double, AngleUnit>(), "longitude"_a, "latitude"_a, "units"_a);
62  cls.def(py::init<sphgeom::Vector3d const &>(), "vector"_a);
63  cls.def(py::init<sphgeom::UnitVector3d const &>(), "unitVector"_a);
64  cls.def(py::init<sphgeom::LonLat const &>(), "lonLat"_a);
65  cls.def(py::init<SpherePoint const &>(), "other"_a);
66 
67  py::implicitly_convertible<SpherePoint, sphgeom::LonLat>();
68  py::implicitly_convertible<sphgeom::LonLat, SpherePoint>();
69 
70  /* Operators */
71  cls.def("__getitem__",
72  [](SpherePoint const &self, std::ptrdiff_t i) { return self[utils::python::cppIndex(2, i)]; });
73  cls.def("__eq__", &SpherePoint::operator==, py::is_operator());
74  cls.def("__ne__", &SpherePoint::operator!=, py::is_operator());
75 
76  /* Members */
77  cls.def("getLongitude", &SpherePoint::getLongitude);
78  cls.def("getLatitude", &SpherePoint::getLatitude);
79  cls.def("getRa", &SpherePoint::getRa);
80  cls.def("getDec", &SpherePoint::getDec);
81  cls.def("getVector", &SpherePoint::getVector);
82  cls.def("getPosition", &SpherePoint::getPosition, "units"_a);
83  cls.def("atPole", &SpherePoint::atPole);
84  cls.def("isFinite", &SpherePoint::isFinite);
85  cls.def("bearingTo", &SpherePoint::bearingTo, "other"_a);
86  cls.def("separation", &SpherePoint::separation, "other"_a);
87  cls.def("rotated", &SpherePoint::rotated, "axis"_a, "amount"_a);
88  cls.def("offset", &SpherePoint::offset, "bearing"_a, "amount"_a);
89  cls.def("getTangentPlaneOffset", &SpherePoint::getTangentPlaneOffset, "other"_a);
90  utils::python::addOutputOp(cls, "__str__");
91  cls.def("__len__", [](SpherePoint const &) { return 2; });
92  cls.def("__reduce__", [cls](SpherePoint const &self) {
93  return py::make_tuple(cls,
94  py::make_tuple(py::cast(self.getLongitude()), py::cast(self.getLatitude())));
95  });
96 
97  return mod.ptr();
98 }
99 }
100 }
101 } // namespace lsst::afw::geom
Point in an unspecified spherical coordinate system.
Definition: SpherePoint.h:61
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
py::class_< SpherePoint, std::shared_ptr< SpherePoint > > PySpherePoint
Definition: spherePoint.cc:45
PYBIND11_PLUGIN(spherePoint)
Definition: spherePoint.cc:47
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:232