From d432fe00a18e48d39d0b375cd6459620c4da4d34 Mon Sep 17 00:00:00 2001 From: Wilfred Tyler Gee Date: Fri, 25 Aug 2023 19:16:02 -1000 Subject: [PATCH] * Adding a `pocs run alignment` command that will take polar alignment pictures. --- src/panoptes/pocs/utils/cli/run.py | 58 ++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/panoptes/pocs/utils/cli/run.py b/src/panoptes/pocs/utils/cli/run.py index 2de24c41d..e573a5bba 100644 --- a/src/panoptes/pocs/utils/cli/run.py +++ b/src/panoptes/pocs/utils/cli/run.py @@ -1,8 +1,12 @@ import typer +from panoptes.utils.time import current_time +from panoptes.utils.utils import altaz_to_radec from rich import print from typing_extensions import Annotated from panoptes.pocs.core import POCS +from panoptes.pocs.scheduler.field import Field +from panoptes.pocs.scheduler.observation.base import Observation app = typer.Typer() @@ -24,3 +28,57 @@ def run_auto(confirm: Annotated[bool, typer.Option(prompt='Are you sure you want pocs.power_down() except Exception: print('[bold red]POCS encountered an error.[/bold red]') + + +@app.command(name='alignment') +def run_alignment(confirm: Annotated[ + bool, typer.Option(prompt='Are you sure you want to run the polar alignment script?')], + exptime: float = 30, + num_exposures: int = 10, + field_name: str = 'PolarAlignment', + move_mount=True + ) -> None: + """Runs POCS in alignment mode.""" + if confirm is False: + print('Exit.') + raise typer.Abort() + + altaz_coords = [ + # (alt, az) + (40, 90), + (55, 60), + (55, 120), + (70, 210), + (70, 330), + ] + + # Helper function to make an observation from altaz coordinates. + def get_altaz_observation(coords) -> Observation: + alt, az = coords + coord = altaz_to_radec(alt, az, pocs.observatory.earth_location, current_time()) + alignment_observation = Observation(Field(field_name, coord), + exptime=exptime, + min_nexp=num_exposures, + exp_set_size=num_exposures) + + return alignment_observation + + print('[green]Running POCS in alignment mode!\tPress Ctrl-c to quit.[/green]') + pocs = POCS.from_config() + pocs.initialize() + + # Start the polar alignment sequence. + mount = pocs.observatory.mount + for i, altaz_coord in enumerate(altaz_coords): + print(f'Starting coord #{i:02d} {altaz_coord=}...', end='') + observation = get_altaz_observation(altaz_coord) + pocs.observatory.current_observation = observation + + if move_mount: + print(f'Slewing to {observation.field.coord=} for {altaz_coord=}') + mount.set_target_coordinates(observation.field.coord) + mount.slew_to_target(blocking=True) + + # Take the observation. + pocs.observatory.take_observation(blocking=True) + print(f'done.')