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. | The temperature of the black body.
* | **temp_unit:** str, *optional* = "K" * | **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``. | The unit of the black body's temperature. This has to be one of [``K``, ``Celsius``]. The default is ``K``.
* | **mag:** float * | **mag:** float, *optional* = None
| The apparent magnitude of the black body in magnitudes. In case of a magnitude per solid angle, an extended target is assumed. | 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" * | **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``. | The unit of the black body's magnitude. This has to be [``mag``, ``mag / arcsec**2``, ``mag / sr``]. The default is ``mag``.
* | **band:** str * | **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))) 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]) @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"): band: str = "V"):
""" """
Initialize a new black body point source Initialize a new black body point source
@ -50,18 +50,20 @@ class BlackBodyTarget(ATarget):
# Create blackbody model with given temperature # Create blackbody model with given temperature
bb = BlackBody(temperature=temp, scale=1 * u.W / (u.m ** 2 * u.nm * u.sr)) 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 if mag is not None:
# for the central wavelength of the given band # Calculate the correction factor for a star of 0th magnitude using the spectral flux density
if mag.unit.is_equivalent(u.mag / u.sr): # for the central wavelength of the given band
solid_angle_unit = (u.mag / mag.unit) if mag.unit.is_equivalent(u.mag / u.sr):
mag = mag * solid_angle_unit solid_angle_unit = (u.mag / mag.unit)
factor = self._band[band.upper()]["sfd"] / (bb(self._band[band.upper()]["wl"]) * ( mag = mag * solid_angle_unit
solid_angle_unit.to(u.sr) * u.sr)) 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: else:
factor = self._band[band.upper()]["sfd"] / (bb(self._band[band.upper()]["wl"]) * u.sr) * u.sr sfd = bb(wl_bins)
# 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
# Initialize super class # Initialize super class
super().__init__(SpectralQty(wl_bins, sfd), wl_bins) super().__init__(SpectralQty(wl_bins, sfd), wl_bins)
@ -83,11 +85,12 @@ class BlackBodyTarget(ATarget):
mes = conf.check_quantity("temp", u.K) mes = conf.check_quantity("temp", u.K)
if mes is not None: if mes is not None:
return mes return mes
mes = conf.check_quantity("mag", u.mag) if hasattr(conf, "mag"):
if mes is not None: mes = conf.check_quantity("mag", u.mag)
mes = conf.check_quantity("mag", u.mag / u.sr) 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: if mes is not None:
return mes 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