Skip to content

Commit

Permalink
Fix #1284 by saving any already existing photon array in an image ret…
Browse files Browse the repository at this point in the history
…urned by GSObject.drawImage rather than replacing with new array.
  • Loading branch information
welucas2 committed Apr 30, 2024
1 parent 223ea23 commit 34e138c
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion galsim/gsobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -1834,7 +1834,21 @@ def drawImage(self, image=None, nx=None, ny=None, bounds=None, scale=None, wcs=N

image.added_flux = added_photons / flux_scale
if save_photons:
image.photons = photons
# We need to check if image already contains photons from a previous call to drawImage,
# for example if doing a ChromaticSum.
if not hasattr(image, 'photons'):
# If not, then simply put the photons into the image.
image.photons = photons
else:
# If photons have already been saved, need to create a new larger array and copy
# in from both the original and new photon arrays.
n_orig_photons = image.photons.size()
n_new_photons = photons.size()
n_total_photons = n_orig_photons + n_new_photons
total_photons = pa.PhotonArray(n_total_photons)
total_photons.copyFrom(image.photons, slice(0, n_orig_photons))
total_photons.copyFrom(photons, slice(n_orig_photons, n_total_photons))
image.photons = total_photons

return image

Expand Down

0 comments on commit 34e138c

Please sign in to comment.