GalSim-developers / GalSim-Euclid-Like

Helper functions to generate simulations of Euclid-Like images.
Other
1 stars 0 forks source link

Noise handling + New outputs #68

Closed aguinot closed 2 months ago

aguinot commented 3 months ago

Note 1: Should be merged after #67 Note 2: This should fix issue #54

@matroxel if you have some time, I would be very happy to have your opinion on how I implemented the noise using custom features of galsim.config.

Noise handling

I "fixed" the handling the handling of the noise in _euclidlikeimsim. Originally the noise was added through these lines:

poisson_noise = galsim.noise.PoissonNoise(rng)
if self.draw_method == "phot":
    logger.debug("Adding poisson noise to sky photons")
    sky_image1 = sky_image.copy()
    sky_image1.addNoise(poisson_noise)
    image.quantize()  # In case any profiles used InterpolatedImage, in which case
    # the image won't necessarily be integers.
    image += sky_image1
else:
    logger.debug("Adding poisson noise")
    image += sky_image
    image.addNoise(poisson_noise)

The default drawing method is "auto" so it will do the else statement which is a problem because the majority of our objects are drawn using the phot method so the poisson noise will be counted twice (this is the case on all the images I have done so far).
With the new implementation, the noise is handled independently of the drawing method. That raise a new issue, the bright objects are drawn with the fft method so there will be no poisson noise on them. If we believe this is important I have some ideas how to fix that.

New outputs

With the new implementation of the noise I was able to make new ouptuts:

The new outputs are done with custom galsim.config.ExtraOutputBuilder. I can easily add more or modify the existing one. I did not thought useful to output a noiseless image since you can get it from the noise image. If you think it could be useful to have one, I can add it.

Tests

Here is a list of tests I have done:

All feedback is very welcome 🙂.

matroxel commented 3 months ago

Noise is already added to the fft-drawn objects at this line: https://github.com/GalSim-developers/GalSim-Euclid-Like/blob/cce5f516a1926ef520fde13bf89a0606d76a6b3e/euclidlike_imsim/stamp.py#L285

So you should be able to always treat the image like the self.draw_method == "phot" block quoted in your post.

matroxel commented 3 months ago

I think your changes will work also.

aguinot commented 3 months ago

Noise is already added to the fft-drawn objects at this line:

https://github.com/GalSim-developers/GalSim-Euclid-Like/blob/cce5f516a1926ef520fde13bf89a0606d76a6b3e/euclidlike_imsim/stamp.py#L285

So you should be able to always treat the image like the self.draw_method == "phot" block quoted in your post.

Thank you for pointing that, I did not look carefully enough to the code. Thank you for having a look at the changes!

aguinot commented 3 months ago

@rmandelb the conflicts have been solved. It is ready for review.