24#include "pybind11/pybind11.h"
25#include "pybind11/eigen.h"
26#include "pybind11/stl.h"
28#include "ndarray/pybind11.h"
43using namespace pybind11::literals;
49using utils::python::WrapperCollection;
62template <
typename Box>
65using PyCoordKey = py::class_<CoordKey, std::shared_ptr<CoordKey>>;
67using PyQuadrupoleKey = py::class_<QuadrupoleKey, std::shared_ptr<QuadrupoleKey>>;
69using PyEllipseKey = py::class_<EllipseKey, std::shared_ptr<EllipseKey>>;
71template <
typename T,
int N>
72using PyCovarianceMatrixKey =
76static void declarePointKey(WrapperCollection &wrappers,
std::string const &suffix) {
78 PyPointKey<T>(wrappers.module, (
"Point" + suffix +
"Key").c_str()), [](
auto &mod,
auto &cls) {
79 cls.def(py::init<>());
80 cls.def(py::init<Key<T> const &, Key<T> const &>(),
"x"_a,
"y"_a);
81 cls.def(py::init<SubSchema const &>());
82 cls.def(
"__eq__", &PointKey<T>::operator==, py::is_operator());
83 cls.def(
"__ne__", &PointKey<T>::operator!=, py::is_operator());
84 cls.def(
"getX", &PointKey<T>::getX);
85 cls.def(
"getY", &PointKey<T>::getY);
86 cls.def(
"isValid", &PointKey<T>::isValid);
87 cls.def_static(
"addFields", &PointKey<T>::addFields,
"schema"_a,
"name"_a,
"doc"_a,
"unit"_a);
88 cls.def(
"set", [](PointKey<T> &self, BaseRecord &record,
89 lsst::geom::Point<T, 2> const &value) { return self.set(record, value); });
95static void declarePoint3Key(WrapperCollection &wrappers,
std::string const &suffix) {
97 PyPoint3Key<T>(wrappers.module, (
"Point3" + suffix +
"Key").c_str()), [](
auto &mod,
auto &cls) {
98 cls.def(py::init<>());
99 cls.def(py::init<Key<T> const &, Key<T> const &, Key<T> const &>(),
"x"_a,
"y"_a,
"z"_a);
100 cls.def(py::init<SubSchema const &>());
101 cls.def(
"__eq__", &Point3Key<T>::operator==, py::is_operator());
102 cls.def(
"__ne__", &Point3Key<T>::operator!=, py::is_operator());
103 cls.def(
"getX", &Point3Key<T>::getX);
104 cls.def(
"getY", &Point3Key<T>::getY);
105 cls.def(
"isValid", &Point3Key<T>::isValid);
106 cls.def_static(
"addFields", &Point3Key<T>::addFields,
"schema"_a,
"name"_a,
"doc"_a,
"unit"_a);
107 cls.def(
"set", [](Point3Key<T> &self, BaseRecord &record,
108 lsst::geom::Point<T, 3> const &value) { return self.set(record, value); });
113template <
typename Box>
114static void declareBoxKey(WrapperCollection &wrappers,
std::string const &suffix) {
116 PyBoxKey<Box>(wrappers.module, (
"Box" + suffix +
"Key").c_str()), [](
auto &mod,
auto &cls) {
117 using Element = typename Box::Element;
118 cls.def(py::init<>());
119 cls.def(py::init<PointKey<Element> const &, PointKey<Element> const &>(),
"min"_a,
"max"_a);
120 cls.def(py::init<SubSchema const &>());
121 cls.def(
"__eq__", &BoxKey<Box>::operator==, py::is_operator());
122 cls.def(
"__ne__", &BoxKey<Box>::operator!=, py::is_operator());
123 cls.def(
"getMin", &BoxKey<Box>::getMin);
124 cls.def(
"getMax", &BoxKey<Box>::getMax);
125 cls.def(
"isValid", &BoxKey<Box>::isValid);
126 cls.def_static(
"addFields", &BoxKey<Box>::addFields,
"schema"_a,
"name"_a,
"doc"_a,
"unit"_a);
127 cls.def(
"set", &BoxKey<Box>::set);
128 cls.def(
"get", &BoxKey<Box>::get);
133static void declareCoordKey(WrapperCollection &wrappers) {
134 wrappers.wrapType(PyCoordKey(wrappers.module,
"CoordKey"), [](
auto &mod,
auto &cls) {
135 cls.def(py::init<>());
136 cls.def(py::init<Key<lsst::geom::Angle>, Key<lsst::geom::Angle>>(),
"ra"_a,
"dec"_a);
137 cls.def(py::init<SubSchema const &>());
138 cls.def(
"__eq__", &CoordKey::operator==, py::is_operator());
139 cls.def(
"__ne__", &CoordKey::operator!=, py::is_operator());
140 cls.def_static(
"addFields", &CoordKey::addFields,
"schema"_a,
"name"_a,
"doc"_a);
141 cls.def(
"getRa", &CoordKey::getRa);
142 cls.def(
"getDec", &CoordKey::getDec);
143 cls.def(
"isValid", &CoordKey::isValid);
144 cls.def(
"get", [](CoordKey &self, BaseRecord const &record) { return self.get(record); });
145 cls.def(
"set", &CoordKey::set);
149static void declareQuadrupoleKey(WrapperCollection &wrappers) {
150 wrappers.wrapType(PyQuadrupoleKey(wrappers.module,
"QuadrupoleKey"), [](
auto &mod,
auto &cls) {
151 cls.def(py::init<>());
152 cls.def(py::init<Key<double> const &, Key<double> const &, Key<double> const &>(),
"ixx"_a,
"iyy"_a,
154 cls.def(py::init<SubSchema const &>());
155 cls.def(
"__eq__", &QuadrupoleKey::operator==, py::is_operator());
156 cls.def(
"__nq__", &QuadrupoleKey::operator!=, py::is_operator());
157 cls.def_static(
"addFields", &QuadrupoleKey::addFields,
"schema"_a,
"name"_a,
"doc"_a,
158 "coordType"_a = CoordinateType::PIXEL);
159 cls.def(
"getIxx", &QuadrupoleKey::getIxx);
160 cls.def(
"getIyy", &QuadrupoleKey::getIyy);
161 cls.def(
"getIxy", &QuadrupoleKey::getIxy);
162 cls.def(
"isValid", &QuadrupoleKey::isValid);
163 cls.def(
"set", &QuadrupoleKey::set);
164 cls.def(
"get", &QuadrupoleKey::get);
168static void declareEllipseKey(WrapperCollection &wrappers) {
169 wrappers.wrapType(PyEllipseKey(wrappers.module,
"EllipseKey"), [](
auto &mod,
auto &cls) {
170 cls.def(py::init<>());
171 cls.def(py::init<QuadrupoleKey const &, PointKey<double> const &>(),
"qKey"_a,
"pKey"_a);
172 cls.def(py::init<SubSchema const &>());
173 cls.def(
"__eq__", &EllipseKey::operator==, py::is_operator());
174 cls.def(
"__nq__", &EllipseKey::operator!=, py::is_operator());
175 cls.def_static(
"addFields", &EllipseKey::addFields,
"schema"_a,
"name"_a,
"doc"_a,
"unit"_a);
176 cls.def(
"get", &EllipseKey::get);
177 cls.def(
"set", &EllipseKey::set);
178 cls.def(
"isValid", &EllipseKey::isValid);
179 cls.def(
"getCore", &EllipseKey::getCore);
180 cls.def(
"getCenter", &EllipseKey::getCenter);
184template <
typename T,
int N>
185static void declareCovarianceMatrixKey(WrapperCollection &wrappers, const ::std::string &suffix) {
187 PyCovarianceMatrixKey<T, N>(wrappers.module, (
"CovarianceMatrix" + suffix +
"Key").c_str()),
188 [](
auto &mod,
auto &cls) {
189 using ErrKeyArray = std::vector<Key<T>>;
190 using CovarianceKeyArray = std::vector<Key<T>>;
191 using NameArray = std::vector<std::string>;
193 cls.def(py::init<>());
195 cls.def(py::init<SubSchema const &, NameArray const &>());
196 cls.def(py::init<ErrKeyArray const &, CovarianceKeyArray const &>(),
"err"_a,
197 "cov"_a = CovarianceKeyArray());
198 cls.def(
"__eq__", &CovarianceMatrixKey<T, N>::operator==, py::is_operator());
199 cls.def(
"__ne__", &CovarianceMatrixKey<T, N>::operator!=, py::is_operator());
200 cls.def_static(
"addFields",
201 (CovarianceMatrixKey<T, N>(*)(Schema &, std::string const &, NameArray const &,
202 std::string const &, bool)) &
203 CovarianceMatrixKey<T, N>::addFields,
204 "schema"_a,
"prefix"_a,
"names"_a,
"unit"_a,
"diagonalOnly"_a = false);
205 cls.def_static(
"addFields",
206 (CovarianceMatrixKey<T, N>(*)(Schema &, std::string const &, NameArray const &,
207 NameArray const &, bool)) &
208 CovarianceMatrixKey<T, N>::addFields,
209 "schema"_a,
"prefix"_a,
"names"_a,
"units"_a,
"diagonalOnly"_a = false);
210 cls.def(
"set", [](CovarianceMatrixKey<T, N> &cov, BaseRecord &record,
211 Eigen::Matrix<T, N, N> const &value) { return cov.set(record, value); });
212 cls.def(
"get", [](CovarianceMatrixKey<T, N> &cov, BaseRecord
const &record) {
213 return cov.get(record);
215 cls.def(
"isValid", &CovarianceMatrixKey<T, N>::isValid);
216 cls.def(
"setElement", &CovarianceMatrixKey<T, N>::setElement);
217 cls.def(
"getElement", &CovarianceMatrixKey<T, N>::getElement);
227 wrappers.wrapType(py::enum_<CoordinateType>(wrappers.module,
"CoordinateType"), [](
auto &mod,
auto &enm) {
228 enm.value(
"PIXEL", CoordinateType::PIXEL);
229 enm.value(
"CELESTIAL", CoordinateType::CELESTIAL);
233 declarePointKey<double>(wrappers,
"2D");
234 declarePointKey<int>(wrappers,
"2I");
235 declarePoint3Key<double>(wrappers,
"D");
236 declarePoint3Key<int>(wrappers,
"I");
238 declareBoxKey<lsst::geom::Box2D>(wrappers,
"2D");
239 declareBoxKey<lsst::geom::Box2I>(wrappers,
"2I");
241 declareCoordKey(wrappers);
242 declareQuadrupoleKey(wrappers);
243 declareEllipseKey(wrappers);
245 declareCovarianceMatrixKey<float, 2>(wrappers,
"2f");
246 declareCovarianceMatrixKey<float, 3>(wrappers,
"3f");
247 declareCovarianceMatrixKey<float, 4>(wrappers,
"4f");
248 declareCovarianceMatrixKey<float, Eigen::Dynamic>(wrappers,
"Xf");
249 declareCovarianceMatrixKey<double, 2>(wrappers,
"2d");
250 declareCovarianceMatrixKey<double, 3>(wrappers,
"3d");
251 declareCovarianceMatrixKey<double, 4>(wrappers,
"4d");
252 declareCovarianceMatrixKey<double, Eigen::Dynamic>(wrappers,
"Xd");
lsst::geom::Point< T, 3 > get(BaseRecord const &record) const override
Get a Point from the given record.
lsst::geom::Point< T, 2 > get(BaseRecord const &record) const override
Get a Point from the given record.
void wrapAggregates(WrapperCollection &wrappers)