Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-14828: Update pybind11 wrappers for 2.2 #132

Merged
merged 3 commits into from
Jul 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 7 additions & 12 deletions python/lsst/meas/algorithms/coaddBoundedField.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,19 @@ namespace meas {
namespace algorithms {
namespace {

PYBIND11_PLUGIN(coaddBoundedField) {
py::module mod("coaddBoundedField");

PYBIND11_MODULE(coaddBoundedField, mod) {
py::class_<CoaddBoundedFieldElement> clsCoaddBoundedFieldElement(mod, "CoaddBoundedFieldElement");

clsCoaddBoundedFieldElement.def(
"__init__",
[](CoaddBoundedFieldElement &instance, std::shared_ptr<afw::math::BoundedField> field,
std::shared_ptr<afw::geom::SkyWcs const> wcs, py::object polygon, double weight) {
if (polygon == py::none()) {
new (&instance) CoaddBoundedFieldElement(field, wcs, nullptr, weight);
py::init([](std::shared_ptr<afw::math::BoundedField> field,
std::shared_ptr<afw::geom::SkyWcs const> wcs, py::object polygon, double weight) {
if (polygon.is(py::none())) {
return new CoaddBoundedFieldElement(field, wcs, nullptr, weight);
} else {
auto pgon = py::cast<std::shared_ptr<afw::geom::polygon::Polygon const>>(polygon);
new (&instance) CoaddBoundedFieldElement(field, wcs, pgon, weight);
return new CoaddBoundedFieldElement(field, wcs, pgon, weight);
}
},
}),
"field"_a, "wcs"_a, "validPolygon"_a, "weight"_a = 1.0);

clsCoaddBoundedFieldElement.def_readwrite("field", &CoaddBoundedFieldElement::field);
Expand Down Expand Up @@ -87,8 +84,6 @@ PYBIND11_PLUGIN(coaddBoundedField) {
clsCoaddBoundedField.def("getDefault", &CoaddBoundedField::getDefault);
clsCoaddBoundedField.def("getElements", &CoaddBoundedField::getElements);
clsCoaddBoundedField.def("isPersistable", &CoaddBoundedField::isPersistable);

return mod.ptr();
}

} // namespace
Expand Down
6 changes: 1 addition & 5 deletions python/lsst/meas/algorithms/coaddPsf/coaddPsf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ namespace meas {
namespace algorithms {
namespace {

PYBIND11_PLUGIN(coaddPsf) {
py::module mod("coaddPsf");

PYBIND11_MODULE(coaddPsf, mod) {
/* CoaddPsfControl */
py::class_<CoaddPsfControl, std::shared_ptr<CoaddPsfControl>> clsControl(mod, "CoaddPsfControl");
clsControl.def(py::init<std::string, int>(), "warpingKernelName"_a = "lanczos3", "cacheSize"_a = 10000);
Expand Down Expand Up @@ -69,8 +67,6 @@ PYBIND11_PLUGIN(coaddPsf) {
clsCoaddPsf.def("getBBox", &CoaddPsf::getBBox);
clsCoaddPsf.def("getValidPolygon", &CoaddPsf::getValidPolygon);
clsCoaddPsf.def("isPersistable", &CoaddPsf::isPersistable);

return mod.ptr();
}

} // namespace
Expand Down
4 changes: 1 addition & 3 deletions python/lsst/meas/algorithms/coaddTransmissionCurve.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ namespace meas {
namespace algorithms {
namespace {

PYBIND11_PLUGIN(coaddTransmissionCurve) {
py::module mod("coaddTransmissionCurve");
PYBIND11_MODULE(coaddTransmissionCurve, mod) {
py::module::import("lsst.afw.geom");
py::module::import("lsst.afw.image");
py::module::import("lsst.afw.table");
mod.def("makeCoaddTransmissionCurve", &makeCoaddTransmissionCurve, "coaddWcs"_a, "inputSensors"_a);
return mod.ptr();
}

} // namespace
Expand Down
6 changes: 1 addition & 5 deletions python/lsst/meas/algorithms/cr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,8 @@ void declareFindCosmicRays(py::module& mod) {
"policy"_a, "keep"_a = false);
}

PYBIND11_PLUGIN(cr) {
py::module mod("cr");

PYBIND11_MODULE(cr, mod) {
declareFindCosmicRays<float>(mod);

return mod.ptr();
}

} // namespace
Expand Down
8 changes: 1 addition & 7 deletions python/lsst/meas/algorithms/doubleGaussianPsf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,22 @@ namespace meas {
namespace algorithms {
namespace {

PYBIND11_PLUGIN(doubleGaussianPsf) {
py::module mod("doubleGaussianPsf");

PYBIND11_MODULE(doubleGaussianPsf, mod) {
afw::table::io::python::declarePersistableFacade<DoubleGaussianPsf>(mod, "DoubleGaussianPsf");

py::class_<DoubleGaussianPsf, std::shared_ptr<DoubleGaussianPsf>,
afw::table::io::PersistableFacade<DoubleGaussianPsf>, KernelPsf>
clsDoubleGaussianPsf(mod, "DoubleGaussianPsf");

/* Constructors */
clsDoubleGaussianPsf.def(py::init<int, int, double, double, double>(), "width"_a, "height"_a, "sigma1"_a,
"sigma2"_a = 0.0, "b"_a = 0.0);

/* Members */
clsDoubleGaussianPsf.def("clone", &DoubleGaussianPsf::clone);
clsDoubleGaussianPsf.def("resized", &DoubleGaussianPsf::resized, "width"_a, "height"_a);
clsDoubleGaussianPsf.def("getSigma1", &DoubleGaussianPsf::getSigma1);
clsDoubleGaussianPsf.def("getSigma2", &DoubleGaussianPsf::getSigma2);
clsDoubleGaussianPsf.def("getB", &DoubleGaussianPsf::getB);
clsDoubleGaussianPsf.def("isPersistable", &DoubleGaussianPsf::isPersistable);

return mod.ptr();
}

} // namespace
Expand Down
5 changes: 1 addition & 4 deletions python/lsst/meas/algorithms/imagePsf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,14 @@ namespace meas {
namespace algorithms {
namespace {

PYBIND11_PLUGIN(imagePsf) {
PYBIND11_MODULE(imagePsf, mod) {
py::module::import("lsst.afw.detection");
py::module mod("imagePsf");

afw::table::io::python::declarePersistableFacade<ImagePsf>(mod, "ImagePsf");

py::class_<ImagePsf, std::shared_ptr<ImagePsf>, afw::table::io::PersistableFacade<ImagePsf>,
afw::detection::Psf>
clsImagePsf(mod, "ImagePsf");

return mod.ptr();
}

} // namespace
Expand Down
9 changes: 1 addition & 8 deletions python/lsst/meas/algorithms/interp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,11 @@ void declareInterpolateOverDefects(py::module& mod) {
"image"_a, "psf"_a, "badList"_a, "fallBackValue"_a = 0.0, "useFallbackValueAtEdge"_a = false);
}

PYBIND11_PLUGIN(interp) {
PYBIND11_MODULE(interp, mod) {
py::module::import("lsst.afw.image");

py::module mod("interp");

py::class_<Defect, std::shared_ptr<Defect>, afw::image::DefectBase> clsDefect(mod, "Defect");

/* Member types and enums */
py::enum_<Defect::DefectPosition>(clsDefect, "DefectPosition")
.value("LEFT", Defect::DefectPosition::LEFT)
.value("NEAR_LEFT", Defect::DefectPosition::NEAR_LEFT)
Expand All @@ -63,17 +60,13 @@ PYBIND11_PLUGIN(interp) {
.value("RIGHT", Defect::DefectPosition::RIGHT)
.export_values();

/* Constructors */
clsDefect.def(py::init<const geom::BoxI&>(), "bbox"_a = geom::BoxI());

/* Members */
clsDefect.def("classify", &Defect::classify);
clsDefect.def("getType", &Defect::getType);
clsDefect.def("getPos", &Defect::getPos);

declareInterpolateOverDefects<float>(mod);

return mod.ptr();
}

} // namespace
Expand Down
8 changes: 1 addition & 7 deletions python/lsst/meas/algorithms/kernelPsf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,19 @@ namespace meas {
namespace algorithms {
namespace {

PYBIND11_PLUGIN(kernelPsf) {
py::module mod("kernelPsf");

PYBIND11_MODULE(kernelPsf, mod) {
afw::table::io::python::declarePersistableFacade<KernelPsf>(mod, "KernelPsf");

py::class_<KernelPsf, std::shared_ptr<KernelPsf>, afw::table::io::PersistableFacade<KernelPsf>, ImagePsf>
clsKernelPsf(mod, "KernelPsf");

/* Constructors */
clsKernelPsf.def(py::init<afw::math::Kernel const &, geom::Point2D const &>(), "kernel"_a,
"averagePosition"_a = geom::Point2D());

/* Members */
clsKernelPsf.def("getKernel", &KernelPsf::getKernel);
clsKernelPsf.def("getAveragePosition", &KernelPsf::getAveragePosition);
clsKernelPsf.def("clone", &KernelPsf::clone);
clsKernelPsf.def("isPersistable", &KernelPsf::isPersistable);

return mod.ptr();
}

} // namespace
Expand Down
8 changes: 1 addition & 7 deletions python/lsst/meas/algorithms/pcaPsf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,17 @@ namespace meas {
namespace algorithms {
namespace {

PYBIND11_PLUGIN(pcaPsf) {
py::module mod("pcaPsf");

PYBIND11_MODULE(pcaPsf, mod) {
afw::table::io::python::declarePersistableFacade<PcaPsf>(mod, "PcaPsf");

py::class_<PcaPsf, std::shared_ptr<PcaPsf>, afw::table::io::PersistableFacade<PcaPsf>, KernelPsf>
clsPcaPsf(mod, "PcaPsf");

/* Constructors */
clsPcaPsf.def(py::init<std::shared_ptr<afw::math::LinearCombinationKernel>, geom::Point2D const &>(),
"kernel"_a, "averagePosition"_a = geom::Point2D());

/* Members */
clsPcaPsf.def("clone", &PcaPsf::clone);
clsPcaPsf.def("getKernel", &PcaPsf::getKernel);

return mod.ptr();
}

} // namespace
Expand Down
6 changes: 1 addition & 5 deletions python/lsst/meas/algorithms/psfCandidate/psfCandidate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,8 @@ void declarePsfCandidate(py::module& mod, std::string const& suffix) {

} // namespace

PYBIND11_PLUGIN(psfCandidate) {
py::module mod("psfCandidate");

PYBIND11_MODULE(psfCandidate, mod) {
declarePsfCandidate<float>(mod, "F");

return mod.ptr();
}

} // namespace algorithms
Expand Down
8 changes: 1 addition & 7 deletions python/lsst/meas/algorithms/singleGaussianPsf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,19 @@ namespace meas {
namespace algorithms {
namespace {

PYBIND11_PLUGIN(singleGaussianPsf) {
py::module mod("singleGaussianPsf");

PYBIND11_MODULE(singleGaussianPsf, mod) {
afw::table::io::python::declarePersistableFacade<SingleGaussianPsf>(mod, "SingleGaussianPsf");

py::class_<SingleGaussianPsf, std::shared_ptr<SingleGaussianPsf>,
afw::table::io::PersistableFacade<SingleGaussianPsf>, KernelPsf>
clsSingleGaussianPsf(mod, "SingleGaussianPsf");

/* Constructors */
clsSingleGaussianPsf.def(py::init<int, int, double>(), "width"_a, "height"_a, "sigma"_a);

/* Members */
clsSingleGaussianPsf.def("clone", &SingleGaussianPsf::clone);
clsSingleGaussianPsf.def("resized", &SingleGaussianPsf::resized, "width"_a, "height"_a);
clsSingleGaussianPsf.def("getSigma", &SingleGaussianPsf::getSigma);
clsSingleGaussianPsf.def("isPersistable", &SingleGaussianPsf::isPersistable);

return mod.ptr();
}

} // namespace
Expand Down
7 changes: 1 addition & 6 deletions python/lsst/meas/algorithms/spatialModelPsf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,8 @@ static void declareFunctions(py::module &mod) {
mod.def("fitKernelToImage", fitKernelToImage<MaskedImageT>, "kernel"_a, "image"_a, "pos"_a);
}

PYBIND11_PLUGIN(spatialModelPsf) {
py::module mod("spatialModelPsf");

/* Module level */
PYBIND11_MODULE(spatialModelPsf, mod) {
declareFunctions<float>(mod);

return mod.ptr();
}

} // namespace
Expand Down
6 changes: 1 addition & 5 deletions python/lsst/meas/algorithms/warpedPsf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ namespace meas {
namespace algorithms {
namespace {

PYBIND11_PLUGIN(warpedPsf) {
py::module mod("warpedPsf");

PYBIND11_MODULE(warpedPsf, mod) {
py::class_<WarpedPsf, std::shared_ptr<WarpedPsf>, ImagePsf> clsWarpedPsf(mod, "WarpedPsf");

/* Constructors */
Expand All @@ -49,8 +47,6 @@ PYBIND11_PLUGIN(warpedPsf) {
/* Members */
clsWarpedPsf.def("getAveragePosition", &WarpedPsf::getAveragePosition);
clsWarpedPsf.def("clone", &WarpedPsf::clone);

return mod.ptr();
}

} // namespace
Expand Down