deepskies / deepskies/deeplenstronomy

Sky brightness inaccurate due to units error

Open
#139 5 comments 0 reactions 0 assignees View on GitHub
bug documentation
Dominant language
HTML
Stars
38
Forks
8
PR merge metrics
No merged PRs in 30d

Description

This is for current version PyPI 0.0.2.3, on macOS Sonoma 14.5. The sky brightness input to deeplenstronomy is shown in the examples (https://deepskies.github.io/deeplenstronomy/Notebooks/ConfigFiles.html) to be:

`sky_brightness: measured light contamination from the atmosphere in magnitude per square arcsecond`

followed by,

```
SURVEY:
PARAMETERS:
BANDS: g,r,i,z,Y
seeing: 0.9
magnitude_zero_point: 30.0
sky_brightness: 23.5
num_exposures: 10

```

This indicates an input in magnitude/sq. arcsec. I believe the `sky_brightness` value is not manipulated and directly passed into `lenstronomy.Util.data_util.bkg_noise()` which takes input in counts/s/sq. arcsec, rather than magnitude/sq. arcsec. See function signature below (https://lenstronomy.readthedocs.io/en/latest/_modules/lenstronomy/Util/data_util.html):

```
def bkg_noise(
readout_noise, exposure_time, sky_brightness, pixel_scale, num_exposures=1
):
"""Computes the expected Gaussian background noise of a pixel in units of
counts/second.

:param readout_noise: noise added per readout
:param exposure_time: exposure time per exposure (in seconds)
:param sky_brightness: counts per second per unit arcseconds square
:param pixel_scale: size of pixel in units arcseonds
:param num_exposures: number of exposures (with same exposure time) to be co-added
:return: estimated Gaussian noise sqrt(variance)
"""
exposure_time_tot = num_exposures * exposure_time
readout_noise_tot = num_exposures * readout_noise**2 # square of readout noise
sky_per_pixel = sky_brightness * pixel_scale**2
sky_brightness_tot = exposure_time_tot * sky_per_pixel
sigma_bkg = np.sqrt(readout_noise_tot + sky_brightness_tot) / exposure_time_tot
return sigma_bkg
```

To test, I attach 3 images with only changing sky brightness in the .yaml file, and show that the sky brightness input is certainly acting like a counts/s input rather than a mag/sq. arcsec input.

![sky1](https://github.com/deepskies/deeplenstronomy/assets/69968384/2f7f9287-3d56-4808-acd5-3c82870b25cc)
![sky235](https://github.com/deepskies/deeplenstronomy/assets/69968384/f6df06b7-8814-434f-9d59-634e39160adb)
![sky10000](https://github.com/deepskies/deeplenstronomy/assets/69968384/32ddcc74-5f7b-4073-990c-06ccfa1b2976)

Testing for a visible change in generated images with changing sky brightness required a `sky_brightness: 10_000` or so before it could be seen, indicating inputs should be in flux. Entering a value of 0. or 1. sky brightness should produce a very bright image for magnitude/sq. arcsec but instead produces an image with no sky noise. Similarly, entering a negative value for the sky_brightness causes nan images, which should not occur for magnitude based inputs.

I also attach .yaml files which can be used to reproduce the same (uploaded as .txt at the end). The only difference in these files is the sky_brightness parameter.

Lastly, the default survey distributions provided in distributions.py (https://github.com/deepskies/deeplenstronomy/blob/9672080cd1a5792887341f4fb13c3b0bcf913600/deeplenstronomy/distributions.py) are also in mag/sq. arcsec. This means that any use of the default survey distributions such as des_sky_brightness causes() a too-low sky brightness input to replicate the survey.

Happy to provide more information or receive corrections if I have misunderstood this.

[sky10000.txt](https://github.com/user-attachments/files/15891240/sky10000.txt)
[sky100.txt](https://github.com/user-attachments/files/15891241/sky100.txt)
[sky1.txt](https://github.com/user-attachments/files/15891242/sky1.txt)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.