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 where appropriate #27

Merged
merged 3 commits into from
Jul 19, 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
7 changes: 4 additions & 3 deletions include/lsst/meas/extensions/simpleShape.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <bitset>

#include "lsst/pex/config.h"
#include "lsst/geom.h"
#include "lsst/afw/geom/ellipses.h"
#include "lsst/afw/table.h"
#include "lsst/afw/image.h"
Expand Down Expand Up @@ -150,7 +151,7 @@ class SimpleShape : public lsst::meas::base::SimpleAlgorithm {
static Eigen::Matrix<double,5,6> convertRawMoments(
Eigen::Matrix<double,6,1> const & q,
afw::geom::ellipses::Quadrupole & quadrupole,
afw::geom::Point2D & center
geom::Point2D & center
);

/**
Expand Down Expand Up @@ -178,7 +179,7 @@ class SimpleShape : public lsst::meas::base::SimpleAlgorithm {
static Eigen::Matrix<double, 5, 5> correctWeightedMoments(
afw::geom::ellipses::Quadrupole const & weight,
afw::geom::ellipses::Quadrupole & ellipse,
afw::geom::Point2D & center
geom::Point2D & center
);

virtual void measure(
Expand All @@ -203,7 +204,7 @@ class SimpleShape : public lsst::meas::base::SimpleAlgorithm {
class SimpleShapeResult {
public:
afw::geom::ellipses::Quadrupole ellipse; ///< Measured second moments.
afw::geom::Point2D center; ///< Measured first moments, or the input center if !recentroid
geom::Point2D center; ///< Measured first moments, or the input center if !recentroid
Eigen::Matrix<double,5,5> covariance; ///< Matrix of uncertainties; ordered Ixx, Iyy, Ixy, Ix, Iy.

#ifndef SWIG
Expand Down
24 changes: 12 additions & 12 deletions src/simpleShape.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace {

using afw::geom::Span;

Span clipSpan(Span const & span, afw::geom::Box2I const & box) {
Span clipSpan(Span const & span, geom::Box2I const & box) {
if (span.getY() < box.getMinY() || span.getY() > box.getMaxY()) return Span();
return Span(span.getY(),
std::min(std::max(span.getMinX(), box.getMinX()), box.getMaxX()),
Expand All @@ -72,7 +72,7 @@ void iterateSpan(Function & function, Iterator pixIter, Span const & span) {

template <typename Function, typename Image, typename Region>
void iterateRegion(Function & function, Image const & image, Region const & region) {
afw::geom::Box2I bbox = image.getBBox(afw::image::PARENT);
geom::Box2I bbox = image.getBBox(afw::image::PARENT);
if (bbox.contains(region.getBBox())) {
// if the box contains the region, there's no need to check each span to make sure it's entirely
// within the image
Expand Down Expand Up @@ -127,9 +127,9 @@ typedef Eigen::Matrix<double,N_M,N_Q> MatrixMQ;
struct RawMomentAccumulator {

template <typename PixelT>
void operator()(afw::geom::Point2I const & pos, PixelT const & pixel) {
afw::geom::Extent2D d = afw::geom::Point2D(pos) - _center;
afw::geom::Extent2D gtd = _gt(d);
void operator()(geom::Point2I const & pos, PixelT const & pixel) {
geom::Extent2D d = geom::Point2D(pos) - _center;
geom::Extent2D gtd = _gt(d);
double w = std::exp(-0.5 * (gtd.getX()*gtd.getX() + gtd.getY()*gtd.getY()));
VectorQ q = VectorQ::Constant(w);
q[QXX] *= d.getX() * d.getX();
Expand All @@ -151,8 +151,8 @@ struct RawMomentAccumulator {
VectorQ moments;
MatrixQ covariance;
private:
afw::geom::Point2D _center;
afw::geom::LinearTransform _gt;
geom::Point2D _center;
geom::LinearTransform _gt;
};

} // anonymous
Expand Down Expand Up @@ -194,7 +194,7 @@ SimpleShapeResult SimpleShape::computeMoments(
result.covariance = dc_dm * mCov.selfadjointView<Eigen::Lower>() * dc_dm.adjoint();

// Finally, we switch back to the native image coordinate system.
result.center += afw::geom::Extent2D(weight.getCenter());
result.center += geom::Extent2D(weight.getCenter());

return result;
}
Expand All @@ -203,7 +203,7 @@ SimpleShapeResult SimpleShape::computeMoments(
MatrixMQ SimpleShape::convertRawMoments(
VectorQ const & q,
afw::geom::ellipses::Quadrupole & ellipse,
afw::geom::Point2D & center
geom::Point2D & center
) {
VectorM m = q.segment<N_M>(1) / q[Q0];
MatrixMQ dm_dq = MatrixMQ::Zero();;
Expand Down Expand Up @@ -234,7 +234,7 @@ MatrixMQ SimpleShape::convertRawMoments(
MatrixM SimpleShape::correctWeightedMoments(
afw::geom::ellipses::Quadrupole const & weight,
afw::geom::ellipses::Quadrupole & ellipse,
afw::geom::Point2D & center
geom::Point2D & center
) {
Eigen::Matrix2d wMat = weight.getMatrix();
Eigen::Vector2d mVec = center.asEigen();
Expand Down Expand Up @@ -325,7 +325,7 @@ SimpleShapeResultKey SimpleShapeResultKey::addFields(
name, "elliptical Gaussian moments");
r._centroidResult = lsst::afw::table::Point2DKey::addFields(schema,
name, "elliptical Gaussian moments", "pixel");
r._uncertantyResult = lsst::afw::table::CovarianceMatrixKey<double, 5>::addFields(schema,name,
r._uncertantyResult = lsst::afw::table::CovarianceMatrixKey<double, 5>::addFields(schema,name,
std::vector<std::string> ({"Ixx", "Iyy", "Ixy",
"Ix", "Iy"}), "pixel");
r._flagHandler = lsst::meas::base::FlagHandler::addFields(schema,
Expand Down Expand Up @@ -389,7 +389,7 @@ void SimpleShape::measure(
afw::table::SourceRecord & source,
afw::image::Exposure<float> const & exposure
) const {
afw::geom::Point2D center = _centroidExtractor(source, _resultKey.getFlagHandler());
geom::Point2D center = _centroidExtractor(source, _resultKey.getFlagHandler());
afw::geom::ellipses::Ellipse weight(afw::geom::ellipses::Axes(_ctrl.sigma), center);
// set flags so an exception throw produces a flagged source
SimpleShapeResult result = computeMoments(weight, exposure.getMaskedImage(), _ctrl.nSigmaRegion);
Expand Down
8 changes: 5 additions & 3 deletions tests/test_measurementFramework.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#
import unittest

import lsst.geom
import lsst.afw.geom
import lsst.utils.tests
import lsst.meas.base.tests
from lsst.meas.base.tests import AlgorithmTestCase
Expand All @@ -31,10 +33,10 @@
class SimpleShapeMFTestCase(AlgorithmTestCase, lsst.utils.tests.TestCase):

def setUp(self):
self.bbox = lsst.afw.geom.Box2I(lsst.afw.geom.Point2I(-20, -30),
lsst.afw.geom.Extent2I(240, 160))
self.bbox = lsst.geom.Box2I(lsst.geom.Point2I(-20, -30),
lsst.geom.Extent2I(240, 160))
self.dataset = lsst.meas.base.tests.TestDataset(self.bbox)
self.dataset.addSource(100000.0, lsst.afw.geom.Point2D(149.9, 50.3),
self.dataset.addSource(100000.0, lsst.geom.Point2D(149.9, 50.3),
lsst.afw.geom.ellipses.Quadrupole(8, 9, 3))

self.expectedKeySet = set(['ext_simpleShape_SimpleShape_IxErr',
Expand Down
12 changes: 6 additions & 6 deletions tests/test_simpleShape.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import numpy as np

import lsst.utils.tests
import lsst.afw.geom
import lsst.geom
import lsst.afw.geom.ellipses as el
import lsst.afw.image
from lsst.meas.extensions.simpleShape import SimpleShape
Expand All @@ -40,13 +40,13 @@ def setUp(self):
el.Quadrupole(23.0, 28.0, 2.0),
]
self.centers = [
lsst.afw.geom.Point2D(0.0, 0.0),
lsst.afw.geom.Point2D(2.0, 3.0),
lsst.afw.geom.Point2D(-1.0, 2.5),
lsst.geom.Point2D(0.0, 0.0),
lsst.geom.Point2D(2.0, 3.0),
lsst.geom.Point2D(-1.0, 2.5),
]
for ellipseCore in self.ellipseCores:
ellipseCore.scale(2)
self.bbox = lsst.afw.geom.Box2I(lsst.afw.geom.Point2I(-500, -500), lsst.afw.geom.Point2I(50, 50))
self.bbox = lsst.geom.Box2I(lsst.geom.Point2I(-500, -500), lsst.geom.Point2I(50, 50))
self.xg, self.yg = np.meshgrid(
np.arange(self.bbox.getBeginX(), self.bbox.getEndX(), dtype=float),
np.arange(self.bbox.getBeginY(), self.bbox.getEndY(), dtype=float)
Expand Down Expand Up @@ -99,7 +99,7 @@ def testCorrectWeightedMoments(self):
iyy = np.sum(product * (self.yg - iy)**2) / i0
ixy = np.sum(product * (self.xg - ix) * (self.yg - iy)) / i0
mEllipseCore = el.Quadrupole(ixx, iyy, ixy)
mCenter = lsst.afw.geom.Point2D(ix, iy)
mCenter = lsst.geom.Point2D(ix, iy)
SimpleShape.correctWeightedMoments(wEllipseCore, mEllipseCore, mCenter)
self.assertFloatsAlmostEqual(mEllipseCore.getParameterVector(),
dEllipseCore.getParameterVector(),
Expand Down
1 change: 1 addition & 0 deletions ups/meas_extensions_simpleShape.table
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ setupRequired(meas_base)
setupRequired(utils)
setupRequired(pex_config)
setupRequired(pex_exceptions)
setupRequired(geom)

# The following is boilerplate for all packages.
# Pure-Python packages only need the last line.
Expand Down