Skip to content

Commit

Permalink
Merge pull request #82 from lsst/tickets/DM-20566-meas_modelfit
Browse files Browse the repository at this point in the history
DM-20566: Switch from afw.geom to geom
  • Loading branch information
timj committed Jul 18, 2019
2 parents a759dd9 + 94a647b commit 000ad9a
Show file tree
Hide file tree
Showing 30 changed files with 120 additions and 126 deletions.
9 changes: 5 additions & 4 deletions include/lsst/meas/modelfit/CModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include "ndarray.h"

#include "lsst/geom.h"
#include "lsst/pex/config.h"
#include "lsst/meas/base/exceptions.h"
#include "lsst/afw/table/Source.h"
Expand Down Expand Up @@ -461,7 +462,7 @@ class CModelAlgorithm {
Result apply(
afw::image::Exposure<Pixel> const & exposure,
shapelet::MultiShapeletFunction const & psf,
afw::geom::Point2D const & center,
geom::Point2D const & center,
afw::geom::ellipses::Quadrupole const & moments,
Scalar approxFlux=-1,
Scalar kronRadius=-1,
Expand All @@ -483,7 +484,7 @@ class CModelAlgorithm {
Result applyForced(
afw::image::Exposure<Pixel> const & exposure,
shapelet::MultiShapeletFunction const & psf,
afw::geom::Point2D const & center,
geom::Point2D const & center,
Result const & reference,
Scalar approxFlux=-1
) const;
Expand Down Expand Up @@ -552,7 +553,7 @@ class CModelAlgorithm {
Result & result,
afw::image::Exposure<Pixel> const & exposure,
shapelet::MultiShapeletFunction const & psf,
afw::geom::Point2D const & center,
geom::Point2D const & center,
afw::geom::ellipses::Quadrupole const & moments,
Scalar approxFlux,
Scalar kronRadius=-1,
Expand All @@ -565,7 +566,7 @@ class CModelAlgorithm {
Result & result,
afw::image::Exposure<Pixel> const & exposure,
shapelet::MultiShapeletFunction const & psf,
afw::geom::Point2D const & center,
geom::Point2D const & center,
Result const & reference,
Scalar approxFlux
) const;
Expand Down
3 changes: 2 additions & 1 deletion include/lsst/meas/modelfit/GeneralPsfFitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "lsst/meas/modelfit/Model.h"
#include "lsst/meas/modelfit/Prior.h"
#include "lsst/meas/modelfit/Likelihood.h"
#include "lsst/geom.h"
#include "lsst/afw/geom.h"
#include "lsst/afw/table/Source.h"
#include "lsst/meas/base/exceptions.h"
Expand Down Expand Up @@ -316,7 +317,7 @@ class MultiShapeletPsfLikelihood : public Likelihood {

MultiShapeletPsfLikelihood(
ndarray::Array<Pixel const,2,1> const & image,
afw::geom::Point2I const & xy0,
geom::Point2I const & xy0,
PTR(Model) model,
Scalar sigma,
ndarray::Array<Scalar const,1,1> const & fixed
Expand Down
5 changes: 2 additions & 3 deletions include/lsst/meas/modelfit/PixelFitRegion.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#include "lsst/pex/config.h"
#include "lsst/meas/modelfit/common.h"
#include "lsst/afw/geom/Point.h"
#include "lsst/geom/Point.h"
#include "lsst/afw/image/Mask.h"
#include "lsst/afw/detection/Footprint.h"
#include "lsst/afw/geom/ellipses.h"
Expand Down Expand Up @@ -121,7 +121,7 @@ class PixelFitRegion {
afw::geom::ellipses::Quadrupole const & psfMoments
);

void applyMask(afw::image::Mask<> const & mask, afw::geom::Point2D const & center);
void applyMask(afw::image::Mask<> const & mask, geom::Point2D const & center);

afw::geom::ellipses::Quadrupole ellipse;
PTR(afw::detection::Footprint) footprint;
Expand All @@ -141,4 +141,3 @@ class PixelFitRegion {
}}} // lsst::meas::modelfit

#endif // !LSST_MEAS_MODELFIT_PixelFitRegion_h_INCLUDED

12 changes: 6 additions & 6 deletions include/lsst/meas/modelfit/UnitSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
#define LSST_MEAS_MODELFIT_UnitSystem_h_INCLUDED

#include "lsst/afw/image/Exposure.h"
#include "lsst/afw/geom/SpherePoint.h"
#include "lsst/geom/SpherePoint.h"
#include "lsst/afw/geom/SkyWcs.h"
#include "lsst/afw/image/PhotoCalib.h"
#include "lsst/afw/geom/AffineTransform.h"
#include "lsst/geom/AffineTransform.h"

#include "lsst/meas/modelfit/common.h"

Expand All @@ -50,9 +50,9 @@ struct UnitSystem {
* set such that unit flux is the given magnitude. See @ref modelfitUnits for an explanation
* of why we frequently use this system.
*/
UnitSystem(afw::geom::SpherePoint const& position,
UnitSystem(geom::SpherePoint const& position,
std::shared_ptr<const afw::image::PhotoCalib> photoCalib, double flux);
UnitSystem(afw::geom::SpherePoint const& position, Scalar mag);
UnitSystem(geom::SpherePoint const& position, Scalar mag);

/// Construct a UnitSystem from a given Wcs and PhotoCalib
UnitSystem(std::shared_ptr<afw::geom::SkyWcs const> wcs_,
Expand All @@ -79,15 +79,15 @@ struct UnitSystem {
*/
struct LocalUnitTransform {
/// Maps source pixel coordinates to destination pixel coordinates
afw::geom::AffineTransform geometric;
geom::AffineTransform geometric;

/// Multiply source fluxes by this to get destination fluxes
double flux;

/// Multiply source surface brightnesses by this to get destination surface brightnesses
double sb;

LocalUnitTransform(afw::geom::Point2D const& sourcePixel, UnitSystem const& source,
LocalUnitTransform(geom::Point2D const& sourcePixel, UnitSystem const& source,
UnitSystem const& destination);

/// Construct an identity transform for both geometry and flux.
Expand Down
6 changes: 3 additions & 3 deletions include/lsst/meas/modelfit/UnitTransformedLikelihood.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "ndarray.h"

#include "lsst/pex/config.h"
#include "lsst/afw/geom/SpherePoint.h"
#include "lsst/geom/SpherePoint.h"
#include "lsst/afw/geom/ellipses/Ellipse.h"
#include "lsst/afw/image/Exposure.h"
#include "lsst/afw/detection/Footprint.h"
Expand Down Expand Up @@ -123,7 +123,7 @@ class UnitTransformedLikelihood : public Likelihood {
PTR(Model) model,
ndarray::Array<Scalar const,1,1> const & fixed,
UnitSystem const & fitSys,
afw::geom::SpherePoint const & position,
geom::SpherePoint const & position,
std::vector<PTR(EpochFootprint)> const & epochFootprintList,
UnitTransformedLikelihoodControl const & ctrl
);
Expand All @@ -144,7 +144,7 @@ class UnitTransformedLikelihood : public Likelihood {
PTR(Model) model,
ndarray::Array<Scalar const,1,1> const & fixed,
UnitSystem const & fitSys,
afw::geom::SpherePoint const & position,
geom::SpherePoint const & position,
afw::image::Exposure<Pixel> const & exposure,
afw::detection::Footprint const & footprint,
shapelet::MultiShapeletFunction const & psf,
Expand Down
6 changes: 3 additions & 3 deletions python/lsst/meas/modelfit/unitSystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ PYBIND11_MODULE(unitSystem, mod) {
clsUnitSystem.def_readonly("wcs", &UnitSystem::wcs);
clsUnitSystem.def_readonly("photoCalib", &UnitSystem::photoCalib);
clsUnitSystem.def(
py::init<afw::geom::SpherePoint const &, std::shared_ptr<afw::image::PhotoCalib const>, double>(),
py::init<geom::SpherePoint const &, std::shared_ptr<afw::image::PhotoCalib const>, double>(),
"position"_a, "calibIn"_a, "flux"_a);
clsUnitSystem.def(py::init<afw::geom::SpherePoint const &, Scalar>(), "position"_a, "mag"_a);
clsUnitSystem.def(py::init<geom::SpherePoint const &, Scalar>(), "position"_a, "mag"_a);
clsUnitSystem.def(
py::init<std::shared_ptr<afw::geom::SkyWcs const>, std::shared_ptr<afw::image::PhotoCalib const>>(),
"wcs"_a, "photoCalib"_a);
Expand All @@ -60,7 +60,7 @@ PYBIND11_MODULE(unitSystem, mod) {
clsLocalUnitTransform.def_readonly("geometric", &LocalUnitTransform::geometric);
clsLocalUnitTransform.def_readonly("flux", &LocalUnitTransform::flux);
clsLocalUnitTransform.def_readonly("sb", &LocalUnitTransform::sb);
clsLocalUnitTransform.def(py::init<afw::geom::Point2D const &, UnitSystem const &, UnitSystem const &>(),
clsLocalUnitTransform.def(py::init<geom::Point2D const &, UnitSystem const &, UnitSystem const &>(),
"sourcePixel"_a, "source"_a, "destination"_a);
clsLocalUnitTransform.def(py::init<>());
}
Expand Down
4 changes: 2 additions & 2 deletions python/lsst/meas/modelfit/unitTransformedLikelihood.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ PYBIND11_MODULE(unitTransformedLikelihood, mod) {
PyUnitTransformedLikelihood clsUnitTransformedLikelihood(mod, "UnitTransformedLikelihood");
clsUnitTransformedLikelihood.def(
py::init<std::shared_ptr<Model>, ndarray::Array<Scalar const, 1, 1> const &, UnitSystem const &,
afw::geom::SpherePoint const &, afw::image::Exposure<Pixel> const &,
geom::SpherePoint const &, afw::image::Exposure<Pixel> const &,
afw::detection::Footprint const &, shapelet::MultiShapeletFunction const &,
UnitTransformedLikelihoodControl const &>(),
"model"_a, "fixed"_a, "fitSys"_a, "position"_a, "exposure"_a, "footprint"_a, "psf"_a, "ctrl"_a);
clsUnitTransformedLikelihood.def(
py::init<std::shared_ptr<Model>, ndarray::Array<Scalar const, 1, 1> const &, UnitSystem const &,
afw::geom::SpherePoint const &, std::vector<std::shared_ptr<EpochFootprint>> const &,
geom::SpherePoint const &, std::vector<std::shared_ptr<EpochFootprint>> const &,
UnitTransformedLikelihoodControl const &>(),
"model"_a, "fixed"_a, "fitSys"_a, "position"_a, "epochFootprintList"_a, "ctrl"_a);
}
Expand Down
22 changes: 11 additions & 11 deletions src/CModel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#include "lsst/afw/detection/FootprintSet.h"
#include "lsst/afw/detection/Psf.h"
#include "lsst/afw/geom/SpherePoint.h"
#include "lsst/geom/SpherePoint.h"
#include "lsst/afw/math/LeastSquares.h"
#include "lsst/shapelet/FunctorKeys.h"
#include "lsst/meas/modelfit/TruncatedGaussian.h"
Expand Down Expand Up @@ -542,8 +542,8 @@ struct CModelKeys {
namespace {

struct CModelStageData {
afw::geom::Point2D measSysCenter; // position of the object in image ("meas") coordinates
afw::geom::SpherePoint position; // position of the object in ICRS ra,dec
geom::Point2D measSysCenter; // position of the object in image ("meas") coordinates
geom::SpherePoint position; // position of the object in ICRS ra,dec
UnitSystem measSys; // coordinate systems for the image being measured
UnitSystem fitSys; // coordinate systems for the model parameters
LocalUnitTransform fitSysToMeasSys; // coordinate transform from fitSys to measSys
Expand All @@ -555,7 +555,7 @@ struct CModelStageData {

CModelStageData(
afw::image::Exposure<Pixel> const & exposure,
Scalar approxFlux, afw::geom::Point2D const & center,
Scalar approxFlux, geom::Point2D const & center,
shapelet::MultiShapeletFunction const & psf_,
Model const & model
) :
Expand Down Expand Up @@ -954,7 +954,7 @@ class CModelAlgorithm::Impl {
}
afw::geom::ellipses::Ellipse deconvolvedEllipse(
deconvolvedMoments,
afw::geom::Point2D(data.measSysCenter - psfEllipse.getCenter())
geom::Point2D(data.measSysCenter - psfEllipse.getCenter())
);
// Convert ellipse from moments to half-light using the ratio for this profile
deconvolvedEllipse.getCore().scale(1.0 / initial.profile->getMomentsRadiusFactor());
Expand Down Expand Up @@ -1044,7 +1044,7 @@ CModelAlgorithm::CModelAlgorithm(Control const & ctrl) :
CModelAlgorithm::Result CModelAlgorithm::apply(
afw::image::Exposure<Pixel> const & exposure,
shapelet::MultiShapeletFunction const & psf,
afw::geom::Point2D const & center,
geom::Point2D const & center,
afw::geom::ellipses::Quadrupole const & moments,
Scalar approxFlux,
Scalar kronRadius,
Expand All @@ -1059,7 +1059,7 @@ void CModelAlgorithm::_applyImpl(
Result & result,
afw::image::Exposure<Pixel> const & exposure,
shapelet::MultiShapeletFunction const & psf,
afw::geom::Point2D const & center,
geom::Point2D const & center,
afw::geom::ellipses::Quadrupole const & moments,
Scalar approxFlux,
Scalar kronRadius,
Expand All @@ -1069,7 +1069,7 @@ void CModelAlgorithm::_applyImpl(
afw::geom::ellipses::Quadrupole psfMoments;
try {
psfMoments = psf.evaluate().computeMoments().getCore();
} catch (afw::geom::SingularTransformException const& exc) {
} catch (geom::SingularTransformException const& exc) {
throw LSST_EXCEPT(
meas::base::MeasurementError,
std::string("Singular transform in shapelets: ") + exc.what(),
Expand Down Expand Up @@ -1157,7 +1157,7 @@ void CModelAlgorithm::_applyImpl(
CModelAlgorithm::Result CModelAlgorithm::applyForced(
afw::image::Exposure<Pixel> const & exposure,
shapelet::MultiShapeletFunction const & psf,
afw::geom::Point2D const & center,
geom::Point2D const & center,
CModelResult const & reference,
Scalar approxFlux
) const {
Expand Down Expand Up @@ -1199,7 +1199,7 @@ void CModelAlgorithm::_applyForcedImpl(
Result & result,
afw::image::Exposure<Pixel> const & exposure,
shapelet::MultiShapeletFunction const & psf,
afw::geom::Point2D const & center,
geom::Point2D const & center,
CModelResult const & reference,
Scalar approxFlux
) const {
Expand Down Expand Up @@ -1344,7 +1344,7 @@ void CModelAlgorithm::measure(
result.flags[Result::NO_SHAPE] = true;
try {
moments = psf.evaluate().computeMoments().getCore();
} catch (afw::geom::SingularTransformException const& exc) {
} catch (geom::SingularTransformException const& exc) {
throw LSST_EXCEPT(
meas::base::MeasurementError,
std::string("Singular transform in shapelets: ") + exc.what(),
Expand Down
13 changes: 7 additions & 6 deletions src/DoubleShapeletPsfApprox.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <array>

#include "lsst/shapelet/MatrixBuilder.h"
#include "lsst/geom.h"
#include "lsst/afw/math/LeastSquares.h"
#include "lsst/afw/detection/Psf.h"
#include "lsst/afw/table/Source.h"
Expand Down Expand Up @@ -79,7 +80,7 @@ class MomentsFunctor {
Scalar getSum() const { return _m0; }

afw::geom::ellipses::Ellipse getEllipse() const {
afw::geom::Point2D center(_mx/_m0, _my/_m0);
geom::Point2D center(_mx/_m0, _my/_m0);
afw::geom::ellipses::Quadrupole quadrupole(
_mxx/_m0 - center.getX()*center.getX(),
_myy/_m0 - center.getY()*center.getY(),
Expand Down Expand Up @@ -131,20 +132,20 @@ class GaussianArgFunctor {
GaussianArgFunctor(
ndarray::Array<Scalar,1,1> const & data,
ndarray::Array<Scalar,1,1> const & arg,
afw::geom::AffineTransform const * gt
geom::AffineTransform const * gt
) : _dataIter(data.begin()), _argIter(arg.begin()), _gt(gt) {}

void operator()(Scalar value, Scalar x, Scalar y) {
*_dataIter = value;
*_argIter = -0.5*(*_gt)(afw::geom::Point2D(x, y)).asEigen().squaredNorm();
*_argIter = -0.5*(*_gt)(geom::Point2D(x, y)).asEigen().squaredNorm();
++_dataIter;
++_argIter;
}

private:
ndarray::Array<Scalar,1,1>::Iterator _dataIter;
ndarray::Array<Scalar,1,1>::Iterator _argIter;
afw::geom::AffineTransform const * _gt;
geom::AffineTransform const * _gt;
};

} // anonymous
Expand Down Expand Up @@ -268,11 +269,11 @@ class ProfileObjective : public OptimizerObjective {
// We now compute most of the exponential argument to the Gaussian function up
// front (everything but the factor of 1/r^2), since that won't change as
// the parameters change.
afw::geom::AffineTransform gt = moments.getGridTransform();
geom::AffineTransform gt = moments.getGridTransform();
GaussianArgFunctor func(_data.shallow(), _arg.shallow(), &gt);
applyPixelFunctor(image, func);
_normalization = gt.getLinear().computeDeterminant() * shapelet::ShapeletFunction::FLUX_FACTOR /
(2.0*afw::geom::PI);
(2.0*geom::PI);
}

virtual void computeResiduals(
Expand Down
2 changes: 1 addition & 1 deletion src/GeneralPsfFitter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ class MultiShapeletPsfLikelihood::Impl {

MultiShapeletPsfLikelihood::MultiShapeletPsfLikelihood(
ndarray::Array<Pixel const,2,1> const & image,
afw::geom::Point2I const & xy0,
geom::Point2I const & xy0,
PTR(Model) model,
Scalar sigma,
ndarray::Array<Scalar const,1,1> const & fixed
Expand Down
4 changes: 2 additions & 2 deletions src/Model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class SingleCenterModel : public Model {
Scalar const * nonlinearIter, Scalar const * fixedIter,
EllipseIterator ellipseIter
) const override {
afw::geom::Point2D center(nonlinearIter[getNonlinearDim()-2], nonlinearIter[getNonlinearDim()-1]);
geom::Point2D center(nonlinearIter[getNonlinearDim()-2], nonlinearIter[getNonlinearDim()-1]);
for (int i = 0; i < getBasisCount(); ++i, ++ellipseIter) {
if (getBasisVector()[i]) {
ellipseIter->getCore().readParameters(nonlinearIter);
Expand Down Expand Up @@ -233,7 +233,7 @@ class MultiCenterModel : public Model {
ellipseIter->getCore().readParameters(nonlinearIter);
nonlinearIter += 3;
}
ellipseIter->setCenter(afw::geom::Point2D(centerIter[0], centerIter[1]));
ellipseIter->setCenter(geom::Point2D(centerIter[0], centerIter[1]));
centerIter += 2;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/PixelFitRegion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ bool PixelFitRegion::applyEllipse(
return constrained;
}

void PixelFitRegion::applyMask(afw::image::Mask<> const & mask, afw::geom::Point2D const & center) {
void PixelFitRegion::applyMask(afw::image::Mask<> const & mask, geom::Point2D const & center) {
Scalar originalArea = ellipse.getArea();
footprint = std::make_shared<afw::detection::Footprint>(
afw::geom::SpanSet::fromShape(afw::geom::ellipses::Ellipse(ellipse, center)),
Expand Down

0 comments on commit 000ad9a

Please sign in to comment.