LSST Applications g070148d5b3+33e5256705,g0d53e28543+25c8b88941,g0da5cf3356+2dd1178308,g1081da9e2a+62d12e78cb,g17e5ecfddb+7e422d6136,g1c76d35bf8+ede3a706f7,g295839609d+225697d880,g2e2c1a68ba+cc1f6f037e,g2ffcdf413f+853cd4dcde,g38293774b4+62d12e78cb,g3b44f30a73+d953f1ac34,g48ccf36440+885b902d19,g4b2f1765b6+7dedbde6d2,g5320a0a9f6+0c5d6105b6,g56b687f8c9+ede3a706f7,g5c4744a4d9+ef6ac23297,g5ffd174ac0+0c5d6105b6,g6075d09f38+66af417445,g667d525e37+2ced63db88,g670421136f+2ced63db88,g71f27ac40c+2ced63db88,g774830318a+463cbe8d1f,g7876bc68e5+1d137996f1,g7985c39107+62d12e78cb,g7fdac2220c+0fd8241c05,g96f01af41f+368e6903a7,g9ca82378b8+2ced63db88,g9d27549199+ef6ac23297,gabe93b2c52+e3573e3735,gb065e2a02a+3dfbe639da,gbc3249ced9+0c5d6105b6,gbec6a3398f+0c5d6105b6,gc9534b9d65+35b9f25267,gd01420fc67+0c5d6105b6,geee7ff78d7+a14128c129,gf63283c776+ede3a706f7,gfed783d017+0c5d6105b6,w.2022.47
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"
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"
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::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",
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",
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) &
116 "coord"_a, "skyUnit"_a);
117 cls.def("linearizePixelToSky",
119 lsst::geom::AngleUnit const &) const) &
121 "coord"_a, "skyUnit"_a);
122 cls.def("linearizeSkyToPixel",
124 lsst::geom::AngleUnit const &) const) &
126 "coord"_a, "skyUnit"_a);
127 cls.def("linearizeSkyToPixel",
129 lsst::geom::AngleUnit const &) const) &
131 "coord"_a, "skyUnit"_a);
132 cls.def("pixelToSky",
133 (lsst::geom::SpherePoint(SkyWcs::*)(lsst::geom::Point2D const &) const) &
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) &
143 "pixel"_a);
144 cls.def("skyToPixel",
145 (lsst::geom::Point2D(SkyWcs::*)(lsst::geom::SpherePoint const &) const) &
147 "sky"_a);
148 cls.def("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
165void wrapSkyWcs(lsst::utils::python::WrapperCollection &wrappers) {
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
std::string writeString() const
Serialize this SkyWcs to a string, using the same format as writeStream.
Definition: SkyWcs.cc:342
lsst::geom::SpherePoint pixelToSky(lsst::geom::Point2D const &pixel) const
Compute sky position(s) from pixel position(s)
Definition: SkyWcs.h:334
static std::shared_ptr< SkyWcs > readString(std::string &str)
Deserialize a SkyWcs from a string, using the same format as readStream.
Definition: SkyWcs.cc:332
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:275
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:284
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 isFlipped() const
Does the WCS follow the convention of North=Up, East=Left?
Definition: SkyWcs.cc:296
bool isFits() const
Return true getFitsMetadata(true) will succeed, false if not.
Definition: SkyWcs.cc:264
An affine coordinate transformation consisting of a linear transformation and an offset.
A class representing an angle.
Definition: Angle.h:128
A class used to convert scalar POD types such as double to Angle.
Definition: Angle.h:71
Point in an unspecified spherical coordinate system.
Definition: SpherePoint.h:57
void wrapSkyWcs(lsst::utils::python::WrapperCollection &)
Definition: _skyWcs.cc:165
Transform< Point2Endpoint, Point2Endpoint > TransformPoint2ToPoint2
Definition: Transform.h:300
AngleUnit constexpr degrees
constant with units of degrees
Definition: Angle.h:110