Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
get_limmag should accept a synphot.SourceSpectrum
Browse files Browse the repository at this point in the history
  • Loading branch information
lpsinger committed Mar 19, 2021
1 parent 8f1aaaa commit 36271de
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 18 deletions.
4 changes: 3 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

## Version 0.3.0 (unreleased)

- No changes yet.
- The ``get_limmag`` function now accepts ``synphot.SourceSpectrum``
instance, rather than a spectral model class, for more consistency with the
other methods and for more flexibility.

## Version 0.2.0 (2021-03-03)

Expand Down
16 changes: 9 additions & 7 deletions dorado/sensitivity/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from astropy import units as u
import numpy as np
from synphot.exceptions import SynphotError
from synphot import Observation, SourceSpectrum
from synphot import Observation

from . import backgrounds
from . import bandpasses
Expand Down Expand Up @@ -75,13 +75,13 @@ def _amp_for_signal_to_noise_oir_ccd(
return 0.5 * snr2 / signal * (1 + np.sqrt(1 + 4 * noise2 / snr2))


def get_limmag(model, *, snr, exptime, coord, time, night):
def get_limmag(source_spectrum, *, snr, exptime, coord, time, night):
"""Get the limiting magnitude for a given SNR.
Parameters
----------
source_model : synphot.Model
The spectral model of the source.
source_spectrum : synphot.SourceSpectrum
The spectrum of the source.
snr : float
The desired SNR.
exptime : astropy.units.Quantity
Expand All @@ -99,11 +99,13 @@ def get_limmag(model, *, snr, exptime, coord, time, night):
astropy.units.Quantity
The AB magnitude of the source
"""
mag0 = Observation(source_spectrum, bandpasses.NUV_D).effstim(
u.ABmag, area=constants.AREA)

result = _amp_for_signal_to_noise_oir_ccd(
snr,
exptime,
constants.APERTURE_CORRECTION * _get_count_rate(
SourceSpectrum(model, amplitude=0*u.ABmag)),
constants.APERTURE_CORRECTION * _get_count_rate(source_spectrum),
(
_get_count_rate(backgrounds.get_zodiacal_light(coord, time)) +
_get_count_rate(backgrounds.get_airglow(night))
Expand All @@ -113,7 +115,7 @@ def get_limmag(model, *, snr, exptime, coord, time, night):
constants.NPIX
).to_value(u.dimensionless_unscaled)

return -2.5 * np.log10(result) * u.ABmag
return -2.5 * np.log10(result) * u.mag + mag0


def _exptime_for_signal_to_noise_oir_ccd(
Expand Down
3 changes: 2 additions & 1 deletion dorado/sensitivity/tests/test_sensitivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def test_round_trip_snr_limmag(snr, exptime, ra, dec, time, night):
coord=SkyCoord(ra * u.deg, dec * u.deg),
time=time, night=night)

limmag = get_limmag(ConstFlux1D, snr=snr, **kwargs)
limmag = get_limmag(
SourceSpectrum(ConstFlux1D, amplitude=0*u.ABmag), snr=snr, **kwargs)
snr_2 = get_snr(SourceSpectrum(ConstFlux1D, amplitude=limmag), **kwargs)
assert snr_2 == approx(snr)

Expand Down
38 changes: 29 additions & 9 deletions example.ipynb

Large diffs are not rendered by default.

0 comments on commit 36271de

Please sign in to comment.