22 #include "pybind11/pybind11.h" 23 #include "pybind11/stl.h" 25 #include "lsst/afw/image/Image.h" 26 #include "lsst/afw/image/MaskedImage.h" 27 #include "lsst/afw/detection/Footprint.h" 28 #include "lsst/afw/detection/Peak.h" 32 namespace py = pybind11;
41 template <
typename ImagePixelT,
typename MaskPixelT = lsst::afw::image::MaskPixel,
42 typename VariancePixelT = lsst::afw::image::VariancePixel>
43 void declareBaselineUtils(py::module& mod,
const std::string& suffix) {
44 using MaskedImageT = lsst::afw::image::MaskedImage<ImagePixelT, MaskPixelT, VariancePixelT>;
45 using ImagePtrT = std::shared_ptr<lsst::afw::image::Image<ImagePixelT>>;
46 using FootprintPtrT = std::shared_ptr<lsst::afw::detection::Footprint>;
47 using Class = BaselineUtils<ImagePixelT, MaskPixelT, VariancePixelT>;
48 using PyClass = py::class_<Class, std::shared_ptr<Class>>;
50 py::class_<Class> cls(mod, (
"BaselineUtils" + suffix).c_str());
51 cls.def_static(
"symmetrizeFootprint", &Class::symmetrizeFootprint,
"foot"_a,
"cx"_a,
"cy"_a);
56 cls.def_static(
"buildSymmetricTemplate", [](MaskedImageT
const& img,
57 lsst::afw::detection::Footprint
const& foot,
58 lsst::afw::detection::PeakRecord
const& pk,
double sigma1,
59 bool minZero,
bool patchEdges) {
61 std::pair<ImagePtrT, FootprintPtrT> result;
63 result = Class::buildSymmetricTemplate(img, foot, pk, sigma1, minZero, patchEdges, &patchedEdges);
64 return py::make_tuple(result.first, result.second, patchedEdges);
66 cls.def_static(
"medianFilter", &Class::medianFilter,
"img"_a,
"outimg"_a,
"halfsize"_a);
67 cls.def_static(
"makeMonotonic", &Class::makeMonotonic,
"img"_a,
"pk"_a);
72 cls.def_static(
"apportionFlux", [](MaskedImageT
const& img, lsst::afw::detection::Footprint
const& foot,
73 std::vector<std::shared_ptr<lsst::afw::image::Image<ImagePixelT>>>
75 std::vector<std::shared_ptr<lsst::afw::detection::Footprint>>
77 ImagePtrT templ_sum, std::vector<bool>
const& ispsf,
78 std::vector<int>
const& pkx, std::vector<int>
const& pky,
79 int strayFluxOptions,
double clipStrayFluxFraction) {
80 using HeavyFootprintPtrList = std::vector<std::shared_ptr<
81 typename lsst::afw::detection::HeavyFootprint<ImagePixelT, MaskPixelT, VariancePixelT>>>;
83 std::vector<std::shared_ptr<lsst::afw::image::MaskedImage<ImagePixelT, MaskPixelT, VariancePixelT>>>
85 HeavyFootprintPtrList strays;
86 result =
Class::apportionFlux(img, foot, templates, templ_footprints, templ_sum, ispsf, pkx, pky,
87 strays, strayFluxOptions, clipStrayFluxFraction);
89 return py::make_tuple(result, strays);
91 cls.def_static(
"hasSignificantFluxAtEdge", &Class::hasSignificantFluxAtEdge,
"img"_a,
"sfoot"_a,
93 cls.def_static(
"getSignificantEdgePixels", &Class::getSignificantEdgePixels,
"img"_a,
"sfoot"_a,
97 cls.attr(
"ASSIGN_STRAYFLUX") = py::cast(Class::ASSIGN_STRAYFLUX);
98 cls.attr(
"STRAYFLUX_TO_POINT_SOURCES_WHEN_NECESSARY") =
99 py::cast(Class::STRAYFLUX_TO_POINT_SOURCES_WHEN_NECESSARY);
100 cls.attr(
"STRAYFLUX_TO_POINT_SOURCES_ALWAYS") = py::cast(Class::STRAYFLUX_TO_POINT_SOURCES_ALWAYS);
101 cls.attr(
"STRAYFLUX_R_TO_FOOTPRINT") = py::cast(Class::STRAYFLUX_R_TO_FOOTPRINT);
102 cls.attr(
"STRAYFLUX_NEAREST_FOOTPRINT") = py::cast(Class::STRAYFLUX_NEAREST_FOOTPRINT);
103 cls.attr(
"STRAYFLUX_TRIM") = py::cast(Class::STRAYFLUX_TRIM);
109 py::module::import(
"lsst.afw.image");
110 py::module::import(
"lsst.afw.detection");
112 py::module mod(
"baselineUtils");
114 declareBaselineUtils<float>(mod,
"F");
def apportionFlux(debResult, log, assignStrayFlux=True, strayFluxAssignment='r-to-peak', strayFluxToPointSources='necessary', clipStrayFluxFraction=0.001, getTemplateSum=False)
PYBIND11_PLUGIN(baselineUtils)