Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: make offsets to convert to MJD variables #306

Merged
merged 3 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions pyTMD/astro.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

UPDATE HISTORY:
Updated 07/2024: made a wrapper function for normalizing angles
make number of days to convert days since an epoch to MJD variables
Updated 04/2024: use wrapper to importlib for optional dependencies
Updated 01/2024: refactored lunisolar ephemerides functions
Updated 12/2023: refactored phase_angles function to doodson_arguments
Expand Down Expand Up @@ -63,6 +64,13 @@
# default JPL Spacecraft and Planet ephemerides kernel
_default_kernel = get_data_path(['data','de440s.bsp'])

# number of days between the Julian day epoch and MJD
_jd_mjd = 2400000.5
# number of days between MJD and the J2000 epoch
_mjd_j2000 = 51544.5
# Julian century
_century = 36525.0

# PURPOSE: calculate the sum of a polynomial function of time
def polynomial_sum(coefficients: list | np.ndarray, t: np.ndarray):
"""
Expand Down Expand Up @@ -179,7 +187,7 @@
"""
if MEEUS:
# convert from MJD to days relative to 2000-01-01T12:00:00
T = MJD - 51544.5
T = MJD - _mjd_j2000

Check warning on line 190 in pyTMD/astro.py

View check run for this annotation

Codecov / codecov/patch

pyTMD/astro.py#L190

Added line #L190 was not covered by tests
# mean longitude of moon
lunar_longitude = np.array([218.3164591, 13.17639647754579,
-9.9454632e-13, 3.8086292e-20, -8.6184958e-27])
Expand All @@ -197,10 +205,10 @@
1.55628359e-12, 4.390675353e-20, -9.26940435e-27])
N = polynomial_sum(lunar_node, T)
# mean longitude of solar perigee (Simon et al., 1994)
PP = 282.94 + 1.7192 * T / 36525.0
PP = 282.94 + (1.7192 * T)/_century

Check warning on line 208 in pyTMD/astro.py

View check run for this annotation

Codecov / codecov/patch

pyTMD/astro.py#L208

Added line #L208 was not covered by tests
elif ASTRO5:
# convert from MJD to centuries relative to 2000-01-01T12:00:00
T = (MJD - 51544.5)/36525.0
T = (MJD - _mjd_j2000)/_century
# mean longitude of moon (p. 338)
lunar_longitude = np.array([218.3164477, 481267.88123421, -1.5786e-3,
1.855835e-6, -1.53388e-8])
Expand Down Expand Up @@ -299,7 +307,7 @@
# degrees to radians
dtr = np.pi/180.0
# convert from MJD to centuries relative to 2000-01-01T12:00:00
T = (MJD - 51544.5)/36525.0
T = (MJD - _mjd_j2000)/_century
# hour of the day
hour = np.mod(MJD, 1)*24.0
# calculate Doodson phase angles
Expand Down Expand Up @@ -383,7 +391,7 @@
# arcseconds to radians
atr = np.pi/648000.0
# convert from MJD to centuries relative to 2000-01-01T12:00:00
T = (MJD - 51544.5)/36525.0
T = (MJD - _mjd_j2000)/_century
# 360 degrees
circle = 1296000
# mean anomaly of the moon (arcseconds)
Expand Down Expand Up @@ -436,7 +444,7 @@
# arcseconds to radians
atr = np.pi/648000.0
# convert from MJD to centuries relative to 2000-01-01T12:00:00
T = (MJD - 51544.5)/36525.0
T = (MJD - _mjd_j2000)/_century
# mean obliquity of the ecliptic (arcseconds)
epsilon0 = np.array([84381.406, -46.836769, -1.831e-4,
2.00340e-4, -5.76e-07, -4.34e-08])
Expand Down Expand Up @@ -794,9 +802,9 @@
<https://iers-conventions.obspm.fr/content/tn36.pdf>`_
"""
# create timescale from centuries relative to 2000-01-01T12:00:00
ts = timescale.time.Timescale(MJD=T*36525.0 + 51544.5)
ts = timescale.time.Timescale(MJD=T*_century + _mjd_j2000)
# convert dynamical time to modified Julian days
MJD = ts.tt - 2400000.5
MJD = ts.tt - _jd_mjd
# estimate the mean obliquity
epsilon = mean_obliquity(MJD)
# estimate the nutation in longitude and obliquity
Expand Down Expand Up @@ -838,9 +846,9 @@
<https://iers-conventions.obspm.fr/content/tn36.pdf>`_
"""
# create timescale from centuries relative to 2000-01-01T12:00:00
ts = timescale.time.Timescale(MJD=T*36525.0 + 51544.5)
ts = timescale.time.Timescale(MJD=T*_century + _mjd_j2000)
# convert dynamical time to modified Julian days
MJD = ts.tt - 2400000.5
MJD = ts.tt - _jd_mjd
# estimate the mean obliquity
epsilon = mean_obliquity(MJD)
# estimate the nutation in longitude and obliquity
Expand Down Expand Up @@ -892,7 +900,7 @@
<https://iers-conventions.obspm.fr/content/tn36.pdf>`_
"""
# create timescale from centuries relative to 2000-01-01T12:00:00
ts = timescale.time.Timescale(MJD=T*36525.0 + 51544.5)
ts = timescale.time.Timescale(MJD=T*_century + _mjd_j2000)
# get the fundamental arguments in radians
fa = np.zeros((14, len(ts)))
# mean anomaly of the moon (arcseconds)
Expand Down Expand Up @@ -988,9 +996,9 @@
<https://iers-conventions.obspm.fr/content/tn36.pdf>`_
"""
# create timescale from centuries relative to 2000-01-01T12:00:00
ts = timescale.time.Timescale(MJD=T*36525.0 + 51544.5)
ts = timescale.time.Timescale(MJD=T*_century + _mjd_j2000)
# convert dynamical time to modified Julian days
MJD = ts.tt - 2400000.5
MJD = ts.tt - _jd_mjd
# get the fundamental arguments in radians
l, lp, F, D, Om = delaunay_arguments(MJD)
# non-polynomial terms in the equation of the equinoxes
Expand Down Expand Up @@ -1064,7 +1072,7 @@
# arcseconds to radians
atr = np.pi/648000.0
# convert to MJD from centuries relative to 2000-01-01T12:00:00
MJD = T*36525.0 + 51544.5
MJD = T*_century + _mjd_j2000
sprime = -4.7e-5*T
px, py = timescale.eop.iers_polar_motion(MJD)
# calculate the rotation matrices
Expand Down
8 changes: 6 additions & 2 deletions pyTMD/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@

