diff --git a/setup.cfg b/setup.cfg index be00d71ad..d7aef2b17 100644 --- a/setup.cfg +++ b/setup.cfg @@ -57,6 +57,7 @@ console_scripts = pintk = pint.scripts.pintk:main convert_parfile = pint.scripts.convert_parfile:main compare_parfiles = pint.scripts.compare_parfiles:main + export_clocks = pint.scripts.export_clocks:main # See the docstring in versioneer.py for instructions. Note that you must diff --git a/src/pint/observatory/topo_obs.py b/src/pint/observatory/topo_obs.py index 29b2f5b34..1b5c4ffc4 100644 --- a/src/pint/observatory/topo_obs.py +++ b/src/pint/observatory/topo_obs.py @@ -350,16 +350,25 @@ def export_all_clock_files(directory): """ directory = Path(directory) if pint.observatory._gps_clock is not None: + log.debug( + f"Exporting GPS clock file to {directory / Path(pint.observatory._gps_clock.filename).name}" + ) pint.observatory._gps_clock.export( directory / Path(pint.observatory._gps_clock.filename).name ) for version, clock in pint.observatory._bipm_clock_versions.items(): + log.debug( + f"Exporting BIPM ({version}) clock file to {directory / Path(clock.filename).name}" + ) clock.export(directory / Path(clock.filename).name) for name in Observatory.names(): o = get_observatory(name) if hasattr(o, "_clock") and o._clock is not None: for clock in o._clock: if clock.filename is not None: + log.debug( + f"Exporting clock file for {o.name} to {directory / Path(clock.filename).name}" + ) clock.export(directory / Path(clock.filename).name) diff --git a/src/pint/scripts/export_clocks.py b/src/pint/scripts/export_clocks.py new file mode 100644 index 000000000..e562e91ab --- /dev/null +++ b/src/pint/scripts/export_clocks.py @@ -0,0 +1,51 @@ +import argparse +import os +import sys + +import pint.logging +from loguru import logger as log + +pint.logging.setup(level=pint.logging.script_level) + +import pint.observatory +import pint.observatory.topo_obs + +__all__ = ["main"] + + +def main(argv=None): + parser = argparse.ArgumentParser( + description="PINT tool for export clock files", + formatter_class=argparse.ArgumentDefaultsHelpFormatter, + epilog=f"Example: export_clocks -o clock_dir/ GBT Arecibo CHIME VLA", + ) + parser.add_argument( + "observatories", help="Observatories to export", type=str, nargs="+" + ) + parser.add_argument( + "-o", + "--out", + default=os.path.abspath(os.curdir), + type=str, + dest="directory", + help="Destination directory (set $PINT_CLOCK_OVERRIDE to this value to look here first for clock files)", + ) + parser.add_argument( + "--log-level", + type=str, + choices=("TRACE", "DEBUG", "INFO", "WARNING", "ERROR"), + default="WARNING", + help="Logging level", + dest="loglevel", + ) + args = parser.parse_args(argv) + pint.logging.setup(level=args.loglevel) + if not os.path.isdir(args.directory): + log.error(f"Destination {args.directory} is not a directory") + sys.exit(1) + + for obsname in args.observatories: + obs = pint.observatory.get_observatory(obsname) + obs._load_clock_corrections() + + pint.observatory.topo_obs.export_all_clock_files(args.directory)