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
|
2020-05-19 09:41:03 +02:00
|
|
|
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-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",
|
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'))
|
|
|
|
|
2020-09-09 16:53:08 +02:00
|
|
|
# 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()
|
2020-04-06 17:17:31 +02:00
|
|
|
|
2020-09-09 16:53:08 +02:00
|
|
|
# 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())
|
2020-05-29 09:36:40 +02:00
|
|
|
logger.info("Finished.", extra={"spinning": False})
|