From 3d1a430ca46048ae38bd14a8af01de83b30c4a39 Mon Sep 17 00:00:00 2001 From: LukasK13 Date: Tue, 21 Jul 2020 11:22:01 +0200 Subject: [PATCH] mag parameter optional --- docs/source/configuration/target.rst | 4 +-- esbo_etc/classes/target/BlackBodyTarget.py | 39 ++++++++++++---------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/docs/source/configuration/target.rst b/docs/source/configuration/target.rst index ae45e04..5f96229 100644 --- a/docs/source/configuration/target.rst +++ b/docs/source/configuration/target.rst @@ -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 diff --git a/esbo_etc/classes/target/BlackBodyTarget.py b/esbo_etc/classes/target/BlackBodyTarget.py index 03f280e..f8223cc 100644 --- a/esbo_etc/classes/target/BlackBodyTarget.py +++ b/esbo_etc/classes/target/BlackBodyTarget.py @@ -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