lsst.afw  14.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
skyWcs.cc
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 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 <http://www.lsstcorp.org/LegalNotices/>.
21  */
22 #include "pybind11/pybind11.h"
23 
24 #include <utility>
25 #include <memory>
26 
27 #include "astshim.h"
28 #include "Eigen/Core"
29 #include "pybind11/stl.h"
30 #include "numpy/arrayobject.h"
31 #include "ndarray/pybind11.h"
32 
33 #include "lsst/afw/coord/Coord.h"
34 #include "lsst/afw/geom/Endpoint.h"
35 #include "lsst/afw/geom/Point.h"
37 #include "lsst/afw/geom/SkyWcs.h"
38 
39 namespace py = pybind11;
40 using namespace py::literals;
41 
42 namespace lsst {
43 namespace afw {
44 namespace geom {
45 namespace {
46 
47 PYBIND11_PLUGIN(skyWcs) {
48  py::module mod("skyWcs");
49 
50  py::module::import("lsst.afw.geom.transform");
51 
52  // Need to import numpy for ndarray and eigen conversions
53  if (_import_array() < 0) {
54  PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import");
55  return nullptr;
56  }
57 
58  mod.def("makeCdMatrix", makeCdMatrix, "scale"_a, "orientation"_a = 0 * degrees, "flipX"_a = false);
59 
60  py::class_<SkyWcs, std::shared_ptr<SkyWcs>, Transform<Point2Endpoint, IcrsCoordEndpoint>> cls(mod,
61  "SkyWcs");
62 
63  cls.def(py::init<Point2D const &, coord::IcrsCoord const &, Eigen::Matrix2d const &>(), "crpix"_a, "crval"_a,
64  "cdMatrix"_a);
65  cls.def(py::init<daf::base::PropertyList &>(), "metadata"_a);
66  cls.def(py::init<ast::FrameSet const&>(), "frameSet"_a);
67 
68  cls.def("getPixelScale", (Angle (SkyWcs::*)(Point2D const &) const) &SkyWcs::getPixelScale, "pixel"_a);
69  cls.def("getPixelScale", (Angle (SkyWcs::*)() const) &SkyWcs::getPixelScale);
70  cls.def("getPixelOrigin", &SkyWcs::getPixelOrigin);
71  cls.def("getSkyOrigin", &SkyWcs::getSkyOrigin);
72  cls.def("getCdMatrix", (Eigen::Matrix2d(SkyWcs::*)(Point2D const &) const) & SkyWcs::getCdMatrix,
73  "pixel"_a);
74  cls.def("getCdMatrix", (Eigen::Matrix2d(SkyWcs::*)() const) & SkyWcs::getCdMatrix);
75  cls.def("copyAtShiftedPixelOrigin", &SkyWcs::copyAtShiftedPixelOrigin, "shift"_a);
76  cls.def("pixelToSky", (std::pair<Angle, Angle>(SkyWcs::*)(double, double) const) & SkyWcs::pixelToSky,
77  "x"_a, "y"_a);
78  cls.def("pixelToSky", (coord::IcrsCoord(SkyWcs::*)(Point2D const &) const) & SkyWcs::pixelToSky, "pixel"_a);
79  cls.def("pixelToSky",
80  (std::vector<coord::IcrsCoord>(SkyWcs::*)(std::vector<Point2D> const &) const) & SkyWcs::pixelToSky,
81  "pixel"_a);
82  cls.def("skyToPixel",
83  (std::pair<double, double>(SkyWcs::*)(Angle const &, Angle const &) const) & SkyWcs::skyToPixel,
84  "ra"_a, "dec"_a);
85  cls.def("skyToPixel", (Point2D(SkyWcs::*)(coord::IcrsCoord const &) const) & SkyWcs::skyToPixel, "sky"_a);
86  cls.def("skyToPixel",
87  (std::vector<Point2D>(SkyWcs::*)(std::vector<coord::IcrsCoord> const &) const) & SkyWcs::skyToPixel,
88  "sky"_a);
89  // Do not wrap getShortClassName because it returns the name of the class;
90  // use `<class>.__name__` or `type(<instance>).__name__` instead.
91  // Do not wrap readStream or writeStream because C++ streams are not easy to wrap.
92  cls.def_static("readString", &SkyWcs::readString);
93  cls.def("writeString", &SkyWcs::writeString);
94 
95  return mod.ptr();
96 }
97 
98 } // namespace
99 } // namespace geom
100 } // namespace afw
101 } // namespace lsst
lsst::afw::geom::Angle Angle
Definition: misc.h:36
AngleUnit constexpr degrees
constant with units of degrees
Definition: Angle.h:88
PYBIND11_PLUGIN(_cameraPoint)
Definition: cameraPoint.cc:35
lsst::afw::coord::IcrsCoord IcrsCoord
Definition: misc.h:35
Point< double, 2 > Point2D
Definition: Point.h:273
double const _a
Definition: RandomImage.cc:77
Eigen::Matrix2d makeCdMatrix(Angle const &scale, Angle const &orientation=0 *degrees, bool flipX=false)
Make a WCS CD matrix.