Skip to content

Commit

Permalink
Don't rebuild a new GSParams if all gsp to be combined are the same
Browse files Browse the repository at this point in the history
  • Loading branch information
rmjarvis committed Dec 15, 2018
1 parent fe361c9 commit abf989e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions galsim/gsparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ def combine(gsp_list):
"""
if len(gsp_list) == 1:
return gsp_list[0]
elif all(g is gsp_list[0] for g in gsp_list[1:]):
return gsp_list[0]
else:
return GSParams(
max([g.minimum_fft_size for g in gsp_list]),
Expand Down
10 changes: 10 additions & 0 deletions tests/test_convolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,17 @@ def test_convolve():
np.testing.assert_array_almost_equal(
myImg.array, savedImg.array, 4,
err_msg="Moffat convolved with Pixel disagrees with expected result")
assert psf.gsparams is galsim.GSParams.default
assert pixel.gsparams is galsim.GSParams.default
assert conv.gsparams is galsim.GSParams.default

# Other ways to do the convolution:
conv = galsim.Convolve(psf,pixel,real_space=False)
conv.drawImage(myImg,scale=dx, method="sb", use_true_center=False)
np.testing.assert_array_almost_equal(
myImg.array, savedImg.array, 4,
err_msg="Using GSObject Convolve(psf,pixel) disagrees with expected result")
assert conv.gsparams is galsim.GSParams.default

# Check with default_params
conv = galsim.Convolve([psf,pixel],real_space=False,gsparams=default_params)
Expand All @@ -73,12 +77,18 @@ def test_convolve():
myImg.array, savedImg.array, 4,
err_msg="Using GSObject Convolve([psf,pixel]) with default_params disagrees with"
"expected result")
# In this case, it's not the same object, but it should be ==
assert conv.gsparams is not galsim.GSParams.default
assert conv.gsparams == galsim.GSParams.default

conv = galsim.Convolve([psf,pixel],real_space=False,gsparams=galsim.GSParams())
conv.drawImage(myImg,scale=dx, method="sb", use_true_center=False)
np.testing.assert_array_almost_equal(
myImg.array, savedImg.array, 4,
err_msg="Using GSObject Convolve([psf,pixel]) with GSParams() disagrees with"
"expected result")
assert conv.gsparams is not galsim.GSParams.default
assert conv.gsparams == galsim.GSParams.default

cen = galsim.PositionD(0,0)
np.testing.assert_equal(conv.centroid, cen)
Expand Down

0 comments on commit abf989e

Please sign in to comment.