UPDATE HISTORY:
Updated 07/2024: assert that data type is a known value
make number of days to convert JD to MJD a variable
Updated 06/2024: use np.clongdouble instead of np.longcomplex
Updated 04/2024: use wrapper to importlib for optional dependencies
Updated 02/2024: changed class name for ellipsoid parameters to datum
Expand Down Expand Up @@ -125,6 +126,9 @@
# attempt imports
pyproj = pyTMD.utilities.import_dependency('pyproj')

# number of days between the Julian day epoch and MJD
_jd_mjd = 2400000.5

# PURPOSE: wrapper function for computing values
def corrections(
x: np.ndarray, y: np.ndarray, delta_time: np.ndarray,
Expand Down Expand Up @@ -828,7 +832,7 @@
epoch=EPOCH, standard=TIME)

# convert dynamic time to Modified Julian Days (MJD)
MJD = ts.tt - 2400000.5
MJD = ts.tt - _jd_mjd

Check warning on line 835 in pyTMD/compute.py

View check run for this annotation

Codecov / codecov/patch

pyTMD/compute.py#L835

Added line #L835 was not covered by tests
# convert Julian days to calendar dates
Y,M,D,h,m,s = timescale.time.convert_julian(ts.tt, format='tuple')
# calculate time in year-decimal format
Expand Down Expand Up @@ -1008,7 +1012,7 @@
epoch=EPOCH, standard=TIME)

# convert dynamic time to Modified Julian Days (MJD)
MJD = ts.tt - 2400000.5
MJD = ts.tt - _jd_mjd

Check warning on line 1015 in pyTMD/compute.py

View check run for this annotation

Codecov / codecov/patch

pyTMD/compute.py#L1015

Added line #L1015 was not covered by tests
# convert Julian days to calendar dates
Y,M,D,h,m,s = timescale.time.convert_julian(ts.tt, format='tuple')
# calculate time in year-decimal format
Expand Down
14 changes: 9 additions & 5 deletions pyTMD/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

