Skip to content

Commit

Permalink
fix bug for datetime input in sc_distance
Browse files Browse the repository at this point in the history
  • Loading branch information
jgieseler committed Aug 28, 2023
1 parent f22c6be commit dbb02ab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions solarmach/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1557,6 +1557,8 @@ def sc_distance(sc1, sc2, dtime):
except ValueError:
print(f"Unable to extract datetime from '{dtime}'. Please try a different format.")
return np.nan*u.AU
else:
obstime = dtime

# standardize body names (e.g. 'PSP' => 'Parker Solar Probe')
try:
Expand All @@ -1572,13 +1574,13 @@ def sc_distance(sc1, sc2, dtime):
try:
sc1_coord = get_horizons_coord(sc1, obstime, None)
except ValueError:
print(f"Unable to obtain position for '{sc1}' at {dtime}. Please try a different name or date.")
print(f"Unable to obtain position for '{sc1}' at {obstime}. Please try a different name or date.")
return np.nan*u.AU
#
try:
sc2_coord = get_horizons_coord(sc2, obstime, None)
except ValueError:
print(f"Unable to obtain position for '{sc2}' at {dtime}. Please try a different name or date.")
print(f"Unable to obtain position for '{sc2}' at {obstime}. Please try a different name or date.")
return np.nan*u.AU

return sc1_coord.separation_3d(sc2_coord)
Expand Down
5 changes: 5 additions & 0 deletions solarmach/tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import astropy
import astropy.units as u
import datetime as dt
import matplotlib
import numpy as np
import pandas
Expand Down Expand Up @@ -99,6 +100,10 @@ def test_sc_distance():
assert np.round(distance.value, 8) == 1.45237361
assert distance.unit == u.AU
#
distance = sc_distance('SolO', 'PSP', dt.date(2020, 12, 12))
assert np.round(distance.value, 8) == 1.45237361
assert distance.unit == u.AU
#
distance = sc_distance('SolO', 'PSP', "2000/12/12")
assert np.isnan(distance.value)
assert distance.unit == u.AU

0 comments on commit dbb02ab

Please sign in to comment.