LSST Applications  21.0.0+c4f5df5339,21.0.0+e70536a077,21.0.0-1-ga51b5d4+7c60f8a6ea,21.0.0-10-g560fb7b+411cd868f8,21.0.0-10-gcf60f90+8c49d86aa0,21.0.0-13-gc485e61d+38156233bf,21.0.0-16-g7a993c7b9+1041c3824f,21.0.0-2-g103fe59+d9ceee3e5a,21.0.0-2-g1367e85+0b2f7db15a,21.0.0-2-g45278ab+e70536a077,21.0.0-2-g5242d73+0b2f7db15a,21.0.0-2-g7f82c8f+feb9862f5e,21.0.0-2-g8f08a60+9c9a9cfcc8,21.0.0-2-ga326454+feb9862f5e,21.0.0-2-gde069b7+bedfc5e1fb,21.0.0-2-gecfae73+417509110f,21.0.0-2-gfc62afb+0b2f7db15a,21.0.0-3-g21c7a62+a91f7c0b59,21.0.0-3-g357aad2+062581ff1a,21.0.0-3-g4be5c26+0b2f7db15a,21.0.0-3-g65f322c+85aa0ead76,21.0.0-3-g7d9da8d+c4f5df5339,21.0.0-3-gaa929c8+411cd868f8,21.0.0-3-gc44e71e+fd4029fd48,21.0.0-3-ge02ed75+5d9b90b8aa,21.0.0-38-g070523fc+44fda2b515,21.0.0-4-g591bb35+5d9b90b8aa,21.0.0-4-g88306b8+3cdc83ea97,21.0.0-4-gc004bbf+d52368b591,21.0.0-4-gccdca77+a5c54364a0,21.0.0-5-g7ebb681+81e2098694,21.0.0-5-gdf36809+87b8d260e6,21.0.0-6-g2d4f3f3+e70536a077,21.0.0-6-g4e60332+5d9b90b8aa,21.0.0-6-g5ef7dad+3f4e29eeae,21.0.0-7-gc8ca178+0f5e56d48f,21.0.0-9-g9eb8d17+cc2c7a81aa,master-gac4afde19b+5d9b90b8aa,w.2021.07
LSST Data Management Base Package
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
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
T copy(T... args)
PYBIND11_MODULE(camera, mod)
Definition: camera.cc:133
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
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.