-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement utility functions purely related to survey and filter numbers #24
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b3e4b17
Tentative implementation of functions
aboucaud b51487a
Merge branch 'main' into utility-functions
aboucaud 3612deb
Simplify the computation for the conversion
aboucaud cb9dc7d
Add docstring explainations
aboucaud 4ee3c02
Cast value to integer
aboucaud c78f5ca
Add tests
aboucaud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import astropy.units as u | ||
|
||
from galcheat.helpers import get_filter, get_survey | ||
|
||
|
||
def mag2counts(magnitude, survey_name, filter_name): | ||
"""Convert source magnitude to counts for a given filter of a survey | ||
|
||
To perform the computation, we use the filter zeropoint computed | ||
with `speclite` under classical atmospheric conditions and at a | ||
given airmass and we integrate over the survey lifetime using the | ||
full filter exposure time. | ||
|
||
Expect a rough estimate from this calculation since e.g. it does not | ||
take into account the atmospheric extinction. Therefore the result | ||
is casted to an integer. | ||
|
||
Parameters | ||
---------- | ||
magnitude: float | ||
magnitude of source | ||
survey_name: str | ||
Name of a given survey | ||
filter_name: str | ||
Name of the survey filter | ||
|
||
Returns | ||
------- | ||
The corresponding flux in counts | ||
|
||
References | ||
---------- | ||
The `WeakLensingDeblending` package | ||
https://github.com/LSSTDESC/WeakLensingDeblending | ||
|
||
""" | ||
if not isinstance(magnitude, u.Quantity): | ||
magnitude *= u.mag(u.ct / u.s) | ||
else: | ||
magnitude = magnitude.value * u.mag(u.ct / u.s) | ||
|
||
filter = get_filter(filter_name, survey_name) | ||
|
||
flux = (magnitude - filter.zeropoint).to(u.ct / u.s) | ||
counts = flux * filter.exposure_time | ||
|
||
return counts.astype(int) | ||
|
||
|
||
def mean_sky_level(survey_name, filter_name): | ||
"""Computes the mean sky level for a given survey and a filter | ||
|
||
This computation uses the sky brightness parameter from galcheat, | ||
expressed as a magnitude per square arcminute, weights it by the | ||
aboucaud marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pixel area and converts it to counts. | ||
|
||
Parameters | ||
---------- | ||
survey_name: str | ||
Name of a given survey | ||
filter_name: str | ||
Name of the survey filter | ||
|
||
Returns | ||
------- | ||
The corresponding mean sky level in counts | ||
|
||
""" | ||
survey = get_survey(survey_name) | ||
filter = get_filter(filter_name, survey_name) | ||
|
||
sky_brightness_counts = mag2counts(filter.sky_brightness, survey_name, filter_name) | ||
pixel_area = survey.pixel_scale.to_value(u.arcsec) ** 2 | ||
|
||
mean_sky_level = sky_brightness_counts * pixel_area | ||
|
||
return mean_sky_level |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from galcheat.utilities import mag2counts, mean_sky_level | ||
|
||
BTK_COUNTS_MAG24 = { | ||
"Rubin_u": 15321.782101179268, | ||
"Rubin_g": 121397.91888074754, | ||
"Rubin_r": 240956.73939657194, | ||
"Rubin_i": 179448.18815675998, | ||
"Rubin_z": 108953.51289042353, | ||
"Rubin_y": 50727.240442255556, | ||
} | ||
|
||
BTK_MEAN_SKY_LEVEL = { | ||
"Rubin_u": 1687.9876819744386, | ||
"Rubin_g": 23241.878848667337, | ||
"Rubin_r": 127057.1381640446, | ||
"Rubin_i": 180301.3875959776, | ||
"Rubin_z": 250784.8105213134, | ||
"Rubin_y": 293292.6831817095, | ||
} | ||
|
||
|
||
def test_mag2counts(): | ||
survey = "Rubin" | ||
for filt in "ugrizy": | ||
counts = mag2counts(24, survey, filt).value | ||
assert counts == int(BTK_COUNTS_MAG24[f"{survey}_{filt}"]) | ||
|
||
|
||
def test_mean_sky_level(): | ||
survey = "Rubin" | ||
for filt in "ugrizy": | ||
sky_level = mean_sky_level(survey, filt).value | ||
assert int(sky_level) == int(BTK_MEAN_SKY_LEVEL[f"{survey}_{filt}"]) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may mention that it consists of electron counts ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But is it really ?
For me, this is photon count. To be electron counts it needs to be multiplied by the gain.
It does not change a thing for LSST because the gain is set to 1.0 but for other surveys this is relevant.
This comes back to another related question about the units of the gain currently in electron/adu that should be changed to electron/count if we would like them to be compatible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm I think that the conversion from photons to electrons depends on the quantum efficiency while the gain is effectively transforming electrons to ADUs (it is in e-/ADU such that going from e- to ADUs is done by dividing by the gain).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coming back to this, as we are using zeropoints indicating magnitudes giving 1e-/s, I would say that the fluxes we compute with those zeropoints should be in e-.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #93