Code clean up

This commit is contained in:
Lukas Klass 2020-04-16 09:35:24 +02:00
parent 03b4870918
commit d1eb1c5738
26 changed files with 118 additions and 104 deletions

View File

@ -0,0 +1,31 @@
from abc import ABC, abstractmethod
from .SpectralQty import SpectralQty
class IRadiant(ABC):
"""
Interface for getting the signal and the noise of a emitting, reflecting or transmitting component in the beam.
"""
@abstractmethod
def calcSignal(self) -> SpectralQty:
"""
Calculate the signal coming from the component
Returns
-------
signal : SpectralQty
The emitted, reflected or transmitted signal
"""
pass
@abstractmethod
def calcNoise(self) -> SpectralQty:
"""
Calculate the noise coming from the component
Returns
-------
signal : SpectralQty
The emitted, reflected or transmitted noise
"""
pass

View File

@ -1,12 +0,0 @@
from abc import ABC, abstractmethod
from .SpectralQty import SpectralQty
class ITransmissive(ABC):
@abstractmethod
def calcSignal(self) -> SpectralQty:
pass
@abstractmethod
def calcNoise(self) -> SpectralQty:
pass

View File

@ -1,5 +1,5 @@
from esbo_etc.classes.config import * from esbo_etc.classes.config import *
from esbo_etc.classes.ITransmissive import * from esbo_etc.classes.IRadiant import *
from esbo_etc.classes.SpectralQty import * from esbo_etc.classes.SpectralQty import *
from esbo_etc.classes.target import * from esbo_etc.classes.target import *
from esbo_etc.classes.optical_component import * from esbo_etc.classes.optical_component import *

View File

