lsst.afw  13.0-91-g2a3e2ee
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
wcs.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 
25 #include <memory>
26 
27 #include "numpy/arrayobject.h"
28 #include "ndarray/pybind11.h"
29 
30 #include "lsst/daf/base/Citizen.h"
31 #include "lsst/daf/base/PropertySet.h"
32 #include "lsst/afw/coord/Coord.h"
34 #include "lsst/afw/geom/Extent.h"
35 #include "lsst/afw/geom/Point.h"
38 #include "lsst/afw/table/io/python.h" // for declarePersistableFacade
39 #include "lsst/afw/image/Wcs.h"
40 
41 namespace py = pybind11;
42 using namespace py::literals;
43 
44 namespace lsst {
45 namespace afw {
46 namespace image {
47 
48 namespace {
49 
50 using PyWcs = py::class_<Wcs, std::shared_ptr<Wcs>, daf::base::Citizen, table::io::Persistable,
51  table::io::PersistableFacade<Wcs>>;
52 
53 using PyXYTransformFromWcsPair =
54  py::class_<XYTransformFromWcsPair, std::shared_ptr<XYTransformFromWcsPair>, geom::XYTransform>;
55 
57 void declareWcs(py::module &mod) {
58  table::io::python::declarePersistableFacade<Wcs>(mod, "Wcs");
59 
60  /* Module level */
61  PyWcs cls(mod, "Wcs");
62 
63  /* Constructors */
64  cls.def(py::init<geom::Point2D const &, geom::Point2D const &, Eigen::Matrix2d const &,
65  std::string const &, std::string const &, double, std::string const &,
66  std::string const &, std::string const &>(),
67  "crval"_a, "crpix"_a, "CD"_a, "ctype1"_a = "RA---TAN", "ctype2"_a = "DEC--TAN",
68  "equinox"_a = 2000, "raDecSys"_a = "ICRS", "cunits1"_a = "deg", "cunits2"_a = "deg");
69 
70  /* Operators */
71  cls.def("__eq__", [](Wcs const &self, Wcs const &other) { return self == other; }, py::is_operator());
72  cls.def("__ne__", [](Wcs const &self, Wcs const &other) { return self != other; }, py::is_operator());
73 
74  /* Members */
75  cls.def("clone", &Wcs::clone);
76  cls.def("getSkyOrigin", &Wcs::getSkyOrigin);
77  cls.def("getPixelOrigin", &Wcs::getPixelOrigin);
78  cls.def("getCDMatrix", &Wcs::getCDMatrix);
79  cls.def("flipImage", &Wcs::flipImage);
80  cls.def("rotateImageBy90", &Wcs::rotateImageBy90);
81  cls.def("getFitsMetadata", &Wcs::getFitsMetadata);
82  cls.def("isFlipped", &Wcs::isFlipped);
83  cls.def("pixArea", &Wcs::pixArea);
84  cls.def("pixelScale", &Wcs::pixelScale);
85  cls.def("pixelToSky", (std::shared_ptr<coord::Coord> (Wcs::*)(double, double) const) & Wcs::pixelToSky);
86  cls.def("pixelToSky",
87  (std::shared_ptr<coord::Coord> (Wcs::*)(geom::Point2D const &) const) & Wcs::pixelToSky);
88  cls.def("pixelToSky",
89  (void (Wcs::*)(double, double, geom::Angle &, geom::Angle &) const) & Wcs::pixelToSky);
90  cls.def("skyToPixel", (geom::Point2D (Wcs::*)(geom::Angle, geom::Angle) const) & Wcs::skyToPixel);
91  cls.def("skyToPixel", (geom::Point2D (Wcs::*)(coord::Coord const &) const) & Wcs::skyToPixel);
92  cls.def("skyToIntermediateWorldCoord", &Wcs::skyToIntermediateWorldCoord);
93  cls.def("hasDistortion", &Wcs::hasDistortion);
94  cls.def("getCoordSystem", &Wcs::getCoordSystem);
95  cls.def("getEquinox", &Wcs::getEquinox);
96  cls.def("isSameSkySystem", &Wcs::isSameSkySystem);
97  cls.def("getLinearTransform", &Wcs::getLinearTransform);
98  cls.def("linearizePixelToSky",
99  (geom::AffineTransform (Wcs::*)(coord::Coord const &, geom::AngleUnit) const) &
100  Wcs::linearizePixelToSky,
101  "coord"_a, "skyUnit"_a = geom::degrees);
102  cls.def("linearizePixelToSky",
103  (geom::AffineTransform (Wcs::*)(geom::Point2D const &, geom::AngleUnit) const) &
104  Wcs::linearizePixelToSky,
105  "coord"_a, "skyUnit"_a = geom::degrees);
106  cls.def("linearizeSkyToPixel",
107  (geom::AffineTransform (Wcs::*)(coord::Coord const &, geom::AngleUnit) const) &
108  Wcs::linearizeSkyToPixel,
109  "coord"_a, "skyUnit"_a = geom::degrees);
110  cls.def("linearizeSkyToPixel",
111  (geom::AffineTransform (Wcs::*)(geom::Point2D const &, geom::AngleUnit) const) &
112  Wcs::linearizeSkyToPixel,
113  "coord"_a, "skyUnit"_a = geom::degrees);
114  cls.def("shiftReferencePixel", (void (Wcs::*)(double, double)) & Wcs::shiftReferencePixel);
115  cls.def("shiftReferencePixel", (void (Wcs::*)(geom::Extent2D const &)) & Wcs::shiftReferencePixel);
116  cls.def("isPersistable", &Wcs::isPersistable);
117 }
118 
120 void declareXYTransformFromWcsPair(py::module &mod) {
121  PyXYTransformFromWcsPair cls(mod, "XYTransformFromWcsPair");
122  cls.def(py::init<std::shared_ptr<Wcs const>, std::shared_ptr<Wcs const>>(), "dst"_a, "src"_a);
123  // virtual methods already wrapped by XYTransform base class.
124 }
125 
126 } // anonymous namespace
127 
129  py::module mod("wcs");
130 
131  py::module::import("lsst.afw.geom");
132 
133  if (_import_array() < 0) {
134  PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import");
135  return nullptr;
136  };
137 
138  mod.def("makeWcs",
139  (std::shared_ptr<Wcs>(*)(std::shared_ptr<daf::base::PropertySet> const &, bool)) & makeWcs,
140  "fitsMetadata"_a, "stripMetadata"_a = false);
141  mod.def("makeWcs", (std::shared_ptr<Wcs>(*)(coord::Coord const &, lsst::afw::geom::Point2D const &,
142  double, double, double, double)) &
143  makeWcs);
144 
145  declareWcs(mod);
146 
147  declareXYTransformFromWcsPair(mod);
148 
149  return mod.ptr();
150 }
151 }
152 }
153 } // namespace lsst::afw::image
lsst::afw::geom::Angle Angle
Definition: misc.h:36
lsst::afw::coord::Coord Coord
Definition: misc.h:33
Extent< double, 2 > Extent2D
Definition: Extent.h:344
std::shared_ptr< ImageT > flipImage(ImageT const &inImage, bool flipLR, bool flipTB)
Flip an image left–right and/or top–bottom.
Definition: rotateImage.cc:92
AngleUnit constexpr degrees
constant with units of degrees
Definition: Angle.h:88
PYBIND11_PLUGIN(_cameraPoint)
Definition: cameraPoint.cc:35
Point< double, 2 > Point2D
Definition: Point.h:273
std::shared_ptr< ImageT > rotateImageBy90(ImageT const &image, int nQuarter)
Rotate an image by an integral number of quarter turns.
Definition: rotateImage.cc:39
double const _a
Definition: RandomImage.cc:77
afw::table::Key< afw::table::Array< ImagePixelT > > image
This is the base class for spherical coordinates.
Definition: Coord.h:63
std::shared_ptr< Wcs > makeWcs(std::shared_ptr< lsst::daf::base::PropertySet > const &fitsMetadata, bool stripMetadata=false)
Create a Wcs object from a fits header.