Skip to content

Commit

Permalink
all working
Browse files Browse the repository at this point in the history
  • Loading branch information
arunkannawadi committed Jan 23, 2024
1 parent a7185cc commit 75644d1
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 71 deletions.
54 changes: 36 additions & 18 deletions include/lsst/meas/algorithms/CloughTocher2DInterpolatorUtils.h
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 <http://www.lsstcorp.org/LegalNotices/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#if !defined(LSST_MEAS_ALGORITHMS_CLOUGHTOCHER2DINTERPOLATORUTILS_H)
Expand All @@ -36,18 +36,36 @@ namespace lsst {
namespace meas {
namespace algorithms {

template <typename MaskedImageT>
std::pair<ndarray::Array<float, 2, 2>, ndarray::Array<float, 2, 2>> findGoodPixelsAroundBadPixels(
MaskedImageT const &mimage, std::vector<std::string> 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<float, 2, 2>, ndarray::Array<float, 2, 2>> findGoodPixelsAroundBadPixels(
afw::image::MaskedImage<PixelT, afw::image::MaskPixel, afw::image::VariancePixel> const &mimage,
std::vector<std::string> const &maskPlanes, int const buffer);

static void updateArrayFromImage(
ndarray::Array<float, 2, 2> const &array, afw::image::Image<PixelT> const &image);

static void updateImageFromArray(
afw::image::Image<PixelT> &image, ndarray::Array<float const, 2, 2> const &array);
};


// template <typename MaskedImageT>
// std::pair<ndarray::Array<float, 2, 2>, ndarray::Array<float, 2, 2>> findGoodPixelsAroundBadPixels(
// MaskedImageT const &mimage, std::vector<std::string> const &maskPlanes,
// int const buffer);

template <typename ImageT>
void updateArrayFromImage(
ndarray::Array<float, 2, 2> &array, ImageT const &image);
// void updateArrayFromImage(
// ndarray::Array<float, 2, 2> const &array, afw::image::Image<float> const &image);

template <typename ImageT>
void updateImageFromArray(
ImageT &image, ndarray::Array<float, 2, 2> const &array);
// template <typename ImageT>
// void updateImageFromArray(
// ImageT &image, ndarray::Array<float const, 2, 2> const &array);

} // namespace algorithms
} // namespace meas
Expand Down
51 changes: 30 additions & 21 deletions python/lsst/meas/algorithms/cloughTocher2DInterpolatorUtils.cc
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 <https://www.lsstcorp.org/LegalNotices/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "pybind11/pybind11.h"
#include "ndarray/pybind11.h"
Expand All @@ -35,37 +37,44 @@ namespace meas {
namespace algorithms {
namespace {

typedef float PixelT;

template <typename PixelT>
void declareFindGoodPixelsAroundBadPixels(py::module& mod) {
mod.def("findGoodPixelsAroundBadPixels",
findGoodPixelsAroundBadPixels<
afw::image::MaskedImage<PixelT, afw::image::MaskPixel, afw::image::VariancePixel>>,
CloughTocher2DInterpolatorUtils::findGoodPixelsAroundBadPixels,
"image"_a, "badList"_a, "buffer"_a = 4);
}

template <typename PixelT>
// template <typename PixelT>
void declareUpdateArrayFromImage(py::module& mod) {
mod.def("updateArrayFromImage",
updateArrayFromImage<
afw::image::Image<PixelT>>,
CloughTocher2DInterpolatorUtils::updateArrayFromImage,
"array"_a, "image"_a);
}

template <typename PixelT>
// template <typename PixelT>
void declareUpdateImageFromArray(py::module& mod) {
mod.def("updateImageFromArray",
updateImageFromArray<
afw::image::Image<PixelT>>,
CloughTocher2DInterpolatorUtils::updateImageFromArray,
"image"_a, "array"_a);
}

void declareCloughTocher2DInterpolatorUtils(lsst::cpputils::python::WrapperCollection &wrappers) {
declareFindGoodPixelsAroundBadPixels<float>(wrappers.module);
declareUpdateArrayFromImage<float>(wrappers.module);
declareUpdateImageFromArray<float>(wrappers.module);
using PyCloughTocher2DInterpolatorUtils = py::class_<CloughTocher2DInterpolatorUtils, std::shared_ptr<CloughTocher2DInterpolatorUtils>>;
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)
{
Expand Down
64 changes: 32 additions & 32 deletions src/CloughTocher2DInterpolatorUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ namespace algorithms {
*/

// Should we return a Struct with the badPixels and goodPixels instead of a pair?
template <typename MaskedImageT>
std::pair<ndarray::Array<float, 2, 2>, ndarray::Array<float, 2, 2>> findGoodPixelsAroundBadPixels(
MaskedImageT const &mimage, std::vector<std::string> const &maskPlanes,
std::pair<ndarray::Array<float, 2, 2>, ndarray::Array<float, 2, 2>> lsst::meas::algorithms::CloughTocher2DInterpolatorUtils::findGoodPixelsAroundBadPixels(
afw::image::MaskedImage<float> const &mimage, std::vector<std::string> const &maskPlanes,
int const buffer) {
afw::image::MaskPixel bitMask = afw::image::Mask<>::getPlaneBitMask(maskPlanes);

Expand Down Expand Up @@ -101,51 +100,52 @@ std::pair<ndarray::Array<float, 2, 2>, ndarray::Array<float, 2, 2>> findGoodPixe
return std::make_pair(badPixels, result);
}

template <typename ImageT>
void updateImageFromArray(
ImageT &image, ndarray::Array<float, 2, 2> const &badPixels){
void ::lsst::meas::algorithms::CloughTocher2DInterpolatorUtils::updateImageFromArray(
afw::image::Image<float> &image, ndarray::Array<float const, 2, 2> const &badPixels){
lsst::afw::image::CheckIndices docheck(true);
for (auto ref = badPixels.begin(); ref != badPixels.end(); ++ref) {
ndarray::Array<float, 2, 2>::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<float, 2, 2>::Value row = ref[0];
// auto row = *iter;
int x = row[0] - x0;
int y = row[1] - y0;
image(x, y, docheck) = row[2];
}
}

template <typename ImageT>
void updateArrayFromImage(
ndarray::Array<float, 2, 2> &badPixels, ImageT const &image){

void ::lsst::meas::algorithms::CloughTocher2DInterpolatorUtils::updateArrayFromImage(
ndarray::Array<float, 2, 2> const &badPixels, afw::image::Image<float> 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<PixelT, 2, 2>::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<float> &image,
ndarray::Array<float, 2, 2> const &badPixels);

template void updateImageFromArray(
afw::image::Image<double> &image,
ndarray::Array<float, 2, 2> const &badPixels);
// template void updateImageFromArray(
// afw::image::Image<float> &image,
// ndarray::Array<float, 2, 2> const &badPixels);

template void updateArrayFromImage(
ndarray::Array<float, 2, 2> &badPixels,
afw::image::Image<float> const &image);
// template void updateImageFromArray(
// afw::image::Image<double> &image,
// ndarray::Array<float, 2, 2> const &badPixels);

template void updateArrayFromImage(
ndarray::Array<float, 2, 2> &badPixels, // How to make this double?
afw::image::Image<double> const &image);
// template void updateArrayFromImage(
// ndarray::Array<float, 2, 2> &badPixels,
// afw::image::Image<float> const &image);

template std::pair<ndarray::Array<float, 2, 2>, ndarray::Array<float, 2, 2>> findGoodPixelsAroundBadPixels(
afw::image::MaskedImage<float, afw::image::MaskPixel, afw::image::VariancePixel> const &mimage,
std::vector<std::string> const &maskPlanes,
int const buffer);
// template std::pair<ndarray::Array<float, 2, 2>, ndarray::Array<float, 2, 2>> findGoodPixelsAroundBadPixels(
// afw::image::MaskedImage<float, afw::image::MaskPixel, afw::image::VariancePixel> const &mimage,
// std::vector<std::string> const &maskPlanes,
// int const buffer);

} // namespace algorithms
} // namespace meas
Expand Down

0 comments on commit 75644d1

Please sign in to comment.