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-14429: Implement RFC-460: move afw.geom content to new geom package #86

Merged
merged 7 commits into from
Jun 1, 2018
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*.so
_build.*
.cache
.pytest_cache
.sconf_temp/
.sconsign.dblite
config.log
Expand Down
9 changes: 5 additions & 4 deletions examples/getSourceSet.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import sys
import lsst.utils
import lsst.pex.policy as policy
import lsst.geom
import lsst.afw.detection as afwDetection
import lsst.afw.geom as afwGeom
import lsst.afw.image as afwImage
Expand Down Expand Up @@ -230,7 +231,7 @@ def makeCcdMosaic(dir, basename, e, c, aList, imageFactory=afwImage.MaskedImageF

for what in ("header", "data"):
if what == "header":
bbox = afwGeom.Box2I()
bbox = lsst.geom.Box2I()
ampBBox = {}
wcs = {}
else:
Expand All @@ -246,12 +247,12 @@ def makeCcdMosaic(dir, basename, e, c, aList, imageFactory=afwImage.MaskedImageF

if what == "header":
md = readMetadata(filename + "_img.fits")
xy0 = afwGeom.Point2I(md.get("CRVAL1A"), md.get("CRVAL2A"))
xy1 = xy0 + afwGeom.Extent2I(md.get("NAXIS1") - 1, md.get("NAXIS2") - 1)
xy0 = lsst.geom.Point2I(md.get("CRVAL1A"), md.get("CRVAL2A"))
xy1 = xy0 + lsst.geom.Extent2I(md.get("NAXIS1") - 1, md.get("NAXIS2") - 1)
bbox.grow(xy0)
bbox.grow(xy1)

ampBBox[a] = afwGeom.Box2I(xy0, xy1)
ampBBox[a] = lsst.geom.Box2I(xy0, xy1)
wcs[a] = afwGeom.makeSkyWcs(md)
else:
try:
Expand Down
97 changes: 47 additions & 50 deletions include/lsst/meas/astrom/PolynomialTransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@
#define LSST_MEAS_ASTROM_PolynomialTransform_INCLUDED

#include "ndarray/eigen.h"
#include "lsst/afw/geom/AffineTransform.h"
#include "lsst/geom/Point.h"
#include "lsst/geom/AffineTransform.h"

namespace lsst { namespace meas { namespace astrom {
namespace lsst {
namespace meas {
namespace astrom {

class SipForwardTransform;
class SipReverseTransform;
Expand All @@ -41,21 +44,20 @@ class ScaledPolynomialTransform;
*/
class PolynomialTransform {
public:

/**
* Convert a ScaledPolynomialTransform to an equivalent PolynomialTransform.
*/
static PolynomialTransform convert(ScaledPolynomialTransform const & other);
static PolynomialTransform convert(ScaledPolynomialTransform const& other);

/**
* Convert a SipForwardTransform to an equivalent PolynomialTransform.
*/
static PolynomialTransform convert(SipForwardTransform const & other);
static PolynomialTransform convert(SipForwardTransform const& other);

/**
* Convert a SipReverseTransform to an equivalent PolynomialTransform.
*/
static PolynomialTransform convert(SipReverseTransform const & other);
static PolynomialTransform convert(SipReverseTransform const& other);

/**
* Construct a new transform from existing coefficient arrays.
Expand All @@ -67,41 +69,39 @@ class PolynomialTransform {
* order of the transform, both arrays should be (N+1)x(N+1), and
* elements with p + q > N should be zero.
*/
PolynomialTransform(
ndarray::Array<double const,2,0> const & xCoeffs,
ndarray::Array<double const,2,0> const & yCoeffs
);
PolynomialTransform(ndarray::Array<double const, 2, 0> const& xCoeffs,
ndarray::Array<double const, 2, 0> const& yCoeffs);

/**
* Copy constructor.
*
* Coefficient arrays are deep-copied.
*/
PolynomialTransform(PolynomialTransform const & other);
PolynomialTransform(PolynomialTransform const& other);

/**
* Move constructor.
*
* Coefficient arrays are moved.
*/
PolynomialTransform(PolynomialTransform && other);
PolynomialTransform(PolynomialTransform&& other);

/**
* Copy assignment.
*
* Coefficient arrays are deep-copied.
*/
PolynomialTransform & operator=(PolynomialTransform const & other);
PolynomialTransform& operator=(PolynomialTransform const& other);

/**
* Move constructor.
*
* Coefficient arrays are moved.
*/
PolynomialTransform & operator=(PolynomialTransform && other);
PolynomialTransform& operator=(PolynomialTransform&& other);

/// Lightweight swap.
void swap(PolynomialTransform & other);
void swap(PolynomialTransform& other);

/// Return the order of the polynomials.
int getOrder() const { return _xCoeffs.rows() - 1; }
Expand All @@ -112,40 +112,39 @@ class PolynomialTransform {
* Indexing the result by [p][q] gives the coefficient of
* @f$x_{\mathrm{in}}^p\,y_{\mathrm{in}}^q@f$.
*/
ndarray::Array<double const,2,2> getXCoeffs() const { return _xCoeffs.shallow(); }
ndarray::Array<double const, 2, 2> getXCoeffs() const { return _xCoeffs.shallow(); }

/**
* 2-D polynomial coefficients that compute the output x coordinate.
*
* Indexing the result by [p][q] gives the coefficient of
* @f$x_{\mathrm{in}}^p\,y_{\mathrm{in}}^q@f$.
*/
ndarray::Array<double const,2,2> getYCoeffs() const { return _yCoeffs.shallow(); }
ndarray::Array<double const, 2, 2> getYCoeffs() const { return _yCoeffs.shallow(); }

/**
* Return an approximate affine transform at the given point.
*/
afw::geom::AffineTransform linearize(afw::geom::Point2D const & in) const;
geom::AffineTransform linearize(geom::Point2D const& in) const;

/**
* Apply the transform to a point.
*/
afw::geom::Point2D operator()(afw::geom::Point2D const & in) const;
geom::Point2D operator()(geom::Point2D const& in) const;

private:

PolynomialTransform(int order);

friend PolynomialTransform compose(afw::geom::AffineTransform const & t1, PolynomialTransform const & t2);
friend PolynomialTransform compose(PolynomialTransform const & t1, afw::geom::AffineTransform const & t2);
friend PolynomialTransform compose(geom::AffineTransform const& t1, PolynomialTransform const& t2);
friend PolynomialTransform compose(PolynomialTransform const& t1, geom::AffineTransform const& t2);
friend class ScaledPolynomialTransformFitter;
friend class SipForwardTransform;
friend class SipReverseTransform;
friend class ScaledPolynomialTransform;

ndarray::EigenView<double,2,2> _xCoeffs;
ndarray::EigenView<double,2,2> _yCoeffs;
mutable Eigen::VectorXd _u; // workspace for operator() and linearize
ndarray::EigenView<double, 2, 2> _xCoeffs;
ndarray::EigenView<double, 2, 2> _yCoeffs;
mutable Eigen::VectorXd _u; // workspace for operator() and linearize
mutable Eigen::VectorXd _v;
};

Expand All @@ -157,14 +156,13 @@ class PolynomialTransform {
*/
class ScaledPolynomialTransform {
public:

/**
* Convert a PolynomialTransform to an equivalent ScaledPolynomialTransform.
*
* This simply inserts identity AffineTransforms before and after applying
* the given PolynomialTransform.
*/
static ScaledPolynomialTransform convert(PolynomialTransform const & poly);
static ScaledPolynomialTransform convert(PolynomialTransform const& poly);

/**
* Convert a SipForwardTransform to an equivalent ScaledPolynomialTransform.
Expand All @@ -173,7 +171,7 @@ class ScaledPolynomialTransform {
* the input and output affine transforms, respectively, leaving the polynomial
* coefficients unmodified.
*/
static ScaledPolynomialTransform convert(SipForwardTransform const & sipForward);
static ScaledPolynomialTransform convert(SipForwardTransform const& sipForward);

/**
* Convert a SipForwardTransform to an equivalent ScaledPolynomialTransform.
Expand All @@ -182,7 +180,7 @@ class ScaledPolynomialTransform {
* the input and output affine transforms, respectively, leaving the polynomial
* coefficients unmodified.
*/
static ScaledPolynomialTransform convert(SipReverseTransform const & sipReverse);
static ScaledPolynomialTransform convert(SipReverseTransform const& sipReverse);

/**
* Construct a new ScaledPolynomialTransform from its constituents.
Expand All @@ -194,46 +192,43 @@ class ScaledPolynomialTransform {
* @param[in] outputScalingInverse An AffineTransform to be applied to points
* after the PolynomialTransform.
*/
ScaledPolynomialTransform(
PolynomialTransform const & poly,
afw::geom::AffineTransform const & inputScaling,
afw::geom::AffineTransform const & outputScalingInverse
);
ScaledPolynomialTransform(PolynomialTransform const& poly, geom::AffineTransform const& inputScaling,
geom::AffineTransform const& outputScalingInverse);

ScaledPolynomialTransform(ScaledPolynomialTransform const & other) = default;
ScaledPolynomialTransform(ScaledPolynomialTransform const& other) = default;

ScaledPolynomialTransform(ScaledPolynomialTransform && other) = default;
ScaledPolynomialTransform(ScaledPolynomialTransform&& other) = default;

ScaledPolynomialTransform & operator=(ScaledPolynomialTransform const & other) = default;
ScaledPolynomialTransform& operator=(ScaledPolynomialTransform const& other) = default;

ScaledPolynomialTransform & operator=(ScaledPolynomialTransform && other) = default;
ScaledPolynomialTransform& operator=(ScaledPolynomialTransform&& other) = default;

void swap(ScaledPolynomialTransform & other);
void swap(ScaledPolynomialTransform& other);

/// Return the polynomial transform applied after the input scaling.
PolynomialTransform const & getPoly() const { return _poly; }
PolynomialTransform const& getPoly() const { return _poly; }

/// Return the first affine transform applied to input points.
afw::geom::AffineTransform const & getInputScaling() const { return _inputScaling; }
geom::AffineTransform const& getInputScaling() const { return _inputScaling; }

/// Return the affine transform applied to points after the polynomial transform.
afw::geom::AffineTransform const & getOutputScalingInverse() const { return _outputScalingInverse; }
geom::AffineTransform const& getOutputScalingInverse() const { return _outputScalingInverse; }

/**
* Return an approximate affine transform at the given point.
*/
afw::geom::AffineTransform linearize(afw::geom::Point2D const & in) const;
geom::AffineTransform linearize(geom::Point2D const& in) const;

/**
* Apply the transform to a point.
*/
afw::geom::Point2D operator()(afw::geom::Point2D const & in) const;
geom::Point2D operator()(geom::Point2D const& in) const;

private:
friend class ScaledPolynomialTransformFitter;
PolynomialTransform _poly;
afw::geom::AffineTransform _inputScaling;
afw::geom::AffineTransform _outputScalingInverse;
geom::AffineTransform _inputScaling;
geom::AffineTransform _outputScalingInverse;
};

/**
Expand All @@ -242,16 +237,18 @@ class ScaledPolynomialTransform {
* The returned composition would be exact in ideal arithmetic, but may suffer from
* significant round-off error for high-order polynomials.
*/
PolynomialTransform compose(afw::geom::AffineTransform const & t1, PolynomialTransform const & t2);
PolynomialTransform compose(geom::AffineTransform const& t1, PolynomialTransform const& t2);

/**
* Return a PolynomialTransform that is equivalent to the composition t1(t2())
*
* The returned composition would be exact in ideal arithmetic, but may suffer from
* significant round-off error for high-order polynomials.
*/
PolynomialTransform compose(PolynomialTransform const & t1, afw::geom::AffineTransform const & t2);
PolynomialTransform compose(PolynomialTransform const& t1, geom::AffineTransform const& t2);

}}} // namespace lsst::meas::astrom
} // namespace astrom
} // namespace meas
} // namespace lsst

#endif // !LSST_MEAS_ASTROM_PolynomialTransform_INCLUDED
#endif // !LSST_MEAS_ASTROM_PolynomialTransform_INCLUDED