Skip to content

Commit

Permalink
fix: include tools in init to address #106 (#107)
Browse files Browse the repository at this point in the history
fix: place some imports behind try/except

update version
  • Loading branch information
tsutterley committed Aug 19, 2022
1 parent 3f5c711 commit 75c4c7c
Show file tree
Hide file tree
Showing 78 changed files with 5,197 additions and 5,170 deletions.
2 changes: 1 addition & 1 deletion doc/source/api_reference/utilities.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ General Methods

.. autofunction:: pyTMD.utilities.get_hash

.. autofunction:: pyTMD.utilities.url_split(s)
.. autofunction:: pyTMD.utilities.url_split

.. autofunction:: pyTMD.utilities.roman_to_int

Expand Down
8 changes: 4 additions & 4 deletions doc/source/getting_started/Getting-Started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ Presently, the following models and their directories parameterized within ``pyT

* GOT4.7: ``<path_to_tide_models>/GOT4.7/grids_oceantide/``
* GOT4.7_load: ``<path_to_tide_models>/GOT4.7/grids_loadtide/``
* GOT4.8: ``<path_to_tide_models>/got4.8/grids_oceantide/``
* GOT4.8_load: ``<path_to_tide_models>/got4.8/grids_loadtide/``
* GOT4.10: ``<path_to_tide_models>/GOT4.10c/grids_oceantide/``
* GOT4.10_load: ``<path_to_tide_models>/GOT4.10c/grids_loadtide/``
* `GOT4.8 <https://earth.gsfc.nasa.gov/sites/default/files/2022-07/got4.8.tar.gz>`_: ``<path_to_tide_models>/got4.8/grids_oceantide/``
* `GOT4.8_load <https://earth.gsfc.nasa.gov/sites/default/files/2022-07/got4.8.tar.gz>`_: ``<path_to_tide_models>/got4.8/grids_loadtide/``
* `GOT4.10 <https://earth.gsfc.nasa.gov/sites/default/files/2022-07/got4.10c.tar.gz>`_: ``<path_to_tide_models>/GOT4.10c/grids_oceantide/``
* `GOT4.10_load <https://earth.gsfc.nasa.gov/sites/default/files/2022-07/got4.10c.tar.gz>`_: ``<path_to_tide_models>/GOT4.10c/grids_loadtide/``

- Finite Element Solution tide models [Lyard2020]_

Expand Down
2 changes: 1 addition & 1 deletion notebooks/Check Tide Map.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
" if model.format in ('OTIS','ATLAS','ESR'):\n",
" # if reading a single OTIS solution\n",
" xi,yi,hz,mz,iob,dt = pyTMD.read_tide_model.read_tide_grid(model.grid_file)\n",
" #-- convert coordinate systems of input latitude and longitude\n",
" # convert coordinate systems of input latitude and longitude\n",
" x,y = pyTMD.convert_ll_xy(np.atleast_1d(LON), np.atleast_1d(LAT),\n",
" model.projection, 'F')\n",
" # adjust longitudinal convention of input latitude and longitude\n",
Expand Down
2 changes: 1 addition & 1 deletion notebooks/Plot Antarctic Tidal Currents.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@
"cbar.ax.set_xlabel('{0} Tidal Velocity'.format(model.name), fontsize=13)\n",
"cbar.ax.set_ylabel('cm/s', fontsize=13, rotation=0)\n",
"cbar.ax.yaxis.set_label_coords(1.04, 0.15)\n",
"#-- ticks lines all the way across\n",
"# ticks lines all the way across\n",
"cbar.ax.tick_params(which='both', width=1, length=18,\n",
" labelsize=13, direction='in')\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion notebooks/Plot Antarctic Tide Range.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
" zmin[:,14] = 0.0040*z8[:,5] + 0.0074*z8[:,6]# lambda2\n",
" zmin[:,15] = 0.0131*z8[:,5] + 0.0326*z8[:,6]# L2\n",
" zmin[:,16] = 0.0033*z8[:,5] + 0.0082*z8[:,6]# L2\n",
" zmin[:,17] = 0.0585*z8[:,6]#-- t2\n",
" zmin[:,17] = 0.0585*z8[:,6]# t2\n",
" # only add minor constituents that are not major\n",
" return np.where(minor_flag, np.abs(zmin), 0.0)"
]
Expand Down
1 change: 1 addition & 0 deletions postBuild
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
jupyter labextension install --clean @jupyter-widgets/jupyterlab-manager \
jupyter-matplotlib jupyter-leaflet
pip install -e .
1 change: 1 addition & 0 deletions pyTMD/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"""
import pyTMD.eop
import pyTMD.time
import pyTMD.tools
import pyTMD.utilities
import pyTMD.version
from pyTMD.bilinear_interp import bilinear_interp
Expand Down
48 changes: 24 additions & 24 deletions pyTMD/calc_astrol_longitudes.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"""
import numpy as np

