LSST Applications  21.0.0+04719a4bac,21.0.0-1-ga51b5d4+f5e6047307,21.0.0-11-g2b59f77+a9c1acf22d,21.0.0-11-ga42c5b2+86977b0b17,21.0.0-12-gf4ce030+76814010d2,21.0.0-13-g1721dae+760e7a6536,21.0.0-13-g3a573fe+768d78a30a,21.0.0-15-g5a7caf0+f21cbc5713,21.0.0-16-g0fb55c1+b60e2d390c,21.0.0-19-g4cded4ca+71a93a33c0,21.0.0-2-g103fe59+bb20972958,21.0.0-2-g45278ab+04719a4bac,21.0.0-2-g5242d73+3ad5d60fb1,21.0.0-2-g7f82c8f+8babb168e8,21.0.0-2-g8f08a60+06509c8b61,21.0.0-2-g8faa9b5+616205b9df,21.0.0-2-ga326454+8babb168e8,21.0.0-2-gde069b7+5e4aea9c2f,21.0.0-2-gecfae73+1d3a86e577,21.0.0-2-gfc62afb+3ad5d60fb1,21.0.0-25-g1d57be3cd+e73869a214,21.0.0-3-g357aad2+ed88757d29,21.0.0-3-g4a4ce7f+3ad5d60fb1,21.0.0-3-g4be5c26+3ad5d60fb1,21.0.0-3-g65f322c+e0b24896a3,21.0.0-3-g7d9da8d+616205b9df,21.0.0-3-ge02ed75+a9c1acf22d,21.0.0-4-g591bb35+a9c1acf22d,21.0.0-4-g65b4814+b60e2d390c,21.0.0-4-gccdca77+0de219a2bc,21.0.0-4-ge8a399c+6c55c39e83,21.0.0-5-gd00fb1e+05fce91b99,21.0.0-6-gc675373+3ad5d60fb1,21.0.0-64-g1122c245+4fb2b8f86e,21.0.0-7-g04766d7+cd19d05db2,21.0.0-7-gdf92d54+04719a4bac,21.0.0-8-g5674e7b+d1bd76f71f,master-gac4afde19b+a9c1acf22d,w.2021.13
LSST Data Management Base Package
_skyWcs.cc
Go to the documentation of this file.
1 /*
2  * This file is part of afw.
3  *
4  * Developed for the LSST Data Management System.
5  * This product includes software developed by the LSST Project
6  * (https://www.lsst.org).
7  * See the COPYRIGHT file at the top-level directory of this distribution
8  * for details of code ownership.
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <https://www.gnu.org/licenses/>.
22  */
23 
24 #include "pybind11/pybind11.h"
25 #include <lsst/utils/python.h>
26 #include "pybind11/eigen.h"
27 
28 #include <memory>
29 
30 #include "astshim.h"
31 #include "Eigen/Core"
32 #include "pybind11/stl.h"
33 #include "ndarray/pybind11.h"
34 
35 #include "lsst/geom.h"
38 #include "lsst/afw/geom/SkyWcs.h"
39 #include "lsst/afw/table/io/python.h" // for addPersistableMethods
40 
41 namespace py = pybind11;
42 using namespace py::literals;
43 
44 namespace lsst {
45 namespace afw {
46 namespace geom {
47 namespace {
48 
49 void declareSkyWcs(lsst::utils::python::WrapperCollection &wrappers) {
50  wrappers.wrap([](auto &mod) {
51  mod.def("makeCdMatrix", makeCdMatrix, "scale"_a, "orientation"_a = 0 * lsst::geom::degrees,
52  "flipX"_a = false);
53  mod.def("makeFlippedWcs", makeFlippedWcs, "wcs"_a, "flipLR"_a, "flipTB"_a, "center"_a);
54  mod.def("makeModifiedWcs", makeModifiedWcs, "pixelTransform"_a, "wcs"_a, "modifyActualPixels"_a);
55  mod.def("makeSkyWcs",
57  Eigen::Matrix2d const &, std::string const &))makeSkyWcs,
58  "crpix"_a, "crval"_a, "cdMatrix"_a, "projection"_a = "TAN");
59  mod.def("makeSkyWcs", (std::shared_ptr<SkyWcs>(*)(daf::base::PropertySet &, bool))makeSkyWcs,
60  "metadata"_a, "strip"_a = false);
61  mod.def("makeSkyWcs",
64  "pixelsToFieldAngle"_a, "orientation"_a, "flipX"_a, "boresight"_a, "projection"_a = "TAN");
65  mod.def("makeTanSipWcs",
67  Eigen::Matrix2d const &, Eigen::MatrixXd const &,
68  Eigen::MatrixXd const &))makeTanSipWcs,
69  "crpix"_a, "crval"_a, "cdMatrix"_a, "sipA"_a, "sipB"_a);
70  mod.def("makeTanSipWcs",
72  Eigen::Matrix2d const &, Eigen::MatrixXd const &,
73  Eigen::MatrixXd const &, Eigen::MatrixXd const &,
74  Eigen::MatrixXd const &))makeTanSipWcs,
75  "crpix"_a, "crval"_a, "cdMatrix"_a, "sipA"_a, "sipB"_a, "sipAp"_a, "sipBp"_a);
76  mod.def("makeWcsPairTransform", makeWcsPairTransform, "src"_a, "dst"_a);
77  mod.def("getIntermediateWorldCoordsToSky", getIntermediateWorldCoordsToSky, "wcs"_a,
78  "simplify"_a = true);
79  mod.def("getPixelToIntermediateWorldCoords", getPixelToIntermediateWorldCoords, "wcs"_a,
80  "simplify"_a = true);
81  });
82  wrappers.wrapType(
83  py::class_<SkyWcs, std::shared_ptr<SkyWcs>, typehandling::Storable>(wrappers.module, "SkyWcs"),
84  [](auto &mod, auto &cls) {
85  cls.def(py::init<daf::base::PropertySet &, bool>(), "metadata"_a, "strip"_a = false);
86  cls.def(py::init<ast::FrameDict const &>(), "frameDict"_a);
87 
88  cls.def("__eq__", &SkyWcs::operator==, py::is_operator());
89  cls.def("__ne__", &SkyWcs::operator!=, py::is_operator());
90 
91  table::io::python::addPersistableMethods<SkyWcs>(cls);
92 
93  cls.def("copyAtShiftedPixelOrigin", &SkyWcs::copyAtShiftedPixelOrigin, "shift"_a);
94  cls.def("getFitsMetadata", &SkyWcs::getFitsMetadata, "precise"_a = false);
95  cls.def("getPixelScale",
96  (lsst::geom::Angle(SkyWcs::*)(lsst::geom::Point2D const &) const) &
97  SkyWcs::getPixelScale,
98  "pixel"_a);
99  cls.def("getPixelScale", (lsst::geom::Angle(SkyWcs::*)() const) & SkyWcs::getPixelScale);
100  cls.def("getPixelOrigin", &SkyWcs::getPixelOrigin);
101  cls.def("getSkyOrigin", &SkyWcs::getSkyOrigin);
102  cls.def("getCdMatrix",
103  (Eigen::Matrix2d(SkyWcs::*)(lsst::geom::Point2D const &) const) & SkyWcs::getCdMatrix,
104  "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) &
134  SkyWcs::pixelToSky,
135  "pixel"_a);
136  cls.def("pixelToSky",
137  (lsst::geom::SpherePoint(SkyWcs::*)(double, double) const) & SkyWcs::pixelToSky,
138  "x"_a, "y"_a);
139  cls.def("pixelToSky",
141  std::vector<lsst::geom::Point2D> const &) const) &
142  SkyWcs::pixelToSky,
143  "pixel"_a);
144  cls.def("skyToPixel",
145  (lsst::geom::Point2D(SkyWcs::*)(lsst::geom::SpherePoint const &) const) &
146  SkyWcs::skyToPixel,
147  "sky"_a);
148  cls.def("skyToPixel",
150  std::vector<lsst::geom::SpherePoint> const &) const) &
151  SkyWcs::skyToPixel,
152  "sky"_a);
153  // Do not wrap getShortClassName because it returns the name of the class;
154  // use `<class>.__name__` or `type(<instance>).__name__` instead.
155  // Do not wrap readStream or writeStream because C++ streams are not easy to wrap.
156  cls.def_static("readString", &SkyWcs::readString);
157  cls.def("writeString", &SkyWcs::writeString);
158 
159  utils::python::addOutputOp(cls, "__str__");
160  // For repr, we could instead call writeString for the very long AST Frame/Mapping output.
161  utils::python::addOutputOp(cls, "__repr__");
162  });
163 }
164 } // namespace
166  wrappers.addInheritanceDependency("lsst.afw.table.io");
167  wrappers.addInheritanceDependency("lsst.afw.typehandling");
168  wrappers.addSignatureDependency("astshim");
169  declareSkyWcs(wrappers);
170 }
171 } // namespace geom
172 } // namespace afw
173 } // namespace lsst
An affine coordinate transformation consisting of a linear transformation and an offset.
A class representing an angle.
Definition: Angle.h:127
A class used to convert scalar POD types such as double to Angle.
Definition: Angle.h:70
Point in an unspecified spherical coordinate system.
Definition: SpherePoint.h:57
A helper class for subdividing pybind11 module across multiple translation units (i....
Definition: python.h:242
pybind11::module module
The module object passed to the PYBIND11_MODULE block that contains this WrapperCollection.
Definition: python.h:448
PyType wrapType(PyType cls, ClassWrapperCallback function, bool setModuleName=true)
Add a type (class or enum) wrapper, deferring method and other attribute definitions until finish() i...
Definition: python.h:391
void addInheritanceDependency(std::string const &name)
Indicate an external module that provides a base class for a subsequent addType call.
Definition: python.h:343
void wrap(WrapperCallback function)
Add a set of wrappers without defining a class.
Definition: python.h:369
void addSignatureDependency(std::string const &name)
Indicate an external module that provides a type used in function/method signatures.
Definition: python.h:357
std::shared_ptr< SkyWcs > makeSkyWcs(daf::base::PropertySet &metadata, bool strip=false)
Construct a SkyWcs from FITS keywords.
Definition: SkyWcs.cc:526
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
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
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
std::shared_ptr< TransformPoint2ToSpherePoint > getIntermediateWorldCoordsToSky(SkyWcs const &wcs, bool simplify=true)
Return a transform from intermediate world coordinates to sky.
Definition: SkyWcs.cc:558
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
void wrapSkyWcs(lsst::utils::python::WrapperCollection &)
Definition: _skyWcs.cc:165
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
Transform< Point2Endpoint, Point2Endpoint > TransformPoint2ToPoint2
Definition: Transform.h:300
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
constexpr AngleUnit degrees
constant with units of degrees
Definition: Angle.h:109
void addOutputOp(PyClass &cls, std::string const &method)
Add __str__ or __repr__ method implemented by operator<<.
Definition: python.h:87
A base class for image defects.