Skip to content

Commit

Permalink
Return geodetics as a dictionary rather than numpy array
Browse files Browse the repository at this point in the history
  • Loading branch information
moeyensj committed Jun 29, 2023
1 parent 5e9ea6c commit c2e58ef
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
12 changes: 7 additions & 5 deletions adam_core/observers/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,14 @@ def get_observer_state(
setup_SPICE()

# Get observatory geodetic information
geodetics = OBSERVATORY_GEODETICS.select("code", code).values[0]
geodetics = OBSERVATORY_GEODETICS.select("code", code).table.to_pylist()[0]

if np.any(np.isnan(geodetics)):
# Unpack geodetic information
longitude = geodetics["longitude"]
cos_phi = geodetics["cos_phi"]
sin_phi = geodetics["sin_phi"]

if np.any(np.isnan([longitude, cos_phi, sin_phi])):
err = (
f"{code} is missing information on Earth-based geodetic coordinates. The MPC Obs Code\n"
"file may be missing this information or the observer is a space-based observatory.\n"
Expand All @@ -86,9 +91,6 @@ def get_observer_state(
# If not then we need to add a topocentric correction
else:
# Get observer location on Earth
longitude = geodetics[0]
cos_phi = geodetics[1]
sin_phi = geodetics[2]
sin_longitude = np.sin(np.radians(longitude))
cos_longitude = np.cos(np.radians(longitude))

Expand Down
14 changes: 14 additions & 0 deletions adam_core/observers/tests/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import numpy as np
import pandas as pd
import pytest
from astropy.time import Time

from ...constants import KM_P_AU, S_P_DAY
from ...coordinates import Residuals
Expand Down Expand Up @@ -212,3 +214,15 @@ def test_get_observer_state_500():
np.testing.assert_array_less(
v_offset, 0.01
) # Velocities agree to within 0.01 mm/s


def test_get_observer_state_raises():
# Test that when we ask for a space-based observatory we raise an error
code = "C51"
with pytest.raises(ValueError):
# Get the observer state using adam_core
s = get_observer_state(
code,
Time([59000, 59001], format="mjd", scale="tdb"),
)
print(s.to_dataframe())

0 comments on commit c2e58ef

Please sign in to comment.