@ -3,23 +3,28 @@ import numpy as np
import astropy.units as u import astropy.units as u
import os import os
import logging import logging
from esbo_etc.lib.helpers import error from ..lib.helpers import error
from typing import Union
class Entry(object): class Entry(object):
""" """
A class used to represent a configuration entry. A class used to represent a configuration entry.
Copied from ExoSim (https://github.com/ExoSim/ExoSimPublic) Taken from ExoSim (https://github.com/ExoSim/ExoSimPublic)
""" """
val: Union[str, bool, u.Quantity]
def __call__(self): def __call__(self):
return self.val if hasattr(self, "val") else None return self.val if hasattr(self, "val") else None
def parse(self, xml): def parse(self, xml: eT.Element):
""" """
Parse attributes of a XML element Parse attributes of a XML element
:param xml: XML element to parse the attributes from Parameters
----------
xml : xml.etree.ElementTree.Element
XML element to parse the attributes from
""" """
# Copy the XML attributes to object attributes # Copy the XML attributes to object attributes
for attrib in xml.attrib.keys(): for attrib in xml.attrib.keys():
@ -30,8 +35,6 @@ class Entry(object):
try: try:
self.val = u.Quantity(list(map(float, self.val.split(','))), self.val = u.Quantity(list(map(float, self.val.split(','))),
self.units) self.units)
# if self.units == 'deg':
# self.val = [val * pq.rad for val in self.val] # workaround for qt unit conversion
if len(self.val) == 1: if len(self.val) == 1:
self.val = self.val[0] self.val = self.val[0]
except (ValueError, LookupError): except (ValueError, LookupError):
@ -52,7 +55,7 @@ class Configuration(object):
""" """
conf = None conf = None
def __init__(self, filename="esbo-etc_defaults.xml", default_path=None): def __init__(self, filename="esbo-etc_defaults.xml"):
""" """
Parse a XML configuration file. Parse a XML configuration file.
@ -60,8 +63,6 @@ class Configuration(object):
---------- ----------
filename : str filename : str
configuration file to parse configuration file to parse
default_path : str
default path to use for relative paths
""" """
# Check if configuration file exists # Check if configuration file exists
@ -111,18 +112,12 @@ class Configuration(object):
def calc_metaoptions(self): def calc_metaoptions(self):
""" """
Calculate additional attributes e.g. the wavelength grid Calculate additional attributes e.g. the wavelength grid
Returns
-------
""" """
self.calc_metaoption_wl_delta() self.calc_metaoption_wl_delta()
def calc_metaoption_wl_delta(self): def calc_metaoption_wl_delta(self):
""" """
Calculate the wavelength grid used for the calculations. Calculate the wavelength grid used for the calculations.
Returns
-------
""" """
if hasattr(self.conf.common, "wl_delta"): if hasattr(self.conf.common, "wl_delta"):
wl_delta = self.conf.common.wl_delta() wl_delta = self.conf.common.wl_delta()
@ -131,7 +126,3 @@ class Configuration(object):
setattr(self.conf.common, 'wl_bins', np.arange(self.conf.common.wl_min().to(u.micron).value, setattr(self.conf.common, 'wl_bins', np.arange(self.conf.common.wl_min().to(u.micron).value,
self.conf.common.wl_max().to(u.micron).value, self.conf.common.wl_max().to(u.micron).value,
wl_delta.to(u.micron).value) * u.micron) wl_delta.to(u.micron).value) * u.micron)
if __name__ == "__main__":
conf = Configuration()

View File

@ -1,5 +1,5 @@
from esbo_etc.classes.optical_component.AOpticalComponent import AOpticalComponent from esbo_etc.classes.optical_component.AOpticalComponent import AOpticalComponent
from esbo_etc.classes.ITransmissive import ITransmissive from esbo_etc.classes.IRadiant import IRadiant
from esbo_etc.classes.SpectralQty import SpectralQty from esbo_etc.classes.SpectralQty import SpectralQty
from abc import abstractmethod from abc import abstractmethod
import astropy.units as u import astropy.units as u
@ -13,14 +13,14 @@ class AHotOpticalComponent(AOpticalComponent):
""" """
@abstractmethod @abstractmethod
@u.quantity_input(wl_bins='length', temp=[u.Kelvin, u.Celsius], obstruction_temp=[u.Kelvin, u.Celsius]) @u.quantity_input(wl_bins='length', temp=[u.Kelvin, u.Celsius], obstruction_temp=[u.Kelvin, u.Celsius])
def __init__(self, parent: ITransmissive, emissivity: Union[SpectralQty, int, float, str], temp: u.Quantity, def __init__(self, parent: IRadiant, emissivity: Union[SpectralQty, int, float, str], temp: u.Quantity,
obstruction: float = 0, obstructor_temp: u.Quantity = 0 * u.K, obstructor_emissivity: float = 1): obstruction: float = 0, obstructor_temp: u.Quantity = 0 * u.K, obstructor_emissivity: float = 1):
""" """
Initialize a new optical component with thermal emission Initialize a new optical component with thermal emission
Parameters Parameters
---------- ----------
parent : ITransmissive parent : IRadiant
The parent element of the optical component from which the electromagnetic radiation is received. The parent element of the optical component from which the electromagnetic radiation is received.
emissivity : Union[SpectralQty, int, float, str] emissivity : Union[SpectralQty, int, float, str]
The spectral emissivity coefficient for the optical surface. The spectral emissivity coefficient for the optical surface.
@ -47,7 +47,7 @@ class AHotOpticalComponent(AOpticalComponent):
elif isinstance(emissivity, str): elif isinstance(emissivity, str):
em = SpectralQty.fromFile(emissivity, u.nm, u.dimensionless_unscaled) em = SpectralQty.fromFile(emissivity, u.nm, u.dimensionless_unscaled)
bb = self._gb_factory(temp) bb = self._gb_factory(temp)
self._noise = SpectralQty(emissivity.wl, bb(emissivity.wl)) * em self._noise = SpectralQty(em.wl, bb(em.wl)) * em
else: else:
bb = self._gb_factory(temp, emissivity) bb = self._gb_factory(temp, emissivity)
self._noise = bb self._noise = bb

View File

@ -1,20 +1,20 @@
from ..ITransmissive import ITransmissive from ..IRadiant import IRadiant
from abc import abstractmethod
from ..SpectralQty import SpectralQty from ..SpectralQty import SpectralQty
from esbo_etc.lib.helpers import error, isLambda from ...lib.helpers import error
from abc import abstractmethod
import astropy.units as u import astropy.units as u
from astropy.modeling.models import BlackBody from astropy.modeling.models import BlackBody
from typing import Union, Callable from typing import Union, Callable
class AOpticalComponent(ITransmissive): class AOpticalComponent(IRadiant):
""" """
Abstract super class for an optical component Abstract super class for an optical component
""" """
@abstractmethod @abstractmethod
@u.quantity_input(obstructor_temp=[u.K, u.Celsius]) @u.quantity_input(obstructor_temp=[u.K, u.Celsius])
def __init__(self, parent: ITransmissive, transreflectivity: Union[SpectralQty, int, float, u.Quantity] = None, def __init__(self, parent: IRadiant, transreflectivity: Union[SpectralQty, int, float, u.Quantity] = None,
noise: Union[SpectralQty, int, float, u.Quantity] = None, obstruction: float = 0, noise: Union[SpectralQty, int, float, u.Quantity] = None, obstruction: float = 0,
obstructor_temp: u.Quantity = 0 * u.K, obstructor_emissivity: float = 1): obstructor_temp: u.Quantity = 0 * u.K, obstructor_emissivity: float = 1):
""" """
@ -22,7 +22,7 @@ class AOpticalComponent(ITransmissive):
Parameters Parameters
---------- ----------
parent : ITransmissive parent : IRadiant
The parent element of the optical component from which the electromagnetic radiation is received The parent element of the optical component from which the electromagnetic radiation is received
transreflectivity : SpectralQty transreflectivity : SpectralQty
The spectral transmission / reflectivity coefficient of the component. This coefficient is multiplied with The spectral transmission / reflectivity coefficient of the component. This coefficient is multiplied with
@ -79,7 +79,6 @@ class AOpticalComponent(ITransmissive):
noise = parent * (1. - self._obstruction) noise = parent * (1. - self._obstruction)
return noise + self.ownNoise() return noise + self.ownNoise()
def propagate(self, sqty: SpectralQty) -> SpectralQty: def propagate(self, sqty: SpectralQty) -> SpectralQty:
""" """
Propagate incoming radiation through the optical component Propagate incoming radiation through the optical component

View File

@ -1,6 +1,6 @@
from esbo_etc.classes.optical_component.AOpticalComponent import AOpticalComponent from .AOpticalComponent import AOpticalComponent
from esbo_etc.classes.ITransmissive import ITransmissive from ..IRadiant import IRadiant
from esbo_etc.classes.SpectralQty import SpectralQty from ..SpectralQty import SpectralQty
import astropy.units as u import astropy.units as u
@ -8,13 +8,14 @@ class Atmosphere(AOpticalComponent):
""" """
A class to model the atmosphere including the atmosphere's spectral transmittance and emission. A class to model the atmosphere including the atmosphere's spectral transmittance and emission.
""" """
def __init__(self, parent: ITransmissive, transmittance: str, emission: str = None) -> "Atmosphere":
def __init__(self, parent: IRadiant, transmittance: str, emission: str = None):
""" """
Initialize a new atmosphere model Initialize a new atmosphere model
Parameters Parameters
---------- ----------
parent : ITransmissive parent : IRadiant
The parent element of the atmosphere from which the electromagnetic radiation is received. The parent element of the atmosphere from which the electromagnetic radiation is received.
This element is usually of type Target or StrayLight. This element is usually of type Target or StrayLight.
transmittance : str transmittance : str
@ -26,13 +27,13 @@ class Atmosphere(AOpticalComponent):
""" """
# Read the transmittance # Read the transmittance
transmittance_sqty = SpectralQty.fromFile(transmittance, wl_unit_default=u.nm, transmittance_sqty = SpectralQty.fromFile(transmittance, wl_unit_default=u.nm,
qty_unit_default=u.dimensionless_unscaled) qty_unit_default=u.dimensionless_unscaled)
if emission is None: if emission is None:
# No emission is given, initialize the super class # No emission is given, initialize the super class
super().__init__(parent, transmittance_sqty) super().__init__(parent, transmittance_sqty)
else: else:
# Read the emission # Read the emission
emission_sqty = SpectralQty.fromFile(emission, wl_unit_default=u.nm, emission_sqty = SpectralQty.fromFile(emission, wl_unit_default=u.nm,
qty_unit_default=u.W / (u.m**2 * u.nm * u.sr)) qty_unit_default=u.W / (u.m ** 2 * u.nm * u.sr))
# Initialize the super class # Initialize the super class
super().__init__(parent, transmittance_sqty, emission_sqty) super().__init__(parent, transmittance_sqty, emission_sqty)

View File

@ -1,6 +1,6 @@
from .AHotOpticalComponent import AHotOpticalComponent from .AHotOpticalComponent import AHotOpticalComponent
from ..SpectralQty import SpectralQty from ..SpectralQty import SpectralQty
from ..ITransmissive import ITransmissive from ..IRadiant import IRadiant
from astropy import units as u from astropy import units as u
from typing import Union from typing import Union
@ -10,7 +10,7 @@ class BeamSplitter(AHotOpticalComponent):
A class to model the optical characteristics of a beam splitter. A class to model the optical characteristics of a beam splitter.
""" """
@u.quantity_input(temp=[u.Kelvin, u.Celsius], obstructor_temp=[u.Kelvin, u.Celsius]) @u.quantity_input(temp=[u.Kelvin, u.Celsius], obstructor_temp=[u.Kelvin, u.Celsius])
def __init__(self, parent: ITransmissive, transmittance: str, def __init__(self, parent: IRadiant, transmittance: str,
emissivity: Union[int, float, str] = 1, temp: u.Quantity = 0 * u.K, emissivity: Union[int, float, str] = 1, temp: u.Quantity = 0 * u.K,
obstruction: float = 0, obstructor_temp: u.Quantity = 0 * u.K, obstructor_emissivity: float = 1): obstruction: float = 0, obstructor_temp: u.Quantity = 0 * u.K, obstructor_emissivity: float = 1):
""" """
@ -18,7 +18,7 @@ class BeamSplitter(AHotOpticalComponent):
Parameters Parameters
---------- ----------
parent : ITransmissive parent : IRadiant
The parent element of the optical component from which the electromagnetic radiation is received. The parent element of the optical component from which the electromagnetic radiation is received.
transmittance : str transmittance : str
The spectral transmittance coefficients of the filter. The spectral transmittance coefficients of the filter.

View File

@ -1,6 +1,6 @@
from .AHotOpticalComponent import AHotOpticalComponent from .AHotOpticalComponent import AHotOpticalComponent
from ..SpectralQty import SpectralQty from ..SpectralQty import SpectralQty
from ..ITransmissive import ITransmissive from ..IRadiant import IRadiant
from ...lib.helpers import error from ...lib.helpers import error
from astropy import units as u from astropy import units as u
from typing import Union, Callable from typing import Union, Callable
@ -17,7 +17,7 @@ class Filter(AHotOpticalComponent):
H=dict(cwl=1630 * u.nm, bw=400 * u.nm), K=dict(cwl=2190 * u.nm, bw=600 * 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]) @u.quantity_input(temp=[u.Kelvin, u.Celsius], obstructor_temp=[u.Kelvin, u.Celsius])
def __init__(self, parent: ITransmissive, transmittance: Union[SpectralQty, Callable], def __init__(self, parent: IRadiant, transmittance: Union[SpectralQty, Callable],
emissivity: Union[int, float, str] = 1, temp: u.Quantity = 0 * u.K, emissivity: Union[int, float, str] = 1, temp: u.Quantity = 0 * u.K,
obstruction: float = 0, obstructor_temp: u.Quantity = 0 * u.K, obstructor_emissivity: float = 1): obstruction: float = 0, obstructor_temp: u.Quantity = 0 * u.K, obstructor_emissivity: float = 1):
""" """
@ -25,7 +25,7 @@ class Filter(AHotOpticalComponent):
Parameters Parameters
---------- ----------
parent : ITransmissive parent : IRadiant
The parent element of the optical component from which the electromagnetic radiation is received. The parent element of the optical component from which the electromagnetic radiation is received.
transmittance : Union[SpectralQty, Callable] transmittance : Union[SpectralQty, Callable]
The spectral transmittance coefficients of the filter. The spectral transmittance coefficients of the filter.
@ -48,7 +48,7 @@ class Filter(AHotOpticalComponent):
@classmethod @classmethod
# @u.quantity_input(temp=[u.Kelvin, u.Celsius], obstructor_temp=[u.Kelvin, u.Celsius]) # @u.quantity_input(temp=[u.Kelvin, u.Celsius], obstructor_temp=[u.Kelvin, u.Celsius])
def fromBand(cls, parent: ITransmissive, band: str, emissivity: Union[str, int, float] = 1, def fromBand(cls, parent: IRadiant, band: str, emissivity: Union[str, int, float] = 1,
temp: u.Quantity = 0 * u.K, obstruction: float = 0, obstructor_temp: u.Quantity = 0 * u.K, temp: u.Quantity = 0 * u.K, obstruction: float = 0, obstructor_temp: u.Quantity = 0 * u.K,
obstructor_emissivity: float = 1) -> "Filter": obstructor_emissivity: float = 1) -> "Filter":
""" """
@ -57,7 +57,7 @@ class Filter(AHotOpticalComponent):
Parameters Parameters
---------- ----------
parent : ITransmissive parent : IRadiant
The parent element of the optical component from which the electromagnetic radiation is received. The parent element of the optical component from which the electromagnetic radiation is received.
band : str band : str
The spectral band of the filter. Can be one of [U, B, V, R, I, J, H, K]. The spectral band of the filter. Can be one of [U, B, V, R, I, J, H, K].
@ -88,7 +88,7 @@ class Filter(AHotOpticalComponent):
@classmethod @classmethod
# @u.quantity_input(temp=[u.Kelvin, u.Celsius], obstructor_temp=[u.Kelvin, u.Celsius]) # @u.quantity_input(temp=[u.Kelvin, u.Celsius], obstructor_temp=[u.Kelvin, u.Celsius])
def fromFile(cls, parent: ITransmissive, transmittance: str, emissivity: Union[str, int, float] = 1, def fromFile(cls, parent: IRadiant, transmittance: str, emissivity: Union[str, int, float] = 1,
temp: u.Quantity = 0 * u.K, obstruction: float = 0, obstructor_temp: u.Quantity = 0 * u.K, temp: u.Quantity = 0 * u.K, obstruction: float = 0, obstructor_temp: u.Quantity = 0 * u.K,
obstructor_emissivity: float = 1) -> "Filter": obstructor_emissivity: float = 1) -> "Filter":
""" """
@ -96,7 +96,7 @@ class Filter(AHotOpticalComponent):
Parameters Parameters
---------- ----------
parent : ITransmissive parent : IRadiant
The parent element of the optical component from which the electromagnetic radiation is received. The parent element of the optical component from which the electromagnetic radiation is received.
transmittance : str transmittance : str
Path to the file containing the spectral transmittance-coefficients of the filter element. Path to the file containing the spectral transmittance-coefficients of the filter element.
@ -125,7 +125,7 @@ class Filter(AHotOpticalComponent):
@classmethod @classmethod
# @u.quantity_input(start="length", end="length", temp=[u.Kelvin, u.Celsius], obstructor_temp=[u.Kelvin, u.Celsius]) # @u.quantity_input(start="length", end="length", temp=[u.Kelvin, u.Celsius], obstructor_temp=[u.Kelvin, u.Celsius])
def fromRange(cls, parent: ITransmissive, start: u.Quantity, end: u.Quantity, def fromRange(cls, parent: IRadiant, start: u.Quantity, end: u.Quantity,
emissivity: Union[str, int, float] = 1, temp: u.Quantity = 0 * u.K, obstruction: float = 0, emissivity: Union[str, int, float] = 1, temp: u.Quantity = 0 * u.K, obstruction: float = 0,
obstructor_temp: u.Quantity = 0 * u.K, obstructor_emissivity: float = 1) -> "Filter": obstructor_temp: u.Quantity = 0 * u.K, obstructor_emissivity: float = 1) -> "Filter":
""" """
@ -134,7 +134,7 @@ class Filter(AHotOpticalComponent):
Parameters Parameters
---------- ----------
parent : ITransmissive parent : IRadiant
The parent element of the optical component from which the electromagnetic radiation is received. The parent element of the optical component from which the electromagnetic radiation is received.
start : length-quantity start : length-quantity
Start wavelength of the pass-band Start wavelength of the pass-band

