LSST Applications g0fba68d861+5616995c1c,g1ebb85f214+2420ccdea7,g1fd858c14a+44c57a1f81,g21d47ad084+8e51fce9ac,g262e1987ae+1a7d68eb3b,g2cef7863aa+3bd8df3d95,g35bb328faa+fcb1d3bbc8,g36ff55ed5b+2420ccdea7,g47891489e3+5c6313fe9a,g53246c7159+fcb1d3bbc8,g646c943bdb+dbb9921566,g67b6fd64d1+5c6313fe9a,g6bd32b75b5+2420ccdea7,g74acd417e5+37fc0c974d,g786e29fd12+cf7ec2a62a,g86c591e316+6e13bcb9e9,g87389fa792+1e0a283bba,g89139ef638+5c6313fe9a,g90f42f885a+fce05a46d3,g9125e01d80+fcb1d3bbc8,g93e38de9ac+5345a64125,g95a1e89356+47d08a1cc6,g97be763408+bba861c665,ga9e4eb89a6+85210110a1,gb0b61e0e8e+1f27f70249,gb58c049af0+f03b321e39,gb89ab40317+5c6313fe9a,gc4e39d7843+4e09c98c3d,gd16ba4ae74+5402bcf54a,gd8ff7fe66e+2420ccdea7,gd9a9a58781+fcb1d3bbc8,gdab6d2f7ff+37fc0c974d,gde280f09ee+604b327636,ge278dab8ac+50e2446c94,ge410e46f29+5c6313fe9a,gef3c2e6661+6b480e0fb7,gf67bdafdda+5c6313fe9a,gffca2db377+fcb1d3bbc8,v29.2.0.rc1
LSST Data Management Base Package
Loading...
Searching...
No Matches
_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"
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"
39#include "lsst/afw/table/io/python.h" // for addPersistableMethods
40
41namespace py = pybind11;
42using namespace py::literals;
43
44namespace lsst {
45namespace afw {
46namespace geom {
47namespace {
48
49void declareSkyWcs(lsst::cpputils::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",
56 (std::shared_ptr<SkyWcs>(*)(lsst::geom::Point2D const &, lsst::geom::SpherePoint const &,
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",
62 (std::shared_ptr<SkyWcs>(*)(TransformPoint2ToPoint2 const &, lsst::geom::Angle const &, bool,
63 lsst::geom::SpherePoint const &, std::string const &))makeSkyWcs,
64 "pixelsToFieldAngle"_a, "orientation"_a, "flipX"_a, "boresight"_a, "projection"_a = "TAN");
65 mod.def("makeTanSipWcs",
66 (std::shared_ptr<SkyWcs>(*)(lsst::geom::Point2D const &, lsst::geom::SpherePoint const &,
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",
71 (std::shared_ptr<SkyWcs>(*)(lsst::geom::Point2D const &, lsst::geom::SpherePoint const &,
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::classh<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("hasFitsApproximation", &SkyWcs::hasFitsApproximation);
96 cls.def("getFitsApproximation", &SkyWcs::getFitsApproximation);
97 cls.def("copyWithFitsApproximation", &SkyWcs::copyWithFitsApproximation);
98 cls.def("getPixelScale",
99 (lsst::geom::Angle(SkyWcs::*)(lsst::geom::Point2D const &) const) &
100 SkyWcs::getPixelScale,
101 "pixel"_a);
102 cls.def("getPixelScale", (lsst::geom::Angle(SkyWcs::*)() const) & SkyWcs::getPixelScale);
103 cls.def("getPixelOrigin", &SkyWcs::getPixelOrigin);
104 cls.def("getSkyOrigin", &SkyWcs::getSkyOrigin);
105 cls.def("getCdMatrix",
106 (Eigen::Matrix2d(SkyWcs::*)(lsst::geom::Point2D const &) const) & SkyWcs::getCdMatrix,
107 "pixel"_a);
108 cls.def("getCdMatrix", (Eigen::Matrix2d(SkyWcs::*)() const) & SkyWcs::getCdMatrix);
109 cls.def("getTanWcs", &SkyWcs::getTanWcs, "pixel"_a);
110 cls.def("getFrameDict", [](SkyWcs const &self) { return self.getFrameDict()->copy(); });
111 cls.def("getTransform", &SkyWcs::getTransform);
112
113 cls.def_property_readonly("isFits", &SkyWcs::isFits);
114 cls.def_property_readonly("isFlipped", &SkyWcs::isFlipped);
115 cls.def("linearizePixelToSky",
116 (lsst::geom::AffineTransform(SkyWcs::*)(lsst::geom::SpherePoint const &,
117 lsst::geom::AngleUnit const &) const) &
119 "coord"_a, "skyUnit"_a);
120 cls.def("linearizePixelToSky",
121 (lsst::geom::AffineTransform(SkyWcs::*)(lsst::geom::Point2D const &,
122 lsst::geom::AngleUnit const &) const) &
124 "coord"_a, "skyUnit"_a);
125 cls.def("linearizeSkyToPixel",
126 (lsst::geom::AffineTransform(SkyWcs::*)(lsst::geom::SpherePoint const &,
127 lsst::geom::AngleUnit const &) const) &
129 "coord"_a, "skyUnit"_a);
130 cls.def("linearizeSkyToPixel",
131 (lsst::geom::AffineTransform(SkyWcs::*)(lsst::geom::Point2D const &,
132 lsst::geom::AngleUnit const &) const) &
134 "coord"_a, "skyUnit"_a);
135 cls.def("pixelToSky",
136 (lsst::geom::SpherePoint(SkyWcs::*)(lsst::geom::Point2D const &) const) &
138 "pixel"_a);
139 cls.def("pixelToSky",
140 (lsst::geom::SpherePoint(SkyWcs::*)(double, double) const) & SkyWcs::pixelToSky,
141 "x"_a, "y"_a);
142 cls.def("pixelToSky",
143 (std::vector<lsst::geom::SpherePoint>(SkyWcs::*)(
144 std::vector<lsst::geom::Point2D> const &) const) &
146 "pixel"_a);
147 cls.def("skyToPixel",
148 (lsst::geom::Point2D(SkyWcs::*)(lsst::geom::SpherePoint const &) const) &
150 "sky"_a);
151 cls.def("skyToPixel",
152 (std::vector<lsst::geom::Point2D>(SkyWcs::*)(
153 std::vector<lsst::geom::SpherePoint> const &) const) &
155 "sky"_a);
156 // Do not wrap getShortClassName because it returns the name of the class;
157 // use `<class>.__name__` or `type(<instance>).__name__` instead.
158 // Do not wrap readStream or writeStream because C++ streams are not easy to wrap.
159 cls.def_static("readString", &SkyWcs::readString);
160 cls.def("writeString", &SkyWcs::writeString);
161
162 cpputils::python::addOutputOp(cls, "__str__");
163 // For repr, we could instead call writeString for the very long AST Frame/Mapping output.
164 cpputils::python::addOutputOp(cls, "__repr__");
165 });
166}
167} // namespace
169 wrappers.addInheritanceDependency("lsst.afw.table.io");
170 wrappers.addInheritanceDependency("lsst.afw.typehandling");
171 wrappers.addSignatureDependency("astshim");
172 declareSkyWcs(wrappers);
173}
174} // namespace geom
175} // namespace afw
176} // namespace lsst
A 2-dimensional celestial WCS that transform pixels to ICRS RA/Dec, using the LSST standard for pixel...
Definition SkyWcs.h:118
lsst::geom::SpherePoint pixelToSky(lsst::geom::Point2D const &pixel) const
Compute sky position(s) from pixel position(s)
Definition SkyWcs.h:334
lsst::geom::AffineTransform linearizeSkyToPixel(lsst::geom::SpherePoint const &coord, lsst::geom::AngleUnit const &skyUnit) const
Return the local linear approximation to skyToPixel at a point given in sky coordinates.
Definition SkyWcs.cc:303
bool isFlipped() const
Does the WCS follow the convention of North=Up, East=Left?
Definition SkyWcs.cc:315
std::string writeString() const
Serialize this SkyWcs to a string, using the same format as writeStream.
Definition SkyWcs.cc:361
lsst::geom::AffineTransform linearizePixelToSky(lsst::geom::SpherePoint const &coord, lsst::geom::AngleUnit const &skyUnit) const
Return the local linear approximation to pixelToSky at a point given in sky coordinates.
Definition SkyWcs.cc:294
std::shared_ptr< const TransformPoint2ToSpherePoint > getTransform() const
Get a TransformPoint2ToSpherePoint that transforms pixels to sky in the forward direction and sky to ...
Definition SkyWcs.h:257
lsst::geom::Point2D skyToPixel(lsst::geom::SpherePoint const &sky) const
Compute pixel position(s) from sky position(s)
Definition SkyWcs.h:349
bool isFits() const
Return true getFitsMetadata(true) will succeed, false if not.
Definition SkyWcs.cc:292
static std::shared_ptr< SkyWcs > readString(std::string &str)
Deserialize a SkyWcs from a string, using the same format as readStream.
Definition SkyWcs.cc:351
A helper class for subdividing pybind11 module across multiple translation units (i....
Definition python.h:242
void addSignatureDependency(std::string const &name)
Indicate an external module that provides a type used in function/method signatures.
Definition python.h:357
void wrap(WrapperCallback function)
Add a set of wrappers without defining a class.
Definition python.h:369
void addInheritanceDependency(std::string const &name)
Indicate an external module that provides a base class for a subsequent addType call.
Definition python.h:343
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
pybind11::module module
The module object passed to the PYBIND11_MODULE block that contains this WrapperCollection.
Definition python.h:448
std::shared_ptr< SkyWcs > makeSkyWcs(daf::base::PropertySet &metadata, bool strip=false)
Construct a SkyWcs from FITS keywords.
Definition SkyWcs.cc:543
std::shared_ptr< TransformPoint2ToPoint2 > getPixelToIntermediateWorldCoords(SkyWcs const &wcs, bool simplify=true)
Return a transform from pixel coordinates to intermediate world coordinates.
Definition SkyWcs.cc:581
void wrapSkyWcs(lsst::cpputils::python::WrapperCollection &)
Definition _skyWcs.cc:168
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:560
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:148
std::shared_ptr< TransformPoint2ToSpherePoint > getIntermediateWorldCoordsToSky(SkyWcs const &wcs, bool simplify=true)
Return a transform from intermediate world coordinates to sky.
Definition SkyWcs.cc:575
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:508
Transform< Point2Endpoint, Point2Endpoint > TransformPoint2ToPoint2
Definition Transform.h:300
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:161
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:489
void addOutputOp(PyClass &cls, std::string const &method)
Add __str__ or __repr__ method implemented by operator<<.
Definition python.h:87
AngleUnit constexpr degrees
constant with units of degrees
Definition Angle.h:110
Point< double, 2 > Point2D
Definition Point.h:324