ESBO-ETC/esbo-etc.py

60 lines
2.7 KiB
Python
Raw Normal View History

2020-05-18 10:37:30 +02:00
import esbo_etc as eetc
2020-04-06 17:17:31 +02:00
import argparse
2020-05-29 09:36:40 +02:00
from esbo_etc.lib.logger import logger
2020-04-06 17:17:31 +02:00
import logging
from pyfiglet import Figlet
from rich import console, markdown
2020-04-06 17:17:31 +02:00
if __name__ == "__main__":
# Parse arguments
2020-07-13 15:24:32 +02:00
parser = argparse.ArgumentParser(prog="esbo-etc.py", description='Exposure time calculator for ESBO-DS')
2020-04-06 17:17:31 +02:00
parser.add_argument("-c", "--config", dest='config', default="esbo-etc_defaults.xml",
metavar="config.xml", help="Path to the configuration file. Default is esbo-etc_defaults.xml.")
parser.add_argument("-l", "--logging", dest="logging", default="WARNING",
help="Log level for the application. Possible levels are DEBUG, INFO, WARNING, ERROR.")
2020-04-06 17:17:31 +02:00
parser.add_argument("-v", "--version", action="version", version="ESBO-ETC version 1.0.0",
help="Show version information.")
parser.add_argument("-m", "--manual", action="store_true", dest="manual",
help="Print the user manual from the readme.")
2020-04-21 14:47:31 +02:00
args, _ = parser.parse_known_args() # fix for PyCharm python console
2020-04-06 17:17:31 +02:00
# Print manual from README.md
if args.manual:
console = console.Console()
with open("README.md") as readme:
markdown = markdown.Markdown(readme.read())
console.print(markdown)
exit(0)
# Print title
f = Figlet(font='slant')
2020-05-19 15:58:39 +02:00
print("")
print(f.renderText('ESBO-ETC'))
# Set up logging
2020-05-29 09:36:40 +02:00
logger.setLevel(logging.WARNING if args.logging is None else getattr(logging, args.logging.upper()))
logger.addHandler(eetc.SpinnerHandler())
2020-04-06 17:17:31 +02:00
# Parse Configuration
2020-05-29 09:36:40 +02:00
logger.info("Parsing configuration...", extra={"spinning": True})
2020-05-18 10:37:30 +02:00
conf = eetc.Configuration(args.config).conf
2020-04-06 17:17:31 +02:00
# Set up components
2020-05-29 09:36:40 +02:00
logger.info("Setting up components...", extra={"spinning": True})
2020-05-18 10:37:30 +02:00
oc_factory = eetc.classes.RadiantFactory(conf.common.wl_bins())
2020-05-15 14:59:07 +02:00
parent = oc_factory.fromConfigBatch(conf)
2020-05-18 10:37:30 +02:00
sensor_factory = eetc.SensorFactory(parent, conf.common)
2020-07-14 12:01:39 +02:00
detector = sensor_factory.create(conf.instrument.sensor)
2020-05-18 10:37:30 +02:00
# Calculate results
2020-05-16 15:52:27 +02:00
if hasattr(conf.common, "exposure_time") and hasattr(conf.common, "snr"):
2020-07-14 12:01:39 +02:00
sensitivity = detector.getSensitivity(conf.common.exposure_time(), conf.common.snr(), conf.astroscene.target.mag)
eetc.printSensitivity(conf.common.exposure_time(), conf.common.snr(), sensitivity)
2020-05-16 15:52:27 +02:00
elif hasattr(conf.common, "exposure_time"):
2020-07-14 12:01:39 +02:00
snr = detector.getSNR(conf.common.exposure_time())
eetc.printSNR(conf.common.exposure_time(), snr)
2020-05-15 14:59:07 +02:00
elif hasattr(conf.common, "snr"):
2020-07-14 12:01:39 +02:00
exp_time = detector.getExpTime(conf.common.snr())
eetc.printExposureTime(exp_time, conf.common.snr())
2020-05-29 09:36:40 +02:00
logger.info("Finished.", extra={"spinning": False})