View File

@ -1,6 +1,6 @@
from .AHotOpticalComponent import AHotOpticalComponent from .AHotOpticalComponent import AHotOpticalComponent
from ..SpectralQty import SpectralQty from ..SpectralQty import SpectralQty
from ..ITransmissive import ITransmissive from ..IRadiant import IRadiant
from astropy import units as u from astropy import units as u
from typing import Union from typing import Union
@ -10,7 +10,7 @@ class Lens(AHotOpticalComponent):
A class to model the optical characteristics of a lens. A class to model the optical characteristics of a lens.
""" """
@u.quantity_input(temp=[u.Kelvin, u.Celsius], obstructor_temp=[u.Kelvin, u.Celsius]) @u.quantity_input(temp=[u.Kelvin, u.Celsius], obstructor_temp=[u.Kelvin, u.Celsius])
def __init__(self, parent: ITransmissive, transmittance: str, def __init__(self, parent: IRadiant, transmittance: str,
emissivity: Union[int, float, str] = 1, temp: u.Quantity = 0 * u.K, emissivity: Union[int, float, str] = 1, temp: u.Quantity = 0 * u.K,
obstruction: float = 0, obstructor_temp: u.Quantity = 0 * u.K, obstructor_emissivity: float = 1): obstruction: float = 0, obstructor_temp: u.Quantity = 0 * u.K, obstructor_emissivity: float = 1):
""" """
@ -18,7 +18,7 @@ class Lens(AHotOpticalComponent):
Parameters Parameters
---------- ----------
parent : ITransmissive parent : IRadiant
The parent element of the optical component from which the electromagnetic radiation is received. The parent element of the optical component from which the electromagnetic radiation is received.
transmittance : str transmittance : str
The spectral transmittance coefficients of the filter. The spectral transmittance coefficients of the filter.

