Skip to content

Commit

Permalink
Merge pull request #28 from lsst/tickets/DM-20566-meas_extensions_sha…
Browse files Browse the repository at this point in the history
…peHSM

DM-20566: Replace afwGeom with geom where appropriate
  • Loading branch information
timj committed Jul 16, 2019
2 parents b33841f + 30e1495 commit 5afa1ba
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 26 deletions.
8 changes: 4 additions & 4 deletions include/lsst/meas/extensions/shapeHSM/HsmAdapter.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef LSST_MEAS_EXTENSIONS_SHAPEHSM_HSMADAPTER_H
#define LSST_MEAS_EXTENSIONS_SHAPEHSM_HSMADAPTER_H

#include "lsst/afw/geom/Box.h"
#include "lsst/geom/Box.h"
#include "lsst/afw/image/Image.h"
#include "galsim/Image.h"

Expand All @@ -19,7 +19,7 @@ class ImageConverter
/// doesn't allow us to access a shared_ptr to the pixels. Instead, we use a
/// dummy shared ptr to a single (new) pixel. The ImageConverter is holding
/// on to this too (RAII) so we shouldn't have any memory worries.
ImageConverter(PTR(afw::image::Image<PixelT>) image, afw::geom::Box2I box) :
ImageConverter(PTR(afw::image::Image<PixelT>) image, geom::Box2I box) :
_image(image), _owner(new PixelT), _box(box) {}
ImageConverter(PTR(afw::image::Image<PixelT>) image) :
_image(image), _owner(new PixelT), _box(image->getBBox(afw::image::LOCAL)) {}
Expand Down Expand Up @@ -63,7 +63,7 @@ class ImageConverter
private:
PTR(afw::image::Image<PixelT>) _image;
std::shared_ptr<PixelT> _owner;
afw::geom::Box2I _box;
geom::Box2I _box;
};


