Skip to content

Commit

Permalink
Proposed changes
Browse files Browse the repository at this point in the history
  • Loading branch information
natelust committed Oct 29, 2021
1 parent c495574 commit c9fd27e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
10 changes: 4 additions & 6 deletions python/lsst/afw/detection/_heavyFootprintContinued.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ def addTo(self, image):
----------
image : `lsst.afw.image`
"""
indices = [np.array(index) for index in self.spans.indices()]
bbox = image.getBBox()
image.array[indices[0] - bbox.getMinY(), indices[1] - bbox.getMinX()] += self.getImageArray()
yind, xind = self.spans.indices() - np.expand_dims(image.getXY0(), 1)[::-1]
image.array[yind, xind] += self.getImageArray()

def subtractFrom(self, image):
"""Subtract this heavy footprint from an image.
Expand All @@ -44,9 +43,8 @@ def subtractFrom(self, image):
----------
image : `lsst.afw.image`
"""
indices = [np.array(index) for index in self.spans.indices()]
bbox = image.getBBox()
image.array[indices[0] - bbox.getMinY(), indices[1] - bbox.getMinX()] -= self.getImageArray()
yind, xind = self.spans.indices() - np.expand_dims(image.getXY0(), 1)[::-1]
image.array[yind, xind] -= self.getImageArray()


HeavyFootprint.register(np.int32, HeavyFootprintI)
Expand Down
17 changes: 9 additions & 8 deletions python/lsst/afw/geom/_spanSet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <iostream>

#include "ndarray/pybind11.h"
#include "ndarray/Array.h"

#include "lsst/afw/geom/ellipses/Quadrupole.h"
#include "lsst/afw/geom/SpanSet.h"
Expand Down Expand Up @@ -259,19 +260,19 @@ void declareSpanSet(lsst::utils::python::WrapperCollection &wrappers) {
(std::shared_ptr<SpanSet>(*)(geom::ellipses::Ellipse const &)) & SpanSet::fromShape);
cls.def("split", &SpanSet::split);
cls.def("findEdgePixels", &SpanSet::findEdgePixels);
cls.def("indices", [](SpanSet const &self) -> std::pair<std::vector<int>, std::vector<int>> {
std::vector<int> yind;
std::vector<int> xind;
yind.reserve(self.getArea());
xind.reserve(self.getArea());
cls.def("indices", [](SpanSet const &self) -> ndarray::Array<int, 2, 2> {
unsigned long dims = 2;
ndarray::Array<int, 2, 2> inds = ndarray::allocate(ndarray::makeVector(dims, self.getArea()));
int element = 0;
for (auto const &span : self) {
auto y = span.getY();
for (int x = span.getX0(); x <= span.getX1(); ++x) {
yind.push_back(y);
xind.push_back(x);
inds[0][element] = y;
inds[1][element] = x;
element++;
}
}
return std::make_pair(yind, xind);
return inds;
});

/* SpanSet Operators */
Expand Down

0 comments on commit c9fd27e

Please sign in to comment.