Skip to content

Commit

Permalink
Up coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkelley committed Dec 6, 2023
1 parent 803e445 commit c32cc79
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
27 changes: 16 additions & 11 deletions sbpy/activity/dust/dynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
from ... import data as sbd
from ...data.ephem import Ephem
from ...exceptions import SbpyException
from ... import time
from ... import time # noqa: F401


class SolverFailed(SbpyException):
pass
"""DynamicalModel solver failed."""


StateType = TypeVar("StateType", bound="State")
Expand Down Expand Up @@ -363,10 +363,16 @@ def from_ephem(cls, eph: Ephem, frame: Optional[FrameType] = None) -> StateType:
"""

t: Time = eph["date"]

rectangular = ("x", "y", "z", "vx", "vy", "vz")
spherical = ("ra", "dec", "Delta", "RA*cos(Dec)_rate", "Dec_rate", "deltadot")
rectangular: Tuple[str] = ("x", "y", "z", "vx", "vy", "vz", "date")
spherical: Tuple[str] = (
"ra",
"dec",
"Delta",
"RA*cos(Dec)_rate",
"Dec_rate",
"deltadot",
"date",
)

if all([x in eph for x in rectangular]):
r: u.Quantity[u.physical.length] = (
Expand Down Expand Up @@ -396,7 +402,8 @@ def from_ephem(cls, eph: Ephem, frame: Optional[FrameType] = None) -> StateType:
return cls(r, v, eph["date"], frame=frame)

raise ValueError(
"`Ephem` does not have the required time, position, and/or velocity fields."
"`Ephem` does not have the required time, position, and/or"
" velocity fields."
)


Expand Down Expand Up @@ -453,7 +460,6 @@ def dx_dt(cls, t: float, rv: np.ndarray, *args) -> np.ndarray:
First three elements for :math:`dr/dt`, next three for :math:`dv/dt`.
"""
pass

@abc.abstractclassmethod
def df_drv(cls, t: float, rv: np.ndarray, *args) -> np.ndarray:
Expand All @@ -480,8 +486,8 @@ def df_drv(cls, t: float, rv: np.ndarray, *args) -> np.ndarray:
:math:`df/dv`.
"""
pass


def solve(
self,
initial: State,
Expand Down Expand Up @@ -593,7 +599,6 @@ def df_drv(cls, t: float, rv: np.ndarray, *args) -> np.ndarray:
r = rv[:3]
r2 = (r**2).sum()
r1 = np.sqrt(r2)
r3 = r1 * r2
GM_r3 = cls._GM
GM_r5 = GM_r3 / r2

Expand Down
16 changes: 16 additions & 0 deletions sbpy/activity/dust/tests/test_dynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,11 +499,22 @@ def test_from_ephem(self):
"date": t,
},
)

# initialize without specifying a frame
state = State.from_ephem(eph)

# and with the frame
state = State.from_ephem(eph, frame="icrs")
assert u.allclose(state.r, r)
assert u.allclose(state.v, v)
assert np.isclose((state.t - t).jd, 0)

for k in ("x", "y", "z", "vx", "vy", "vz", "date"):
incomplete = Ephem.from_table(eph.table.copy())
del incomplete.table[k]
with pytest.raises(ValueError):
State.from_ephem(incomplete)

# note, these are coordinates of 12P as seen by the solar system
# barycenter
eph = Ephem.from_dict(
Expand All @@ -522,6 +533,11 @@ def test_from_ephem(self):
assert u.allclose(state.v, v)
assert np.isclose((state.t - t).jd, 0)

for k in ("ra", "dec", "delta", "RA*cos(Dec)_rate", "Dec_rate", "delta_rate"):
incomplete = Ephem.from_table(eph.table.copy())
del incomplete.table[k]
with pytest.raises(ValueError):
State.from_ephem(incomplete)

def test_spice_prop2b():
"""Test case from SPICE NAIF toolkit prop2b, v2.2.0
Expand Down

0 comments on commit c32cc79

Please sign in to comment.