Skip to content

Commit

Permalink
Reaplce afwGeom with geom where appropriate in C++
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Jul 18, 2019
1 parent faf6691 commit cbc1571
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 90 deletions.
50 changes: 25 additions & 25 deletions examples/maskedKernel.cc
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#include "Eigen/Core"
#include "lsst/afw/math.h"
#include "lsst/afw/geom.h"
#include "lsst/geom.h"
#include "lsst/afw/image.h"
#include "lsst/ip/diffim.h"

namespace ipDiffim = lsst::ip::diffim;
namespace afwMath = lsst::afw::math;
namespace afwGeom = lsst::afw::geom;
namespace geom = lsst::geom;
namespace afwImage = lsst::afw::image;
int main() {
int dimen = 11;
afwImage::Image<float> foo(afwGeom::Extent2I(dimen,dimen));
afwImage::Image<float> foo(geom::Extent2I(dimen,dimen));
for (int y = 0, n = 0; y < dimen; y++) {
for (int x = 0; x < dimen; x++, n++) {
foo(x,y) = n;
Expand All @@ -32,11 +32,11 @@ int main() {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9;
*/

afwImage::Image<double> kImage(afwGeom::Extent2I(5, 5));
afwImage::Image<double> kImage(geom::Extent2I(5, 5));
afwMath::FixedKernel kernel(kImage);

std::cout << "All data:" << std::endl << test << std::endl << std::endl;
afwGeom::Box2I goodBBox = kernel.shrinkBBox(foo.getBBox(afwImage::LOCAL));
geom::Box2I goodBBox = kernel.shrinkBBox(foo.getBBox(afwImage::LOCAL));
int startCol = goodBBox.getMinX();
int startRow = goodBBox.getMinY();
// endCol/Row is one past the index of the last good col/row
Expand All @@ -52,8 +52,8 @@ int main() {
std::cout << "Good pixels after convolution:" << std::endl << subimage << std::endl << std::endl;

/* We want to ignore all pixels from 4,4 to 6,6 */
afwGeom::Box2I maskBox(afwGeom::Point2I(4, 4),
afwGeom::Point2I(6, 6));
geom::Box2I maskBox(geom::Point2I(4, 4),
geom::Point2I(6, 6));

int maskStartCol = maskBox.getMinX();
int maskStartRow = maskBox.getMinY();
Expand All @@ -63,40 +63,40 @@ int main() {
std::cout << "B " << maskStartCol << " " << maskStartRow << " " << maskEndCol << " " << maskEndRow << std::endl;

/*
afwGeom::Box2I tBox = afwGeom::Box2I(afwGeom::Point2I(startCol, maskEndRow),
afwGeom::Point2I(endCol, endRow));
geom::Box2I tBox = geom::Box2I(geom::Point2I(startCol, maskEndRow),
geom::Point2I(endCol, endRow));
afwGeom::Box2I bBox = afwGeom::Box2I(afwGeom::Point2I(startCol, startRow),
afwGeom::Point2I(endCol, maskStartRow));
geom::Box2I bBox = geom::Box2I(geom::Point2I(startCol, startRow),
geom::Point2I(endCol, maskStartRow));
afwGeom::Box2I lBox = afwGeom::Box2I(afwGeom::Point2I(startCol, maskStartRow),
afwGeom::Point2I(maskStartCol, maskEndRow));
geom::Box2I lBox = geom::Box2I(geom::Point2I(startCol, maskStartRow),
geom::Point2I(maskStartCol, maskEndRow));
afwGeom::Box2I rBox = afwGeom::Box2I(afwGeom::Point2I(maskEndCol, maskStartRow),
afwGeom::Point2I(endCol, maskEndRow));
geom::Box2I rBox = geom::Box2I(geom::Point2I(maskEndCol, maskStartRow),
geom::Point2I(endCol, maskEndRow));
*/

endCol -= 1;
endRow -= 1;
afwGeom::Box2I tBox = afwGeom::Box2I(afwGeom::Point2I(startCol, maskEndRow + 1),
afwGeom::Point2I(endCol, endRow));
geom::Box2I tBox = geom::Box2I(geom::Point2I(startCol, maskEndRow + 1),
geom::Point2I(endCol, endRow));

afwGeom::Box2I bBox = afwGeom::Box2I(afwGeom::Point2I(startCol, startRow),
afwGeom::Point2I(endCol, maskStartRow - 1));
geom::Box2I bBox = geom::Box2I(geom::Point2I(startCol, startRow),
geom::Point2I(endCol, maskStartRow - 1));

afwGeom::Box2I lBox = afwGeom::Box2I(afwGeom::Point2I(startCol, maskStartRow),
afwGeom::Point2I(maskStartCol - 1, maskEndRow));
geom::Box2I lBox = geom::Box2I(geom::Point2I(startCol, maskStartRow),
geom::Point2I(maskStartCol - 1, maskEndRow));

afwGeom::Box2I rBox = afwGeom::Box2I(afwGeom::Point2I(maskEndCol + 1, maskStartRow),
afwGeom::Point2I(endCol, maskEndRow));
geom::Box2I rBox = geom::Box2I(geom::Point2I(maskEndCol + 1, maskStartRow),
geom::Point2I(endCol, maskEndRow));


std::vector<afwGeom::Box2I> boxArray;
std::vector<geom::Box2I> boxArray;
boxArray.push_back(tBox);
boxArray.push_back(bBox);
boxArray.push_back(lBox);
boxArray.push_back(rBox);
std::vector<afwGeom::Box2I>::iterator biter = boxArray.begin();
std::vector<geom::Box2I>::iterator biter = boxArray.begin();
for (; biter != boxArray.end(); ++biter) {
int area = (*biter).getWidth() * (*biter).getHeight();
afwImage::Image<float> subimage = afwImage::Image<float>(foo, *biter, afwImage::LOCAL);
Expand Down
6 changes: 3 additions & 3 deletions examples/pixelAccess.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
#include <memory>
#include "boost/timer.hpp"

#include "lsst/afw/geom.h"
#include "lsst/geom.h"
#include "lsst/afw/image.h"
#include "lsst/ip/diffim/ImageSubtract.h"

namespace afwGeom = lsst::afw::geom;
namespace geom = lsst::geom;
namespace afwImage = lsst::afw::image;
namespace diffim = lsst::ip::diffim;

Expand Down Expand Up @@ -179,7 +179,7 @@ Eigen::MatrixXd test(afwImage::Image<ImageT> varianceEstimate,
int main() {
boost::timer t;

afwImage::Image<float> varianceEstimate(afwGeom::Extent2I(100, 100));
afwImage::Image<float> varianceEstimate(geom::Extent2I(100, 100));
varianceEstimate = 1;

t.restart();
Expand Down
8 changes: 4 additions & 4 deletions examples/spatialKernel.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* LSST Data Management System
* Copyright 2008, 2009, 2010 LSST Corporation.
*
Expand All @@ -22,12 +22,12 @@

#include <cmath>

#include "lsst/afw/geom.h"
#include "lsst/geom.h"
#include "lsst/afw/math.h"
#include "lsst/afw/image.h"
#include "lsst/ip/diffim.h"

namespace afwGeom = lsst::afw::geom;
namespace geom = lsst::geom;
namespace afwImage = lsst::afw::image;
namespace afwMath = lsst::afw::math;
using namespace lsst::ip::diffim;
Expand Down Expand Up @@ -66,7 +66,7 @@ int main() {

unsigned int loc = 50;
std::shared_ptr<afwImage::MaskedImage<PixelT>> mimg1(
new afwImage::MaskedImage<PixelT>(afwGeom::Extent2I(100,100))
new afwImage::MaskedImage<PixelT>(geom::Extent2I(100,100))
);
*mimg1->at(loc, loc) = afwImage::MaskedImage<PixelT>::Pixel(1, 0x0, 1);
std::shared_ptr<afwImage::MaskedImage<PixelT>> mimg2(
Expand Down
5 changes: 3 additions & 2 deletions include/lsst/ip/diffim/BuildSpatialKernelVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#define LSST_IP_DIFFIM_BUILDSPATIALKERNELVISITOR_H

#include "Eigen/Core"
#include "lsst/geom.h"
#include "lsst/afw/math.h"
#include "lsst/afw/image.h"
#include "lsst/ip/diffim.h"
Expand All @@ -30,7 +31,7 @@ namespace detail {

BuildSpatialKernelVisitor(
lsst::afw::math::KernelList const& basisList, ///< Basis functions
lsst::afw::geom::Box2I const& regionBBox, ///< Spatial region over which the function is fit
lsst::geom::Box2I const& regionBBox, ///< Spatial region over which the function is fit
lsst::pex::policy::Policy policy ///< Policy file directing behavior
);

Expand All @@ -54,7 +55,7 @@ namespace detail {
std::shared_ptr<BuildSpatialKernelVisitor<PixelT> >
makeBuildSpatialKernelVisitor(
lsst::afw::math::KernelList const& basisList,
lsst::afw::geom::Box2I const& regionBBox,
lsst::geom::Box2I const& regionBBox,
lsst::pex::policy::Policy policy
) {

Expand Down
8 changes: 4 additions & 4 deletions include/lsst/ip/diffim/KernelSolution.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "Eigen/Core"

#include "lsst/afw/math.h"
#include "lsst/afw/geom.h"
#include "lsst/geom.h"
#include "lsst/afw/image.h"
#include "lsst/pex/policy.h"

Expand Down Expand Up @@ -139,7 +139,7 @@ namespace diffim {
lsst::afw::image::Image<InputT> const &scienceImage,
lsst::afw::image::Image<lsst::afw::image::VariancePixel>
const &varianceEstimate,
lsst::afw::geom::Box2I maskBox);
lsst::geom::Box2I maskBox);
};


Expand Down Expand Up @@ -183,13 +183,13 @@ namespace diffim {
);

virtual ~SpatialKernelSolution() {};

void addConstraint(float xCenter, float yCenter,
Eigen::MatrixXd const& qMat,
Eigen::VectorXd const& wVec);

void solve();
std::shared_ptr<lsst::afw::image::Image<lsst::afw::math::Kernel::Pixel>> makeKernelImage(lsst::afw::geom::Point2D const& pos);
std::shared_ptr<lsst::afw::image::Image<lsst::afw::math::Kernel::Pixel>> makeKernelImage(lsst::geom::Point2D const& pos);
std::pair<std::shared_ptr<lsst::afw::math::LinearCombinationKernel>,
lsst::afw::math::Kernel::SpatialFunctionPtr> getSolutionPair();

Expand Down
2 changes: 1 addition & 1 deletion python/lsst/ip/diffim/detail/buildSpatialKernelVisitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void declareBuildSpatialKernelVisitor(py::module& mod, std::string const& suffix
afw::math::CandidateVisitor>
cls(mod, ("BuildSpatialKernelVisitor" + suffix).c_str());

cls.def(py::init<afw::math::KernelList, afw::geom::Box2I const&, pex::policy::Policy>(), "basisList"_a,
cls.def(py::init<afw::math::KernelList, geom::Box2I const&, pex::policy::Policy>(), "basisList"_a,
"regionBBox"_a, "policy"_a);

cls.def("getNCandidates", &BuildSpatialKernelVisitor<PixelT>::getNCandidates);
Expand Down
8 changes: 4 additions & 4 deletions src/BasisLists.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@

#include "lsst/pex/exceptions/Exception.h"
#include "lsst/pex/policy/Policy.h"
#include "lsst/afw/geom.h"
#include "lsst/geom.h"
#include "lsst/afw/image.h"
#include "lsst/afw/math.h"
#include "lsst/log/Log.h"
#include "lsst/ip/diffim/BasisLists.h"

namespace pexExcept = lsst::pex::exceptions;
namespace afwGeom = lsst::afw::geom;
namespace geom = lsst::geom;
namespace afwImage = lsst::afw::image;
namespace afwMath = lsst::afw::math;

Expand Down Expand Up @@ -57,7 +57,7 @@ namespace diffim {
for (int row = 0; row < signedHeight; ++row) {
for (int col = 0; col < signedWidth; ++col) {
std::shared_ptr<afwMath::Kernel>
kernelPtr(new afwMath::DeltaFunctionKernel(width, height, afwGeom::Point2I(col,row)));
kernelPtr(new afwMath::DeltaFunctionKernel(width, height, geom::Point2I(col,row)));
kernelBasisList.push_back(kernelPtr);
}
}
Expand Down Expand Up @@ -94,7 +94,7 @@ namespace diffim {
throw LSST_EXCEPT(pexExcept::Exception, "degGauss does not have enough entries");
}
int fullWidth = 2 * halfWidth + 1;
Image image(afwGeom::Extent2I(fullWidth, fullWidth));
Image image(geom::Extent2I(fullWidth, fullWidth));

afwMath::KernelList kernelBasisList;
for (int i = 0; i < nGauss; i++) {
Expand Down
10 changes: 5 additions & 5 deletions src/BuildSpatialKernelVisitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "Eigen/QR"

#include "lsst/afw/math.h"
#include "lsst/afw/geom.h"
#include "lsst/geom.h"
#include "lsst/log/Log.h"
#include "lsst/pex/policy/Policy.h"
#include "lsst/pex/exceptions/Runtime.h"
Expand All @@ -28,7 +28,7 @@
#include "lsst/ip/diffim/BuildSpatialKernelVisitor.h"

namespace afwMath = lsst::afw::math;
namespace afwGeom = lsst::afw::geom;
namespace geom = lsst::afw::geom;
namespace pexPolicy = lsst::pex::policy;
namespace pexExcept = lsst::pex::exceptions;

Expand Down Expand Up @@ -72,7 +72,7 @@ namespace detail {
template<typename PixelT>
BuildSpatialKernelVisitor<PixelT>::BuildSpatialKernelVisitor(
lsst::afw::math::KernelList const& basisList, ///< Basis functions used in the fit
lsst::afw::geom::Box2I const& regionBBox, ///< Spatial region over which the function is fit
lsst::geom::Box2I const& regionBBox, ///< Spatial region over which the function is fit
lsst::pex::policy::Policy policy ///< Policy file directing behavior
) :
afwMath::CandidateVisitor(),
Expand All @@ -89,10 +89,10 @@ namespace detail {
std::string spatialModelType = policy.getString("spatialModelType");
if (spatialModelType == "chebyshev1") {
spatialKernelFunction = afwMath::Kernel::SpatialFunctionPtr(
new afwMath::Chebyshev1Function2<double>(spatialKernelOrder, afwGeom::Box2D(regionBBox))
new afwMath::Chebyshev1Function2<double>(spatialKernelOrder, geom::Box2D(regionBBox))
);
background = afwMath::Kernel::SpatialFunctionPtr(
new afwMath::Chebyshev1Function2<double>(spatialBgOrder, afwGeom::Box2D(regionBBox))
new afwMath::Chebyshev1Function2<double>(spatialBgOrder, geom::Box2D(regionBBox))
);

}
Expand Down

0 comments on commit cbc1571

Please sign in to comment.