GalSim-developers / JAX-GalSim

JAX port of GalSim, for parallelized, GPU accelerated, and differentiable galaxy image simulations.
Other
27 stars 3 forks source link

GalSim/JAX-GalSim : relatively sizeable differences in Gaussian profile #24

Closed jecampagne closed 1 year ago

jecampagne commented 1 year ago

Hi, I have performed in Galsim (using demo1.py)

gal_flux = 1.e5 
gal_sigma = 2.
gal = galsim.Gaussian(flux=gal_flux, sigma=gal_sigma)
gal_real = gal.drawImage(scale=1.0, method='real_space')

and then write the image on fits file and load as gal_galsim 2D array.

Now using JaxGalsim I try to do the same

gal = galsim.Gaussian(flux=1.e5, sigma=2.)
im = gal.drawImage(nx=26, ny=26, scale=1.0) # gives nx,ny to get the same image size as the Galsim output

and now using im.array.

The two arrays look very similar image

but when I plot the relative differences

plt.figure(figsize=(8,8))
plt.imshow((gal_galsim-im.array)/gal_galsim, cmap='jet'); plt.colorbar() 

I get image

which I think is too much differences for this kind a very basic outputs. Any idea?

jecampagne commented 1 year ago

Humm, one way to explain the difference is the convolution by a Pixel in Galsim

           prof = Convolve(prof, Pixel(scale=1.0, gsparams=self.gsparams),
                            real_space=real_space, gsparams=self.gsparams)

Then, using a method that avoid this convolution leads that the two arrays agrees perfectly.

jmeyers314 commented 1 year ago

Hi @jecampagne , GSObject.drawImage does implicitly convolve by a pixel for most drawing methods (the exceptions are no_pixel and sb). In fact, GalSim will raise a warning if it sees you've already convolved by a Pixel and the call to drawImage would convolve the profile again: https://github.com/GalSim-developers/GalSim/blob/releases/2.4/galsim/gsobject.py#L1660-L1670

It sounds like this is probably what you're seeing here. Take a look at https://github.com/GalSim-developers/GalSim/blob/releases/2.4/galsim/gsobject.py#L1332-L1387 for more details.

jecampagne commented 1 year ago

In fact, currently JaxGalSim does not yet convolve with a Pixel, so when I choose in GalSim the "no-pixel" method there is a perfect match between the two codes. The next step would be to introduce a Convolution mechanism in JaxGalSim. Thanks.