Skip to content

Commit

Permalink
made C++ applyShear that takes a Shear, and made python only see that…
Browse files Browse the repository at this point in the history
… version rather than the g1/g2 version

(#134)
  • Loading branch information
Rachel Mandelbaum committed Jun 17, 2012
1 parent 6cb46dc commit 89413bb
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
4 changes: 2 additions & 2 deletions galsim/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ def applyShear(self, *args, **kwargs):
raise TypeError("Error, gave both unnamed and named arguments to applyShear!")
if not isinstance(args[0], galsim.Shear):
raise TypeError("Error, unnamed argument to applyShear is not a galsim.Shear!")
self.SBProfile.applyShear(args[0].g1, args[0].g2)
self.SBProfile.applyShear(args[0]._shear)
elif len(args) > 1:
raise TypeError("Error, too many unnamed arguments to applyShear!")
else:
shear = galsim.Shear(**kwargs)
self.SBProfile.applyShear(shear.g1, shear.g2)
self.SBProfile.applyShear(shear._shear)

def applyRotation(self, theta):
"""@brief Apply a rotation theta (Angle object, +ve anticlockwise) to this object.
Expand Down
14 changes: 12 additions & 2 deletions include/galsim/SBProfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,22 @@ namespace galsim {
*
* @param[in] g1 Reduced shear g1 by which to shear the SBProfile.
* @param[in] g2 Reduced shear g2 by which to shear the SBProfile.
* This shears the object by the given shear. As with scaleFlux, it does not
* This shears the object by the given shear. As with scaleFlux, it does not
* invalidate any previous uses of this object.
*/
void applyShear(double g1, double g2);

/**
/**
* @brief Apply a given shear.
*
* @param[in] g1 Reduced shear g1 by which to shear the SBProfile.
* @param[in] g2 Reduced shear g2 by which to shear the SBProfile.
* This shears the object by the given shear. As with scaleFlux, it does not
* invalidate any previous uses of this object.
*/
void applyShear(Shear s);

/**
* @brief Apply a given rotation.
*
* This rotates the object by the given angle. As with scaleFlux, it does not
Expand Down
4 changes: 3 additions & 1 deletion pysrc/SBProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ struct PySBProfile {
.def("scaleFlux", &SBProfile::setFlux, bp::args("fluxRatio"))
.def("setFlux", &SBProfile::setFlux, bp::args("flux"))
.def("applyTransformation", &SBProfile::applyTransformation, bp::args("e"))
.def("applyShear", &SBProfile::applyShear, bp::args("g1", "g2"))
.def("applyShear",
(void (SBProfile::*)(Shear))&SBProfile::applyShear,
(bp::arg("s")))
.def("applyRotation", &SBProfile::applyRotation, bp::args("theta"))
.def("applyShift", &SBProfile::applyShift, bp::args("dx", "dy"))
.def("shoot", &SBProfile::shoot, bp::args("n", "u"))
Expand Down
7 changes: 7 additions & 0 deletions src/SBProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ namespace galsim {
_pimpl = d._pimpl;
}

void SBProfile::applyShear(Shear s)
{
Ellipse e(s);
SBTransform d(*this,e);
_pimpl = d._pimpl;
}

void SBProfile::applyRotation(const Angle& theta)
{
SBTransform d(*this,
Expand Down
10 changes: 5 additions & 5 deletions tests/test_SBProfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def test_sbprofile_smallshear():
savedImg = galsim.fits.read(os.path.join(imgdir, "gauss_smallshear.fits"))
myImg = galsim.ImageF(savedImg.bounds)
mySBP = galsim.SBGaussian(flux=1, sigma=1)
mySBP.applyShear(g1=myShear._shear.getG1(), g2=myShear._shear.getG2())
mySBP.applyShear(myShear._shear)
mySBP.draw(myImg,dx=0.2)
printval(myImg, savedImg)
np.testing.assert_array_almost_equal(myImg.array, savedImg.array, 5,
Expand Down Expand Up @@ -538,7 +538,7 @@ def test_sbprofile_largeshear():
savedImg = galsim.fits.read(os.path.join(imgdir, "sersic_largeshear.fits"))
myImg = galsim.ImageF(savedImg.bounds)
mySBP = galsim.SBDeVaucouleurs(flux=1, half_light_radius=1)
mySBP.applyShear(g1=myShear._shear.getG1(), g2=myShear._shear.getG2())
mySBP.applyShear(myShear._shear)
mySBP.draw(myImg,dx=0.2)
printval(myImg, savedImg)
np.testing.assert_array_almost_equal(myImg.array, savedImg.array, 5,
Expand Down Expand Up @@ -633,7 +633,7 @@ def test_sbprofile_shearconvolve():
myEllipse = galsim.Ellipse(e1=e1, e2=e2)
# test at SBProfile level using applyShear
mySBP = galsim.SBGaussian(flux=1, sigma=1)
mySBP.applyShear(g1=myShear.g1, g2=myShear.g2)
mySBP.applyShear(myShear._shear)
mySBP2 = galsim.SBBox(xw=0.2, yw=0.2, flux=1.)
myConv = galsim.SBConvolve([mySBP,mySBP2])
savedImg = galsim.fits.read(os.path.join(imgdir, "gauss_smallshear_convolve_box.fits"))
Expand Down Expand Up @@ -744,10 +744,10 @@ def test_sbprofile_realspace_distorted_convolve():
import time
t1 = time.time()
psf = galsim.SBMoffat(beta=1.5, truncationFWHM=4, flux=1, half_light_radius=1)
psf.applyShear(g1=0.11,g2=0.17)
psf.applyShear(galsim.Shear(g1=0.11,g2=0.17)._shear)
psf.applyRotation(13 * galsim.degrees)
pixel = galsim.SBBox(xw=0.2, yw=0.2, flux=1.)
pixel.applyShear(g1=0.2,g2=0.0)
pixel.applyShear(galsim.Shear(g1=0.2,g2=0.0)._shear)
pixel.applyRotation(80 * galsim.degrees)
pixel.applyShift(0.13,0.27)
conv = galsim.SBConvolve([psf,pixel],real_space=True)
Expand Down

0 comments on commit 89413bb

Please sign in to comment.