mag parameter optional

This commit is contained in:
Lukas Klass 2020-07-21 11:22:01 +02:00
parent 6ab69f5c2b
commit 3d1a430ca4
2 changed files with 23 additions and 20 deletions

View File

@ -28,8 +28,8 @@ Attributes:
| The temperature of the black body.
* | **temp_unit:** str, *optional* = "K"
| The unit of the black body's temperature. This has to be one of [``K``, ``Celsius``]. The default is ``K``.
* | **mag:** float
| The apparent magnitude of the black body in magnitudes. In case of a magnitude per solid angle, an extended target is assumed.
* | **mag:** float, *optional* = None
| The apparent magnitude of the black body in magnitudes. In case of None or magnitude per solid angle, an extended target is assumed.
* | **mag_unit:** str, *optional* = "mag"
| The unit of the black body's magnitude. This has to be [``mag``, ``mag / arcsec**2``, ``mag / sr``]. The default is ``mag``.
* | **band:** str

View File

@ -25,7 +25,7 @@ class BlackBodyTarget(ATarget):
N=dict(wl=10200 * u.nm, sfd=1.23e-15 * u.W / (u.m ** 2 * u.nm)))
@u.quantity_input(wl_bins='length', temp=[u.Kelvin, u.Celsius], mag=[u.mag, u.mag / u.sr])
def __init__(self, wl_bins: u.Quantity, temp: u.Quantity = 5778 * u.K, mag: u.Quantity = 0 * u.mag,
def __init__(self, wl_bins: u.Quantity, temp: u.Quantity = 5778 * u.K, mag: u.Quantity = None,
band: str = "V"):
"""
Initialize a new black body point source
@ -50,18 +50,20 @@ class BlackBodyTarget(ATarget):
# Create blackbody model with given temperature
bb = BlackBody(temperature=temp, scale=1 * u.W / (u.m ** 2 * u.nm * u.sr))
# Calculate the correction factor for a star of 0th magnitude using the spectral flux density
# for the central wavelength of the given band
if mag.unit.is_equivalent(u.mag / u.sr):
solid_angle_unit = (u.mag / mag.unit)
mag = mag * solid_angle_unit
factor = self._band[band.upper()]["sfd"] / (bb(self._band[band.upper()]["wl"]) * (
solid_angle_unit.to(u.sr) * u.sr))
if mag is not None:
# Calculate the correction factor for a star of 0th magnitude using the spectral flux density
# for the central wavelength of the given band
if mag.unit.is_equivalent(u.mag / u.sr):
solid_angle_unit = (u.mag / mag.unit)
mag = mag * solid_angle_unit
factor = self._band[band.upper()]["sfd"] / (bb(self._band[band.upper()]["wl"]) * (
solid_angle_unit.to(u.sr) * u.sr))
else:
factor = self._band[band.upper()]["sfd"] / (bb(self._band[band.upper()]["wl"]) * u.sr) * u.sr
# Calculate spectral flux density for the given wavelengths and scale it for a star of the given magnitude
sfd = bb(wl_bins) * factor * 10 ** (- 2 / 5 * mag / u.mag) # / 1.195 * 1.16 # scaling for AETC validation
else:
factor = self._band[band.upper()]["sfd"] / (bb(self._band[band.upper()]["wl"]) * u.sr) * u.sr
# Calculate spectral flux density for the given wavelengths and scale it for a star of the given magnitude
sfd = bb(wl_bins) * factor * 10 ** (- 2 / 5 * mag / u.mag) # / 1.195 * 1.16 # scaling for AETC validation
sfd = bb(wl_bins)
# Initialize super class
super().__init__(SpectralQty(wl_bins, sfd), wl_bins)
@ -83,11 +85,12 @@ class BlackBodyTarget(ATarget):
mes = conf.check_quantity("temp", u.K)
if mes is not None:
return mes
mes = conf.check_quantity("mag", u.mag)
if mes is not None:
mes = conf.check_quantity("mag", u.mag / u.sr)
if hasattr(conf, "mag"):
mes = conf.check_quantity("mag", u.mag)
if mes is not None:
mes = conf.check_quantity("mag", u.mag / u.sr)
if mes is not None:
return mes
mes = conf.check_selection("band", ["U", "B", "V", "R", "I", "J", "H", "K", "L", "M", "N"])
if mes is not None:
return mes
mes = conf.check_selection("band", ["U", "B", "V", "R", "I", "J", "H", "K", "L", "M", "N"])
if mes is not None:
return mes