From 75644d10b6ba6b5d6ef308a7bb84030a61c5c5b8 Mon Sep 17 00:00:00 2001 From: Arun Kannawadi Date: Tue, 23 Jan 2024 15:58:45 -0500 Subject: [PATCH] all working --- .../CloughTocher2DInterpolatorUtils.h | 54 ++++++++++------ .../cloughTocher2DInterpolatorUtils.cc | 51 +++++++++------ src/CloughTocher2DInterpolatorUtils.cc | 64 +++++++++---------- 3 files changed, 98 insertions(+), 71 deletions(-) diff --git a/include/lsst/meas/algorithms/CloughTocher2DInterpolatorUtils.h b/include/lsst/meas/algorithms/CloughTocher2DInterpolatorUtils.h index e70b506a1..bee1d96d2 100644 --- a/include/lsst/meas/algorithms/CloughTocher2DInterpolatorUtils.h +++ b/include/lsst/meas/algorithms/CloughTocher2DInterpolatorUtils.h @@ -1,11 +1,12 @@ // -*- LSST-C++ -*- - /* - * LSST Data Management System - * Copyright 2008-2015 LSST Corporation. + * This file is part of meas_algorithms. * - * This product includes software developed by the - * LSST Project (http://www.lsst.org/). + * Developed for the LSST Data Management System. + * This product includes software developed by the LSST Project + * (https://www.lsst.org). + * See the COPYRIGHT file at the top-level directory of this distribution + * for details of code ownership. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,9 +18,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the LSST License Statement and - * the GNU General Public License along with this program. If not, - * see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #if !defined(LSST_MEAS_ALGORITHMS_CLOUGHTOCHER2DINTERPOLATORUTILS_H) @@ -36,18 +36,36 @@ namespace lsst { namespace meas { namespace algorithms { -template -std::pair, ndarray::Array> findGoodPixelsAroundBadPixels( - MaskedImageT const &mimage, std::vector const &maskPlanes, - int const buffer); +/* +@brief This class contains static utility methods that are used by the CloughTocher2DInterpolatorTask +and exists solely to provide a namespace. +*/ +class CloughTocher2DInterpolatorUtils{ +typedef float PixelT; +public: + static std::pair, ndarray::Array> findGoodPixelsAroundBadPixels( + afw::image::MaskedImage const &mimage, + std::vector const &maskPlanes, int const buffer); + + static void updateArrayFromImage( + ndarray::Array const &array, afw::image::Image const &image); + + static void updateImageFromArray( + afw::image::Image &image, ndarray::Array const &array); +}; + + +// template +// std::pair, ndarray::Array> findGoodPixelsAroundBadPixels( +// MaskedImageT const &mimage, std::vector const &maskPlanes, +// int const buffer); -template -void updateArrayFromImage( - ndarray::Array &array, ImageT const &image); +// void updateArrayFromImage( +// ndarray::Array const &array, afw::image::Image const &image); -template -void updateImageFromArray( - ImageT &image, ndarray::Array const &array); +// template +// void updateImageFromArray( +// ImageT &image, ndarray::Array const &array); } // namespace algorithms } // namespace meas diff --git a/python/lsst/meas/algorithms/cloughTocher2DInterpolatorUtils.cc b/python/lsst/meas/algorithms/cloughTocher2DInterpolatorUtils.cc index 12b001c2c..c0e7dcb77 100644 --- a/python/lsst/meas/algorithms/cloughTocher2DInterpolatorUtils.cc +++ b/python/lsst/meas/algorithms/cloughTocher2DInterpolatorUtils.cc @@ -1,9 +1,12 @@ - /* - * LSST Data Management System +// -*- LSST-C++ -*- +/* + * This file is part of meas_algorithms. * - * This product includes software developed by the - * LSST Project (http://www.lsst.org/). - * See the COPYRIGHT file + * Developed for the LSST Data Management System. + * This product includes software developed by the LSST Project + * (https://www.lsst.org). + * See the COPYRIGHT file at the top-level directory of this distribution + * for details of code ownership. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,9 +18,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the LSST License Statement and - * the GNU General Public License along with this program. If not, - * see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include "pybind11/pybind11.h" #include "ndarray/pybind11.h" @@ -35,37 +37,44 @@ namespace meas { namespace algorithms { namespace { +typedef float PixelT; -template void declareFindGoodPixelsAroundBadPixels(py::module& mod) { mod.def("findGoodPixelsAroundBadPixels", - findGoodPixelsAroundBadPixels< - afw::image::MaskedImage>, + CloughTocher2DInterpolatorUtils::findGoodPixelsAroundBadPixels, "image"_a, "badList"_a, "buffer"_a = 4); } -template +// template void declareUpdateArrayFromImage(py::module& mod) { mod.def("updateArrayFromImage", - updateArrayFromImage< - afw::image::Image>, + CloughTocher2DInterpolatorUtils::updateArrayFromImage, "array"_a, "image"_a); } -template +// template void declareUpdateImageFromArray(py::module& mod) { mod.def("updateImageFromArray", - updateImageFromArray< - afw::image::Image>, + CloughTocher2DInterpolatorUtils::updateImageFromArray, "image"_a, "array"_a); } void declareCloughTocher2DInterpolatorUtils(lsst::cpputils::python::WrapperCollection &wrappers) { - declareFindGoodPixelsAroundBadPixels(wrappers.module); - declareUpdateArrayFromImage(wrappers.module); - declareUpdateImageFromArray(wrappers.module); + using PyCloughTocher2DInterpolatorUtils = py::class_>; + auto clsCloughTocher2DInterpolatorUtils = wrappers.wrapType( + PyCloughTocher2DInterpolatorUtils( + wrappers.module, "CloughTocher2DInterpolatorUtils"), + [](auto &mod, auto &cls) { + // cls.def(py::init<>()); // can we get away without it? + cls.def_static("findGoodPixelsAroundBadPixels", + &CloughTocher2DInterpolatorUtils::findGoodPixelsAroundBadPixels, + "mimage"_a, "badList"_a, "buffer"_a); + cls.def_static("updateArrayFromImage", &CloughTocher2DInterpolatorUtils::updateArrayFromImage, + "array"_a, "image"_a); + cls.def_static("updateImageFromArray", &CloughTocher2DInterpolatorUtils::updateImageFromArray, + "image"_a, "array"_a); + }); } - } // namespace void wrapCloughTocher2DInterpolatorUtils(lsst::cpputils::python::WrapperCollection &wrappers) { diff --git a/src/CloughTocher2DInterpolatorUtils.cc b/src/CloughTocher2DInterpolatorUtils.cc index 739aa99b1..36340dd57 100644 --- a/src/CloughTocher2DInterpolatorUtils.cc +++ b/src/CloughTocher2DInterpolatorUtils.cc @@ -59,9 +59,8 @@ namespace algorithms { */ // Should we return a Struct with the badPixels and goodPixels instead of a pair? -template -std::pair, ndarray::Array> findGoodPixelsAroundBadPixels( - MaskedImageT const &mimage, std::vector const &maskPlanes, +std::pair, ndarray::Array> lsst::meas::algorithms::CloughTocher2DInterpolatorUtils::findGoodPixelsAroundBadPixels( + afw::image::MaskedImage const &mimage, std::vector const &maskPlanes, int const buffer) { afw::image::MaskPixel bitMask = afw::image::Mask<>::getPlaneBitMask(maskPlanes); @@ -101,51 +100,52 @@ std::pair, ndarray::Array> findGoodPixe return std::make_pair(badPixels, result); } -template -void updateImageFromArray( - ImageT &image, ndarray::Array const &badPixels){ +void ::lsst::meas::algorithms::CloughTocher2DInterpolatorUtils::updateImageFromArray( + afw::image::Image &image, ndarray::Array const &badPixels){ lsst::afw::image::CheckIndices docheck(true); - for (auto ref = badPixels.begin(); ref != badPixels.end(); ++ref) { - ndarray::Array::Value row = ref[0]; - int x = row[0]; - int y = row[1]; + auto x0 = image.getX0(); + auto y0 = image.getY0(); + // for (auto iter = badPixels.begin(); iter != badPixels.end(); ++iter) { + for (auto row : badPixels) { + // ndarray::Array::Value row = ref[0]; + // auto row = *iter; + int x = row[0] - x0; + int y = row[1] - y0; image(x, y, docheck) = row[2]; } } -template -void updateArrayFromImage( - ndarray::Array &badPixels, ImageT const &image){ + +void ::lsst::meas::algorithms::CloughTocher2DInterpolatorUtils::updateArrayFromImage( + ndarray::Array const &badPixels, afw::image::Image const &image){ lsst::afw::image::CheckIndices docheck(true); + auto x0 = image.getX0(); + auto y0 = image.getY0(); for (auto ref = badPixels.begin(); ref != badPixels.end(); ++ref) { //ndarray::Array::Value row = ref[0]; auto row = ref[0]; - int x = row[0]; - int y = row[1]; + int x = row[0] -x0 ; + int y = row[1] - y0; row[2] = image(x, y, docheck); } } -template void updateImageFromArray( - afw::image::Image &image, - ndarray::Array const &badPixels); - -template void updateImageFromArray( - afw::image::Image &image, - ndarray::Array const &badPixels); +// template void updateImageFromArray( +// afw::image::Image &image, +// ndarray::Array const &badPixels); -template void updateArrayFromImage( - ndarray::Array &badPixels, - afw::image::Image const &image); +// template void updateImageFromArray( +// afw::image::Image &image, +// ndarray::Array const &badPixels); -template void updateArrayFromImage( - ndarray::Array &badPixels, // How to make this double? - afw::image::Image const &image); +// template void updateArrayFromImage( +// ndarray::Array &badPixels, +// afw::image::Image const &image); -template std::pair, ndarray::Array> findGoodPixelsAroundBadPixels( - afw::image::MaskedImage const &mimage, - std::vector const &maskPlanes, - int const buffer); +// template std::pair, ndarray::Array> findGoodPixelsAroundBadPixels( +// afw::image::MaskedImage const &mimage, +// std::vector const &maskPlanes, +// int const buffer); } // namespace algorithms } // namespace meas