#-- PURPOSE: calculate the sum of a polynomial function of time
# PURPOSE: calculate the sum of a polynomial function of time
def polynomial_sum(coefficients, t):
"""
Calculates the sum of a polynomial function of time
Expand All @@ -61,11 +61,11 @@ def polynomial_sum(coefficients, t):
t: float
delta time in units for a given astronomical longitudes calculation
"""
#-- convert time to array if importing a single value
# convert time to array if importing a single value
t = np.atleast_1d(t)
return np.sum([c * (t ** i) for i,c in enumerate(coefficients)],axis=0)

#-- PURPOSE: compute the basic astronomical mean longitudes
# PURPOSE: compute the basic astronomical mean longitudes
def calc_astrol_longitudes(MJD, MEEUS=False, ASTRO5=False):
"""
Computes the basic astronomical mean longitudes: s, h, p, N and PP
Expand Down Expand Up @@ -99,66 +99,66 @@ def calc_astrol_longitudes(MJD, MEEUS=False, ASTRO5=False):
"""
circle = 360.0
if MEEUS:
#-- convert from MJD to days relative to 2000-01-01T12:00:00
# convert from MJD to days relative to 2000-01-01T12:00:00
T = MJD - 51544.5
#-- mean longitude of moon
# mean longitude of moon
lunar_longitude = np.array([218.3164591, 13.17639647754579,
-9.9454632e-13, 3.8086292e-20, -8.6184958e-27])
s = polynomial_sum(lunar_longitude,T)
#-- mean longitude of sun
# mean longitude of sun
solar_longitude = np.array([280.46645, 0.985647360164271,
2.2727347e-13])
h = polynomial_sum(solar_longitude,T)
#-- mean longitude of lunar perigee
# mean longitude of lunar perigee
lunar_perigee = np.array([83.3532430, 0.11140352391786447,
-7.7385418e-12, -2.5636086e-19, 2.95738836e-26])
p = polynomial_sum(lunar_perigee,T)
#-- mean longitude of ascending lunar node
# mean longitude of ascending lunar node
lunar_node = np.array([125.0445550, -0.052953762762491446,
1.55628359e-12, 4.390675353e-20, -9.26940435e-27])
N = polynomial_sum(lunar_node,T)
#-- mean longitude of solar perigee (Simon et al., 1994)
# mean longitude of solar perigee (Simon et al., 1994)
PP = 282.94 + 1.7192 * T
elif ASTRO5:
#-- convert from MJD to centuries relative to 2000-01-01T12:00:00
# convert from MJD to centuries relative to 2000-01-01T12:00:00
T = (MJD - 51544.5)/36525.0
#-- mean longitude of moon (p. 338)
# mean longitude of moon (p. 338)
lunar_longitude = np.array([218.3164477, 481267.88123421, -1.5786e-3,
1.855835e-6, -1.53388e-8])
s = polynomial_sum(lunar_longitude,T)
#-- mean longitude of sun (p. 338)
# mean longitude of sun (p. 338)
lunar_elongation = np.array([297.8501921, 445267.1114034, -1.8819e-3,
1.83195e-6, -8.8445e-9])
h = polynomial_sum(lunar_longitude-lunar_elongation,T)
#-- mean longitude of lunar perigee (p. 343)
# mean longitude of lunar perigee (p. 343)
lunar_perigee = np.array([83.3532465, 4069.0137287, -1.032e-2,
-1.249172e-5])
p = polynomial_sum(lunar_perigee,T)
#-- mean longitude of ascending lunar node (p. 144)
# mean longitude of ascending lunar node (p. 144)
lunar_node = np.array([125.04452, -1934.136261, 2.0708e-3, 2.22222e-6])
N = polynomial_sum(lunar_node,T)
#-- mean longitude of solar perigee (Simon et al., 1994)
# mean longitude of solar perigee (Simon et al., 1994)
PP = 282.94 + 1.7192 * T
else:
#-- convert from MJD to days relative to 2000-01-01T12:00:00
#-- convert from Universal Time to Dynamic Time at 2000-01-01
# convert from MJD to days relative to 2000-01-01T12:00:00
# convert from Universal Time to Dynamic Time at 2000-01-01
T = MJD - 51544.4993
#-- mean longitude of moon
# mean longitude of moon
s = 218.3164 + 13.17639648 * T
#-- mean longitude of sun
# mean longitude of sun
h = 280.4661 + 0.98564736 * T
#-- mean longitude of lunar perigee
# mean longitude of lunar perigee
p = 83.3535 + 0.11140353 * T
#-- mean longitude of ascending lunar node
# mean longitude of ascending lunar node
N = 125.0445 - 0.05295377 * T
#-- solar perigee at epoch 2000
# solar perigee at epoch 2000
PP = 282.8

#-- take the modulus of each
# take the modulus of each
s = np.mod(s, circle)
h = np.mod(h, circle)
p = np.mod(p, circle)
N = np.mod(N, circle)

