Solve Synthetic Tides
This notebook demonstrates solving for the harmonic constants of a tidal time series at a given location
Important
Need to download tide model prior to running this notebook.
OTIS format tidal solutions provided by Oregon State University and ESR
Global Tide Model (GOT) solutions provided by Richard Ray at GSFC
Finite Element Solution (FES) provided by AVISO
Python Dependencies
Program Dependencies
astro.py: computes the basic astronomical mean longitudesconstituents.py: calculates constituent parameters and nodal argumentsio.model.py: retrieves tide model parameters for named tide modelsio.OTIS.py: extract tidal harmonic constants from OTIS tide modelsio.ATLAS.py: extract tidal harmonic constants from ATLAS netCDF4 tide modelsio.GOT.py: extract tidal harmonic constants from GOT tide modelsio.FES.py: extract tidal harmonic constants from FES tide modelspredict.py: predict tidal values using harmonic constantssolve.py: estimates the harmonic constants for ocean tidesutilities.py: download and management utilities for files
Note
This notebook uses Jupyter widgets to set parameters for calculating the tidal maps.
Load modules
from __future__ import print_function
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import IPython.display
import ipywidgets
# import tide programs
import pyTMD.tools
import timescale.time
# autoreload
%load_ext autoreload
%autoreload 2
Set parameters for program
Model directory
Tide model for synthetic
# available model list
model_list = sorted(pyTMD.io.model.ocean_elevation())
# display widgets for setting directory and model
TMDwidgets = pyTMD.tools.widgets()
TMDwidgets.model.options = model_list
TMDwidgets.model.value = "GOT4.10_nc"
TMDwidgets.VBox(
[
TMDwidgets.directory,
TMDwidgets.model,
]
)
Select location for tide synthetic
# default coordinates to use
LAT, LON = (-76.0, -40.0)
m = pyTMD.tools.leaflet(
center=(LAT, LON),
zoom=3,
zoom_control=True,
marker_control=True,
attribution=False,
)
# show map
m.map
HTML table with outputs
table = ipywidgets.HTML()
display(table)
Calculate and plot solution
# get model parameters and open dataset
model = pyTMD.io.model(TMDwidgets.directory.value).from_database(
TMDwidgets.model.value
)
ds = model.open_dataset(group="z")
# list of model constituents
c = ds.tmd.constituents
# convert time to days relative to Jan 1, 1992 (48622 MJD)
minutes = np.arange(366 * 1440)
ts = timescale.from_calendar(2000, 1, 1, minute=minutes)
# delta time (TT - UT1)
if model.format in ("GOT-ascii", "GOT-netcdf", "FES-netcdf"):
DELTAT = ts.tt_ut1
elif model.format == "FES-netcdf":
DELTAT = np.zeros_like(ts.tide)
# update the tide solution
def update_tide_solution(*args):
# leaflet location
LAT, LON = np.copy(m.marker.location)
# verify longitudes
LON = m.wrap_longitudes(LON)
# convert to model grid coordinates
x, y = ds.tmd.coords_as(LON, LAT)
# interpolate to grid points and convert to centimeters
local = ds.tmd.interp(x, y, extrapolate=True)
local = local.tmd.to_units("cm")
# predict tidal elevations at time
TIDE = local.tmd.predict(
ts.tide, deltat=DELTAT, corrections=model.corrections
)
# infer minor constituents and add to major components
TIDE += local.tmd.infer(
ts.tide, deltat=DELTAT, corrections=model.corrections
)
# solve for harmonic constants
dsolve = pyTMD.solve.constants(
ts.tide,
TIDE.values,
c,
deltat=DELTAT,
corrections=model.corrections,
infer_minor=True,
)
# create data table for original and solution amplitudes and phases
columns = [
"Constituent",
"Original Amplitude",
"Original Phase",
"Solution Amplitude",
"Solution Phase",
]
data = {col: [] for col in columns}
# add constituents to data table
for i, con in enumerate(c):
data["Constituent"].append(con)
data["Original Amplitude"].append(f"{local[con].tmd.amplitude:0.1f}cm")
data["Original Phase"].append(f"{local[con].tmd.phase:0.1f}\u00b0")
data["Solution Amplitude"].append(f"{dsolve[con].tmd.amplitude:0.1f}cm")
data["Solution Phase"].append(f"{dsolve[con].tmd.phase:0.1f}\u00b0")
# create dataframe and HTML table
df = pd.DataFrame(data)
table.value = df.to_html(index=False)
# run tide prediction and solution at initial location
update_tide_solution()
# watch marker location for changes
m.marker_text.observe(update_tide_solution)