View File

@ -1,6 +1,6 @@
from .AHotOpticalComponent import AHotOpticalComponent from .AHotOpticalComponent import AHotOpticalComponent
from ..SpectralQty import SpectralQty from ..SpectralQty import SpectralQty
from ..ITransmissive import ITransmissive from ..IRadiant import IRadiant
from astropy import units as u from astropy import units as u
from typing import Union from typing import Union
@ -10,7 +10,7 @@ class Mirror(AHotOpticalComponent):
A class to model the optical characteristics of a mirror. A class to model the optical characteristics of a mirror.
""" """
@u.quantity_input(temp=[u.Kelvin, u.Celsius], obstructor_temp=[u.Kelvin, u.Celsius]) @u.quantity_input(temp=[u.Kelvin, u.Celsius], obstructor_temp=[u.Kelvin, u.Celsius])
def __init__(self, parent: ITransmissive, reflectance: str, def __init__(self, parent: IRadiant, reflectance: str,
emissivity: Union[int, float, str] = 1, temp: u.Quantity = 0 * u.K, emissivity: Union[int, float, str] = 1, temp: u.Quantity = 0 * u.K,
obstruction: float = 0, obstructor_temp: u.Quantity = 0 * u.K, obstructor_emissivity: float = 1): obstruction: float = 0, obstructor_temp: u.Quantity = 0 * u.K, obstructor_emissivity: float = 1):
""" """
@ -18,7 +18,7 @@ class Mirror(AHotOpticalComponent):
Parameters Parameters
---------- ----------
parent : ITransmissive parent : IRadiant
The parent element of the optical component from which the electromagnetic radiation is received. The parent element of the optical component from which the electromagnetic radiation is received.
reflectance : str reflectance : str
The spectral transmittance coefficients of the filter. The spectral transmittance coefficients of the filter.

