Skip to content

Commit

Permalink
Alignment safety (#1271)
Browse files Browse the repository at this point in the history
* Alignment safety

* Adding safety checks to alignment loop.
* Creating a `pocs.update_status` thin wrapper.

* Raise an exception to break observing loop if not safe.

* * Don't park during the safety check, but let the alignment script do it.
  • Loading branch information
wtgee committed May 18, 2024
1 parent f8c4873 commit 311e777
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
8 changes: 8 additions & 0 deletions src/panoptes/pocs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ def status(self) -> dict:
self.logger.warning(f"Can't get status: {e!r}")
return {}

def update_status(self) -> dict:
"""Thin-wrapper around status property.
This method will update the status of the system in the database.
"""
return self.status

################################################################################################
# Methods
################################################################################################
Expand Down Expand Up @@ -394,6 +401,7 @@ def is_safe(self, no_warning=False, horizon='observe', ignore=None, park_if_not_
self.logger.warning(f'Safety failed, setting {self.next_state=} to "parking"')
self.next_state = 'parking'

self.update_status()
return safe

def _in_simulator(self, key):
Expand Down
40 changes: 26 additions & 14 deletions src/panoptes/pocs/utils/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import List

import typer
from panoptes.utils.error import PanError
from panoptes.utils.time import current_time
from panoptes.utils.utils import altaz_to_radec, listify
from rich import print
Expand All @@ -22,9 +23,9 @@

@app.callback()
def common(
context: typer.Context,
simulator: List[str] = typer.Option(None, '--simulator', '-s', help='Simulators to load'),
cloud_logging: bool = typer.Option(False, '--cloud-logging', '-c', help='Enable cloud logging'),
context: typer.Context,
simulator: List[str] = typer.Option(None, '--simulator', '-s', help='Simulators to load'),
cloud_logging: bool = typer.Option(False, '--cloud-logging', '-c', help='Enable cloud logging'),
):
context.obj = [simulator, cloud_logging]

Expand Down Expand Up @@ -90,17 +91,17 @@ def run_auto(context: typer.Context) -> None:

@app.command(name='alignment')
def run_alignment(
context: typer.Context,
coords: List[str] = typer.Option(
None, '--coords', '-c',
help='Alt/Az coordinates to use, e.g. 40,120'
),
exptime: float = typer.Option(30.0, '--exptime', '-e', help='Exposure time in seconds.'),
num_exposures: int = typer.Option(
5, '--num-exposures', '-n',
help='Number of exposures per coordinate.'
),
field_name: str = typer.Option('PolarAlignment', '--field-name', '-f', help='Name of field.'),
context: typer.Context,
coords: List[str] = typer.Option(
None, '--coords', '-c',
help='Alt/Az coordinates to use, e.g. 40,120'
),
exptime: float = typer.Option(30.0, '--exptime', '-e', help='Exposure time in seconds.'),
num_exposures: int = typer.Option(
5, '--num-exposures', '-n',
help='Number of exposures per coordinate.'
),
field_name: str = typer.Option('PolarAlignment', '--field-name', '-f', help='Name of field.'),
) -> None:
"""Runs POCS in alignment mode.
Expand All @@ -109,6 +110,8 @@ def run_alignment(
-c 70,60 -c 70,120 -c 70,240 -c 70,300
"""
pocs = get_pocs(context)
print(f'[bold yellow]Starting POCS in alignment mode.[/bold yellow]')
pocs.update_status()

alts = [55, 70]
azs = [60, 120, 240, 300]
Expand Down Expand Up @@ -140,6 +143,11 @@ def get_altaz_observation(coords, seq_time) -> Observation:

procs = list()
for i, altaz_coord in enumerate(altaz_coords):
# Check safety (parking happens below if unsafe).
if pocs.is_safe(park_if_not_safe=False) is False:
print('[red]POCS is not safe, shutting down.[/red]')
raise PanError('POCS is not safe.')

print(f'{field_name} #{i:02d}/{len(altaz_coords):02d} {altaz_coord=}')

# Create an observation and set it as current.
Expand All @@ -166,6 +174,7 @@ def get_altaz_observation(coords, seq_time) -> Observation:
for j in range(num_exposures):
print(f'\tStarting {exptime}s exposure #{j + 1:02d}/{num_exposures:02d}')
pocs.observatory.take_observation(blocking=True)
pocs.update_status()

# Do processing in background (if exposure time is long enough).
if exptime > 10:
Expand All @@ -180,6 +189,9 @@ def get_altaz_observation(coords, seq_time) -> Observation:
except Exception as e:
print('[bold red]POCS encountered an error.[/bold red]')
print(e)
except PanError as e:
print('[bold red]POCS encountered an error.[/bold red]')
print(e)
else:
print('[green]POCS alignment finished, shutting down.[/green]')
finally:
Expand Down

0 comments on commit 311e777

Please sign in to comment.