Expand All @@ -73,7 +73,7 @@ class ImageConverter
inline
PTR(afw::image::Image<int>) convertMask(
afw::image::Mask<afw::image::MaskPixel> const& afwMask, ///< Traditional afw Mask using mask planes
afw::geom::Box2I const& bbox, ///< Bounding box of interest
geom::Box2I const& bbox, ///< Bounding box of interest
afw::image::MaskPixel const badPixelMask ///< Mask for selecting bad pixels
)
{
Expand Down
4 changes: 2 additions & 2 deletions include/lsst/meas/extensions/shapeHSM/HsmMomentsControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ class HsmMomentsAlgorithm : public base::SimpleAlgorithm {
afw::table::SourceRecord& source, // Source for recording moments
PTR(afw::image::Image<PixelT>) const& afwImage, // Image on which to measure moments
PTR(afw::image::Mask<afw::image::MaskPixel>) const& afwMask, // Mask for image
afw::geom::Box2I const& bbox, // Bounding box
afw::geom::Point2D const& center, // Starting center for measuring moments
geom::Box2I const& bbox, // Bounding box
geom::Point2D const& center, // Starting center for measuring moments
afw::image::MaskPixel const badPixelMask, // Bitmask for bad pixels
float const width, // PSF width estimate, for starting moments
bool roundMoments=false, // Use round weight function
Expand Down
14 changes: 7 additions & 7 deletions src/HsmMoments.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ void HsmMomentsAlgorithm::calculate(
afw::table::SourceRecord& source,
PTR(afw::image::Image<PixelT>) const& afwImage,
PTR(afw::image::Mask<afw::image::MaskPixel>) const& afwMask,
afw::geom::Box2I const& bbox,
afw::geom::Point2D const& center,
geom::Box2I const& bbox,
geom::Point2D const& center,
afw::image::MaskPixel const badPixelMask,
float const width,
bool roundMoments,
Expand Down Expand Up @@ -108,20 +108,20 @@ void HsmSourceMomentsAlgorithm::measure(
afw::image::Exposure<float> const & exposure
) const {

afw::geom::Point2D center = _centroidExtractor(source, _flagHandler);
geom::Point2D center = _centroidExtractor(source, _flagHandler);

std::vector<std::string> const & badMaskPlanes = _ctrl.badMaskPlanes;
afw::image::MaskPixel badPixelMask = exposure.getMaskedImage().getMask()->getPlaneBitMask(badMaskPlanes);

afw::geom::Box2I bbox = source.getFootprint()->getBBox();
geom::Box2I bbox = source.getFootprint()->getBBox();
if (bbox.getArea() == 0) {
throw LSST_EXCEPT(
base::MeasurementError,
NO_PIXELS.doc,
NO_PIXELS.number
);
}
if (!bbox.contains(afw::geom::Point2I(center))) {
if (!bbox.contains(geom::Point2I(center))) {
throw LSST_EXCEPT(
base::MeasurementError,
NOT_CONTAINED.doc,
Expand All @@ -142,7 +142,7 @@ void HsmPsfMomentsAlgorithm::measure(
afw::image::Exposure<float> const & exposure
) const {

afw::geom::Point2D center = _centroidExtractor(source, _flagHandler);
geom::Point2D center = _centroidExtractor(source, _flagHandler);

typedef afw::image::Mask<afw::image::MaskPixel> Mask;
PTR(afw::detection::Psf::Image) image = exposure.getPsf()->computeKernelImage(center);
Expand All @@ -154,7 +154,7 @@ void HsmPsfMomentsAlgorithm::measure(

double const psfSigma = exposure.getPsf()->computeShape(center).getTraceRadius();
HsmMomentsAlgorithm::calculate(source, image, mask, image->getBBox(afw::image::PARENT),
afw::geom::Point2D(0, 0), 0, psfSigma);
geom::Point2D(0, 0), 0, psfSigma);
}

}}}} // namespace lsst::meas::extensions::shapeHSM
8 changes: 4 additions & 4 deletions src/HsmShape.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/

#include "lsst/pex/exceptions.h"
#include "lsst/afw/geom/Box.h"
#include "lsst/geom/Box.h"
#include "lsst/afw/image.h"
#include "lsst/afw/detection/Psf.h"
#include "lsst/afw/math/Statistics.h"
Expand Down Expand Up @@ -138,7 +138,7 @@ void HsmShapeAlgorithm::measure(
afw::table::SourceRecord & source,
afw::image::Exposure<float> const & exposure
) const {
afw::geom::Point2D center = _centroidExtractor(source, _flagHandler);
geom::Point2D center = _centroidExtractor(source, _flagHandler);
if (_hasDeblendKey && source.get(_deblendKey) > 0) {
throw LSST_EXCEPT(base::MeasurementError, "Ignoring parent source", PARENT_SOURCE.number);
}
Expand All @@ -147,15 +147,15 @@ void HsmShapeAlgorithm::measure(

afw::image::MaskPixel badPixelMask = exposure.getMaskedImage().getMask()->getPlaneBitMask(badMaskPlanes);

afw::geom::Box2I bbox = source.getFootprint()->getBBox();
geom::Box2I bbox = source.getFootprint()->getBBox();
if (bbox.getArea() == 0) {
throw LSST_EXCEPT(
base::MeasurementError,
NO_PIXELS.doc,
NO_PIXELS.number
);
}
if (!bbox.contains(afw::geom::Point2I(center))) {
if (!bbox.contains(geom::Point2I(center))) {
throw LSST_EXCEPT(
base::MeasurementError,
NOT_CONTAINED.doc,
Expand Down
19 changes: 10 additions & 9 deletions tests/test_hsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import lsst.afw.detection as afwDetection
import lsst.afw.table as afwTable
import lsst.afw.geom as afwGeom
import lsst.geom as geom
import lsst.afw.geom.ellipses as afwEll
import lsst.utils.tests
import lsst.meas.extensions.shapeHSM
Expand Down Expand Up @@ -157,8 +158,8 @@ def setUp(self):
# load the known values
self.dataDir = os.path.join(os.getenv('MEAS_EXTENSIONS_SHAPEHSM_DIR'), "tests", "data")
self.bkgd = 1000.0 # standard for atlas image
self.offset = afwGeom.Extent2I(1234, 1234)
self.xy0 = afwGeom.Point2I(5678, 9876)
self.offset = geom.Extent2I(1234, 1234)
self.xy0 = geom.Point2I(5678, 9876)

def tearDown(self):
del self.offset
Expand All @@ -171,8 +172,8 @@ def runMeasurement(self, algorithmName, imageid, x, y, v):
img = afwImage.ImageF(imgFile)
img -= self.bkgd
nx, ny = img.getWidth(), img.getHeight()
msk = afwImage.Mask(afwGeom.Extent2I(nx, ny), 0x0)
var = afwImage.ImageF(afwGeom.Extent2I(nx, ny), v)
msk = afwImage.Mask(geom.Extent2I(nx, ny), 0x0)
var = afwImage.ImageF(geom.Extent2I(nx, ny), v)
mimg = afwImage.MaskedImageF(img, msk, var)
msk.getArray()[:] = np.where(np.fabs(img.getArray()) < 1.0e-8, msk.getPlaneBitMask("BAD"), 0)

Expand All @@ -181,16 +182,16 @@ def runMeasurement(self, algorithmName, imageid, x, y, v):
big.getImage().set(0)
big.getMask().set(0)
big.getVariance().set(v)
subBig = afwImage.MaskedImageF(big, afwGeom.Box2I(big.getXY0() + self.offset, mimg.getDimensions()))
subBig = afwImage.MaskedImageF(big, geom.Box2I(big.getXY0() + self.offset, mimg.getDimensions()))
subBig <<= mimg
mimg = big
mimg.setXY0(self.xy0)

exposure = afwImage.makeExposure(mimg)
cdMatrix = np.array([1.0/(2.53*3600.0), 0.0, 0.0, 1.0/(2.53*3600.0)])
cdMatrix.shape = (2, 2)
exposure.setWcs(afwGeom.makeSkyWcs(crpix=afwGeom.Point2D(1.0, 1.0),
crval=afwGeom.SpherePoint(0, 0, afwGeom.degrees),
exposure.setWcs(afwGeom.makeSkyWcs(crpix=geom.Point2D(1.0, 1.0),
crval=geom.SpherePoint(0, 0, geom.degrees),
cdMatrix=cdMatrix))

# load the corresponding test psf
Expand All @@ -211,7 +212,7 @@ def runMeasurement(self, algorithmName, imageid, x, y, v):
# Algorithm._apply. Otherwise, when the PSF is realised it will have been warped
# to account for the sub-pixel offset and we won't get *exactly* this PSF.
plugin, table = makePluginAndCat(alg, algorithmName, control, centroid="centroid")
center = afwGeom.Point2D(int(x), int(y)) + afwGeom.Extent2D(self.offset + afwGeom.Extent2I(self.xy0))
center = geom.Point2D(int(x), int(y)) + geom.Extent2D(self.offset + geom.Extent2I(self.xy0))
source = table.makeRecord()
source.set("centroid_x", center.getX())
source.set("centroid_y", center.getY())
Expand Down Expand Up @@ -340,7 +341,7 @@ def testHsmPsfMoments(self):
source = cat.addNew()
source.set("centroid_x", 23)
source.set("centroid_y", 34)
offset = afwGeom.Point2I(23, 34)
offset = geom.Point2I(23, 34)
tmpSpans = afwGeom.SpanSet.fromShape(int(width), offset=offset)
source.setFootprint(afwDetection.Footprint(tmpSpans))
plugin.measure(source, exposure)
Expand Down
1 change: 1 addition & 0 deletions ups/meas_extensions_shapeHSM.table
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ setupRequired(meas_base)
setupRequired(meas_algorithms)
setupRequired(galsim)

setupRequired(geom)
setupRequired(afw)
setupRequired(daf_base)
setupRequired(numpy)
Expand Down

0 comments on commit 5afa1ba

Please sign in to comment.