View File

@ -1,6 +1,6 @@
from esbo_etc.classes.optical_component.AOpticalComponent import AOpticalComponent from .AOpticalComponent import AOpticalComponent
from esbo_etc.classes.ITransmissive import ITransmissive from ..IRadiant import IRadiant
from esbo_etc.classes.SpectralQty import SpectralQty from ..SpectralQty import SpectralQty
import astropy.units as u import astropy.units as u
@ -8,13 +8,14 @@ class StrayLight(AOpticalComponent):
""" """
A class to model additional stray light sources e.g. zodiacal light A class to model additional stray light sources e.g. zodiacal light
""" """
def __init__(self, parent: ITransmissive, emission: str = None) -> "Atmosphere":
def __init__(self, parent: IRadiant, emission: str = None):
""" """
Initialize a new stray light source Initialize a new stray light source
Parameters Parameters
---------- ----------
parent : ITransmissive parent : IRadiant
The parent element from which the electromagnetic radiation is received. The parent element from which the electromagnetic radiation is received.
This element is usually of type Target or StrayLight. This element is usually of type Target or StrayLight.
emission : str emission : str
@ -23,6 +24,6 @@ class StrayLight(AOpticalComponent):
""" """
# Read the emission # Read the emission
emission_sqty = SpectralQty.fromFile(emission, wl_unit_default=u.nm, emission_sqty = SpectralQty.fromFile(emission, wl_unit_default=u.nm,
qty_unit_default=u.W / (u.m**2 * u.nm * u.sr)) qty_unit_default=u.W / (u.m ** 2 * u.nm * u.sr))
# Initialize the super class # Initialize the super class
super().__init__(parent, 1.0, emission_sqty) super().__init__(parent, 1.0, emission_sqty)

