From 35488b4fb5467f5e99b5da6b09eb862265694c56 Mon Sep 17 00:00:00 2001 From: LukasK13 Date: Fri, 8 May 2020 15:06:13 +0200 Subject: [PATCH] Configuration checks added --- .../optical_component/AHotOpticalComponent.py | 19 +++++ .../optical_component/AOpticalComponent.py | 19 +++++ .../classes/optical_component/Atmosphere.py | 25 ++++++ .../classes/optical_component/BeamSplitter.py | 50 +++++++++++- esbo_etc/classes/optical_component/Filter.py | 76 ++++++++++++++++--- esbo_etc/classes/optical_component/Lens.py | 50 +++++++++++- esbo_etc/classes/optical_component/Mirror.py | 50 +++++++++++- .../classes/optical_component/StrayLight.py | 21 +++++ esbo_etc/classes/sensor/ASensor.py | 19 +++++ esbo_etc/classes/target/ATarget.py | 19 +++++ esbo_etc/classes/target/BlackBodyTarget.py | 34 ++++++++- esbo_etc/classes/target/FileTarget.py | 28 +++++++ 12 files changed, 384 insertions(+), 26 deletions(-) diff --git a/esbo_etc/classes/optical_component/AHotOpticalComponent.py b/esbo_etc/classes/optical_component/AHotOpticalComponent.py index 837a55f..55178b1 100644 --- a/esbo_etc/classes/optical_component/AHotOpticalComponent.py +++ b/esbo_etc/classes/optical_component/AHotOpticalComponent.py @@ -5,6 +5,7 @@ from abc import abstractmethod import astropy.units as u from astropy.modeling.models import BlackBody from typing import Union, Callable +from ..Entry import Entry class AHotOpticalComponent(AOpticalComponent): @@ -90,3 +91,21 @@ class AHotOpticalComponent(AOpticalComponent): """ bb = BlackBody(temperature=temp, scale=em * u.W / (u.m ** 2 * u.nm * u.sr)) return lambda wl: bb(wl) + + @staticmethod + @abstractmethod + def check_config(conf: Entry) -> Union[None, str]: + """ + Check the configuration for this class + + Parameters + ---------- + conf : Entry + The configuration entry to be checked. + + Returns + ------- + mes : Union[None, str] + The error message of the check. This will be None if the check was successful. + """ + pass diff --git a/esbo_etc/classes/optical_component/AOpticalComponent.py b/esbo_etc/classes/optical_component/AOpticalComponent.py index 3c8bd4c..09fbc1c 100644 --- a/esbo_etc/classes/optical_component/AOpticalComponent.py +++ b/esbo_etc/classes/optical_component/AOpticalComponent.py @@ -6,6 +6,7 @@ import astropy.units as u from astropy.modeling.models import BlackBody from typing import Union, Callable, Tuple from logging import info, debug +from ..Entry import Entry class AOpticalComponent(IRadiant): @@ -122,3 +123,21 @@ class AOpticalComponent(IRadiant): return self.__noise except AttributeError: error("noise not given. Method ownNoise() needs to be implemented.") + + @staticmethod + @abstractmethod + def check_config(conf: Entry) -> Union[None, str]: + """ + Check the configuration for this class + + Parameters + ---------- + conf : Entry + The configuration entry to be checked. + + Returns + ------- + mes : Union[None, str] + The error message of the check. This will be None if the check was successful. + """ + pass diff --git a/esbo_etc/classes/optical_component/Atmosphere.py b/esbo_etc/classes/optical_component/Atmosphere.py index fc614c2..f82a76f 100644 --- a/esbo_etc/classes/optical_component/Atmosphere.py +++ b/esbo_etc/classes/optical_component/Atmosphere.py @@ -1,7 +1,9 @@ from .AOpticalComponent import AOpticalComponent from ..IRadiant import IRadiant from ..SpectralQty import SpectralQty +from ..Entry import Entry import astropy.units as u +from typing import Union class Atmosphere(AOpticalComponent): @@ -37,3 +39,26 @@ class Atmosphere(AOpticalComponent): qty_unit_default=u.W / (u.m ** 2 * u.nm * u.sr)) # Initialize the super class super().__init__(parent, transmittance_sqty, emission_sqty) + + @staticmethod + def check_config(conf: Entry) -> Union[None, str]: + """ + Check the configuration for this class + + Parameters + ---------- + conf : Entry + The configuration entry to be checked. + + Returns + ------- + mes : Union[None, str] + The error message of the check. This will be None if the check was successful. + """ + mes = conf.check_file("transmittance") + if mes is not None: + return mes + if hasattr(conf, "emission"): + mes = conf.check_file("emission") + if mes is not None: + return mes diff --git a/esbo_etc/classes/optical_component/BeamSplitter.py b/esbo_etc/classes/optical_component/BeamSplitter.py index bd9df0c..d993902 100644 --- a/esbo_etc/classes/optical_component/BeamSplitter.py +++ b/esbo_etc/classes/optical_component/BeamSplitter.py @@ -1,6 +1,7 @@ from .AHotOpticalComponent import AHotOpticalComponent from ..SpectralQty import SpectralQty from ..IRadiant import IRadiant +from ..Entry import Entry from astropy import units as u from typing import Union @@ -10,9 +11,9 @@ 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: 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): + def __init__(self, parent: IRadiant, transmittance: str, emissivity: Union[str, float] = 1, + temp: u.Quantity = 0 * u.K, obstruction: float = 0, obstructor_temp: u.Quantity = 0 * u.K, + obstructor_emissivity: float = 1): """ Instantiate a new beam splitter model @@ -22,7 +23,7 @@ class BeamSplitter(AHotOpticalComponent): The parent element of the optical component from which the electromagnetic radiation is received. transmittance : str The spectral transmittance coefficients of the filter. - emissivity : Union[int, float, str] + emissivity : Union[str, u.Quantity] The spectral emissivity coefficient for the optical surface. temp: Quantity in Kelvin / Celsius Temperature of the optical component @@ -54,3 +55,44 @@ class BeamSplitter(AHotOpticalComponent): Manipulated incoming radiation """ return rad * self._transmittance + + @staticmethod + def check_config(conf: Entry) -> Union[None, str]: + """ + Check the configuration for this class + + Parameters + ---------- + conf : Entry + The configuration entry to be checked. + + Returns + ------- + mes : Union[None, str] + The error message of the check. This will be None if the check was successful. + """ + mes = conf.check_file("transmittance") + if mes is not None: + return mes + if hasattr(conf, "emissivity"): + mes = conf.check_file("emissivity") + if mes is not None: + mes = conf.check_float("emissivity") + if mes is not None: + return mes + if hasattr(conf, "temp"): + mes = conf.check_quantity("temp", u.K) + if mes is not None: + return mes + if hasattr(conf, "obstruction"): + mes = conf.check_float("obstruction") + if mes is not None: + return mes + if hasattr(conf, "obstructor_temp"): + mes = conf.check_quantity("obstructor_temp", u.K) + if mes is not None: + return mes + if hasattr(conf, "obstructor_emissivity"): + mes = conf.check_float("obstructor_emissivity") + if mes is not None: + return mes diff --git a/esbo_etc/classes/optical_component/Filter.py b/esbo_etc/classes/optical_component/Filter.py index d4a7519..c1559d2 100644 --- a/esbo_etc/classes/optical_component/Filter.py +++ b/esbo_etc/classes/optical_component/Filter.py @@ -2,6 +2,7 @@ from .AHotOpticalComponent import AHotOpticalComponent from ..SpectralQty import SpectralQty from ..IRadiant import IRadiant from ...lib.helpers import error +from ..Entry import Entry from astropy import units as u from typing import Union, Callable import numpy as np @@ -22,8 +23,8 @@ class Filter(AHotOpticalComponent): @u.quantity_input(temp=[u.Kelvin, u.Celsius], obstructor_temp=[u.Kelvin, u.Celsius]) def __init__(self, parent: IRadiant, transmittance: Union[SpectralQty, Callable[[u.Quantity], u.Quantity]], - 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): + emissivity: Union[str, float] = 1, temp: u.Quantity = 0 * u.K, obstruction: float = 0, + obstructor_temp: u.Quantity = 0 * u.K, obstructor_emissivity: float = 1): """ Instantiate a new filter model @@ -33,7 +34,7 @@ class Filter(AHotOpticalComponent): 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. - emissivity : Union[str, int, float] + emissivity : Union[str, float] The spectral emissivity coefficient for the optical surface. temp: Quantity in Kelvin / Celsius Temperature of the optical component @@ -52,8 +53,8 @@ class Filter(AHotOpticalComponent): @classmethod # @u.quantity_input(temp=[u.Kelvin, u.Celsius], obstructor_temp=[u.Kelvin, u.Celsius]) - 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, + def fromBand(cls, parent: IRadiant, band: str, emissivity: Union[str, float] = 1, temp: u.Quantity = 0 * u.K, + obstruction: float = 0, obstructor_temp: u.Quantity = 0 * u.K, obstructor_emissivity: float = 1) -> "Filter": """ Instantiate a new filter model from a spectral band. The filter will be modelled as bandpass filter of @@ -65,7 +66,7 @@ class Filter(AHotOpticalComponent): 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]. - emissivity : Union[str, int, float] + emissivity : Union[str, float] The spectral emissivity coefficient for the optical surface. temp: Quantity in Kelvin / Celsius Temperature of the optical component @@ -92,7 +93,7 @@ class Filter(AHotOpticalComponent): @classmethod # @u.quantity_input(temp=[u.Kelvin, u.Celsius], obstructor_temp=[u.Kelvin, u.Celsius]) - def fromFile(cls, parent: IRadiant, transmittance: str, emissivity: Union[str, int, float] = 1, + def fromFile(cls, parent: IRadiant, transmittance: str, emissivity: Union[str, float] = 1, temp: u.Quantity = 0 * u.K, obstruction: float = 0, obstructor_temp: u.Quantity = 0 * u.K, obstructor_emissivity: float = 1) -> "Filter": """ @@ -105,7 +106,7 @@ class Filter(AHotOpticalComponent): transmittance : str Path to the file containing the spectral transmittance-coefficients of the filter element. The format of the file will be guessed by `astropy.io.ascii.read()`. - emissivity : Union[str, int, float] + emissivity : Union[str, float] The spectral emissivity coefficient for the optical surface. temp: Quantity in Kelvin / Celsius Temperature of the optical component @@ -129,9 +130,9 @@ 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: 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": + def fromRange(cls, parent: IRadiant, start: u.Quantity, end: u.Quantity, emissivity: Union[str, float] = 1, + temp: u.Quantity = 0 * u.K, obstruction: float = 0, obstructor_temp: u.Quantity = 0 * u.K, + obstructor_emissivity: float = 1) -> "Filter": """ Instantiate a new filter model from a spectral range. The filter will be modelled as bandpass filter of infinite order and therefore similar to a hat-function. @@ -144,7 +145,7 @@ class Filter(AHotOpticalComponent): Start wavelength of the pass-band end : length-quantity End wavelength of the pass-band - emissivity : Union[str, int, float] + emissivity : Union[str, float] The spectral emissivity coefficient for the optical surface. temp: Quantity in Kelvin / Celsius Temperature of the optical component @@ -202,3 +203,54 @@ class Filter(AHotOpticalComponent): """ return lambda wl: np.logical_and(np.greater_equal(wl, start), np.greater_equal(end, wl)).astype(int) *\ u.dimensionless_unscaled + + @staticmethod + def check_config(conf: Entry) -> Union[None, str]: + """ + Check the configuration for this class + + Parameters + ---------- + conf : Entry + The configuration entry to be checked. + + Returns + ------- + mes : Union[None, str] + The error message of the check. This will be None if the check was successful. + """ + if hasattr(conf, "band"): + mes = conf.check_selection("band", ["U", "B", "V", "R", "I", "J", "H", "K", "L", "M", "N"]) + elif hasattr(conf, "transmittance"): + mes = conf.check_file("transmittance") + elif hasattr(conf, "start") and hasattr(conf, "end"): + mes = conf.check_quantity("start", u.m) + if mes is not None: + return mes + mes = conf.check_quantity("end", u.m) + else: + mes = "Expected one of 'band' / 'transmittance' / 'start' & 'end'." + if mes is not None: + return mes + if hasattr(conf, "emissivity"): + mes = conf.check_file("emissivity") + if mes is not None: + mes = conf.check_float("emissivity") + if mes is not None: + return mes + if hasattr(conf, "temp"): + mes = conf.check_quantity("temp", u.K) + if mes is not None: + return mes + if hasattr(conf, "obstruction"): + mes = conf.check_float("obstruction") + if mes is not None: + return mes + if hasattr(conf, "obstructor_temp"): + mes = conf.check_quantity("obstructor_temp", u.K) + if mes is not None: + return mes + if hasattr(conf, "obstructor_emissivity"): + mes = conf.check_float("obstructor_emissivity") + if mes is not None: + return mes diff --git a/esbo_etc/classes/optical_component/Lens.py b/esbo_etc/classes/optical_component/Lens.py index 944072b..26b392f 100644 --- a/esbo_etc/classes/optical_component/Lens.py +++ b/esbo_etc/classes/optical_component/Lens.py @@ -1,6 +1,7 @@ from .AHotOpticalComponent import AHotOpticalComponent from ..SpectralQty import SpectralQty from ..IRadiant import IRadiant +from ..Entry import Entry from astropy import units as u from typing import Union @@ -10,9 +11,9 @@ 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: 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): + def __init__(self, parent: IRadiant, transmittance: str, emissivity: Union[str, float] = 1, + temp: u.Quantity = 0 * u.K, obstruction: float = 0, obstructor_temp: u.Quantity = 0 * u.K, + obstructor_emissivity: float = 1): """ Instantiate a new lens model @@ -22,7 +23,7 @@ class Lens(AHotOpticalComponent): The parent element of the optical component from which the electromagnetic radiation is received. transmittance : str The spectral transmittance coefficients of the filter. - emissivity : Union[int, float, str] + emissivity : Union[str, float] The spectral emissivity coefficient for the optical surface. temp: Quantity in Kelvin / Celsius Temperature of the optical component @@ -54,3 +55,44 @@ class Lens(AHotOpticalComponent): Manipulated incoming radiation """ return rad * self._transmittance + + @staticmethod + def check_config(conf: Entry) -> Union[None, str]: + """ + Check the configuration for this class + + Parameters + ---------- + conf : Entry + The configuration entry to be checked. + + Returns + ------- + mes : Union[None, str] + The error message of the check. This will be None if the check was successful. + """ + mes = conf.check_file("transmittance") + if mes is not None: + return mes + if hasattr(conf, "emissivity"): + mes = conf.check_file("emissivity") + if mes is not None: + mes = conf.check_float("emissivity") + if mes is not None: + return mes + if hasattr(conf, "temp"): + mes = conf.check_quantity("temp", u.K) + if mes is not None: + return mes + if hasattr(conf, "obstruction"): + mes = conf.check_float("obstruction") + if mes is not None: + return mes + if hasattr(conf, "obstructor_temp"): + mes = conf.check_quantity("obstructor_temp", u.K) + if mes is not None: + return mes + if hasattr(conf, "obstructor_emissivity"): + mes = conf.check_float("obstructor_emissivity") + if mes is not None: + return mes diff --git a/esbo_etc/classes/optical_component/Mirror.py b/esbo_etc/classes/optical_component/Mirror.py index 90d723c..5fdea4c 100644 --- a/esbo_etc/classes/optical_component/Mirror.py +++ b/esbo_etc/classes/optical_component/Mirror.py @@ -1,6 +1,7 @@ from .AHotOpticalComponent import AHotOpticalComponent from ..SpectralQty import SpectralQty from ..IRadiant import IRadiant +from ..Entry import Entry from astropy import units as u from typing import Union @@ -10,9 +11,9 @@ 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: 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): + def __init__(self, parent: IRadiant, reflectance: str, emissivity: Union[str, float] = 1, + temp: u.Quantity = 0 * u.K, obstruction: float = 0, obstructor_temp: u.Quantity = 0 * u.K, + obstructor_emissivity: float = 1): """ Instantiate a new mirror model @@ -22,7 +23,7 @@ class Mirror(AHotOpticalComponent): The parent element of the optical component from which the electromagnetic radiation is received. reflectance : str The spectral transmittance coefficients of the filter. - emissivity : Union[int, float, str] + emissivity : Union[str, float] The spectral emissivity coefficient for the optical surface. temp: Quantity in Kelvin / Celsius Temperature of the optical component @@ -54,3 +55,44 @@ class Mirror(AHotOpticalComponent): Manipulated incoming radiation """ return rad * self._reflectance + + @staticmethod + def check_config(conf: Entry) -> Union[None, str]: + """ + Check the configuration for this class + + Parameters + ---------- + conf : Entry + The configuration entry to be checked. + + Returns + ------- + mes : Union[None, str] + The error message of the check. This will be None if the check was successful. + """ + mes = conf.check_file("reflectance") + if mes is not None: + return mes + if hasattr(conf, "emissivity"): + mes = conf.check_file("emissivity") + if mes is not None: + mes = conf.check_float("emissivity") + if mes is not None: + return mes + if hasattr(conf, "temp"): + mes = conf.check_quantity("temp", u.K) + if mes is not None: + return mes + if hasattr(conf, "obstruction"): + mes = conf.check_float("obstruction") + if mes is not None: + return mes + if hasattr(conf, "obstructor_temp"): + mes = conf.check_quantity("obstructor_temp", u.K) + if mes is not None: + return mes + if hasattr(conf, "obstructor_emissivity"): + mes = conf.check_float("obstructor_emissivity") + if mes is not None: + return mes diff --git a/esbo_etc/classes/optical_component/StrayLight.py b/esbo_etc/classes/optical_component/StrayLight.py index 82a290e..aa03b7e 100644 --- a/esbo_etc/classes/optical_component/StrayLight.py +++ b/esbo_etc/classes/optical_component/StrayLight.py @@ -1,7 +1,9 @@ from .AOpticalComponent import AOpticalComponent from ..IRadiant import IRadiant from ..SpectralQty import SpectralQty +from ..Entry import Entry import astropy.units as u +from typing import Union class StrayLight(AOpticalComponent): @@ -27,3 +29,22 @@ class StrayLight(AOpticalComponent): qty_unit_default=u.W / (u.m ** 2 * u.nm * u.sr)) # Initialize the super class super().__init__(parent, 1.0, emission_sqty) + + @staticmethod + def check_config(conf: Entry) -> Union[None, str]: + """ + Check the configuration for this class + + Parameters + ---------- + conf : Entry + The configuration entry to be checked. + + Returns + ------- + mes : Union[None, str] + The error message of the check. This will be None if the check was successful. + """ + mes = conf.check_file("emission") + if mes is not None: + return mes diff --git a/esbo_etc/classes/sensor/ASensor.py b/esbo_etc/classes/sensor/ASensor.py index 6b3139e..fd35b5c 100644 --- a/esbo_etc/classes/sensor/ASensor.py +++ b/esbo_etc/classes/sensor/ASensor.py @@ -1,6 +1,8 @@ from ..IRadiant import IRadiant import astropy.units as u from abc import abstractmethod +from ..Entry import Entry +from typing import Union class ASensor: @@ -52,3 +54,20 @@ class ASensor: The necessary exposure time in seconds. """ pass + + @staticmethod + def check_config(conf: Entry) -> Union[None, str]: + """ + Check the configuration for this class + + Parameters + ---------- + conf : Entry + The configuration entry to be checked. + + Returns + ------- + mes : Union[None, str] + The error message of the check. This will be None if the check was succesful. + """ + pass diff --git a/esbo_etc/classes/target/ATarget.py b/esbo_etc/classes/target/ATarget.py index adef083..c614343 100644 --- a/esbo_etc/classes/target/ATarget.py +++ b/esbo_etc/classes/target/ATarget.py @@ -5,6 +5,7 @@ import astropy.units as u import numpy as np from logging import info, debug from typing import Tuple +from ..Entry import Entry class ATarget(IRadiant): @@ -59,3 +60,21 @@ class ATarget(IRadiant): info("Calculating Signal for class '" + self.__class__.__name__ + "'.") debug(self.__sfd) return self.__sfd, self.__size + + @staticmethod + @abstractmethod + def check_config(conf: Entry) -> bool: + """ + Check the configuration for this class + + Parameters + ---------- + conf : Entry + The configuration entry to be checked. + + Returns + ------- + mes : Union[None, str] + The error message of the check. This will be None if the check was successful. + """ + pass diff --git a/esbo_etc/classes/target/BlackBodyTarget.py b/esbo_etc/classes/target/BlackBodyTarget.py index 2191999..5529e8a 100644 --- a/esbo_etc/classes/target/BlackBodyTarget.py +++ b/esbo_etc/classes/target/BlackBodyTarget.py @@ -3,6 +3,8 @@ from ..SpectralQty import SpectralQty import astropy.units as u from astropy.modeling.models import BlackBody from ...lib.helpers import error +from ..Entry import Entry +from typing import Union class BlackBodyTarget(ATarget): @@ -44,16 +46,44 @@ class BlackBodyTarget(ATarget): Returns ------- """ - if band not in self._band.keys(): + if band.upper() 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[band]["sfd"] / (bb(self._band[band]["wl"]) * u.sr) * u.sr + 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) # Initialize super class super().__init__(SpectralQty(wl_bins, sfd), wl_bins, size) + + @staticmethod + def check_config(conf: Entry) -> Union[None, str]: + """ + Check the configuration for this class + + Parameters + ---------- + conf : Entry + The configuration entry to be checked. + + Returns + ------- + mes : Union[None, str] + The error message of the check. This will be None if the check was successful. + """ + 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: + 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("size", ["point", "extended"]) + if mes is not None: + return mes diff --git a/esbo_etc/classes/target/FileTarget.py b/esbo_etc/classes/target/FileTarget.py index 21e375c..976f614 100644 --- a/esbo_etc/classes/target/FileTarget.py +++ b/esbo_etc/classes/target/FileTarget.py @@ -1,6 +1,9 @@ from ..target.ATarget import ATarget from ..SpectralQty import SpectralQty import astropy.units as u +from ..Entry import Entry +from typing import Union +import os.path class FileTarget(ATarget): @@ -29,3 +32,28 @@ class FileTarget(ATarget): sfd = SpectralQty.fromFile(file, u.nm, u.W / (u.m ** 2 * u.nm)) # Initialize the super class super().__init__(sfd, wl_bins, size) + + @staticmethod + def check_config(conf: Entry) -> Union[None, str]: + """ + Check the configuration for this class + + Parameters + ---------- + conf : Entry + The configuration entry to be checked. + + Returns + ------- + mes : Union[None, str] + The error message of the check. This will be None if the check was successful. + """ + mes = conf.check_file("file") + if mes is not None: + return mes + mes = conf.check_quantity("wl_bins", u.m) + if mes is not None: + return mes + mes = conf.check_selection("size", ["point", "extended"]) + if mes is not None: + return mes