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
|
2020-05-19 09:41:03 +02:00
|
|
|
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__":
|
2020-05-19 09:41:03 +02:00
|
|
|
# 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",
|
2020-05-25 16:57:26 +02:00
|
|
|
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",
|
2020-05-25 16:57:26 +02:00
|
|
|
help="Show version information.")
|
2020-05-19 09:41:03 +02:00
|
|
|
parser.add_argument("-m", "--manual", action="store_true", dest="manual",
|
2020-05-25 16:57:26 +02:00
|
|
|
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
|
|
|
|
2020-05-19 09:41:03 +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("")
|
2020-05-19 09:41:03 +02:00
|
|
|
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)
|
2020-05-19 09:41:03 +02:00
|
|
|
logger = logging.getLogger('root')
|
|
|
|
logger.addHandler(SpinnerHandler(spin_style=Spin1))
|
2020-04-06 17:17:31 +02:00
|
|
|
|
2020-05-19 09:41:03 +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
|
|
|
|
2020-05-19 09:41:03 +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
|
|
|
|
2020-05-19 09:41:03 +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)
|
2020-05-19 09:41:03 +02:00
|
|
|
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())
|
2020-05-19 09:41:03 +02:00
|
|
|
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())
|
2020-05-19 09:41:03 +02:00
|
|
|
eetc.printExposureTime(exp_time, conf.common.snr())
|
|
|
|
logging.getLogger("root").info("Finished.", extra={"user_waiting": False})
|