ESBO-ETC/esbo_etc/esbo-etc.py

65 lines
3.0 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
import logging
import sys
from logging_spinner import SpinnerHandler
from pyspin.spin import Spin1
from pyfiglet import Figlet
from rich import console, markdown
2020-04-06 17:17:31 +02:00
if __name__ == "__main__":
# Parse arguments
2020-04-06 17:17:31 +02:00
parser = argparse.ArgumentParser(prog="esbo_etc/esbo-etc.py", description='Exposure time calculator for ESBO-DS')
parser.add_argument("-c", "--config", dest='config', default="esbo-etc_defaults.xml",
metavar="config.xml", help="path to the configuration file")
2020-04-24 11:05:41 +02:00
parser.add_argument("-l", "--logging", dest="logging", default="WARNING", help="print debug information")
2020-04-06 17:17:31 +02:00
parser.add_argument("-o", "--output-dir", dest="output_dir", help="path to the output directory",
default="output")
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-15 14:59:07 +02:00
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.WARNING if args.logging is None else getattr(
logging, args.logging.upper()), stream=sys.stdout)
logger = logging.getLogger('root')
logger.addHandler(SpinnerHandler(spin_style=Spin1))
2020-04-06 17:17:31 +02:00
# Parse Configuration
logging.getLogger("root").info("Parsing configuration...", extra={"user_waiting": 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
logging.getLogger("root").info("Setting up components...", extra={"user_waiting": 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-05-15 14:59:07 +02:00
imager = 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"):
sensitivity = imager.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-05-15 14:59:07 +02:00
snr = imager.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"):
exp_time = imager.getExpTime(conf.common.snr())
eetc.printExposureTime(exp_time, conf.common.snr())
logging.getLogger("root").info("Finished.", extra={"user_waiting": False})