diff --git a/src/iact_estimator/scripts/main.py b/src/iact_estimator/scripts/main.py index e9cb4a5..c1da902 100644 --- a/src/iact_estimator/scripts/main.py +++ b/src/iact_estimator/scripts/main.py @@ -6,6 +6,7 @@ import shutil from astroplan import FixedTarget, Observer +from astropy.coordinates.name_resolve import NameResolveError from astropy.time import Time import astropy.units as u from astropy.visualization import quantity_support @@ -15,6 +16,7 @@ from ..io import read_yaml from ..core import ( setup_logging, + load_target_source_coordinates, initialize_model, check_input_configuration, prepare_data, @@ -97,7 +99,15 @@ def main(): output_path = ( Path(args.output_path) if args.output_path is not None else Path.cwd() ) - source_name = args.source_name + + logging.info("Loading configuration file") + config = read_yaml(args.config) + + source_name = ( + config["target_source"]["name"] + if config["target_source"]["name"] + else "test_source" + ) previous_output = len( [file for file in output_path.rglob(f"**/{source_name}*")] @@ -109,9 +119,6 @@ def main(): logger = setup_logging(args.log_level, source_name) - logger.info("Loading configuration file") - config = read_yaml(args.config) - logging.info("Validating input configuration") if not check_input_configuration(config): logging.critical( @@ -175,7 +182,17 @@ def main(): logger.info("All expected operations have been perfomed succesfully.") - target_source = FixedTarget.from_name(source_name) + if source_name: + try: + target_source = FixedTarget.from_name(source_name) + except NameResolveError: + target_source = load_target_source_coordinates(config) + elif ( + source_name != "test_source" + and config["target_source"]["coordinates"]["force"] + ): + target_source = load_target_source_coordinates(config) + observer = Observer.at_site("Roque de los Muchachos") time = Time(config["observation_datetime"])