diff --git a/sbpy/activity/dust/dynamics.py b/sbpy/activity/dust/dynamics.py index ffad70ae..6d00e4ea 100644 --- a/sbpy/activity/dust/dynamics.py +++ b/sbpy/activity/dust/dynamics.py @@ -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") @@ -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] = ( @@ -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." ) @@ -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: @@ -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, @@ -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 diff --git a/sbpy/activity/dust/tests/test_dynamics.py b/sbpy/activity/dust/tests/test_dynamics.py index c44eda25..fe909666 100644 --- a/sbpy/activity/dust/tests/test_dynamics.py +++ b/sbpy/activity/dust/tests/test_dynamics.py @@ -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( @@ -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