From 03b48709184d61340a1a7a7c3b7985d61fda96bb Mon Sep 17 00:00:00 2001 From: LukasK13 Date: Thu, 16 Apr 2020 08:23:00 +0200 Subject: [PATCH] Code clean up --- esbo_etc/classes/optical_component/Filter.py | 16 ++++++++-------- esbo_etc/classes/target/BlackBodyTarget.py | 18 +++++++++++------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/esbo_etc/classes/optical_component/Filter.py b/esbo_etc/classes/optical_component/Filter.py index dae2db9..e304353 100644 --- a/esbo_etc/classes/optical_component/Filter.py +++ b/esbo_etc/classes/optical_component/Filter.py @@ -11,10 +11,10 @@ class Filter(AHotOpticalComponent): A class to model a filter component and its thermal emission. The model can be created from a file, the name of a band or a custom spectral range. """ - _band_central_wl = dict(U=366 * u.nm, B=438 * u.nm, V=545 * u.nm, R=641 * u.nm, I=798 * u.nm, J=1220 * u.nm, - H=1630 * u.nm, K=2190 * u.nm) - _band_bandwidth = dict(U=68 * u.nm, B=98 * u.nm, V=89 * u.nm, R=220 * u.nm, I=240 * u.nm, J=300 * u.nm, H=400 * u.nm, - K=600 * u.nm) + _band = dict(U=dict(cwl=366 * u.nm, bw=68 * u.nm), B=dict(cwl=438 * u.nm, bw=98 * u.nm), + V=dict(cwl=545 * u.nm, bw=89 * u.nm), R=dict(cwl=641 * u.nm, bw=220 * u.nm), + I=dict(cwl=798 * u.nm, bw=240 * u.nm), J=dict(cwl=1220 * u.nm, bw=300 * u.nm), + H=dict(cwl=1630 * u.nm, bw=400 * u.nm), K=dict(cwl=2190 * u.nm, bw=600 * u.nm)) @u.quantity_input(temp=[u.Kelvin, u.Celsius], obstructor_temp=[u.Kelvin, u.Celsius]) def __init__(self, parent: ITransmissive, transmittance: Union[SpectralQty, Callable], @@ -80,10 +80,10 @@ class Filter(AHotOpticalComponent): filter : Filter The instantiated filter object. """ - if band not in cls._band_central_wl.keys(): - error("Band has to be one of '[" + ", ".join(list(cls._band_central_wl.keys())) + "]'") - return cls.fromRange(parent, cls._band_central_wl[band] - cls._band_bandwidth[band] / 2, - cls._band_central_wl[band] + cls._band_bandwidth[band] / 2, emissivity, temp, obstruction, + if band not in cls._band.keys(): + error("Band has to be one of '[" + ", ".join(list(cls._band.keys())) + "]'") + return cls.fromRange(parent, cls._band[band]["cwl"] - cls._band[band]["bw"] / 2, + cls._band[band]["cwl"] + cls._band[band]["bw"] / 2, emissivity, temp, obstruction, obstructor_temp, obstructor_emissivity) @classmethod diff --git a/esbo_etc/classes/target/BlackBodyTarget.py b/esbo_etc/classes/target/BlackBodyTarget.py index b772974..0c690a2 100644 --- a/esbo_etc/classes/target/BlackBodyTarget.py +++ b/esbo_etc/classes/target/BlackBodyTarget.py @@ -12,10 +12,14 @@ class BlackBodyTarget(ATarget): # Bands from Handbook of Space Astronomy and Astrophysics # band_sfd = {"U": 1790*u.Jansky, "B": 4063*u.Jansky, "V": 3636*u.Jansky, "R": 3064*u.Jansky, # "I": 2416*u.Jansky, "J": 1590*u.Jansky, "H": 1020*u.Jansky, "K": 640*u.Jansky} - band_sfd = dict(U=4.175e-11, B=6.32e-11, V=3.631e-11, R=2.177e-11, I=1.126e-11, J=3.15e-12, H=1.14e-12, K=3.96e-13) - band_sfd = {k: v * u.W / (u.m ** 2 * u.nm) for k, v in band_sfd.items()} - band_wl = dict(U=366 * u.nm, B=438 * u.nm, V=545 * u.nm, R=641 * u.nm, I=798 * u.nm, J=1220 * u.nm, H=1630 * u.nm, - K=2190 * u.nm) + _band = dict(U=dict(wl=366 * u.nm, sfd=4.175e-11 * u.W / (u.m ** 2 * u.nm)), + B=dict(wl=438 * u.nm, sfd=6.32e-11 * u.W / (u.m ** 2 * u.nm)), + V=dict(wl=545 * u.nm, sfd=3.631e-11 * u.W / (u.m ** 2 * u.nm)), + R=dict(wl=641 * u.nm, sfd=2.177e-11 * u.W / (u.m ** 2 * u.nm)), + I=dict(wl=798 * u.nm, sfd=1.126e-11 * u.W / (u.m ** 2 * u.nm)), + J=dict(wl=1220 * u.nm, sfd=3.15e-12 * u.W / (u.m ** 2 * u.nm)), + H=dict(wl=1630 * u.nm, sfd=1.14e-12 * u.W / (u.m ** 2 * u.nm)), + K=dict(wl=2190 * u.nm, sfd=3.96e-13 * u.W / (u.m ** 2 * u.nm))) @u.quantity_input(wl_bins='length', temp=[u.Kelvin, u.Celsius], mag=u.mag) def __init__(self, wl_bins: u.Quantity, temp: u.Quantity = 5778 * u.K, @@ -37,14 +41,14 @@ class BlackBodyTarget(ATarget): Returns ------- """ - if band not in self.band_wl.keys(): - error("Band has to be one of '[" + ", ".join(list(self.band_wl.keys())) + "]'") + if band not in self._band.keys(): + error("Band has to be one of '[" + ", ".join(list(self._band.keys())) + "]'") # 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 - factor = self.band_sfd[band] / (bb(self.band_wl[band]) * u.sr) * u.sr + factor = self._band[band]["sfd"] / (bb(self._band[band]["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)