Skip to content

Commit

Permalink
refactor: add _jd_j2000 variable instead of hard coded
Browse files Browse the repository at this point in the history
  • Loading branch information
tsutterley committed Jul 11, 2024
1 parent a310ad2 commit 38b045e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pyTMD/astro.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
_jd_mjd = 2400000.5
# number of days between MJD and the J2000 epoch
_mjd_j2000 = 51544.5
# number of days between the Julian day epoch and J2000 epoch
_jd_j2000 = _jd_mjd + _mjd_j2000
# Julian century
_century = 36525.0

Expand Down Expand Up @@ -589,8 +591,7 @@ def solar_ephemerides(MJD: np.ndarray, **kwargs):
x, y, z = 1e3*(SSB_to_Sun.compute(ts.tt) - SSB_to_EMB.compute(ts.tt) -
EMB_to_Earth.compute(ts.tt))
# rotate to cartesian (ECEF) coordinates
# use UT1 time as input to itrs rotation function
rot_z = itrs((ts.ut1 - 2451545.0)/ts.century)
rot_z = itrs((ts.ut1 - _jd_j2000)/ts.century)
X = rot_z[0,0,:]*x + rot_z[0,1,:]*y + rot_z[0,2,:]*z
Y = rot_z[1,0,:]*x + rot_z[1,1,:]*y + rot_z[1,2,:]*z
Z = rot_z[2,0,:]*x + rot_z[2,1,:]*y + rot_z[2,2,:]*z
Expand Down Expand Up @@ -768,7 +769,7 @@ def lunar_ephemerides(MJD: np.ndarray, **kwargs):
x, y, z = 1e3*(EMB_to_Moon.compute(ts.tt) - EMB_to_Earth.compute(ts.tt))
# rotate to cartesian (ECEF) coordinates
# use UT1 time as input to itrs rotation function
rot_z = itrs((ts.ut1 - 2451545.0)/ts.century)
rot_z = itrs((ts.ut1 - _jd_j2000)/ts.century)
X = rot_z[0,0,:]*x + rot_z[0,1,:]*y + rot_z[0,2,:]*z
Y = rot_z[1,0,:]*x + rot_z[1,1,:]*y + rot_z[1,2,:]*z
Z = rot_z[2,0,:]*x + rot_z[2,1,:]*y + rot_z[2,2,:]*z
Expand Down
13 changes: 13 additions & 0 deletions test/test_solid_earth.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,3 +365,16 @@ def test_sidereal():
# expected side real time in hours
expected = 20.96154017401333
assert np.isclose(expected, 24.0*ts.st).all()

def test_epochs():
"""Test that the epoch conversions match expected outputs
"""
# Modified Julian Day (MJD)
assert np.isclose(pyTMD.astro._jd_mjd, 2400000.5)
# J2000 time
mjd_j2000 = timescale.time.convert_calendar_dates(
*timescale.time._j2000_epoch,
epoch=timescale.time._mjd_epoch)
assert np.isclose(mjd_j2000, pyTMD.astro._mjd_j2000)
assert np.isclose(pyTMD.astro._mjd_j2000, 51544.5)
assert np.isclose(pyTMD.astro._jd_j2000, 2451545.0)

0 comments on commit 38b045e

Please sign in to comment.