Skip to content

Commit e5dc895

Browse files
committed
sidereal: add test and functionalize
1 parent 61a2736 commit e5dc895

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

src/pymap3d/sidereal.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,31 @@ def datetime2sidereal(time: datetime, lon_radians: float) -> float:
3838
return [datetime2sidereal(t, lon_radians) for t in time]
3939

4040
try:
41-
tsr = (
42-
Time(time)
43-
.sidereal_time(kind="apparent", longitude=Longitude(lon_radians, unit=u.radian))
44-
.radian
45-
)
41+
return datetime2sidereal_astropy(time, lon_radians)
4642
except NameError:
47-
jd = juliandate(str2dt(time))
48-
# %% Greenwich Sidereal time RADIANS
49-
gst = greenwichsrt(jd)
50-
# %% Algorithm 15 p. 188 rotate GST to LOCAL SIDEREAL TIME
51-
tsr = gst + lon_radians
43+
return datetime2sidereal_vallado(time, lon_radians)
5244

53-
return tsr
45+
46+
def datetime2sidereal_astropy(t: datetime, lon_radians: float) -> float:
47+
""" datetime to sidereal time using astropy
48+
see datetime2sidereal() for description
49+
"""
50+
51+
at = Time(t)
52+
tsr = at.sidereal_time(kind="apparent", longitude=Longitude(lon_radians, unit=u.radian))
53+
return tsr.radian
54+
55+
56+
def datetime2sidereal_vallado(t: datetime, lon_radians: float) -> float:
57+
""" datetime to sidereal time using Vallado methods
58+
see datetime2sidereal() for description
59+
"""
60+
61+
jd = juliandate(str2dt(t))
62+
# Greenwich Sidereal time RADIANS
63+
gst = greenwichsrt(jd)
64+
# Algorithm 15 p. 188 rotate GST to LOCAL SIDEREAL TIME
65+
return gst + lon_radians
5466

5567

5668
def juliandate(time: datetime) -> float:

src/pymap3d/tests/test_sidereal.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ def test_sidereal(time):
1919
if isinstance(tsr, list):
2020
tsr = tsr[0]
2121
assert tsr == approx(sra, rel=1e-5)
22+
assert isinstance(tsr, float)
23+
24+
25+
def test_sidereal_astropy():
26+
tsr = pmd.datetime2sidereal_astropy(t0, radians(lon))
27+
assert tsr == approx(sra, rel=1e-5)
28+
assert isinstance(tsr, float)
29+
30+
31+
def test_sidereal_valado():
32+
tsr = pmd.datetime2sidereal_vallado(t0, radians(lon))
33+
assert tsr == approx(sra, rel=1e-5)
34+
assert isinstance(tsr, float)
2235

2336

2437
def test_anglesep():

0 commit comments

Comments
 (0)