View File

@ -1,10 +1,11 @@
from abc import abstractmethod from abc import abstractmethod
from ..ITransmissive import ITransmissive from ..IRadiant import IRadiant
from ..SpectralQty import SpectralQty from ..SpectralQty import SpectralQty
import astropy.units as u import astropy.units as u
import numpy as np
class ATarget(ITransmissive): class ATarget(IRadiant):
""" """
Abstract super class for target models Abstract super class for target models
""" """
@ -30,7 +31,7 @@ class ATarget(ITransmissive):
noise : SpectralQty noise : SpectralQty
The spectral radiance of the target's noise The spectral radiance of the target's noise
""" """
return SpectralQty(self._sfd.wl, [0] * len(self._sfd.wl) << u.W / (u.m**2 * u.nm * u.sr)) return SpectralQty(self._sfd.wl, np.repeat(0, len(self._sfd.wl)) << u.W / (u.m**2 * u.nm * u.sr))
def calcSignal(self) -> SpectralQty: def calcSignal(self) -> SpectralQty:
""" """
@ -42,4 +43,3 @@ class ATarget(ITransmissive):
The spectral flux density of the target's signal The spectral flux density of the target's signal
""" """
return self._sfd return self._sfd

View File

@ -2,7 +2,7 @@ from ..target.ATarget import ATarget
from ..SpectralQty import SpectralQty from ..SpectralQty import SpectralQty
import astropy.units as u import astropy.units as u
from astropy.modeling.models import BlackBody from astropy.modeling.models import BlackBody
from esbo_etc.lib.helpers import error from ...lib.helpers import error
class BlackBodyTarget(ATarget): class BlackBodyTarget(ATarget):

View File

@ -1,8 +1,6 @@
from ..target.ATarget import ATarget from ..target.ATarget import ATarget
from ..SpectralQty import SpectralQty from ..SpectralQty import SpectralQty
import astropy.units as u import astropy.units as u
from astropy.io import ascii
import re
class FileTarget(ATarget): class FileTarget(ATarget):
@ -19,8 +17,8 @@ class FileTarget(ATarget):
file : str file : str
The file to read the spectral flux density values from. The file needs to provide two columns: wavelength The file to read the spectral flux density values from. The file needs to provide two columns: wavelength
and the corresponding spectral flux density. The format of the file will be guessed by and the corresponding spectral flux density. The format of the file will be guessed by
`astropy.io.ascii.read(). If the file doesn't provide units via astropy's enhanced CSV format, the units will `astropy.io.ascii.read(). If the file doesn't provide units via astropy's enhanced CSV format, the units
be read from the column headers or otherwise assumed to be *nm* and *W / m^2 / nm*. will be read from the column headers or otherwise assumed to be *nm* and *W / m^2 / nm*.
""" """
# Create spectral quantity from file # Create spectral quantity from file
sfd = SpectralQty.fromFile(file, u.nm, u.W / (u.m ** 2 * u.nm)) sfd = SpectralQty.fromFile(file, u.nm, u.W / (u.m ** 2 * u.nm))