#-- return as tuple
# return as tuple
return (s, h, p, N, PP)
12 changes: 6 additions & 6 deletions pyTMD/calc_delta_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
import scipy.interpolate
import pyTMD.time

#-- PURPOSE: calculate the difference between universal time and dynamical time
#-- by interpolating a delta time file to a given date
# PURPOSE: calculate the difference between universal time and dynamical time
# by interpolating a delta time file to a given date
def calc_delta_time(delta_file, idays):
"""
Calculates the difference between universal time (UT) and
Expand All @@ -61,12 +61,12 @@ def calc_delta_time(delta_file, idays):
----------
.. [Meeus1998] J. Meeus, *Astronomical Algorithms*, 2nd edition, 477 pp., (1998).
"""
#-- read delta time file
# read delta time file
dinput = np.loadtxt(os.path.expanduser(delta_file))
#-- calculate Julian days and then convert to days since 1992-01-01T00:00:00
# calculate Julian days and then convert to days since 1992-01-01T00:00:00
days = pyTMD.time.convert_calendar_dates(dinput[:,0],dinput[:,1],dinput[:,2],
epoch=(1992,1,1,0,0,0))
#-- use scipy interpolating splines to interpolate delta times
# use scipy interpolating splines to interpolate delta times
spl = scipy.interpolate.UnivariateSpline(days,dinput[:,3],k=1,s=0,ext=0)
#-- return the delta time for the input date converted to days
# return the delta time for the input date converted to days
return spl(idays)/86400.0
4 changes: 2 additions & 2 deletions pyTMD/check_tide_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ def check_tide_points(x, y, DIRECTORY=None, MODEL=None,
array describing if input coordinate is within model domain
"""

#-- check that tide directory is accessible
# check that tide directory is accessible
try:
os.access(DIRECTORY, os.F_OK)
except:
raise FileNotFoundError("Invalid tide directory")

#-- get parameters for tide model
# get parameters for tide model
if DEFINITION_FILE is not None:
model = pyTMD.model(DIRECTORY).from_file(DEFINITION_FILE)
else:
Expand Down
24 changes: 12 additions & 12 deletions pyTMD/compute_equilibrium_tide.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,25 @@ def compute_equilibrium_tide(t, lat):
.. [1] Cartwright & Tayler, Geophys. J. R.A.S., 23, 45, 1971.
.. [2] Cartwright & Edden, Geophys. J. R.A.S., 33, 253, 1973.
"""
#-- longitude of moon
#-- longitude of sun
#-- longitude of lunar perigee
#-- longitude of ascending lunar node
# longitude of moon
# longitude of sun
# longitude of lunar perigee
# longitude of ascending lunar node
PHC = np.array([290.21,280.12,274.35,343.51])
DPD = np.array([13.1763965,0.9856473,0.1114041,0.0529539])

#-- number of input points
# number of input points
nt = len(np.atleast_1d(t))
nlat = len(np.atleast_1d(lat))
#-- compute 4 principal mean longitudes in radians at delta time (SHPN)
# compute 4 principal mean longitudes in radians at delta time (SHPN)
SHPN = np.zeros((4,nt))
for N in range(4):
#-- convert time from days relative to 1992-01-01 to 1987-01-01
# convert time from days relative to 1992-01-01 to 1987-01-01
ANGLE = PHC[N] + (t + 1826.0)*DPD[N]
SHPN[N,:] = np.pi*np.mod(ANGLE, 360.0)/180.0

#-- assemble long-period tide potential from 15 CTE terms greater than 1 mm
#-- nodal term is included but not the constant term.
# assemble long-period tide potential from 15 CTE terms greater than 1 mm
# nodal term is included but not the constant term.
PH = np.zeros((nt))
Z = np.zeros((nt))
Z += 2.79*np.cos(SHPN[3,:]) - 0.49*np.cos(SHPN[1,:] - \
Expand All @@ -80,13 +80,13 @@ def compute_equilibrium_tide(t, lat):
0.53*np.cos(PH - SHPN[2,:] + SHPN[3,:]) - \
0.24*np.cos(PH - 2.0*SHPN[1,:] + SHPN[2,:])

#-- Multiply by gamma_2 * normalization * P20(lat)
# Multiply by gamma_2 * normalization * P20(lat)
gamma_2 = 0.693
P20 = 0.5*(3.0*np.sin(lat*np.pi/180.0)**2 - 1.0)
#-- calculate long-period equilibrium tide and convert to meters
# calculate long-period equilibrium tide and convert to meters
if (nlat != nt):
lpet = gamma_2*np.sqrt((4.0+1.0)/(4.0*np.pi))*np.outer(P20,Z/100.0)
else:
lpet = gamma_2*np.sqrt((4.0+1.0)/(4.0*np.pi))*P20*(Z/100.0)
#-- return the long-period equilibrium tides
# return the long-period equilibrium tides
return lpet
Loading

0 comments on commit 75c4c7c

Please sign in to comment.