UPDATE HISTORY:
Updated 07/2024: use normalize_angle from pyTMD astro module
make number of days to convert tide time to MJD a variable
Updated 02/2024: changed class name for ellipsoid parameters to datum
Updated 01/2024: moved minor arguments calculation into new function
moved constituent parameters function from predict to arguments
Expand Down Expand Up @@ -52,6 +53,9 @@
import pyTMD.astro
from pyTMD.crs import datum

# number of days between MJD and the tide epoch (1992-01-01T00:00:00)
_mjd_tide = 48622.0

# PURPOSE: Predict tides at single times
def map(t: float | np.ndarray,
hc: np.ndarray,
Expand Down Expand Up @@ -93,7 +97,7 @@ def map(t: float | np.ndarray,
npts, nc = np.shape(hc)
# load the nodal corrections
# convert time to Modified Julian Days (MJD)
pu, pf, G = pyTMD.arguments.arguments(t + 48622.0,
pu, pf, G = pyTMD.arguments.arguments(t + _mjd_tide,
constituents,
deltat=deltat,
corrections=corrections
Expand Down Expand Up @@ -159,7 +163,7 @@ def drift(t: float | np.ndarray,
nt = len(t)
# load the nodal corrections
# convert time to Modified Julian Days (MJD)
pu, pf, G = pyTMD.arguments.arguments(t + 48622.0,
pu, pf, G = pyTMD.arguments.arguments(t + _mjd_tide,
constituents,
deltat=deltat,
corrections=corrections
Expand Down Expand Up @@ -225,7 +229,7 @@ def time_series(t: float | np.ndarray,
nt = len(t)
# load the nodal corrections
# convert time to Modified Julian Days (MJD)
pu, pf, G = pyTMD.arguments.arguments(t + 48622.0,
pu, pf, G = pyTMD.arguments.arguments(t + _mjd_tide,
constituents,
deltat=deltat,
corrections=corrections
Expand Down Expand Up @@ -369,7 +373,7 @@ def infer_minor(

# load the nodal corrections for minor constituents
# convert time to Modified Julian Days (MJD)
pu, pf, G = pyTMD.arguments.minor_arguments(t + 48622.0,
pu, pf, G = pyTMD.arguments.minor_arguments(t + _mjd_tide,
deltat=kwargs['deltat'],
corrections=kwargs['corrections']
)
Expand Down Expand Up @@ -535,7 +539,7 @@ def solid_earth_tide(
# number of input coordinates
nt = len(np.atleast_1d(t))
# convert time to Modified Julian Days (MJD)
MJD = t + 48622.0
MJD = t + _mjd_tide
# scalar product of input coordinates with sun/moon vectors
radius = np.sqrt(XYZ[:,0]**2 + XYZ[:,1]**2 + XYZ[:,2]**2)
solar_radius = np.sqrt(SXYZ[:,0]**2 + SXYZ[:,1]**2 + SXYZ[:,2]**2)
Expand Down
6 changes: 6 additions & 0 deletions test/test_solid_earth.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ def test_frequency_dependence_diurnal():
T = (MJD - 51544.5)/36525.0
T_expected = 0.1059411362080767
assert np.isclose(T_expected, T)
T_test = (MJD - pyTMD.astro._mjd_j2000)/pyTMD.astro._century
assert np.isclose(T_expected, T_test)
# expected results
dx_expected = 0.4193085327321284701e-2
dy_expected = 0.1456681241014607395e-2
Expand All @@ -116,6 +118,8 @@ def test_frequency_dependence_long_period():
T = (MJD - 51544.5)/36525.0
T_expected = 0.1059411362080767
assert np.isclose(T_expected, T)
T_test = (MJD - pyTMD.astro._mjd_j2000)/pyTMD.astro._century
assert np.isclose(T_expected, T_test)
# expected results
dx_expected = -0.9780962849562107762e-4
dy_expected = -0.2236349699932734273e-4
Expand Down Expand Up @@ -148,6 +152,8 @@ def test_fundamental_arguments():
# convert to MJD from centuries relative to 2000-01-01T12:00:00
MJD = T*36525.0 + 51544.5
assert np.isclose(MJD, 54465)
MJD_test = T*pyTMD.astro._century + pyTMD.astro._mjd_j2000
assert np.isclose(MJD, MJD_test)
L_expected = 2.291187512612069099
LP_expected = 6.212931111003726414
F_expected = 3.658025792050572989
Expand Down
Loading