View File

@ -1,9 +1,6 @@
import logging import logging
import sys import sys
import traceback import traceback
import astropy.units as u
from astropy.modeling.models import BlackBody
from typing import Union
def error(msg: str, exit_: bool = True): def error(msg: str, exit_: bool = True):
@ -41,5 +38,4 @@ def isLambda(v: object):
res : bool res : bool
Result of the check Result of the check
""" """
LAMBDA = lambda: 0 return isinstance(v, type(lambda: None)) and v.__name__ == (lambda: None).__name__
return isinstance(v, type(LAMBDA)) and v.__name__ == LAMBDA.__name__

View File

@ -0,0 +1,5 @@
wavelength,spectral emissivity
201,0.5
202,0.5
203,0.5
204,0.5
1 wavelength spectral emissivity
2 201 0.5
3 202 0.5
4 203 0.5
5 204 0.5

View File

@ -1,15 +1,16 @@
from unittest import TestCase from unittest import TestCase
from esbo_etc.classes.optical_component.AHotOpticalComponent import AHotOpticalComponent from esbo_etc.classes.optical_component.AHotOpticalComponent import AHotOpticalComponent
from esbo_etc.classes.ITransmissive import ITransmissive from esbo_etc.classes.IRadiant import IRadiant
from esbo_etc.classes.SpectralQty import SpectralQty from esbo_etc.classes.SpectralQty import SpectralQty
from esbo_etc.classes.target.FileTarget import FileTarget from esbo_etc.classes.target.FileTarget import FileTarget
import astropy.units as u import astropy.units as u
import numpy as np import numpy as np
from typing import Union
class HotOpticalComponent(AHotOpticalComponent): class HotOpticalComponent(AHotOpticalComponent):
def __init__(self, parent: ITransmissive, emissivity: SpectralQty, temp: u.Quantity, obstruction: float = 0, def __init__(self, parent: IRadiant, emissivity: Union[SpectralQty, int, float, str], temp: u.Quantity,
obstructor_temp: u.Quantity = 0 * u.K, obstructor_emissivity: float = 1): obstruction: float = 0, obstructor_temp: u.Quantity = 0 * u.K, obstructor_emissivity: float = 1):
super().__init__(parent, emissivity, temp, obstruction, obstructor_temp, obstructor_emissivity) super().__init__(parent, emissivity, temp, obstruction, obstructor_temp, obstructor_emissivity)
def propagate(self, sqty: SpectralQty) -> SpectralQty: def propagate(self, sqty: SpectralQty) -> SpectralQty:
@ -20,9 +21,14 @@ class TestAHotOpticalComponent(TestCase):
wl = np.arange(201, 205, 1) << u.nm wl = np.arange(201, 205, 1) << u.nm
def setUp(self): def setUp(self):
self.target = FileTarget("../data/target/target_demo_1.csv") self.target = FileTarget("data/target/target_demo_1.csv")
self.comp = HotOpticalComponent(self.target, SpectralQty(self.wl, [0.5] * 4), temp=300 * u.K)
def test___init__(self): def test___init__(self):
self.assertEqual(self.comp.calcNoise(), SpectralQty(self.wl, [4.31413931e-96, 1.37122214e-95, 4.30844544e-95, comp = HotOpticalComponent(self.target, SpectralQty(self.wl, np.repeat(0.5, 4) << u.dimensionless_unscaled),
1.33846280e-94] << u.W / (u.m**2 * u.nm * u.sr))) temp=300 * u.K)
self.assertEqual(comp.calcNoise(), SpectralQty(self.wl, [4.31413931e-96, 1.37122214e-95, 4.30844544e-95,
1.33846280e-94] << u.W / (u.m ** 2 * u.nm * u.sr)))
comp = HotOpticalComponent(self.target, "data/mirror/mirror_emissivity.csv", temp=300 * u.K)
self.assertEqual(comp.calcNoise(), SpectralQty(self.wl, [4.31413931e-96, 1.37122214e-95, 4.30844544e-95,
1.33846280e-94] << u.W / (u.m ** 2 * u.nm * u.sr)))

View File

@ -5,7 +5,7 @@ import numpy as np
class OpticalComponent(AOpticalComponent): class OpticalComponent(AOpticalComponent):
def __init__(self, parent: ITransmissive, transreflectivity: SpectralQty = None, def __init__(self, parent: IRadiant, transreflectivity: SpectralQty = None,
noise: SpectralQty = None, obstruction: float = 0, obstructor_temp: u.Quantity = 0 * u.K, noise: SpectralQty = None, obstruction: float = 0, obstructor_temp: u.Quantity = 0 * u.K,
obstructor_emissivity: float = 0): obstructor_emissivity: float = 0):
super().__init__(parent, transreflectivity, noise, obstruction, obstructor_temp, obstructor_emissivity) super().__init__(parent, transreflectivity, noise, obstruction, obstructor_temp, obstructor_emissivity)

