LSSTApplications  20.0.0
LSSTDataManagementBasePackage
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 #include "pybind11/eigen.h"
24 
25 #include <utility>
26 #include <memory>
27 
28 #include "astshim.h"
29 #include "Eigen/Core"
30 #include "pybind11/stl.h"
31 #include "ndarray/pybind11.h"
32 
33 #include "lsst/afw/fits.h"
34 #include "lsst/geom.h"
35 #include "lsst/afw/geom/Endpoint.h"
38 #include "lsst/afw/geom/SkyWcs.h"
39 #include "lsst/afw/table/io/python.h" // for addPersistableMethods
40 #include "lsst/utils/python.h"
41 
42 namespace py = pybind11;
43 using namespace py::literals;
44 
45 namespace lsst {
46 namespace afw {
47 namespace geom {
48 namespace {
49 
50 PYBIND11_MODULE(skyWcs, mod) {
51  py::module::import("lsst.geom");
52  py::module::import("lsst.afw.geom.transform");
53  py::module::import("lsst.afw.typehandling");
54 
55  mod.def("makeCdMatrix", makeCdMatrix, "scale"_a, "orientation"_a = 0 * lsst::geom::degrees,
56  "flipX"_a = false);
57  mod.def("makeFlippedWcs", makeFlippedWcs, "wcs"_a, "flipLR"_a, "flipTB"_a, "center"_a);
58  mod.def("makeModifiedWcs", makeModifiedWcs, "pixelTransform"_a, "wcs"_a, "modifyActualPixels"_a);
59  mod.def("makeSkyWcs",
61  Eigen::Matrix2d const &, std::string const &))makeSkyWcs,
62  "crpix"_a, "crval"_a, "cdMatrix"_a, "projection"_a = "TAN");
63  mod.def("makeSkyWcs", (std::shared_ptr<SkyWcs>(*)(daf::base::PropertySet &, bool))makeSkyWcs,
64  "metadata"_a, "strip"_a = false);
65  mod.def("makeSkyWcs",
68  "pixelsToFieldAngle"_a, "orientation"_a, "flipX"_a, "boresight"_a, "projection"_a = "TAN");
69  mod.def("makeTanSipWcs",
71  Eigen::Matrix2d const &, Eigen::MatrixXd const &,
72  Eigen::MatrixXd const &))makeTanSipWcs,
73  "crpix"_a, "crval"_a, "cdMatrix"_a, "sipA"_a, "sipB"_a);
74  mod.def("makeTanSipWcs",
76  Eigen::Matrix2d const &, Eigen::MatrixXd const &,
77  Eigen::MatrixXd const &, Eigen::MatrixXd const &,
78  Eigen::MatrixXd const &))makeTanSipWcs,
79  "crpix"_a, "crval"_a, "cdMatrix"_a, "sipA"_a, "sipB"_a, "sipAp"_a, "sipBp"_a);
80  mod.def("makeWcsPairTransform", makeWcsPairTransform, "src"_a, "dst"_a);
81  mod.def("getIntermediateWorldCoordsToSky", getIntermediateWorldCoordsToSky, "wcs"_a, "simplify"_a = true);
82  mod.def("getPixelToIntermediateWorldCoords", getPixelToIntermediateWorldCoords, "wcs"_a,
83  "simplify"_a = true);
84 
85  py::class_<SkyWcs, std::shared_ptr<SkyWcs>, typehandling::Storable> cls(mod, "SkyWcs");
86 
87  cls.def(py::init<daf::base::PropertySet &, bool>(), "metadata"_a, "strip"_a = false);
88  cls.def(py::init<ast::FrameDict const &>(), "frameDict"_a);
89 
90  cls.def("__eq__", &SkyWcs::operator==, py::is_operator());
91  cls.def("__ne__", &SkyWcs::operator!=, py::is_operator());
92 
93  table::io::python::addPersistableMethods<SkyWcs>(cls);
94 
95  cls.def("copyAtShiftedPixelOrigin", &SkyWcs::copyAtShiftedPixelOrigin, "shift"_a);
96  cls.def("getFitsMetadata", &SkyWcs::getFitsMetadata, "precise"_a = false);
97  cls.def("getPixelScale",
98  (lsst::geom::Angle(SkyWcs::*)(lsst::geom::Point2D const &) const) & SkyWcs::getPixelScale,
99  "pixel"_a);
100  cls.def("getPixelScale", (lsst::geom::Angle(SkyWcs::*)() const) & SkyWcs::getPixelScale);
101  cls.def("getPixelOrigin", &SkyWcs::getPixelOrigin);
102  cls.def("getSkyOrigin", &SkyWcs::getSkyOrigin);
103  cls.def("getCdMatrix",
104  (Eigen::Matrix2d(SkyWcs::*)(lsst::geom::Point2D const &) const) & SkyWcs::getCdMatrix, "pixel"_a);
105  cls.def("getCdMatrix", (Eigen::Matrix2d(SkyWcs::*)() const) & SkyWcs::getCdMatrix);
106  cls.def("getTanWcs", &SkyWcs::getTanWcs, "pixel"_a);
107  cls.def("getFrameDict", [](SkyWcs const &self) { return self.getFrameDict()->copy(); });
108  cls.def("getTransform", &SkyWcs::getTransform);
109 
110  cls.def_property_readonly("isFits", &SkyWcs::isFits);
111  cls.def_property_readonly("isFlipped", &SkyWcs::isFlipped);
112  cls.def("linearizePixelToSky",
114  lsst::geom::AngleUnit const &) const) &
115  SkyWcs::linearizePixelToSky,
116  "coord"_a, "skyUnit"_a);
117  cls.def("linearizePixelToSky",
119  lsst::geom::AngleUnit const &) const) &
120  SkyWcs::linearizePixelToSky,
121  "coord"_a, "skyUnit"_a);
122  cls.def("linearizeSkyToPixel",
124  lsst::geom::AngleUnit const &) const) &
125  SkyWcs::linearizeSkyToPixel,
126  "coord"_a, "skyUnit"_a);
127  cls.def("linearizeSkyToPixel",
129  lsst::geom::AngleUnit const &) const) &
130  SkyWcs::linearizeSkyToPixel,
131  "coord"_a, "skyUnit"_a);
132  cls.def("pixelToSky",
133  (lsst::geom::SpherePoint(SkyWcs::*)(lsst::geom::Point2D const &) const) & SkyWcs::pixelToSky,
134  "pixel"_a);
135  cls.def("pixelToSky", (lsst::geom::SpherePoint(SkyWcs::*)(double, double) const) & SkyWcs::pixelToSky,
136  "x"_a, "y"_a);
137  cls.def("pixelToSky",
139  const) &
140  SkyWcs::pixelToSky,
141  "pixel"_a);
142  cls.def("skyToPixel",
143  (lsst::geom::Point2D(SkyWcs::*)(lsst::geom::SpherePoint const &) const) & SkyWcs::skyToPixel,
144  "sky"_a);
145  cls.def("skyToPixel",
147  const) &
148  SkyWcs::skyToPixel,
149  "sky"_a);
150  // Do not wrap getShortClassName because it returns the name of the class;
151  // use `<class>.__name__` or `type(<instance>).__name__` instead.
152  // Do not wrap readStream or writeStream because C++ streams are not easy to wrap.
153  cls.def_static("readString", &SkyWcs::readString);
154  cls.def("writeString", &SkyWcs::writeString);
155 
156  utils::python::addOutputOp(cls, "__str__");
157  // For repr, we could instead call writeString for the very long AST Frame/Mapping output.
158  utils::python::addOutputOp(cls, "__repr__");
159 }
160 
161 } // namespace
162 } // namespace geom
163 } // namespace afw
164 } // namespace lsst
lsst::geom::degrees
constexpr AngleUnit degrees
constant with units of degrees
Definition: Angle.h:109
lsst::utils::python::addOutputOp
void addOutputOp(PyClass &cls, std::string const &method)
Add __str__ or __repr__ method implemented by operator<<.
Definition: python.h:87
std::string
STL class.
std::shared_ptr
STL class.
std::vector
STL class.
fits.h
lsst::afw
Definition: imageAlgorithm.dox:1
SkyWcs.h
lsst::afw::geom::makeModifiedWcs
std::shared_ptr< SkyWcs > makeModifiedWcs(TransformPoint2ToPoint2 const &pixelTransform, SkyWcs const &wcs, bool modifyActualPixels)
Create a new SkyWcs whose pixels are transformed by pixelTransform, as described below.
Definition: SkyWcs.cc:491
Endpoint.h
geom.h
Transform.h
astshim.h
lsst::afw::geom.transform.transformContinued.cls
cls
Definition: transformContinued.py:33
lsst::geom::AffineTransform
An affine coordinate transformation consisting of a linear transformation and an offset.
Definition: AffineTransform.h:75
lsst::afw::geom::getPixelToIntermediateWorldCoords
std::shared_ptr< TransformPoint2ToPoint2 > getPixelToIntermediateWorldCoords(SkyWcs const &wcs, bool simplify=true)
Return a transform from pixel coordinates to intermediate world coordinates.
Definition: SkyWcs.cc:564
lsst::afw::geom::makeTanSipWcs
std::shared_ptr< SkyWcs > makeTanSipWcs(lsst::geom::Point2D const &crpix, lsst::geom::SpherePoint const &crval, Eigen::Matrix2d const &cdMatrix, Eigen::MatrixXd const &sipA, Eigen::MatrixXd const &sipB)
Construct a TAN-SIP SkyWcs with forward SIP distortion terms and an iterative inverse.
Definition: SkyWcs.cc:543
lsst::afw::geom::makeFlippedWcs
std::shared_ptr< SkyWcs > makeFlippedWcs(SkyWcs const &wcs, bool flipLR, bool flipTB, lsst::geom::Point2D const &center)
Return a copy of a FITS-WCS with pixel positions flipped around a specified center.
Definition: SkyWcs.cc:472
lsst::afw::geom::TransformPoint2ToPoint2
Transform< Point2Endpoint, Point2Endpoint > TransformPoint2ToPoint2
Definition: Transform.h:300
std::copy
T copy(T... args)
Storable.h
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
python.h
lsst::afw::geom::getIntermediateWorldCoordsToSky
std::shared_ptr< TransformPoint2ToSpherePoint > getIntermediateWorldCoordsToSky(SkyWcs const &wcs, bool simplify=true)
Return a transform from intermediate world coordinates to sky.
Definition: SkyWcs.cc:558
lsst::geom
Definition: geomOperators.dox:4
python.h
lsst::afw::geom::makeCdMatrix
Eigen::Matrix2d makeCdMatrix(lsst::geom::Angle const &scale, lsst::geom::Angle const &orientation=0 *lsst::geom::degrees, bool flipX=false)
Make a WCS CD matrix.
Definition: SkyWcs.cc:138
lsst::afw::geom::makeWcsPairTransform
std::shared_ptr< TransformPoint2ToPoint2 > makeWcsPairTransform(SkyWcs const &src, SkyWcs const &dst)
A Transform obtained by putting two SkyWcs objects "back to back".
Definition: SkyWcs.cc:151
lsst::geom::Point< double, 2 >
lsst::geom::AngleUnit
A class used to convert scalar POD types such as double to Angle.
Definition: Angle.h:70
lsst::geom::Angle
A class representing an angle.
Definition: Angle.h:127
lsst::afw::geom::makeSkyWcs
std::shared_ptr< SkyWcs > makeSkyWcs(daf::base::PropertySet &metadata, bool strip=false)
Construct a SkyWcs from FITS keywords.
Definition: SkyWcs.cc:526
pybind11
Definition: _GenericMap.cc:40
lsst::geom::SpherePoint
Point in an unspecified spherical coordinate system.
Definition: SpherePoint.h:57
lsst::afw::cameraGeom::PYBIND11_MODULE
PYBIND11_MODULE(camera, mod)
Definition: camera.cc:133