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_static(
"addErrorFields", &CoordKey::addErrorFields,
"schema"_a);
142 cls.def_static(
"getErrorKey", &CoordKey::getErrorKey,
"schema"_a);
143 cls.def(
"getRa", &CoordKey::getRa);
144 cls.def(
"getDec", &CoordKey::getDec);
145 cls.def(
"isValid", &CoordKey::isValid);
146 cls.def(
"get", [](CoordKey &self, BaseRecord const &record) { return self.get(record); });
147 cls.def(
"set", &CoordKey::set);
151static void declareQuadrupoleKey(WrapperCollection &wrappers) {
152 wrappers.wrapType(PyQuadrupoleKey(wrappers.module,
"QuadrupoleKey"), [](
auto &mod,
auto &cls) {
153 cls.def(py::init<>());
154 cls.def(py::init<Key<double> const &, Key<double> const &, Key<double> const &>(),
"ixx"_a,
"iyy"_a,
156 cls.def(py::init<SubSchema const &>());
157 cls.def(
"__eq__", &QuadrupoleKey::operator==, py::is_operator());
158 cls.def(
"__nq__", &QuadrupoleKey::operator!=, py::is_operator());
159 cls.def_static(
"addFields", &QuadrupoleKey::addFields,
"schema"_a,
"name"_a,
"doc"_a,
160 "coordType"_a = CoordinateType::PIXEL);
161 cls.def(
"getIxx", &QuadrupoleKey::getIxx);
162 cls.def(
"getIyy", &QuadrupoleKey::getIyy);
163 cls.def(
"getIxy", &QuadrupoleKey::getIxy);
164 cls.def(
"isValid", &QuadrupoleKey::isValid);
165 cls.def(
"set", &QuadrupoleKey::set);
166 cls.def(
"get", &QuadrupoleKey::get);
170static void declareEllipseKey(WrapperCollection &wrappers) {
171 wrappers.wrapType(PyEllipseKey(wrappers.module,
"EllipseKey"), [](
auto &mod,
auto &cls) {
172 cls.def(py::init<>());
173 cls.def(py::init<QuadrupoleKey const &, PointKey<double> const &>(),
"qKey"_a,
"pKey"_a);
174 cls.def(py::init<SubSchema const &>());
175 cls.def(
"__eq__", &EllipseKey::operator==, py::is_operator());
176 cls.def(
"__nq__", &EllipseKey::operator!=, py::is_operator());
177 cls.def_static(
"addFields", &EllipseKey::addFields,
"schema"_a,
"name"_a,
"doc"_a,
"unit"_a);
178 cls.def(
"get", &EllipseKey::get);
179 cls.def(
"set", &EllipseKey::set);
180 cls.def(
"isValid", &EllipseKey::isValid);
181 cls.def(
"getCore", &EllipseKey::getCore);
182 cls.def(
"getCenter", &EllipseKey::getCenter);
186template <
typename T,
int N>
187static void declareCovarianceMatrixKey(WrapperCollection &wrappers, const ::std::string &suffix) {
189 PyCovarianceMatrixKey<T, N>(wrappers.module, (
"CovarianceMatrix" + suffix +
"Key").c_str()),
190 [](
auto &mod,
auto &cls) {
191 using ErrKeyArray = std::vector<Key<T>>;
192 using CovarianceKeyArray = std::vector<Key<T>>;
193 using NameArray = std::vector<std::string>;
195 cls.def(py::init<>());
197 cls.def(py::init<SubSchema const &, NameArray const &>());
198 cls.def(py::init<ErrKeyArray const &, CovarianceKeyArray const &>(),
"err"_a,
199 "cov"_a = CovarianceKeyArray());
200 cls.def(
"__eq__", &CovarianceMatrixKey<T, N>::operator==, py::is_operator());
201 cls.def(
"__ne__", &CovarianceMatrixKey<T, N>::operator!=, py::is_operator());
202 cls.def_static(
"addFields",
203 (CovarianceMatrixKey<T, N>(*)(Schema &, std::string const &, NameArray const &,
204 std::string const &, bool)) &
205 CovarianceMatrixKey<T, N>::addFields,
206 "schema"_a,
"prefix"_a,
"names"_a,
"unit"_a,
"diagonalOnly"_a = false);
207 cls.def_static(
"addFields",
208 (CovarianceMatrixKey<T, N>(*)(Schema &, std::string const &, NameArray const &,
209 NameArray const &, bool)) &
210 CovarianceMatrixKey<T, N>::addFields,
211 "schema"_a,
"prefix"_a,
"names"_a,
"units"_a,
"diagonalOnly"_a = false);
212 cls.def(
"set", [](CovarianceMatrixKey<T, N> &cov, BaseRecord &record,
213 Eigen::Matrix<T, N, N> const &value) { return cov.set(record, value); });
214 cls.def(
"get", [](CovarianceMatrixKey<T, N> &cov, BaseRecord
const &record) {
215 return cov.get(record);
217 cls.def(
"isValid", &CovarianceMatrixKey<T, N>::isValid);
218 cls.def(
"setElement", &CovarianceMatrixKey<T, N>::setElement);
219 cls.def(
"getElement", &CovarianceMatrixKey<T, N>::getElement);
229 wrappers.wrapType(py::enum_<CoordinateType>(wrappers.module,
"CoordinateType"), [](
auto &
mod,
auto &
enm) {
230 enm.value(
"PIXEL", CoordinateType::PIXEL);
231 enm.value(
"CELESTIAL", CoordinateType::CELESTIAL);
Tag types used to declare specialized field types.
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)