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 1402a2a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
5 changes: 0 additions & 5 deletions adam_core/observers/observers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import numpy as np
import pandas as pd
from mpc_obscodes import mpc_obscodes
from quivr import Float64Column, StringColumn, Table
Expand All @@ -11,10 +10,6 @@ class ObservatoryGeodetics(Table):
sin_phi = Float64Column()
name = StringColumn()

@property
def values(self):
return np.array(self.table.select(("longitude", "cos_phi", "sin_phi"))).T


# Read MPC extended observatory codes file
OBSCODES = pd.read_json(
Expand Down
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
13 changes: 13 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,14 @@ 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
get_observer_state(
code,
Time([59000, 59001], format="mjd", scale="tdb"),
)

0 comments on commit 1402a2a

Please sign in to comment.