Code clean up
This commit is contained in:
parent
03b4870918
commit
d1eb1c5738
31
esbo_etc/classes/IRadiant.py
Normal file
31
esbo_etc/classes/IRadiant.py
Normal 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
|
@ -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
|
@ -1,5 +1,5 @@
|
||||
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.target import *
|
||||
from esbo_etc.classes.optical_component import *
|
||||
|
@ -3,23 +3,28 @@ import numpy as np
|
||||
import astropy.units as u
|
||||
import os
|
||||
import logging
|
||||
from esbo_etc.lib.helpers import error
|
||||
from ..lib.helpers import error
|
||||
from typing import Union
|
||||
|
||||
|
||||
class Entry(object):
|
||||
"""
|
||||
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):
|
||||
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
|
||||
|
||||
: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
|
||||
for attrib in xml.attrib.keys():
|
||||
@ -30,8 +35,6 @@ class Entry(object):
|
||||
try:
|
||||
self.val = u.Quantity(list(map(float, self.val.split(','))),
|
||||
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:
|
||||
self.val = self.val[0]
|
||||
except (ValueError, LookupError):
|
||||
@ -52,7 +55,7 @@ class Configuration(object):
|
||||
"""
|
||||
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.
|
||||
|
||||
@ -60,8 +63,6 @@ class Configuration(object):
|
||||
----------
|
||||
filename : str
|
||||
configuration file to parse
|
||||
default_path : str
|
||||
default path to use for relative paths
|
||||
"""
|
||||
|
||||
# Check if configuration file exists
|
||||
@ -111,18 +112,12 @@ class Configuration(object):
|
||||
def calc_metaoptions(self):
|
||||
"""
|
||||
Calculate additional attributes e.g. the wavelength grid
|
||||
Returns
|
||||
-------
|
||||
|
||||
"""
|
||||
self.calc_metaoption_wl_delta()
|
||||
|
||||
def calc_metaoption_wl_delta(self):
|
||||
"""
|
||||
Calculate the wavelength grid used for the calculations.
|
||||
Returns
|
||||
-------
|
||||
|
||||
"""
|
||||
if hasattr(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,
|
||||
self.conf.common.wl_max().to(u.micron).value,
|
||||
wl_delta.to(u.micron).value) * u.micron)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
conf = Configuration()
|
||||
|
@ -1,5 +1,5 @@
|
||||
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 abc import abstractmethod
|
||||
import astropy.units as u
|
||||
@ -13,14 +13,14 @@ class AHotOpticalComponent(AOpticalComponent):
|
||||
"""
|
||||
@abstractmethod
|
||||
@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):
|
||||
"""
|
||||
Initialize a new optical component with thermal emission
|
||||
|
||||
Parameters
|
||||
----------
|
||||
parent : ITransmissive
|
||||
parent : IRadiant
|
||||
The parent element of the optical component from which the electromagnetic radiation is received.
|
||||
emissivity : Union[SpectralQty, int, float, str]
|
||||
The spectral emissivity coefficient for the optical surface.
|
||||
@ -47,7 +47,7 @@ class AHotOpticalComponent(AOpticalComponent):
|
||||
elif isinstance(emissivity, str):
|
||||
em = SpectralQty.fromFile(emissivity, u.nm, u.dimensionless_unscaled)
|
||||
bb = self._gb_factory(temp)
|
||||
self._noise = SpectralQty(emissivity.wl, bb(emissivity.wl)) * em
|
||||
self._noise = SpectralQty(em.wl, bb(em.wl)) * em
|
||||
else:
|
||||
bb = self._gb_factory(temp, emissivity)
|
||||
self._noise = bb
|
||||
|
@ -1,20 +1,20 @@
|
||||
from ..ITransmissive import ITransmissive
|
||||
from abc import abstractmethod
|
||||
from ..IRadiant import IRadiant
|
||||
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
|
||||
from astropy.modeling.models import BlackBody
|
||||
from typing import Union, Callable
|
||||
|
||||
|
||||
class AOpticalComponent(ITransmissive):
|
||||
class AOpticalComponent(IRadiant):
|
||||
"""
|
||||
Abstract super class for an optical component
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
@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,
|
||||
obstructor_temp: u.Quantity = 0 * u.K, obstructor_emissivity: float = 1):
|
||||
"""
|
||||
@ -22,7 +22,7 @@ class AOpticalComponent(ITransmissive):
|
||||
|
||||
Parameters
|
||||
----------
|
||||
parent : ITransmissive
|
||||
parent : IRadiant
|
||||
The parent element of the optical component from which the electromagnetic radiation is received
|
||||
transreflectivity : SpectralQty
|
||||
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)
|
||||
return noise + self.ownNoise()
|
||||
|
||||
|
||||
def propagate(self, sqty: SpectralQty) -> SpectralQty:
|
||||
"""
|
||||
Propagate incoming radiation through the optical component
|
||||
|
@ -1,6 +1,6 @@
|
||||
from esbo_etc.classes.optical_component.AOpticalComponent import AOpticalComponent
|
||||
from esbo_etc.classes.ITransmissive import ITransmissive
|
||||
from esbo_etc.classes.SpectralQty import SpectralQty
|
||||
from .AOpticalComponent import AOpticalComponent
|
||||
from ..IRadiant import IRadiant
|
||||
from ..SpectralQty import SpectralQty
|
||||
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.
|
||||
"""
|
||||
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
|
||||
|
||||
Parameters
|
||||
----------
|
||||
parent : ITransmissive
|
||||
parent : IRadiant
|
||||
The parent element of the atmosphere from which the electromagnetic radiation is received.
|
||||
This element is usually of type Target or StrayLight.
|
||||
transmittance : str
|
||||
@ -26,13 +27,13 @@ class Atmosphere(AOpticalComponent):
|
||||
"""
|
||||
# Read the transmittance
|
||||
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:
|
||||
# No emission is given, initialize the super class
|
||||
super().__init__(parent, transmittance_sqty)
|
||||
else:
|
||||
# Read the emission
|
||||
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
|
||||
super().__init__(parent, transmittance_sqty, emission_sqty)
|
||||
|
@ -1,6 +1,6 @@
|
||||
from .AHotOpticalComponent import AHotOpticalComponent
|
||||
from ..SpectralQty import SpectralQty
|
||||
from ..ITransmissive import ITransmissive
|
||||
from ..IRadiant import IRadiant
|
||||
from astropy import units as u
|
||||
from typing import Union
|
||||
|
||||
@ -10,7 +10,7 @@ class BeamSplitter(AHotOpticalComponent):
|
||||
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])
|
||||
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,
|
||||
obstruction: float = 0, obstructor_temp: u.Quantity = 0 * u.K, obstructor_emissivity: float = 1):
|
||||
"""
|
||||
@ -18,7 +18,7 @@ class BeamSplitter(AHotOpticalComponent):
|
||||
|
||||
Parameters
|
||||
----------
|
||||
parent : ITransmissive
|
||||
parent : IRadiant
|
||||
The parent element of the optical component from which the electromagnetic radiation is received.
|
||||
transmittance : str
|
||||
The spectral transmittance coefficients of the filter.
|
||||
|
@ -1,6 +1,6 @@
|
||||
from .AHotOpticalComponent import AHotOpticalComponent
|
||||
from ..SpectralQty import SpectralQty
|
||||
from ..ITransmissive import ITransmissive
|
||||
from ..IRadiant import IRadiant
|
||||
from ...lib.helpers import error
|
||||
from astropy import units as u
|
||||
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))
|
||||
|
||||
@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,
|
||||
obstruction: float = 0, obstructor_temp: u.Quantity = 0 * u.K, obstructor_emissivity: float = 1):
|
||||
"""
|
||||
@ -25,7 +25,7 @@ class Filter(AHotOpticalComponent):
|
||||
|
||||
Parameters
|
||||
----------
|
||||
parent : ITransmissive
|
||||
parent : IRadiant
|
||||
The parent element of the optical component from which the electromagnetic radiation is received.
|
||||
transmittance : Union[SpectralQty, Callable]
|
||||
The spectral transmittance coefficients of the filter.
|
||||
@ -48,7 +48,7 @@ class Filter(AHotOpticalComponent):
|
||||
|
||||
@classmethod
|
||||
# @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,
|
||||
obstructor_emissivity: float = 1) -> "Filter":
|
||||
"""
|
||||
@ -57,7 +57,7 @@ class Filter(AHotOpticalComponent):
|
||||
|
||||
Parameters
|
||||
----------
|
||||
parent : ITransmissive
|
||||
parent : IRadiant
|
||||
The parent element of the optical component from which the electromagnetic radiation is received.
|
||||
band : str
|
||||
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
|
||||
# @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,
|
||||
obstructor_emissivity: float = 1) -> "Filter":
|
||||
"""
|
||||
@ -96,7 +96,7 @@ class Filter(AHotOpticalComponent):
|
||||
|
||||
Parameters
|
||||
----------
|
||||
parent : ITransmissive
|
||||
parent : IRadiant
|
||||
The parent element of the optical component from which the electromagnetic radiation is received.
|
||||
transmittance : str
|
||||
Path to the file containing the spectral transmittance-coefficients of the filter element.
|
||||
@ -125,7 +125,7 @@ class Filter(AHotOpticalComponent):
|
||||
|
||||
@classmethod
|
||||
# @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,
|
||||
obstructor_temp: u.Quantity = 0 * u.K, obstructor_emissivity: float = 1) -> "Filter":
|
||||
"""
|
||||
@ -134,7 +134,7 @@ class Filter(AHotOpticalComponent):
|
||||
|
||||
Parameters
|
||||
----------
|
||||
parent : ITransmissive
|
||||
parent : IRadiant
|
||||
The parent element of the optical component from which the electromagnetic radiation is received.
|
||||
start : length-quantity
|
||||
Start wavelength of the pass-band
|
||||
|
@ -1,6 +1,6 @@
|
||||
from .AHotOpticalComponent import AHotOpticalComponent
|
||||
from ..SpectralQty import SpectralQty
|
||||
from ..ITransmissive import ITransmissive
|
||||
from ..IRadiant import IRadiant
|
||||
from astropy import units as u
|
||||
from typing import Union
|
||||
|
||||
@ -10,7 +10,7 @@ class Lens(AHotOpticalComponent):
|
||||
A class to model the optical characteristics of a lens.
|
||||
"""
|
||||
@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,
|
||||
obstruction: float = 0, obstructor_temp: u.Quantity = 0 * u.K, obstructor_emissivity: float = 1):
|
||||
"""
|
||||
@ -18,7 +18,7 @@ class Lens(AHotOpticalComponent):
|
||||
|
||||
Parameters
|
||||
----------
|
||||
parent : ITransmissive
|
||||
parent : IRadiant
|
||||
The parent element of the optical component from which the electromagnetic radiation is received.
|
||||
transmittance : str
|
||||
The spectral transmittance coefficients of the filter.
|
||||
|
@ -1,6 +1,6 @@
|
||||
from .AHotOpticalComponent import AHotOpticalComponent
|
||||
from ..SpectralQty import SpectralQty
|
||||
from ..ITransmissive import ITransmissive
|
||||
from ..IRadiant import IRadiant
|
||||
from astropy import units as u
|
||||
from typing import Union
|
||||
|
||||
@ -10,7 +10,7 @@ class Mirror(AHotOpticalComponent):
|
||||
A class to model the optical characteristics of a mirror.
|
||||
"""
|
||||
@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,
|
||||
obstruction: float = 0, obstructor_temp: u.Quantity = 0 * u.K, obstructor_emissivity: float = 1):
|
||||
"""
|
||||
@ -18,7 +18,7 @@ class Mirror(AHotOpticalComponent):
|
||||
|
||||
Parameters
|
||||
----------
|
||||
parent : ITransmissive
|
||||
parent : IRadiant
|
||||
The parent element of the optical component from which the electromagnetic radiation is received.
|
||||
reflectance : str
|
||||
The spectral transmittance coefficients of the filter.
|
||||
|
@ -1,6 +1,6 @@
|
||||
from esbo_etc.classes.optical_component.AOpticalComponent import AOpticalComponent
|
||||
from esbo_etc.classes.ITransmissive import ITransmissive
|
||||
from esbo_etc.classes.SpectralQty import SpectralQty
|
||||
from .AOpticalComponent import AOpticalComponent
|
||||
from ..IRadiant import IRadiant
|
||||
from ..SpectralQty import SpectralQty
|
||||
import astropy.units as u
|
||||
|
||||
|
||||
@ -8,13 +8,14 @@ class StrayLight(AOpticalComponent):
|
||||
"""
|
||||
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
|
||||
|
||||
Parameters
|
||||
----------
|
||||
parent : ITransmissive
|
||||
parent : IRadiant
|
||||
The parent element from which the electromagnetic radiation is received.
|
||||
This element is usually of type Target or StrayLight.
|
||||
emission : str
|
||||
@ -23,6 +24,6 @@ class StrayLight(AOpticalComponent):
|
||||
"""
|
||||
# Read the emission
|
||||
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
|
||||
super().__init__(parent, 1.0, emission_sqty)
|
||||
|
@ -1,10 +1,11 @@
|
||||
from abc import abstractmethod
|
||||
from ..ITransmissive import ITransmissive
|
||||
from ..IRadiant import IRadiant
|
||||
from ..SpectralQty import SpectralQty
|
||||
import astropy.units as u
|
||||
import numpy as np
|
||||
|
||||
|
||||
class ATarget(ITransmissive):
|
||||
class ATarget(IRadiant):
|
||||
"""
|
||||
Abstract super class for target models
|
||||
"""
|
||||
@ -30,7 +31,7 @@ class ATarget(ITransmissive):
|
||||
noise : SpectralQty
|
||||
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:
|
||||
"""
|
||||
@ -42,4 +43,3 @@ class ATarget(ITransmissive):
|
||||
The spectral flux density of the target's signal
|
||||
"""
|
||||
return self._sfd
|
||||
|
||||
|
@ -2,7 +2,7 @@ from ..target.ATarget import ATarget
|
||||
from ..SpectralQty import SpectralQty
|
||||
import astropy.units as u
|
||||
from astropy.modeling.models import BlackBody
|
||||
from esbo_etc.lib.helpers import error
|
||||
from ...lib.helpers import error
|
||||
|
||||
|
||||
class BlackBodyTarget(ATarget):
|
||||
|
@ -1,8 +1,6 @@
|
||||
from ..target.ATarget import ATarget
|
||||
from ..SpectralQty import SpectralQty
|
||||
import astropy.units as u
|
||||
from astropy.io import ascii
|
||||
import re
|
||||
|
||||
|
||||
class FileTarget(ATarget):
|
||||
@ -19,8 +17,8 @@ class FileTarget(ATarget):
|
||||
file : str
|
||||
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
|
||||
`astropy.io.ascii.read(). If the file doesn't provide units via astropy's enhanced CSV format, the units will
|
||||
be read from the column headers or otherwise assumed to be *nm* and *W / m^2 / nm*.
|
||||
`astropy.io.ascii.read(). If the file doesn't provide units via astropy's enhanced CSV format, the units
|
||||
will be read from the column headers or otherwise assumed to be *nm* and *W / m^2 / nm*.
|
||||
"""
|
||||
# Create spectral quantity from file
|
||||
sfd = SpectralQty.fromFile(file, u.nm, u.W / (u.m ** 2 * u.nm))
|
||||
|
@ -1,9 +1,6 @@
|
||||
import logging
|
||||
import sys
|
||||
import traceback
|
||||
import astropy.units as u
|
||||
from astropy.modeling.models import BlackBody
|
||||
from typing import Union
|
||||
|
||||
|
||||
def error(msg: str, exit_: bool = True):
|
||||
@ -41,5 +38,4 @@ def isLambda(v: object):
|
||||
res : bool
|
||||
Result of the check
|
||||
"""
|
||||
LAMBDA = lambda: 0
|
||||
return isinstance(v, type(LAMBDA)) and v.__name__ == LAMBDA.__name__
|
||||
return isinstance(v, type(lambda: None)) and v.__name__ == (lambda: None).__name__
|
||||
|
5
tests/data/mirror/mirror_emissivity.csv
Normal file
5
tests/data/mirror/mirror_emissivity.csv
Normal file
@ -0,0 +1,5 @@
|
||||
wavelength,spectral emissivity
|
||||
201,0.5
|
||||
202,0.5
|
||||
203,0.5
|
||||
204,0.5
|
|
@ -1,15 +1,16 @@
|
||||
from unittest import TestCase
|
||||
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.target.FileTarget import FileTarget
|
||||
import astropy.units as u
|
||||
import numpy as np
|
||||
from typing import Union
|
||||
|
||||
|
||||
class HotOpticalComponent(AHotOpticalComponent):
|
||||
def __init__(self, parent: ITransmissive, emissivity: SpectralQty, temp: u.Quantity, obstruction: float = 0,
|
||||
obstructor_temp: u.Quantity = 0 * u.K, obstructor_emissivity: float = 1):
|
||||
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):
|
||||
super().__init__(parent, emissivity, temp, obstruction, obstructor_temp, obstructor_emissivity)
|
||||
|
||||
def propagate(self, sqty: SpectralQty) -> SpectralQty:
|
||||
@ -20,9 +21,14 @@ class TestAHotOpticalComponent(TestCase):
|
||||
wl = np.arange(201, 205, 1) << u.nm
|
||||
|
||||
def setUp(self):
|
||||
self.target = FileTarget("../data/target/target_demo_1.csv")
|
||||
self.comp = HotOpticalComponent(self.target, SpectralQty(self.wl, [0.5] * 4), temp=300 * u.K)
|
||||
self.target = FileTarget("data/target/target_demo_1.csv")
|
||||
|
||||
def test___init__(self):
|
||||
self.assertEqual(self.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, SpectralQty(self.wl, np.repeat(0.5, 4) << u.dimensionless_unscaled),
|
||||
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)))
|
||||
|
@ -5,7 +5,7 @@ import numpy as np
|
||||
|
||||
|
||||
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,
|
||||
obstructor_emissivity: float = 0):
|
||||
super().__init__(parent, transreflectivity, noise, obstruction, obstructor_temp, obstructor_emissivity)
|
||||
|
@ -6,7 +6,7 @@ import astropy.units as u
|
||||
|
||||
class TestAtmosphere(TestCase):
|
||||
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",
|
||||
"data/atmosphere/atmosphere_emission_1.csv")
|
||||
|
||||
|
@ -10,7 +10,7 @@ class TestBeamSplitter(TestCase):
|
||||
wl = np.arange(201, 205, 1) << u.nm
|
||||
|
||||
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,
|
||||
temp=300 * u.K)
|
||||
|
||||
|
@ -13,7 +13,7 @@ class TestFilter(TestCase):
|
||||
0.0, 0.0] << u.W / (u.m ** 2 * u.nm)))
|
||||
|
||||
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")
|
||||
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,
|
||||
|
@ -10,7 +10,7 @@ class TestLens(TestCase):
|
||||
wl = np.arange(201, 205, 1) << u.nm
|
||||
|
||||
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)
|
||||
|
||||
def test___init__(self):
|
||||
|
@ -10,7 +10,7 @@ class TestMirror(TestCase):
|
||||
wl = np.arange(201, 205, 1) << u.nm
|
||||
|
||||
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)
|
||||
|
||||
def test___init__(self):
|
||||
|
@ -6,7 +6,7 @@ import astropy.units as u
|
||||
|
||||
class TestStrayLight(TestCase):
|
||||
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")
|
||||
|
||||
def test_calcSignal(self):
|
||||
|
@ -116,6 +116,4 @@ class TestSpectralQty(TestCase):
|
||||
self.assertEqual(sqty, res)
|
||||
|
||||
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user