Skip to content

Commit

Permalink
refactor: make offsets to convert to MJD variables
Browse files Browse the repository at this point in the history
  • Loading branch information
tsutterley committed Jul 8, 2024
1 parent 747e7f4 commit 409892d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
10 changes: 7 additions & 3 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 JD to MJD a variable
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,9 @@
# 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

# PURPOSE: calculate the sum of a polynomial function of time
def polynomial_sum(coefficients: list | np.ndarray, t: np.ndarray):
"""
Expand Down Expand Up @@ -796,7 +800,7 @@ def gast(T: float | np.ndarray):
# create timescale from centuries relative to 2000-01-01T12:00:00
ts = timescale.time.Timescale(MJD=T*36525.0 + 51544.5)
# 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 @@ -840,7 +844,7 @@ def itrs(T: float | np.ndarray):
# create timescale from centuries relative to 2000-01-01T12:00:00
ts = timescale.time.Timescale(MJD=T*36525.0 + 51544.5)
# 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 @@ -990,7 +994,7 @@ def _nutation_angles(T: float | np.ndarray):
# create timescale from centuries relative to 2000-01-01T12:00:00
ts = timescale.time.Timescale(MJD=T*36525.0 + 51544.5)
# 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
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 @@ def LPT_displacements(
epoch=EPOCH, standard=TIME)

# convert dynamic time to Modified Julian Days (MJD)
MJD = ts.tt - 2400000.5
MJD = ts.tt - _jd_mjd
# 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 @@ def OPT_displacements(
epoch=EPOCH, standard=TIME)

# convert dynamic time to Modified Julian Days (MJD)
MJD = ts.tt - 2400000.5
MJD = ts.tt - _jd_mjd
# 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

0 comments on commit 409892d

Please sign in to comment.