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-20566: Replace afwGeom with geom #70

Merged
merged 2 commits into from
Jul 18, 2019
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
4 changes: 2 additions & 2 deletions python/lsst/meas/deblender/baseline.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import lsst.pex.exceptions
import lsst.afw.image as afwImage
import lsst.afw.detection as afwDet
import lsst.afw.geom as afwGeom
import lsst.geom as geom
import lsst.afw.math as afwMath

from . import plugins
Expand Down Expand Up @@ -767,7 +767,7 @@ def computeImage(self, cx, cy):
if im is not None:
return im
try:
im = self.psf.computeImage(afwGeom.Point2D(cx, cy))
im = self.psf.computeImage(geom.Point2D(cx, cy))
except lsst.pex.exceptions.Exception:
im = self.psf.computeImage()
self.cache[(cx, cy)] = im
Expand Down
3 changes: 2 additions & 1 deletion python/lsst/meas/deblender/deblend.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import lsst.pipe.base as pipeBase
import lsst.afw.math as afwMath
import lsst.afw.geom as afwGeom
import lsst.geom as geom
import lsst.afw.geom.ellipses as afwEll
import lsst.afw.image as afwImage
import lsst.afw.detection as afwDet
Expand Down Expand Up @@ -390,7 +391,7 @@ def deblend(self, exposure, srcs, psf):
child.set(self.hasStrayFluxKey, peak.strayFlux is not None)
if peak.deblendedAsPsf:
(cx, cy) = peak.psfFitCenter
child.set(self.psfCenterKey, afwGeom.Point2D(cx, cy))
child.set(self.psfCenterKey, geom.Point2D(cx, cy))
child.set(self.psfFluxKey, peak.psfFitFlux)
child.set(self.deblendRampedTemplateKey, peak.hasRampedTemplate)
child.set(self.deblendPatchedTemplateKey, peak.patched)
Expand Down
15 changes: 8 additions & 7 deletions python/lsst/meas/deblender/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import lsst.afw.image as afwImage
import lsst.afw.detection as afwDet
import lsst.afw.geom as afwGeom
import lsst.geom as geom

