LSST Applications g04e9c324dd+8c5ae1fdc5,g134cb467dc+b203dec576,g18429d2f64+358861cd2c,g199a45376c+0ba108daf9,g1fd858c14a+dd066899e3,g262e1987ae+ebfced1d55,g29ae962dfc+72fd90588e,g2cef7863aa+aef1011c0b,g35bb328faa+8c5ae1fdc5,g3fd5ace14f+b668f15bc5,g4595892280+3897dae354,g47891489e3+abcf9c3559,g4d44eb3520+fb4ddce128,g53246c7159+8c5ae1fdc5,g67b6fd64d1+abcf9c3559,g67fd3c3899+1f72b5a9f7,g74acd417e5+cb6b47f07b,g786e29fd12+668abc6043,g87389fa792+8856018cbb,g89139ef638+abcf9c3559,g8d7436a09f+bcf525d20c,g8ea07a8fe4+9f5ccc88ac,g90f42f885a+6054cc57f1,g97be763408+06f794da49,g9dd6db0277+1f72b5a9f7,ga681d05dcb+7e36ad54cd,gabf8522325+735880ea63,gac2eed3f23+abcf9c3559,gb89ab40317+abcf9c3559,gbf99507273+8c5ae1fdc5,gd8ff7fe66e+1f72b5a9f7,gdab6d2f7ff+cb6b47f07b,gdc713202bf+1f72b5a9f7,gdfd2d52018+8225f2b331,ge365c994fd+375fc21c71,ge410e46f29+abcf9c3559,geaed405ab2+562b3308c0,gf9a733ac38+8c5ae1fdc5,w.2025.35
LSST Data Management Base Package
Loading...
Searching...
No Matches
astrometryTransform.cc
Go to the documentation of this file.
1// -*- LSST-C++ -*-
2/*
3 * This file is part of jointcal.
4 *
5 * Developed for the LSST Data Management System.
6 * This product includes software developed by the LSST Project
7 * (https://www.lsst.org).
8 * See the COPYRIGHT file at the top-level directory of this distribution
9 * for details of code ownership.
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
25#include "pybind11/pybind11.h"
26#include "pybind11/eigen.h"
28
29#include "lsst/jointcal/Frame.h"
31#include "lsst/jointcal/Point.h"
32
33namespace py = pybind11;
34using namespace pybind11::literals;
35
36namespace lsst {
37namespace jointcal {
38namespace {
39
40void declareAstrometryTransform(lsst::cpputils::python::WrapperCollection &wrappers) {
41 using PyAstrometryTransform = py::classh<AstrometryTransform>;
42
43 wrappers.wrapType(PyAstrometryTransform(wrappers.module, "AstrometryTransform"), [](auto &mod, auto &cls) {
44 cls.def("apply",
45 (jointcal::Point(AstrometryTransform::*)(const jointcal::Point &) const) &
46 AstrometryTransform::apply,
47 "inPos"_a);
48 cls.def("apply",
49 (jointcal::Frame(AstrometryTransform::*)(Frame const &, bool) const) &AstrometryTransform::apply,
50 "inputframe"_a, "inscribed"_a);
51 cls.def("getNpar", &AstrometryTransform::getNpar);
52 cls.def("offsetParams", &AstrometryTransform::offsetParams);
53 cls.def("linearApproximation", &AstrometryTransform::linearApproximation);
54 cls.def("computeDerivative", [](AstrometryTransform const &self, Point const &where, double const step) {
55 AstrometryTransformLinear derivative;
56 self.computeDerivative(where, derivative, step);
57 return derivative;
58 });
59
60 cpputils::python::addOutputOp(cls, "__str__");
61 });
62}
63
64void declareAstrometryTransformIdentity(lsst::cpputils::python::WrapperCollection &wrappers) {
65 using PyAstrometryTransformIdentity =
66 py::classh<AstrometryTransformIdentity, AstrometryTransform>;
67
68 wrappers.wrapType(PyAstrometryTransformIdentity(wrappers.module, "AstrometryTransformIdentity"),
69 [](auto &mod, auto &cls) {});
70}
71
72void declareAstrometryTransformPolynomial(lsst::cpputils::python::WrapperCollection &wrappers) {
73 using PyAstrometryTransformPolynomial = py::classh<AstrometryTransformPolynomial,
75
76 wrappers.wrapType(
77 PyAstrometryTransformPolynomial(wrappers.module, "AstrometryTransformPolynomial"),
78 [](auto &mod, auto &cls) {
79 cls.def(py::init<const unsigned>(), "order"_a);
80 cls.def("getOrder", &AstrometryTransformPolynomial::getOrder);
81 cls.def("getCoefficient", py::overload_cast<std::size_t, std::size_t, std::size_t>(
82 &AstrometryTransformPolynomial::getCoefficient, py::const_));
83 cls.def("setCoefficient",
84 [](AstrometryTransformPolynomial &self, std::size_t powX, std::size_t powY,
85 std::size_t whichCoord,
86 double value) { self.getCoefficient(powX, powY, whichCoord) = value; });
87 cls.def("determinant", &AstrometryTransformPolynomial::determinant);
88 cls.def("getNpar", &AstrometryTransformPolynomial::getNpar);
89 cls.def("toAstMap", &AstrometryTransformPolynomial::toAstMap);
90 cls.def("write", [](AstrometryTransformPolynomial const &self) {
92 self.write(result);
93 return result.str();
94 });
95 cls.def("read", [](AstrometryTransformPolynomial &self, std::string const &str) {
96 std::istringstream istr(str);
97 self.read(istr);
98 });
99 });
100}
101
102void declareAstrometryTransformLinear(lsst::cpputils::python::WrapperCollection &wrappers) {
103 using PyAstrometryTransformLinear = py::classh<AstrometryTransformLinear,
104 AstrometryTransformPolynomial>;
105
106 wrappers.wrapType(
107 PyAstrometryTransformLinear(wrappers.module, "AstrometryTransformLinear"), [](auto &mod, auto &cls) {
108 cls.def(py::init<>());
109 });
110}
111
112void declareAstrometryTransformLinearShift(lsst::cpputils::python::WrapperCollection &wrappers) {
113 using PyAstrometryTransformLinearShift = py::classh<AstrometryTransformLinearShift,
114 AstrometryTransformLinear>;
115
116 wrappers.wrapType(PyAstrometryTransformLinearShift(wrappers.module, "AstrometryTransformLinearShift"),
117 [](auto &mod, auto &cls) {});
118}
119
120void declareAstrometryTransformLinearRot(lsst::cpputils::python::WrapperCollection &wrappers) {
121 using PyAstrometryTransformLinearRot =
122 py::classh<AstrometryTransformLinearRot,
123 AstrometryTransformLinear>;
124
125 wrappers.wrapType(
126 PyAstrometryTransformLinearRot(wrappers.module, "AstrometryTransformLinearRot"),
127 [](auto &mod, auto &cls) {});
128}
129
130void declareAstrometryTransformLinearScale(lsst::cpputils::python::WrapperCollection &wrappers) {
131 using PyAstrometryTransformLinearScale =
132 py::classh<AstrometryTransformLinearScale,
133 AstrometryTransformLinear>;
134
135 wrappers.wrapType(
136 PyAstrometryTransformLinearScale(wrappers.module, "AstrometryTransformLinearScale"),
137 [](auto &mod, auto &cls) {});
138}
139
140void declareAstrometryTransformSkyWcs(lsst::cpputils::python::WrapperCollection &wrappers) {
141 using PyAstrometryTransformSkyWcs =
142 py::classh<AstrometryTransformSkyWcs, AstrometryTransform>;
143
144 wrappers.wrapType(
145 PyAstrometryTransformSkyWcs(wrappers.module, "AstrometryTransformSkyWcs"), [](auto &mod, auto &cls) {
146 cls.def("getSkyWcs", &AstrometryTransformSkyWcs::getSkyWcs);
147 });
148}
149
150void declareBaseTanWcs(lsst::cpputils::python::WrapperCollection &wrappers) {
151 using PyBaseTanWcs = py::classh<BaseTanWcs, AstrometryTransform> ;
152
153 wrappers.wrapType(PyBaseTanWcs(wrappers.module, "BaseTanWcs"), [](auto &mod, auto &cls) {});
154}
155
156void declareTanPixelToRaDec(lsst::cpputils::python::WrapperCollection &wrappers) {
157 using PyTanPixelToRaDec = py::classh<TanPixelToRaDec, AstrometryTransform>;
158
159 wrappers.wrapType(PyTanPixelToRaDec(wrappers.module, "TanPixelToRaDec"), [](auto &mod, auto &cls) {});
160}
161
162void declareTanRaDecToPixel(lsst::cpputils::python::WrapperCollection &wrappers) {
163 using PyTanRaDecToPixel = py::classh<TanRaDecToPixel, AstrometryTransform>;
164
165 wrappers.wrapType(PyTanRaDecToPixel(wrappers.module, "TanRaDecToPixel"), [](auto &mod, auto &cls) {});
166}
167
168void declareTanSipPixelToRaDec(lsst::cpputils::python::WrapperCollection &wrappers) {
169 using PyTanSipPixelToRaDec = py::classh<TanSipPixelToRaDec, BaseTanWcs>;
170
171 wrappers.wrapType(PyTanSipPixelToRaDec(wrappers.module, "TanSipPixelToRaDec"), [](auto &mod, auto &cls) {});
172}
173} // namespace
174
176 declareAstrometryTransform(wrappers);
177 declareAstrometryTransformIdentity(wrappers);
178 declareAstrometryTransformPolynomial(wrappers);
179 declareAstrometryTransformLinear(wrappers);
180 declareAstrometryTransformLinearShift(wrappers);
181 declareAstrometryTransformLinearRot(wrappers);
182 declareAstrometryTransformLinearScale(wrappers);
183 declareAstrometryTransformSkyWcs(wrappers);
184 declareBaseTanWcs(wrappers);
185 declareTanPixelToRaDec(wrappers);
186 declareTanRaDecToPixel(wrappers);
187 declareTanSipPixelToRaDec(wrappers);
188
189 // utility functions
190 wrappers.module.def("inversePolyTransform", &inversePolyTransform, "forward"_a, "domain"_a, "precision"_a,
191 "maxOrder"_a = 9, "nSteps"_a = 50);
192}
193
194} // namespace jointcal
195} // namespace lsst
A helper class for subdividing pybind11 module across multiple translation units (i....
Definition python.h:242
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
a virtual (interface) class for geometric transformations.
std::shared_ptr< ast::Mapping > toAstMap(jointcal::Frame const &domain) const override
Create an equivalent AST mapping for this transformation, including an analytic inverse if possible.
std::size_t getNpar() const override
total number of parameters
void addOutputOp(PyClass &cls, std::string const &method)
Add __str__ or __repr__ method implemented by operator<<.
Definition python.h:87
std::shared_ptr< AstrometryTransformPolynomial > inversePolyTransform(AstrometryTransform const &forward, Frame const &domain, double precision, std::size_t maxOrder=9, std::size_t nSteps=50)
Approximate the inverse by a polynomial, to some precision.
void wrapAstrometryTransform(WrapperCollection &wrappers)