GalSim-developers / GalSim

The modular galaxy image simulation toolkit. Documentation:
http://galsim-developers.github.io/GalSim/
Other
223 stars 105 forks source link

Only photons from the final object in a `ChromaticSum` are saved #1284

Closed welucas2 closed 3 months ago

welucas2 commented 4 months ago

When save_photons = True, drawing a ChromaticObject returns all the photons requested. However, if those objects are combined into a ChromaticSum only the photons drawn for the final object are returned:

import galsim

rng = galsim.BaseDeviate(215324)
sed = galsim.SED('vega.txt', wave_type="nm", flux_type="fphotons")
bandpass = galsim.Bandpass("LSST_r.dat", wave_type="nm")

# Create a bulge and disk and draw with 1000 photons each.
bulge = galsim.Sersic(n=3, half_light_radius=0.8) * sed
disk = galsim.Exponential(half_light_radius=1.4) * sed
bulge_image = bulge.drawImage(method="phot", n_photons=1000, save_photons=True, bandpass=bandpass, rng=rng)
disk_image = disk.drawImage(method="phot", n_photons=1000, save_photons=True, bandpass=bandpass, rng=rng)

# All 1000 photons are returned for each of the separate bulge and disk.
print(bulge_image.photons, disk_image.photons)

# Create a ChromaticSum object combining the bulge and disk then draw it with 1000 photons.
gal = bulge + disk
gal_image = gal.drawImage(method="phot", n_photons=1000, save_photons=True, bandpass=bandpass, rng=rng)

# The ChromaticSum's photon array only contains 511 photons.
print(gal_image.photons)

ChromaticSum.drawImage loops through the individual components, drawing them in sequence. The photons are actually saved in GSObject.drawImage at the very end of the function but simply does image.photons = photons, replacing any previously saved object's photon array with the current one.

I think either a full-sized photon array should be allocated in ChromaticSum.drawImage and then filled in GSObject.drawImage, or else the latter should check if a photon array has already been stored and if so extend rather than overwrite it.

rmjarvis commented 3 months ago

Fixed in #1289.