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;
59template <
typename Box>
62using PyCoordKey = py::class_<CoordKey, std::shared_ptr<CoordKey>>;
64using PyQuadrupoleKey = py::class_<QuadrupoleKey, std::shared_ptr<QuadrupoleKey>>;
66using PyEllipseKey = py::class_<EllipseKey, std::shared_ptr<EllipseKey>>;
68template <
typename T,
int N>
69using PyCovarianceMatrixKey =
73static void declarePointKey(WrapperCollection &wrappers,
std::string const &suffix) {
75 PyPointKey<T>(wrappers.module, (
"Point" + suffix +
"Key").c_str()), [](
auto &mod,
auto &cls) {
76 cls.def(py::init<>());
77 cls.def(py::init<Key<T> const &, Key<T> const &>(),
"x"_a,
"y"_a);
78 cls.def(py::init<SubSchema const &>());
79 cls.def(
"__eq__", &PointKey<T>::operator==, py::is_operator());
80 cls.def(
"__ne__", &PointKey<T>::operator!=, py::is_operator());
81 cls.def(
"getX", &PointKey<T>::getX);
82 cls.def(
"getY", &PointKey<T>::getY);
83 cls.def(
"isValid", &PointKey<T>::isValid);
84 cls.def_static(
"addFields", &PointKey<T>::addFields,
"schema"_a,
"name"_a,
"doc"_a,
"unit"_a);
85 cls.def(
"set", [](PointKey<T> &self, BaseRecord &record,
86 lsst::geom::Point<T, 2> const &value) { return self.set(record, value); });
91template <
typename Box>
92static void declareBoxKey(WrapperCollection &wrappers,
std::string const &suffix) {
94 PyBoxKey<Box>(wrappers.module, (
"Box" + suffix +
"Key").c_str()), [](
auto &mod,
auto &cls) {
95 using Element = typename Box::Element;
96 cls.def(py::init<>());
97 cls.def(py::init<PointKey<Element> const &, PointKey<Element> const &>(),
"min"_a,
"max"_a);
98 cls.def(py::init<SubSchema const &>());
99 cls.def(
"__eq__", &BoxKey<Box>::operator==, py::is_operator());
100 cls.def(
"__ne__", &BoxKey<Box>::operator!=, py::is_operator());
101 cls.def(
"getMin", &BoxKey<Box>::getMin);
102 cls.def(
"getMax", &BoxKey<Box>::getMax);
103 cls.def(
"isValid", &BoxKey<Box>::isValid);
104 cls.def_static(
"addFields", &BoxKey<Box>::addFields,
"schema"_a,
"name"_a,
"doc"_a,
"unit"_a);
105 cls.def(
"set", &BoxKey<Box>::set);
106 cls.def(
"get", &BoxKey<Box>::get);
111static void declareCoordKey(WrapperCollection &wrappers) {
112 wrappers.wrapType(PyCoordKey(wrappers.module,
"CoordKey"), [](
auto &mod,
auto &cls) {
113 cls.def(py::init<>());
114 cls.def(py::init<Key<lsst::geom::Angle>, Key<lsst::geom::Angle>>(),
"ra"_a,
"dec"_a);
115 cls.def(py::init<SubSchema const &>());
116 cls.def(
"__eq__", &CoordKey::operator==, py::is_operator());
117 cls.def(
"__ne__", &CoordKey::operator!=, py::is_operator());
118 cls.def_static(
"addFields", &CoordKey::addFields,
"schema"_a,
"name"_a,
"doc"_a);
119 cls.def(
"getRa", &CoordKey::getRa);
120 cls.def(
"getDec", &CoordKey::getDec);
121 cls.def(
"isValid", &CoordKey::isValid);
122 cls.def(
"get", [](CoordKey &self, BaseRecord const &record) { return self.get(record); });
127static void declareQuadrupoleKey(WrapperCollection &wrappers) {
128 wrappers.wrapType(PyQuadrupoleKey(wrappers.module,
"QuadrupoleKey"), [](
auto &mod,
auto &cls) {
129 cls.def(py::init<>());
130 cls.def(py::init<Key<double> const &, Key<double> const &, Key<double> const &>(),
"ixx"_a,
"iyy"_a,
132 cls.def(py::init<SubSchema const &>());
133 cls.def(
"__eq__", &QuadrupoleKey::operator==, py::is_operator());
134 cls.def(
"__nq__", &QuadrupoleKey::operator!=, py::is_operator());
135 cls.def_static(
"addFields", &QuadrupoleKey::addFields,
"schema"_a,
"name"_a,
"doc"_a,
136 "coordType"_a = CoordinateType::PIXEL);
137 cls.def(
"getIxx", &QuadrupoleKey::getIxx);
138 cls.def(
"getIyy", &QuadrupoleKey::getIyy);
139 cls.def(
"getIxy", &QuadrupoleKey::getIxy);
140 cls.def(
"isValid", &QuadrupoleKey::isValid);
141 cls.def(
"set", &QuadrupoleKey::set);
142 cls.def(
"get", &QuadrupoleKey::get);
146static void declareEllipseKey(WrapperCollection &wrappers) {
147 wrappers.wrapType(PyEllipseKey(wrappers.module,
"EllipseKey"), [](
auto &mod,
auto &cls) {
148 cls.def(py::init<>());
149 cls.def(py::init<QuadrupoleKey const &, PointKey<double> const &>(),
"qKey"_a,
"pKey"_a);
150 cls.def(py::init<SubSchema const &>());
151 cls.def(
"__eq__", &EllipseKey::operator==, py::is_operator());
152 cls.def(
"__nq__", &EllipseKey::operator!=, py::is_operator());
153 cls.def_static(
"addFields", &EllipseKey::addFields,
"schema"_a,
"name"_a,
"doc"_a,
"unit"_a);
154 cls.def(
"get", &EllipseKey::get);
155 cls.def(
"set", &EllipseKey::set);
156 cls.def(
"isValid", &EllipseKey::isValid);
157 cls.def(
"getCore", &EllipseKey::getCore);
158 cls.def(
"getCenter", &EllipseKey::getCenter);
162template <
typename T,
int N>
163static void declareCovarianceMatrixKey(WrapperCollection &wrappers,
const ::std::string &suffix) {
165 PyCovarianceMatrixKey<T, N>(wrappers.module, (
"CovarianceMatrix" + suffix +
"Key").c_str()),
166 [](
auto &mod,
auto &cls) {
167 using ErrKeyArray = std::vector<Key<T>>;
168 using CovarianceKeyArray = std::vector<Key<T>>;
169 using NameArray = std::vector<std::string>;
171 cls.def(py::init<>());
173 cls.def(py::init<SubSchema const &, NameArray const &>());
174 cls.def(py::init<ErrKeyArray const &, CovarianceKeyArray const &>(),
"err"_a,
175 "cov"_a = CovarianceKeyArray());
176 cls.def(
"__eq__", &CovarianceMatrixKey<T, N>::operator==, py::is_operator());
177 cls.def(
"__ne__", &CovarianceMatrixKey<T, N>::operator!=, py::is_operator());
178 cls.def_static(
"addFields",
179 (CovarianceMatrixKey<T, N>(*)(Schema &, std::string const &, NameArray const &,
180 std::string const &, bool)) &
181 CovarianceMatrixKey<T, N>::addFields,
182 "schema"_a,
"prefix"_a,
"names"_a,
"unit"_a,
"diagonalOnly"_a = false);
183 cls.def_static(
"addFields",
184 (CovarianceMatrixKey<T, N>(*)(Schema &, std::string const &, NameArray const &,
185 NameArray const &, bool)) &
186 CovarianceMatrixKey<T, N>::addFields,
187 "schema"_a,
"prefix"_a,
"names"_a,
"units"_a,
"diagonalOnly"_a = false);
188 cls.def(
"set", [](CovarianceMatrixKey<T, N> &cov, BaseRecord &record,
189 Eigen::Matrix<T, N, N> const &value) { return cov.set(record, value); });
190 cls.def(
"get", [](CovarianceMatrixKey<T, N> &cov, BaseRecord
const &record) {
191 return cov.get(record);
194 cls.def(
"setElement", &CovarianceMatrixKey<T, N>::setElement);
195 cls.def(
"getElement", &CovarianceMatrixKey<T, N>::getElement);
205 wrappers.wrapType(py::enum_<CoordinateType>(wrappers.module,
"CoordinateType"), [](
auto &mod,
auto &enm) {
206 enm.value(
"PIXEL", CoordinateType::PIXEL);
207 enm.value(
"CELESTIAL", CoordinateType::CELESTIAL);
211 declarePointKey<double>(wrappers,
"2D");
212 declarePointKey<int>(wrappers,
"2I");
214 declareBoxKey<lsst::geom::Box2D>(wrappers,
"2D");
215 declareBoxKey<lsst::geom::Box2I>(wrappers,
"2I");
217 declareCoordKey(wrappers);
218 declareQuadrupoleKey(wrappers);
219 declareEllipseKey(wrappers);
221 declareCovarianceMatrixKey<float, 2>(wrappers,
"2f");
222 declareCovarianceMatrixKey<float, 3>(wrappers,
"3f");
223 declareCovarianceMatrixKey<float, 4>(wrappers,
"4f");
224 declareCovarianceMatrixKey<float, Eigen::Dynamic>(wrappers,
"Xf");
225 declareCovarianceMatrixKey<double, 2>(wrappers,
"2d");
226 declareCovarianceMatrixKey<double, 3>(wrappers,
"3d");
227 declareCovarianceMatrixKey<double, 4>(wrappers,
"4d");
228 declareCovarianceMatrixKey<double, Eigen::Dynamic>(wrappers,
"Xd");
void set(BaseRecord &record, lsst::geom::SpherePoint const &value) const override
Set an lsst::geom::SpherePoint in 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)
A base class for image defects.