Skip to content

Commit

Permalink
Merge pull request #21 from tsutterley/interpolation
Browse files Browse the repository at this point in the history
replaced griddata with scipy regular grid interpolators
  • Loading branch information
tsutterley authored Aug 28, 2020
2 parents 030c423 + 9b49f4c commit 41f8caf
Show file tree
Hide file tree
Showing 28 changed files with 1,160 additions and 164 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ wheels/
*.egg-info/
.installed.cfg
*.egg
.pytest_cache
pythonenv*/
# OS generated files #
######################
.DS_Store
Expand Down
2 changes: 1 addition & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
author = 'Tyler C. Sutterley'

# The full version, including alpha/beta/rc tags
release = '1.0.2.10'
release = '1.0.2.11'


# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion doc/source/user_guide/compute_tide_corrections.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ tide = compute_tide_corrections(x, y, delta_time, DIRECTORY=DIRECTORY,
- `METHOD`: interpolation method
* `bilinear`: quick bilinear interpolation
* `spline`: scipy bivariate spline interpolation (default)
* `linear`, `cubic`, `nearest`: scipy griddata interpolations
* `linear`, `nearest`: scipy regular grid interpolations
- `FILL_VALUE`: output invalid value

#### Outputs
Expand Down
2 changes: 1 addition & 1 deletion doc/source/user_guide/read_FES_model.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ amp,ph = read_FES_model(ilon,ilat,directory,model_files,TYPE=type,
- `METHOD`: interpolation method
* `'bilinear'`: quick bilinear interpolation
* `'spline'`: scipy bivariate spline interpolation
* `'linear'`, `'cubic'`, `'nearest'`: scipy griddata interpolations
* `'linear'`, `'nearest'`: scipy regular grid interpolations
- `GZIP`: input files are compressed
- `SCALE`: scaling factor for converting to output units

Expand Down
2 changes: 1 addition & 1 deletion doc/source/user_guide/read_GOT_model.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ amp,ph = read_GOT_model(ilon,ilat,directory,model_files,METHOD='spline')
- `METHOD`: interpolation method
* `'bilinear'`: quick bilinear interpolation
* `'spline'`: scipy bivariate spline interpolation
* `'linear'`, `'cubic'`, `'nearest'`: scipy griddata interpolations
* `'linear'`, `'nearest'`: scipy regular grid interpolations
- `GZIP`: input files are compressed
- `SCALE`: scaling factor for converting to output units

Expand Down
2 changes: 1 addition & 1 deletion doc/source/user_guide/read_netcdf_model.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ amp,ph,D,c = read_netcdf_model(ilon,ilat,directory,model_files,type,METHOD='spli
- `METHOD`: interpolation method
* `'bilinear'`: quick bilinear interpolation
* `'spline'`: scipy bivariate spline interpolation
* `'linear'`, `'cubic'`, `'nearest'`: scipy griddata interpolations
* `'linear'`, `'nearest'`: scipy regular grid interpolations
- `GZIP`: input netCDF4 files are compressed
- `SCALE`: scaling factor for converting to output units

Expand Down
8 changes: 6 additions & 2 deletions doc/source/user_guide/read_ocean_pole_tide.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ read_ocean_pole_tide.py

#### Calling Sequence
```python
from pyTMD.utilities import get_data_path
from pyTMD.read_ocean_pole_tide import read_ocean_pole_tide
ht = read_ocean_pole_tide(input_file)
ocean_pole_tide_file = get_data_path(['data','opoleloadcoefcmcor.txt.gz'])
ur,un,ue,glon,glat = read_ocean_pole_tide(ocean_pole_tide_file)
```
[Source code](https://github.com/tsutterley/pyTMD/blob/master/pyTMD/read_ocean_pole_tide.py)

#### Inputs
1. `input_file`: [IERS 0.5x0.5 map of ocean pole tide coefficients](ftp://maia.usno.navy.mil/conventions/2010/2010_update/chapter7/additional_info/opoleloadcoefcmcor.txt.gz)

#### Outputs
- `ur`: ocean pole tide coefficients
- `ur`: radial ocean pole tide coefficients
- `un`: north ocean pole tide coefficients
- `ue`: east ocean pole tide coefficients
- `glon`: grid longitude
- `glat`: grid latitude
2 changes: 1 addition & 1 deletion doc/source/user_guide/read_tide_model.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ amp,ph,D,c = read_tide_model(ilon, ilat, grid_file, model_file, EPSG,
- `METHOD`: interpolation method
* `'bilinear'`: quick bilinear interpolation
* `'spline'`: scipy bivariate spline interpolation
* `'linear'`, `'cubic'`, `'nearest'`: scipy griddata interpolations
* `'linear'`, `'nearest'`: scipy regular grid interpolations
- `GRID`: binary file type to read
* `'ATLAS'`: reading a global solution with high-resolution local solutions
* `'OTIS'`: combined global solution
Expand Down
7 changes: 3 additions & 4 deletions notebooks/Plot Antarctic Tidal Currents.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"import ipywidgets as widgets\n",
"from IPython.display import HTML\n",
"\n",
"import pyTMD.time\n",
"from pyTMD.calc_delta_time import calc_delta_time\n",
"from pyTMD.read_tide_model import extract_tidal_constants\n",
"from pyTMD.read_netcdf_model import extract_netcdf_constants\n",
Expand Down Expand Up @@ -280,10 +281,8 @@
"source": [
"#-- convert from calendar date to days relative to Jan 1, 1992 (48622 MJD)\n",
"YMD = datepick.value\n",
"tide_time = 367.0*YMD.year - \\\n",
" np.floor(7.0*(YMD.year + np.floor((YMD.month+9.0)/12.0))/4.0) - \\\n",
" np.floor(3.0*(np.floor((YMD.year + (YMD.month - 9.0)/7.0)/100.0) + 1.0)/4.0) + \\\n",
" np.floor(275.*YMD.month/9.0) + YMD.day + np.arange(24)/24.0 - 727594.0\n",
"tide_time = pyTMD.time.convert_calendar_dates(YMD.year, YMD.month,\n",
" YMD.day, hour=np.arange(24))\n",
"\n",
"#-- save tide currents\n",
"tide = {}\n",
Expand Down
7 changes: 3 additions & 4 deletions notebooks/Plot Ross Ice Shelf Map.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"import ipywidgets as widgets\n",
"from IPython.display import HTML\n",
"\n",
"import pyTMD.time\n",
"from pyTMD.calc_delta_time import calc_delta_time\n",
"from pyTMD.read_tide_model import extract_tidal_constants\n",
"from pyTMD.read_netcdf_model import extract_netcdf_constants\n",
Expand Down Expand Up @@ -287,10 +288,8 @@
"source": [
"#-- convert from calendar date to days relative to Jan 1, 1992 (48622 MJD)\n",
"YMD = datepick.value\n",
"tide_time = 367.0*YMD.year - \\\n",
" np.floor(7.0*(YMD.year + np.floor((YMD.month+9.0)/12.0))/4.0) - \\\n",
" np.floor(3.0*(np.floor((YMD.year + (YMD.month - 9.0)/7.0)/100.0) + 1.0)/4.0) + \\\n",
" np.floor(275.*YMD.month/9.0) + YMD.day + np.arange(24)/24.0 - 727594.0\n",
"tide_time = pyTMD.time.convert_calendar_dates(YMD.year, YMD.month,\n",
" YMD.day, hour=np.arange(24))\n",
"\n",
"#-- read tidal constants and interpolate to grid points\n",
"if model_format in ('OTIS','ATLAS'):\n",
Expand Down
9 changes: 4 additions & 5 deletions notebooks/Plot Tide Forecasts.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"import ipywidgets as widgets\n",
"import ipyleaflet as leaflet\n",
"\n",
"import pyTMD.time\n",
"from pyTMD.calc_delta_time import calc_delta_time\n",
"from pyTMD.infer_minor_corrections import infer_minor_corrections\n",
"from pyTMD.predict_tidal_ts import predict_tidal_ts\n",
Expand Down Expand Up @@ -182,11 +183,9 @@
"\n",
"#-- convert from calendar date to days relative to Jan 1, 1992 (48622 MJD)\n",
"YMD = datepick.value\n",
"TIME = np.arange(7*1440)/1440.0\n",
"tide_time = 367.0*YMD.year - \\\n",
" np.floor(7.0*(YMD.year + np.floor((YMD.month+9.0)/12.0))/4.0) - \\\n",
" np.floor(3.0*(np.floor((YMD.year + (YMD.month - 9.0)/7.0)/100.0) + 1.0)/4.0) + \\\n",
" np.floor(275.*YMD.month/9.0) + YMD.day + TIME - 727594.0\n",
"#-- calculate a weeks forecast every minute\n",
"tide_time = pyTMD.time.convert_calendar_dates(YMD.year, YMD.month,\n",
" YMD.day, minute=np.arange(7*1440))\n",
"\n",
"#-- select between tide models\n",
"if (TIDE_MODEL == 'CATS0201'):\n",
Expand Down
24 changes: 16 additions & 8 deletions pyTMD/compute_equilibrium_tide.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""
compute_equilibrium_tide.py (08/2020)
Calculates the long-period equilibrium ocean tides
Fifteen tidal spectral lines from the Cartwright-Tayler-Edden
tables are summed over to compute the long-period tides
Uses the summation of fifteen tidal spectral lines from the
Cartwright-Tayler-Edden tables to compute the long-period tides
INPUTS:
t: days relative to Jan 1, 1992 (48622 MJD)
Expand All @@ -14,6 +14,10 @@
REFERENCES:
Cartwright & Tayler, Geophys. J. R.A.S., 23, 45, 1971.
Cartwright & Edden, Geophys. J. R.A.S., 33, 253, 1973.
UPDATE HISTORY:
Updated 08/2020: use Load love number value of 0.693 for gamma_2
Written 08/2020
"""
import numpy as np

Expand All @@ -25,16 +29,17 @@ def compute_equilibrium_tide(t, lat):
PHC = np.array([290.21,280.12,274.35,343.51])
DPD = np.array([13.1763965,0.9856473,0.1114041,0.0529539])

#-- convert time from days relative to 1992-01-01 to 1987-01-01
#-- Compute 4 principal mean longitudes in radians at delta time
#-- number of input points
npts = len(t)
#-- compute 4 principal mean longitudes in radians at delta time (SHPN)
SHPN = np.zeros((4,npts))
for N in range(4):
#-- 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 > 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((npts))
Z = np.zeros((npts))
Z += 2.79*np.cos(SHPN[3,:]) - 0.49*np.cos(SHPN[1,:] - \
Expand All @@ -51,6 +56,9 @@ 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 * sqrt(5/4 pi) * P20(lat)
lpet = 0.437*Z*(1.5*np.sin(lat*np.pi/180.0)**2 - 0.5)/100.0
#-- 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
lpet = gamma_2*np.sqrt((4.0 + 1.0)/(4.0*np.pi))*P20*(Z/100.0)
return lpet
6 changes: 3 additions & 3 deletions pyTMD/compute_tide_corrections.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
METHOD: interpolation method
bilinear: quick bilinear interpolation
spline: scipy bivariate spline interpolation
linear, cubic, nearest: scipy griddata interpolations
linear, nearest: scipy regular grid interpolations
FILL_VALUE: output invalid value (default NaN)
PYTHON DEPENDENCIES:
Expand Down Expand Up @@ -125,7 +125,7 @@ def compute_tide_corrections(x, y, delta_time, DIRECTORY=None, MODEL=None,
METHOD: interpolation method
bilinear: quick bilinear interpolation
spline: scipy bivariate spline interpolation
linear, cubic, nearest: scipy griddata interpolations
linear, nearest: scipy regular grid interpolations
FILL_VALUE: output invalid value (default NaN)
Returns
Expand Down Expand Up @@ -174,7 +174,7 @@ def compute_tide_corrections(x, y, delta_time, DIRECTORY=None, MODEL=None,
'h_m4_tpxo9_atlas_30_v2.nc.gz','h_ms4_tpxo9_atlas_30_v2.nc.gz',
'h_mn4_tpxo9_atlas_30_v2.nc.gz','h_2n2_tpxo9_atlas_30_v2.nc.gz']
model_format = 'netcdf'
TYPE = 'z'
model_type = 'z'
SCALE = 1.0/1000.0
elif (MODEL == 'TPXO9.1'):
grid_file = os.path.join(DIRECTORY,'TPXO9.1','DATA','grid_tpxo9')
Expand Down
Loading

0 comments on commit 41f8caf

Please sign in to comment.