View File

@ -6,7 +6,7 @@ import astropy.units as u
class TestAtmosphere(TestCase): class TestAtmosphere(TestCase):
def setUp(self): def setUp(self):
self.target = FileTarget("../data/target/target_demo_1.csv") self.target = FileTarget("data/target/target_demo_1.csv")
self.atmosphere = Atmosphere(self.target, "data/atmosphere/atmosphere_transmittance_1.csv", self.atmosphere = Atmosphere(self.target, "data/atmosphere/atmosphere_transmittance_1.csv",
"data/atmosphere/atmosphere_emission_1.csv") "data/atmosphere/atmosphere_emission_1.csv")

View File

@ -10,7 +10,7 @@ class TestBeamSplitter(TestCase):
wl = np.arange(201, 205, 1) << u.nm wl = np.arange(201, 205, 1) << u.nm
def setUp(self): def setUp(self):
self.target = FileTarget("../data/target/target_demo_1.csv") self.target = FileTarget("data/target/target_demo_1.csv")
self.splitter = BeamSplitter(self.target, "data/beamsplitter/beamsplitter_transmittance.csv", 0.5, self.splitter = BeamSplitter(self.target, "data/beamsplitter/beamsplitter_transmittance.csv", 0.5,
temp=300 * u.K) temp=300 * u.K)

View File

@ -13,7 +13,7 @@ class TestFilter(TestCase):
0.0, 0.0] << u.W / (u.m ** 2 * u.nm))) 0.0, 0.0] << u.W / (u.m ** 2 * u.nm)))
def test_fromFile(self): def test_fromFile(self):
target = FileTarget("../data/target/target_demo_1.csv") target = FileTarget("data/target/target_demo_1.csv")
filt = Filter.fromFile(target, "data/filter/filter_transmittance.csv") filt = Filter.fromFile(target, "data/filter/filter_transmittance.csv")
self.assertEqual(filt.calcSignal(), SpectralQty(np.arange(200, 210, 1) << u.nm, self.assertEqual(filt.calcSignal(), SpectralQty(np.arange(200, 210, 1) << u.nm,
[1.10e-15, 1.20e-15, 1.30e-15, 1.40e-15, 1.35e-15, 1.44e-15, [1.10e-15, 1.20e-15, 1.30e-15, 1.40e-15, 1.35e-15, 1.44e-15,

View File

@ -10,7 +10,7 @@ class TestLens(TestCase):
wl = np.arange(201, 205, 1) << u.nm wl = np.arange(201, 205, 1) << u.nm
def setUp(self): def setUp(self):
self.target = FileTarget("../data/target/target_demo_1.csv") self.target = FileTarget("data/target/target_demo_1.csv")
self.lens = Lens(self.target, "data/lens/lens_transmittance.csv", 0.5, temp=300 * u.K) self.lens = Lens(self.target, "data/lens/lens_transmittance.csv", 0.5, temp=300 * u.K)
def test___init__(self): def test___init__(self):

View File

@ -10,7 +10,7 @@ class TestMirror(TestCase):
wl = np.arange(201, 205, 1) << u.nm wl = np.arange(201, 205, 1) << u.nm
def setUp(self): def setUp(self):
self.target = FileTarget("../data/target/target_demo_1.csv") self.target = FileTarget("data/target/target_demo_1.csv")
self.mirror = Mirror(self.target, "data/mirror/mirror_reflectance.csv", 0.5, temp=300 * u.K) self.mirror = Mirror(self.target, "data/mirror/mirror_reflectance.csv", 0.5, temp=300 * u.K)
def test___init__(self): def test___init__(self):

View File

@ -6,7 +6,7 @@ import astropy.units as u
class TestStrayLight(TestCase): class TestStrayLight(TestCase):
def setUp(self): def setUp(self):
self.target = FileTarget("../data/target/target_demo_1.csv") self.target = FileTarget("data/target/target_demo_1.csv")
self.zodiac = StrayLight(self.target, "data/straylight/zodiacal_emission_1.csv") self.zodiac = StrayLight(self.target, "data/straylight/zodiacal_emission_1.csv")
def test_calcSignal(self): def test_calcSignal(self):

View File

@ -116,6 +116,4 @@ class TestSpectralQty(TestCase):
self.assertEqual(sqty, res) self.assertEqual(sqty, res)
sqty = SpectralQty.fromFile("data/target/target_demo_2.csv", u.nm, u.W / (u.m ** 2 * u.nm)) sqty = SpectralQty.fromFile("data/target/target_demo_2.csv", u.nm, u.W / (u.m ** 2 * u.nm))
print(sqty.wl)
print(sqty.qty)
self.assertEqual(sqty, res) self.assertEqual(sqty, res)