Skip to content

Commit

Permalink
Alignment safety
Browse files Browse the repository at this point in the history
* Adding safety checks to alignment loop.
* Creating a `pocs.update_status` thin wrapper.
  • Loading branch information
wtgee committed May 18, 2024
1 parent f8c4873 commit 5dc0d42
Show file tree
Hide file tree
Showing 2 changed files with 29 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
35 changes: 21 additions & 14 deletions src/panoptes/pocs/utils/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,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 +90,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 +109,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()

Check warning on line 113 in src/panoptes/pocs/utils/cli/run.py

View check run for this annotation

Codecov / codecov/patch

src/panoptes/pocs/utils/cli/run.py#L112-L113

Added lines #L112 - L113 were not covered by tests

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

procs = list()
for i, altaz_coord in enumerate(altaz_coords):
if pocs.is_safe() is False:
print('[red]POCS is not safe, shutting down.[/red]')
break

Check warning on line 147 in src/panoptes/pocs/utils/cli/run.py

View check run for this annotation

Codecov / codecov/patch

src/panoptes/pocs/utils/cli/run.py#L146-L147

Added lines #L146 - L147 were not covered by tests

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

# Create an observation and set it as current.
Expand All @@ -166,6 +172,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()

Check warning on line 175 in src/panoptes/pocs/utils/cli/run.py

View check run for this annotation

Codecov / codecov/patch

src/panoptes/pocs/utils/cli/run.py#L175

Added line #L175 was not covered by tests

# Do processing in background (if exposure time is long enough).
if exptime > 10:
Expand Down

0 comments on commit 5dc0d42

Please sign in to comment.