Move all ETC code to master function
This commit is contained in:
parent
a2162c89ba
commit
31714c9235
36
esbo-etc.py
36
esbo-etc.py
@ -31,29 +31,17 @@ if __name__ == "__main__":
|
||||
print("")
|
||||
print(f.renderText('ESBO-ETC'))
|
||||
|
||||
# Set up logging
|
||||
logger.setLevel(logging.WARNING if args.logging is None else getattr(logging, args.logging.upper()))
|
||||
logger.addHandler(eetc.SpinnerHandler())
|
||||
# Initialize the ETC
|
||||
etc = eetc.esbo_etc(args.config,
|
||||
logging.WARNING if args.logging is None else getattr(logging, args.logging.upper()), True)
|
||||
# Run the computation
|
||||
res = etc.run()
|
||||
|
||||
# Parse Configuration
|
||||
logger.info("Parsing configuration...", extra={"spinning": True})
|
||||
conf = eetc.Configuration(args.config).conf
|
||||
|
||||
# Set up components
|
||||
logger.info("Setting up components...", extra={"spinning": True})
|
||||
oc_factory = eetc.classes.RadiantFactory(conf.common.wl_bins())
|
||||
parent = oc_factory.fromConfigBatch(conf)
|
||||
sensor_factory = eetc.SensorFactory(parent, conf.common)
|
||||
detector = sensor_factory.create(conf.instrument.sensor)
|
||||
|
||||
# Calculate results
|
||||
if hasattr(conf.common, "exposure_time") and hasattr(conf.common, "snr"):
|
||||
sensitivity = detector.getSensitivity(conf.common.exposure_time(), conf.common.snr(), conf.astroscene.target.mag)
|
||||
eetc.printSensitivity(conf.common.exposure_time(), conf.common.snr(), sensitivity)
|
||||
elif hasattr(conf.common, "exposure_time"):
|
||||
snr = detector.getSNR(conf.common.exposure_time())
|
||||
eetc.printSNR(conf.common.exposure_time(), snr)
|
||||
elif hasattr(conf.common, "snr"):
|
||||
exp_time = detector.getExpTime(conf.common.snr())
|
||||
eetc.printExposureTime(exp_time, conf.common.snr())
|
||||
# Print the results
|
||||
if hasattr(etc.conf.common, "exposure_time") and hasattr(etc.conf.common, "snr"):
|
||||
eetc.printSensitivity(etc.conf.common.exposure_time(), etc.conf.common.snr(), res)
|
||||
elif hasattr(etc.conf.common, "exposure_time"):
|
||||
eetc.printSNR(etc.conf.common.exposure_time(), res)
|
||||
elif hasattr(etc.conf.common, "snr"):
|
||||
eetc.printExposureTime(res, etc.conf.common.snr())
|
||||
logger.info("Finished.", extra={"spinning": False})
|
||||
|
@ -1,3 +1,4 @@
|
||||
from .esbo_etc import esbo_etc
|
||||
from .Config import *
|
||||
from .IRadiant import *
|
||||
from .SpectralQty import *
|
||||
|
64
esbo_etc/classes/esbo_etc.py
Normal file
64
esbo_etc/classes/esbo_etc.py
Normal file
@ -0,0 +1,64 @@
|
||||
import esbo_etc as eetc
|
||||
from esbo_etc.lib.logger import logger
|
||||
import logging as log
|
||||
import astropy.units as u
|
||||
|
||||
|
||||
class esbo_etc:
|
||||
"""
|
||||
Top level class of the exposure time calculator
|
||||
"""
|
||||
|
||||
def __init__(self, config: str = "esbo-etc_defaults.xml", logging: int = log.WARNING, spin: bool = False):
|
||||
"""
|
||||
Initialize a new exposure time calculator (ETC)
|
||||
|
||||
Parameters
|
||||
----------
|
||||
config : str
|
||||
Path to the configuration file
|
||||
logging : int
|
||||
Loglevel from package logging
|
||||
spin : bool
|
||||
Show a spinner during computations
|
||||
"""
|
||||
self.__config = config
|
||||
self.__logging = logging
|
||||
self.__spin = spin
|
||||
self.conf = None
|
||||
|
||||
def run(self) -> u.Quantity:
|
||||
"""
|
||||
|
||||
Returns
|
||||
-------
|
||||
res: Quantity
|
||||
The result of the computation. Depending on the input parameters, this will be either a dimensionless
|
||||
signal-to-noise ratio (SNR), an exposure time in seconds or a sensitivity in apparent magnitues.
|
||||
"""
|
||||
# Set up logging
|
||||
logger.setLevel(log.WARNING if self.__logging is None else self.__logging)
|
||||
if self.__spin:
|
||||
logger.addHandler(eetc.SpinnerHandler())
|
||||
|
||||
# Parse Configuration
|
||||
logger.info("Parsing configuration...", extra={"spinning": True})
|
||||
self.conf = eetc.Configuration(self.__config).conf
|
||||
|
||||
# Set up components
|
||||
logger.info("Setting up components...", extra={"spinning": True})
|
||||
oc_factory = eetc.classes.RadiantFactory(self.conf.common.wl_bins())
|
||||
parent = oc_factory.fromConfigBatch(self.conf)
|
||||
sensor_factory = eetc.SensorFactory(parent, self.conf.common)
|
||||
detector = sensor_factory.create(self.conf.instrument.sensor)
|
||||
|
||||
# Calculate results
|
||||
res = None
|
||||
if hasattr(self.conf.common, "exposure_time") and hasattr(self.conf.common, "snr"):
|
||||
res = detector.getSensitivity(self.conf.common.exposure_time(), self.conf.common.snr(),
|
||||
self.conf.astroscene.target.mag)
|
||||
elif hasattr(self.conf.common, "exposure_time"):
|
||||
res = detector.getSNR(self.conf.common.exposure_time())
|
||||
elif hasattr(self.conf.common, "snr"):
|
||||
res = detector.getExpTime(self.conf.common.snr())
|
||||
return res
|
Loading…
Reference in New Issue
Block a user