23 #include "pybind11/pybind11.h" 24 #include "pybind11/eigen.h" 25 #include "pybind11/stl.h" 27 #include "ndarray/pybind11.h" 54 template <
typename Box>
57 using PyCoordKey = py::class_<CoordKey, std::shared_ptr<CoordKey>>;
59 using PyQuadrupoleKey = py::class_<QuadrupoleKey, std::shared_ptr<QuadrupoleKey>>;
61 using PyEllipseKey = py::class_<EllipseKey, std::shared_ptr<EllipseKey>>;
63 template <
typename T,
int N>
64 using PyCovarianceMatrixKey =
69 PyPointKey<T>
cls(mod, (
"Point" + suffix +
"Key").c_str());
70 cls.def(py::init<>());
71 cls.def(
py::init<Key<T>
const &, Key<T>
const &>(),
"x"_a,
"y"_a);
72 cls.def(py::init<SubSchema const &>());
73 cls.def(
"__eq__", &PointKey<T>::operator==, py::is_operator());
74 cls.def(
"__ne__", &PointKey<T>::operator!=, py::is_operator());
75 cls.def(
"getX", &PointKey<T>::getX);
76 cls.def(
"getY", &PointKey<T>::getY);
78 cls.def_static(
"addFields", &PointKey<T>::addFields,
"schema"_a,
"name"_a,
"doc"_a,
"unit"_a);
80 return self.set(record, value);
82 cls.def(
"get", &PointKey<T>::get);
85 template <
typename Box>
87 using Element =
typename Box::Element;
88 PyBoxKey<Box>
cls(mod, (
"Box" + suffix +
"Key").c_str());
89 cls.def(py::init<>());
90 cls.def(
py::init<PointKey<Element>
const &, PointKey<Element>
const &>(),
"min"_a,
"max"_a);
91 cls.def(py::init<SubSchema const &>());
92 cls.def(
"__eq__", &BoxKey<Box>::operator==, py::is_operator());
93 cls.def(
"__ne__", &BoxKey<Box>::operator!=, py::is_operator());
94 cls.def(
"getMin", &BoxKey<Box>::getMin);
95 cls.def(
"getMax", &BoxKey<Box>::getMax);
97 cls.def_static(
"addFields", &BoxKey<Box>::addFields,
"schema"_a,
"name"_a,
"doc"_a,
"unit"_a);
99 cls.def(
"get", &BoxKey<Box>::get);
102 static void declareCoordKey(
py::module &mod) {
103 PyCoordKey
cls(mod,
"CoordKey");
104 cls.def(py::init<>());
105 cls.def(
py::init<Key<lsst::geom::Angle>, Key<lsst::geom::Angle>>(),
"ra"_a,
"dec"_a);
106 cls.def(py::init<SubSchema const &>());
107 cls.def(
"__eq__", &CoordKey::operator==, py::is_operator());
108 cls.def(
"__ne__", &CoordKey::operator!=, py::is_operator());
109 cls.def_static(
"addFields", &CoordKey::addFields,
"schema"_a,
"name"_a,
"doc"_a);
110 cls.def(
"getRa", &CoordKey::getRa);
111 cls.def(
"getDec", &CoordKey::getDec);
113 cls.def(
"get", [](CoordKey &
self, BaseRecord
const &record) {
return self.get(record); });
117 static void declareQuadrupoleKey(
py::module &mod) {
118 PyQuadrupoleKey
cls(mod,
"QuadrupoleKey");
119 cls.def(py::init<>());
120 cls.def(
py::init<Key<double>
const &, Key<double>
const &, Key<double>
const &>(),
"ixx"_a,
"iyy"_a,
122 cls.def(py::init<SubSchema const &>());
123 cls.def(
"__eq__", &QuadrupoleKey::operator==, py::is_operator());
124 cls.def(
"__nq__", &QuadrupoleKey::operator!=, py::is_operator());
125 cls.def_static(
"addFields", &QuadrupoleKey::addFields,
"schema"_a,
"name"_a,
"doc"_a,
126 "coordType"_a = CoordinateType::PIXEL);
127 cls.def(
"getIxx", &QuadrupoleKey::getIxx);
128 cls.def(
"getIyy", &QuadrupoleKey::getIyy);
129 cls.def(
"getIxy", &QuadrupoleKey::getIxy);
132 cls.def(
"get", &QuadrupoleKey::get);
135 static void declareEllipseKey(
py::module &mod) {
136 PyEllipseKey
cls(mod,
"EllipseKey");
137 cls.def(py::init<>());
138 cls.def(
py::init<QuadrupoleKey
const &, PointKey<double>
const &>(),
"qKey"_a,
"pKey"_a);
139 cls.def(py::init<SubSchema const &>());
140 cls.def(
"__eq__", &EllipseKey::operator==, py::is_operator());
141 cls.def(
"__nq__", &EllipseKey::operator!=, py::is_operator());
142 cls.def_static(
"addFields", &EllipseKey::addFields,
"schema"_a,
"name"_a,
"doc"_a,
"unit"_a);
143 cls.def(
"get", &EllipseKey::get);
146 cls.def(
"getCore", &EllipseKey::getCore);
147 cls.def(
"getCenter", &EllipseKey::getCenter);
150 template <
typename T,
int N>
151 static void declareCovarianceMatrixKey(
py::module &mod, const ::std::string &suffix) {
156 PyCovarianceMatrixKey<T, N>
cls(mod, (
"CovarianceMatrix" + suffix +
"Key").c_str());
158 cls.def(py::init<>());
160 cls.def(py::init<SubSchema const &, NameArray const &>());
161 cls.def(py::init<ErrKeyArray const &, CovarianceKeyArray const &>(),
"err"_a,
162 "cov"_a = CovarianceKeyArray());
163 cls.def(
"__eq__", &CovarianceMatrixKey<T, N>::operator==, py::is_operator());
164 cls.def(
"__ne__", &CovarianceMatrixKey<T, N>::operator!=, py::is_operator());
165 cls.def_static(
"addFields", (CovarianceMatrixKey<T, N>(*)(Schema &,
std::string const &,
167 CovarianceMatrixKey<T, N>::addFields,
168 "schema"_a,
"prefix"_a,
"names"_a,
"unit"_a,
"diagonalOnly"_a =
false);
169 cls.def_static(
"addFields", (CovarianceMatrixKey<T, N>(*)(Schema &,
std::string const &,
170 NameArray
const &, NameArray
const &,
bool)) &
171 CovarianceMatrixKey<T, N>::addFields,
172 "schema"_a,
"prefix"_a,
"names"_a,
"units"_a,
"diagonalOnly"_a =
false);
173 cls.def(
"set", [](CovarianceMatrixKey<T, N> &cov, BaseRecord &record,
174 Eigen::Matrix<T, N, N>
const &value) {
return cov.set(record, value); });
175 cls.def(
"get", [](CovarianceMatrixKey<T, N> &cov, BaseRecord
const &record) {
return cov.get(record); });
177 cls.def(
"setElement", &CovarianceMatrixKey<T, N>::setElement);
178 cls.def(
"getElement", &CovarianceMatrixKey<T, N>::getElement);
184 py::module::import(
"lsst.afw.geom.ellipses");
185 py::module::import(
"lsst.afw.table.base");
186 py::enum_<CoordinateType>(mod,
"CoordinateType")
187 .value(
"PIXEL", CoordinateType::PIXEL)
188 .value(
"CELESTIAL", CoordinateType::CELESTIAL)
191 declarePointKey<double>(mod,
"2D");
192 declarePointKey<int>(mod,
"2I");
194 declareBoxKey<lsst::geom::Box2D>(mod,
"2D");
195 declareBoxKey<lsst::geom::Box2I>(mod,
"2I");
197 declareCoordKey(mod);
198 declareQuadrupoleKey(mod);
199 declareEllipseKey(mod);
201 declareCovarianceMatrixKey<float, 2>(mod,
"2f");
202 declareCovarianceMatrixKey<float, 3>(mod,
"3f");
203 declareCovarianceMatrixKey<float, 4>(mod,
"4f");
204 declareCovarianceMatrixKey<float, Eigen::Dynamic>(mod,
"Xf");
205 declareCovarianceMatrixKey<double, 2>(mod,
"2d");
206 declareCovarianceMatrixKey<double, 3>(mod,
"3d");
207 declareCovarianceMatrixKey<double, 4>(mod,
"4d");
208 declareCovarianceMatrixKey<double, Eigen::Dynamic>(mod,
"Xd");
A coordinate class intended to represent absolute positions (2-d specialization). ...
PYBIND11_MODULE(aggregates, mod)
daf::base::PropertySet * set
A base class for image defects.