b-remy / gems

GEnerative Morphology for Shear
MIT License
0 stars 0 forks source link

Demonstrating model bias for realistic galaxies #11

Open b-remy opened 2 years ago

b-remy commented 2 years ago

This issue is to report results of experiments aiming to demonstrate the model bias when trying to estimate shear with a forward model.

b-remy commented 2 years ago

We consider here real galaxies from the COSMOS 23.5 catalog. In order to demonstrate model bias we fit a Sersic model on two set of observations:

We remove galaxies such that n < 0.4 or half_light_radius > .3 to get a correct SNR. Gaussian noise of standard deviation 0.01 is added on top of COSMOS stamp noise realization.

Real galaxies simulations

image

Parametric galaxies simulations

image
EiffL commented 2 years ago

Wow, that is awesome!!!

b-remy commented 2 years ago

Something we were wondering is whether there was a pattern in the residuals for the realistic dataset due to something else that the profile discrepancy.

A way to check this is to generate the same image with galsim only for both the real image and the sersic fit and look at the residuals (code to generate the residual image). We can observe the same residuals as for our model fitting measurement.

image
EiffL commented 2 years ago

hummm the code is a little bit confusing to me, a lot is going on, can you just draw the real galaxy and subtract the parametric one? No added noise so it should be like 5 lines of code

b-remy commented 2 years ago

Here is when I only draw the galaxies convolved with their psf (no added noise).

image

I can make the code even simpler but I wanted to look at the same galaxies as in my example above.

EiffL commented 2 years ago

Right right, I just wanted to see clearly the exact steps going into making both parametric and real galaxies. In like 5 lines, just drawing one galaxy is enough for instance. I think I saw a few things that may not be quite right but it was hard to tell as there were 3 different gal objects every time (and that I didn't sleep much ^^')

b-remy commented 2 years ago

Ok, here is the top left galaxy for instance

ind = 2
galp = cat.makeGalaxy(ind, gal_type='parametric')
galr = cat.makeGalaxy(ind, gal_type='real')
psf = galr.original_psf

convr = galsim.Convolve(galr, psf) # real gal
convp = galsim.Convolve(galp, psf) # parametric gal

imr = convr.drawImage(nx=64, ny=64, scale=0.03).array
imp = convp.drawImage(nx=64, ny=64, scale=0.03).array

figure(figsize=(12,4))
subplot(131)
title('real gal')
imshow(imr)
colorbar()
subplot(132)
title('sersic fit')
imshow(imp)
colorbar()
subplot(133)
title('residuals')
imshow(imr-imp)
colorbar()
image
EiffL commented 2 years ago

Ok, so the first thing I saw is that you want to use the method 'no_pixel' to draw the galaxies, b cause the pixel response is already included in the PSF most likely

EiffL commented 2 years ago

And I remembered something similar from some work a long time ago, see this notebook https://github.com/McWilliamsCenter/deep_galaxy_models/blob/master/Figure_autoencode.ipynb

EiffL commented 2 years ago

And I remembered something similar from some work a long time ago, see this notebook https://github.com/McWilliamsCenter/deep_galaxy_models/blob/master/Figure_autoencode.ipynb

EiffL commented 2 years ago

Drawing galaxy from cosmos

gal = cosmos_cat.makeGalaxy(i, gal_type='real', noise_pad_size=0.8*PIXEL_SCALE*STAMP_SIZE)
psf = gal.original_psf
real = galsim.Convolve(psf, gal)
real.drawImage(im_real, method='no_pixel', use_true_center=False);

# Drawing galaxy from parametric model
param_gal = cosmos_cat.makeGalaxy(i, gal_type='parametric')
param = galsim.Convolve(psf, param_gal)
param.drawImage(im_param, method='no_pixel', use_true_center=False);
b-remy commented 2 years ago

It does not seem to change much the result...

ind = 2
galp = cat.makeGalaxy(ind, gal_type='parametric')
galr = cat.makeGalaxy(ind, gal_type='real', noise_pad_size=64*np.sqrt(2)*0.03)
psf = galr.original_psf

convr = galsim.Convolve(psf, galr) # real gal
convp = galsim.Convolve(psf, galp) # parametric gal

imr = convr.drawImage(nx=64, ny=64, scale=0.03, method='no_pixel', use_true_center=False).array
imp = convp.drawImage(nx=64, ny=64, scale=0.03, method='no_pixel', use_true_center=False).array

figure(figsize=(12,4))
subplot(131)
title('real gal')
imshow(imr)
colorbar()
subplot(132)
title('sersic fit')
imshow(imp)
colorbar()
subplot(133)
title('residuals')
imshow(imr-imp)
colorbar()
image
b-remy commented 2 years ago

So it looks like there is an offset in the galsim sersic fit centroid!

I added a centroid shift variable to my model (810ebda) and just ran a MAP for the field above. It fixed the dipole pattern in the residuals :-)

=> So I guess, I will now try to sample the centroid offset in the same time as the other parameters to check the model bias.

EiffL commented 2 years ago

Aaaaah that looks much better!

b-remy commented 2 years ago

Here are the latest results (ab506ca), now fitting e, gamma and centroid shift on realistic sheared images (assuming n, hlr and flux galsim sersic fit parameters:

image

residuals

image

And some chains

image image image