Skip to content

Commit

Permalink
* Ability to search for comets.
Browse files Browse the repository at this point in the history
  • Loading branch information
wtgee committed Oct 15, 2024
1 parent e0f009e commit ed1709c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
1 change: 1 addition & 0 deletions environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ channels:
dependencies:
- astroplan
- astropy
- astroquery
- docopt
- fastapi
- google-cloud-firestore
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ install_requires =
importlib-metadata; python_version<"3.8"
astroplan
astropy
astroquery
certifi>=2023.7.22
fastapi<0.106.0
fastapi-utils
Expand Down
47 changes: 33 additions & 14 deletions src/panoptes/pocs/utils/cli/mount.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from astropy import units as u
from astropy.coordinates import AltAz, SkyCoord
from astropy.coordinates.name_resolve import NameResolveError
from astroquery.jplhorizons import Horizons
from human_readable import time_delta as friendly_time_delta
from panoptes.utils.config.client import set_config
from panoptes.utils.rs232 import SerialData
Expand Down Expand Up @@ -144,26 +145,21 @@ def slew_to_target(
prompt='The name of the target to slew the mount to.',
help='The name of the target to slew the mount to.'
)] = None,
comet: Annotated[bool, typer.Option(
..., '--comet',
help='Include if you want to search for comet named `target`'
)] = False
):
"""Slews the mount target position."""
print(f'Looking for coordinates for {target}.')
coords = None
try:
coords = SkyCoord(target)
except ValueError:
try:
coords = SkyCoord.from_name(target)
except NameResolveError:
pass
finally:
if not coords:
print(f'[red]Could not find a suitable target by name or position.[/red]')
return typer.Abort()

# Get the observer location
location = create_location_from_config()
observe_horizon = location.location.get('horizon', 30 * u.deg)

Check warning on line 156 in src/panoptes/pocs/utils/cli/mount.py

View check run for this annotation

Codecov / codecov/patch

src/panoptes/pocs/utils/cli/mount.py#L155-L156

Added lines #L155 - L156 were not covered by tests

coords = get_target_coords(target, location.location, is_comet=comet)

Check warning on line 158 in src/panoptes/pocs/utils/cli/mount.py

View check run for this annotation

Codecov / codecov/patch

src/panoptes/pocs/utils/cli/mount.py#L158

Added line #L158 was not covered by tests
if not coords:
print(f'[red]Could not find a suitable target by name or position.[/red]')
return typer.Abort()

Check warning on line 161 in src/panoptes/pocs/utils/cli/mount.py

View check run for this annotation

Codecov / codecov/patch

src/panoptes/pocs/utils/cli/mount.py#L160-L161

Added lines #L160 - L161 were not covered by tests

# Check that the target is observable.
is_observable = location.observer.target_is_up(current_time(), coords, horizon=observe_horizon)

Check warning on line 164 in src/panoptes/pocs/utils/cli/mount.py

View check run for this annotation

Codecov / codecov/patch

src/panoptes/pocs/utils/cli/mount.py#L164

Added line #L164 was not covered by tests
if not is_observable:
Expand Down Expand Up @@ -340,3 +336,26 @@ def setup_mount(
return typer.Exit()
except serial.SerialTimeoutException:
pass


def get_target_coords(target: str, location: dict, is_comet: bool = False):
"""Get the coordinates of the target. """
print(f'Looking for coordinates for {target}.')
coords = None

Check warning on line 344 in src/panoptes/pocs/utils/cli/mount.py

View check run for this annotation

Codecov / codecov/patch

src/panoptes/pocs/utils/cli/mount.py#L343-L344

Added lines #L343 - L344 were not covered by tests

if is_comet:
location['lat'] = location['latitude']
location['lon'] = location['longitude']
obj = Horizons(id=target, id_type='smallbody', epochs=current_time().jd1, location=location)
eph = obj.ephemerides()
coords = SkyCoord(eph[0]['RA'], eph[0]['DEC'], unit=(u.deg, u.deg))

Check warning on line 351 in src/panoptes/pocs/utils/cli/mount.py

View check run for this annotation

Codecov / codecov/patch

src/panoptes/pocs/utils/cli/mount.py#L347-L351

Added lines #L347 - L351 were not covered by tests
else:
try:
coords = SkyCoord(target)
except ValueError:
try:
coords = SkyCoord.from_name(target)
except NameResolveError:
pass

Check warning on line 359 in src/panoptes/pocs/utils/cli/mount.py

View check run for this annotation

Codecov / codecov/patch

src/panoptes/pocs/utils/cli/mount.py#L353-L359

Added lines #L353 - L359 were not covered by tests

return coords

Check warning on line 361 in src/panoptes/pocs/utils/cli/mount.py

View check run for this annotation

Codecov / codecov/patch

src/panoptes/pocs/utils/cli/mount.py#L361

Added line #L361 was not covered by tests

0 comments on commit ed1709c

Please sign in to comment.