lsst.meas.astrom  13.0-14-g9415442+44
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Groups Pages
sipTransform.cc
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  *
4  * This product includes software developed by the
5  * LSST Project (http://www.lsst.org/).
6  * See the COPYRIGHT file
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 <https://www.lsstcorp.org/LegalNotices/>.
21  */
22 #include "pybind11/pybind11.h"
23 #include "pybind11/stl.h"
24 
25 #include "lsst/afw/coord/Coord.h"
26 #include "lsst/afw/geom/AffineTransform.h"
27 #include "lsst/afw/image/TanWcs.h"
29 
30 namespace py = pybind11;
31 using namespace pybind11::literals;
32 
33 namespace lsst {
34 namespace meas {
35 namespace astrom {
36 namespace {
37 
38 static void declareSipTransformBase(py::module &mod) {
39  py::class_<SipTransformBase, std::shared_ptr<SipTransformBase>> cls(mod, "_SipTransformBase");
40 
41  cls.def("getPixelOrigin", &SipTransformBase::getPixelOrigin, py::return_value_policy::copy);
42  cls.def("getCDMatrix", &SipTransformBase::getCDMatrix, py::return_value_policy::copy);
43  cls.def("getPoly", &SipTransformBase::getPoly, py::return_value_policy::copy);
44 }
45 
46 static void declareSipForwardTransform(py::module &mod) {
47  py::class_<SipForwardTransform, std::shared_ptr<SipForwardTransform>, SipTransformBase> cls(
48  mod, "SipForwardTransform");
49 
50  cls.def(py::init<afw::geom::Point2D const &, afw::geom::LinearTransform const &,
51  PolynomialTransform const &>(),
52  "pixelOrigin"_a, "cdMatrix"_a, "forwardSipPoly"_a);
53  cls.def(py::init<SipForwardTransform const &>(), "other"_a);
54 
55  cls.def_static("convert", (SipForwardTransform(*)(PolynomialTransform const &, afw::geom::Point2D const &,
56  afw::geom::LinearTransform const &)) &
57  SipForwardTransform::convert,
58  "poly"_a, "pixelOrigin"_a, "cdMatrix"_a);
59  cls.def_static("convert",
60  (SipForwardTransform(*)(ScaledPolynomialTransform const &, afw::geom::Point2D const &,
61  afw::geom::LinearTransform const &)) &
62  SipForwardTransform::convert,
63  "scaled"_a, "pixelOrigin"_a, "cdMatrix"_a);
64  cls.def_static("convert",
65  (SipForwardTransform(*)(ScaledPolynomialTransform const &)) & SipForwardTransform::convert,
66  "scaled"_a);
67  cls.def_static("extract", &SipForwardTransform::extract, "wcs"_a);
68 
69  cls.def("__call__", &SipForwardTransform::operator(), "in"_a);
70  cls.def("transformPixels", &SipForwardTransform::transformPixels, "s"_a);
71 
72  cls.def("linearize", &SipForwardTransform::linearize);
73 }
74 
75 static void declareSipReverseTransform(py::module &mod) {
76  py::class_<SipReverseTransform, std::shared_ptr<SipReverseTransform>, SipTransformBase> cls(
77  mod, "SipReverseTransform");
78 
79  cls.def(py::init<afw::geom::Point2D const &, afw::geom::LinearTransform const &,
80  PolynomialTransform const &>(),
81  "pixelOrigin"_a, "cdMatrix"_a, "reverseSipPoly"_a);
82  cls.def(py::init<SipReverseTransform const &>(), "other"_a);
83 
84  cls.def_static("convert", (SipReverseTransform(*)(PolynomialTransform const &, afw::geom::Point2D const &,
85  afw::geom::LinearTransform const &)) &
86  SipReverseTransform::convert,
87  "poly"_a, "pixelOrigin"_a, "cdMatrix"_a);
88  cls.def_static("convert",
89  (SipReverseTransform(*)(ScaledPolynomialTransform const &, afw::geom::Point2D const &,
90  afw::geom::LinearTransform const &)) &
91  SipReverseTransform::convert,
92  "scaled"_a, "pixelOrigin"_a, "cdMatrix"_a);
93  cls.def_static("convert",
94  (SipReverseTransform(*)(ScaledPolynomialTransform const &)) & SipReverseTransform::convert,
95  "scaled"_a);
96  cls.def_static("extract", &SipReverseTransform::extract, "wcs"_a);
97 
98  cls.def("__call__", &SipReverseTransform::operator(), "in"_a);
99  cls.def("transformPixels", &SipReverseTransform::transformPixels, "s"_a);
100 
101  cls.def("linearize", &SipReverseTransform::linearize);
102 }
103 
104 } // namespace lsst::meas::astrom::<anonymous>
105 
106 PYBIND11_PLUGIN(sipTransform) {
107  py::module mod("sipTransform");
108 
109  declareSipTransformBase(mod);
110  declareSipForwardTransform(mod);
111  declareSipReverseTransform(mod);
112 
113  mod.def("makeWcs", &makeWcs);
114  mod.def("transformWcsPixels", &transformWcsPixels, "wcs"_a, "s"_a);
115  mod.def("rotateWcsPixelsBy90", &rotateWcsPixelsBy90, "wcs"_a, "nQuarter"_a, "dimensions"_a);
116 
117  return mod.ptr();
118 }
119 }
120 }
121 } // namespace lsst::meas::astrom
std::shared_ptr< afw::image::TanWcs > transformWcsPixels(afw::image::TanWcs const &wcs, afw::geom::AffineTransform const &s)
Create a new TanWcs whose pixel coordinate system has been transformed via an affine transform...
PYBIND11_PLUGIN(makeMatchStatistics)
std::shared_ptr< afw::image::TanWcs > rotateWcsPixelsBy90(afw::image::TanWcs const &wcs, int nQuarter, afw::geom::Extent2I const &dimensions)
Return a new TanWcs that represents a rotation of the image it corresponds to about the image&#39;s cente...
std::shared_ptr< afw::image::TanWcs > makeWcs(SipForwardTransform const &sipForward, SipReverseTransform const &sipReverse, afw::coord::Coord const &skyOrigin)
Create a new TAN SIP Wcs from a pair of SIP transforms and the sky origin.