# Import C++ routines
from .baselineUtils import BaselineUtilsF as bUtils
Expand Down Expand Up @@ -287,7 +288,7 @@ def buildMultibandTemplates(debResult, log, useWeights=False, usePsf=False,
imbb = debResult.deblendedParents[debResult.filters[0]].img.getBBox()

# Footprint must be inside the image
if not imbb.contains(afwGeom.Point2I(cx, cy)):
if not imbb.contains(geom.Point2I(cx, cy)):
_setPeakError(debResult, log, pk, cx, cy, debResult.filters,
"peak center is not inside image", "setOutOfBounds")
continue
Expand Down Expand Up @@ -461,7 +462,7 @@ def _fitPsf(fp, fmask, pk, pkF, pkres, fbb, peaks, peaksF, log, psf, psffwhm,

# Make sure we haven't been given a substitute PSF that's nowhere near where we want, as may occur if
# "Cannot compute CoaddPsf at point (xx,yy); no input images at that point."
if not pbb.contains(afwGeom.Point2I(int(cx), int(cy))):
if not pbb.contains(geom.Point2I(int(cx), int(cy))):
pkres.setOutOfBounds()
return

Expand All @@ -470,7 +471,7 @@ def _fitPsf(fp, fmask, pk, pkF, pkres, fbb, peaks, peaksF, log, psf, psffwhm,
ylo = int(np.floor(cy - R1))
xhi = int(np.ceil(cx + R1))
yhi = int(np.ceil(cy + R1))
stampbb = afwGeom.Box2I(afwGeom.Point2I(xlo, ylo), afwGeom.Point2I(xhi, yhi))
stampbb = geom.Box2I(geom.Point2I(xlo, ylo), geom.Point2I(xhi, yhi))
stampbb.clip(fbb)
xlo, xhi = stampbb.getMinX(), stampbb.getMaxX()
ylo, yhi = stampbb.getMinY(), stampbb.getMaxY()
Expand Down Expand Up @@ -729,7 +730,7 @@ def _overlap(xlo, xhi, xmin, xmax):

# Make sure we haven't been given a substitute PSF that's nowhere near where we want, as may occur if
# "Cannot compute CoaddPsf at point (xx,yy); no input images at that point."
if not pbb2.contains(afwGeom.Point2I(int(cx + dx), int(cy + dy))):
if not pbb2.contains(geom.Point2I(int(cx + dx), int(cy + dy))):
ispsf2 = False
else:
# clip image to bbox
Expand Down Expand Up @@ -905,7 +906,7 @@ def buildSymmetricTemplates(debResult, log, patchEdges=False, setOrigTemplate=Tr
modified = True
pk = pkres.peak
cx, cy = pk.getIx(), pk.getIy()
if not imbb.contains(afwGeom.Point2I(cx, cy)):
if not imbb.contains(geom.Point2I(cx, cy)):
log.trace('Peak center is not inside image; skipping %i', pkres.pki)
pkres.setOutOfBounds()
continue
Expand Down Expand Up @@ -1058,14 +1059,14 @@ def _handle_flux_at_edge(log, psffwhm, t1, tfoot, fp, maskedImage,
# instantiate PSF image
xc = int((x0 + x1)/2)
yc = int((y0 + y1)/2)
psfim = psf.computeImage(afwGeom.Point2D(xc, yc))
psfim = psf.computeImage(geom.Point2D(xc, yc))
pbb = psfim.getBBox()
# shift PSF image to be centered on zero
lx, ly = pbb.getMinX(), pbb.getMinY()
psfim.setXY0(lx - xc, ly - yc)
pbb = psfim.getBBox()
# clip PSF to S, if necessary
Sbox = afwGeom.Box2I(afwGeom.Point2I(-S, -S), afwGeom.Extent2I(2*S+1, 2*S+1))
Sbox = geom.Box2I(geom.Point2I(-S, -S), geom.Extent2I(2*S+1, 2*S+1))
if not Sbox.contains(pbb):
# clip PSF image
psfim = psfim.Factory(psfim, Sbox, afwImage.PARENT, True)
Expand Down
44 changes: 23 additions & 21 deletions src/BaselineUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <cstdint>

#include "lsst/log/Log.h"
#include "lsst/geom.h"
#include "lsst/meas/deblender/BaselineUtils.h"
#include "lsst/pex/exceptions.h"
#include "lsst/afw/geom/Span.h"
Expand All @@ -14,6 +15,7 @@ namespace image = lsst::afw::image;
namespace det = lsst::afw::detection;
namespace deblend = lsst::meas::deblender;
namespace afwGeom = lsst::afw::geom;
namespace geom = lsst::geom;

template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
const int deblend::BaselineUtils<ImagePixelT, MaskPixelT, VariancePixelT>::ASSIGN_STRAYFLUX;
Expand Down Expand Up @@ -415,7 +417,7 @@ _find_stray_flux(det::Footprint const& foot,

int ix0 = img.getX0();
int iy0 = img.getY0();
afwGeom::Box2I sumbb = tsum->getBBox();
geom::Box2I sumbb = tsum->getBBox();
int sumx0 = sumbb.getMinX();
int sumy0 = sumbb.getMinY();

Expand Down Expand Up @@ -608,14 +610,14 @@ void
deblend::BaselineUtils<ImagePixelT,MaskPixelT,VariancePixelT>::
_sum_templates(std::vector<ImagePtrT> timgs,
ImagePtrT tsum) {
afwGeom::Box2I sumbb = tsum->getBBox();
geom::Box2I sumbb = tsum->getBBox();
int sumx0 = sumbb.getMinX();
int sumy0 = sumbb.getMinY();

// Compute tsum = the sum of templates
for (size_t i=0; i<timgs.size(); ++i) {
ImagePtrT timg = timgs[i];
afwGeom::Box2I tbb = timg->getBBox();
geom::Box2I tbb = timg->getBBox();
int tx0 = tbb.getMinX();
int ty0 = tbb.getMinY();
// To handle "ramped" templates that can extend outside the
Expand Down Expand Up @@ -730,7 +732,7 @@ apportionFlux(MaskedImageT const& img,

int ix0 = img.getX0();
int iy0 = img.getY0();
afwGeom::Box2I fbb = foot.getBBox();
geom::Box2I fbb = foot.getBBox();

if (!tsum) {
tsum = ImagePtrT(new ImageT(fbb.getDimensions()));
Expand All @@ -742,7 +744,7 @@ apportionFlux(MaskedImageT const& img,
"Template sum image MUST contain parent footprint");
}

afwGeom::Box2I sumbb = tsum->getBBox();
geom::Box2I sumbb = tsum->getBBox();
int sumx0 = sumbb.getMinX();
int sumy0 = sumbb.getMinY();

Expand All @@ -757,7 +759,7 @@ apportionFlux(MaskedImageT const& img,
portions.push_back(port);

// Split flux = image * template / tsum
afwGeom::Box2I tbb = timg->getBBox();
geom::Box2I tbb = timg->getBBox();
int tx0 = tbb.getMinX();
int ty0 = tbb.getMinY();
// As above
Expand Down Expand Up @@ -922,15 +924,15 @@ class RelativeSpanIterator {
// Check symmetrizeFootprint by computing truth naively.
// compute correct answer dumbly
det::Footprint truefoot;
afwGeom::Box2I bbox = foot.getBBox();
geom::Box2I bbox = foot.getBBox();
for (int y=bbox.getMinY(); y<=bbox.getMaxY(); y++) {
for (int x=bbox.getMinX(); x<=bbox.getMaxX(); x++) {
int dy = y - cy;
int dx = x - cx;
int x2 = cx - dx;
int y2 = cy - dy;
if (foot.contains(afwGeom::Point2I(x, y)) &&
foot.contains(afwGeom::Point2I(x2, y2))) {
if (foot.contains(geom::Point2I(x, y)) &&
foot.contains(geom::Point2I(x2, y2))) {
truefoot.addSpan(y, x, x);
}
}
Expand Down Expand Up @@ -1005,7 +1007,7 @@ symmetrizeFootprint(
++peakspan;
sp = *peakspan;
if (!sp.contains(cx, cy)) {
afwGeom::Box2I fbb = foot.getBBox();
geom::Box2I fbb = foot.getBBox();
LOGL_WARN(_log, "Failed to find span containing (%i,%i): nearest is %i, [%i,%i]. "
"Footprint bbox is [%i,%i],[%i,%i]",
cx, cy, sp.getY(), sp.getX0(), sp.getX1(),
Expand Down Expand Up @@ -1269,8 +1271,8 @@ buildSymmetricTemplate(
// of the min pixel

// We have already checked the bounding box, so this should always be satisfied
assert(theimg->getBBox(image::PARENT).contains(afwGeom::Point2I(fx, fy)));
assert(theimg->getBBox(image::PARENT).contains(afwGeom::Point2I(bx, by)));
assert(theimg->getBBox(image::PARENT).contains(geom::Point2I(fx, fy)));
assert(theimg->getBBox(image::PARENT).contains(geom::Point2I(bx, by)));

// FIXME -- we could do this with image iterators instead.
// But first profile to show that it's necessary and an
Expand All @@ -1291,12 +1293,12 @@ buildSymmetricTemplate(
// Find spans whose mirrors fall outside the image bounds,
// grow the footprint to include those spans, and plug in
// their pixel values.
afwGeom::Box2I bb = sfoot->getBBox();
geom::Box2I bb = sfoot->getBBox();

// Actually, it's not necessarily the IMAGE bounds that count
//-- the footprint may not go right to the image edge.
//afwGeom::Box2I imbb = img.getBBox();
afwGeom::Box2I imbb = foot.getBBox();
//geom::Box2I imbb = img.getBBox();
geom::Box2I imbb = foot.getBBox();

LOGL_DEBUG(_log, "Footprint touches EDGE: start bbox [%i,%i],[%i,%i]",
bb.getMinX(), bb.getMaxX(), bb.getMinY(), bb.getMaxY());
Expand All @@ -1308,13 +1310,13 @@ buildSymmetricTemplate(
// mirrored coords
int ym = cy + (cy - y);
int xm = cx + (cx - x);
if (!imbb.contains(afwGeom::Point2I(xm, ym))) {
bb.include(afwGeom::Point2I(x, y));
if (!imbb.contains(geom::Point2I(xm, ym))) {
bb.include(geom::Point2I(x, y));
}
x = fwd->getX1();
xm = cx + (cx - x);
if (!imbb.contains(afwGeom::Point2I(xm, ym))) {
bb.include(afwGeom::Point2I(x, y));
if (!imbb.contains(geom::Point2I(xm, ym))) {
bb.include(geom::Point2I(x, y));
}
}
LOGL_DEBUG(_log, "Footprint touches EDGE: grown bbox [%i,%i],[%i,%i]",
Expand All @@ -1341,8 +1343,8 @@ buildSymmetricTemplate(
int ym = cy + (cy - y);
int xm0 = cx + (cx - x0);
int xm1 = cx + (cx - x1);
bool in0 = imbb.contains(afwGeom::Point2I(xm0, ym));
bool in1 = imbb.contains(afwGeom::Point2I(xm1, ym));
bool in0 = imbb.contains(geom::Point2I(xm0, ym));
bool in1 = imbb.contains(geom::Point2I(xm1, ym));
if (in0 && in1) {
// both endpoints of the symmetric span are in bounds; nothing to do
continue;
Expand Down
5 changes: 3 additions & 2 deletions tests/test_clipFootprintToNonZeroImpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import lsst.utils.tests
import lsst.afw.detection as afwDet
import lsst.geom as geom
import lsst.afw.geom as afwGeom
import lsst.afw.image as afwImage
from lsst.meas.deblender.plugins import clipFootprintToNonzeroImpl
Expand All @@ -37,8 +38,8 @@ class ClipFootprintTestCase(lsst.utils.tests.TestCase):
which occur inside a span will be preserved.
'''
def testClip(self):
im = afwImage.ImageI(afwGeom.Box2I(afwGeom.Point2I(-2, -2),
afwGeom.Extent2I(20, 20)))
im = afwImage.ImageI(geom.Box2I(geom.Point2I(-2, -2),
geom.Extent2I(20, 20)))

span1 = afwGeom.SpanSet.fromShape(5, afwGeom.Stencil.BOX, (6, 6))
span1.setImage(im, 20)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_degenerateTemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import lsst.utils.tests
import lsst.afw.detection as afwDet
import lsst.afw.geom as afwGeom
import lsst.geom as geom
import lsst.afw.image as afwImage
from lsst.meas.deblender.baseline import deblend
import lsst.meas.algorithms as measAlg
Expand Down Expand Up @@ -54,7 +54,7 @@ def testPeakRemoval(self):
'''
H, W = 100, 100

fpbb = afwGeom.Box2I(afwGeom.Point2I(0, 0), afwGeom.Point2I(W - 1, H - 1))
fpbb = geom.Box2I(geom.Point2I(0, 0), geom.Point2I(W - 1, H - 1))

afwimg = afwImage.MaskedImageF(fpbb)
imgbb = afwimg.getBBox()
Expand All @@ -74,7 +74,7 @@ def testPeakRemoval(self):
XY = [(x, 35.), (x, 65.), (50., 50.)]
flux = 1e6
for x, y in XY:
bim = blob_psf.computeImage(afwGeom.Point2D(x, y))
bim = blob_psf.computeImage(geom.Point2D(x, y))
bbb = bim.getBBox()
bbb.clip(imgbb)

Expand Down
14 changes: 7 additions & 7 deletions tests/test_edges.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import lsst.utils.tests
import lsst.afw.detection as afwDet
import lsst.afw.geom as afwGeom
import lsst.geom as geom
import lsst.afw.image as afwImage
import lsst.meas.algorithms as measAlg
from lsst.log import Log
Expand Down Expand Up @@ -78,8 +78,8 @@ def test1(self):

# Create fake image...
H, W = 100, 100
fpbb = afwGeom.Box2I(afwGeom.Point2I(0, 0),
afwGeom.Point2I(W-1, H-1))
fpbb = geom.Box2I(geom.Point2I(0, 0),
geom.Point2I(W-1, H-1))
afwimg = afwImage.MaskedImageF(fpbb)
imgbb = afwimg.getBBox()
img = afwimg.getImage().getArray()
Expand All @@ -99,7 +99,7 @@ def test1(self):
XY = [(50., 50.), (90., 50.)]
flux = 1e6
for x, y in XY:
bim = blob_psf.computeImage(afwGeom.Point2D(x, y))
bim = blob_psf.computeImage(geom.Point2D(x, y))
bbb = bim.getBBox()
bbb.clip(imgbb)

Expand All @@ -123,10 +123,10 @@ def test1(self):
# set EDGE bit on edge pixels.
margin = 5
lo = imgbb.getMin()
lo.shift(afwGeom.Extent2I(margin, margin))
lo.shift(geom.Extent2I(margin, margin))
hi = imgbb.getMax()
hi.shift(afwGeom.Extent2I(-margin, -margin))
goodbbox = afwGeom.Box2I(lo, hi)
hi.shift(geom.Extent2I(-margin, -margin))
goodbbox = geom.Box2I(lo, hi)
print('Good bbox for setting EDGE pixels:', goodbbox)
print('image bbox:', imgbb)
edgebit = afwimg.getMask().getPlaneBitMask("EDGE")
Expand Down
3 changes: 2 additions & 1 deletion tests/test_fitPsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import lsst.utils.tests
import lsst.afw.detection as afwDet
import lsst.geom as geom
import lsst.afw.geom as afwGeom
import lsst.afw.image as afwImage
from lsst.log import Log
Expand Down Expand Up @@ -93,7 +94,7 @@ def makePeak(x, y):

fluxes = [10000., 5000., 5000.]
for pk, f in zip(peaks, fluxes):
psfim = psf1.computeImage(afwGeom.Point2D(pk.getFx(), pk.getFy()))
psfim = psf1.computeImage(geom.Point2D(pk.getFx(), pk.getFy()))
print('psfim x0,y0', psfim.getX0(), psfim.getY0())
pbb = psfim.getBBox()
print('pbb', pbb.getMinX(), pbb.getMaxX(), pbb.getMinY(), pbb.getMaxY())
Expand Down