Check if a given point is within a tide model domain
OTIS format tidal solutions provided by Ohio State University and ESR
convert_ll_xy.py
: convert lat/lon points to and from projected coordinatesmodel.py
: retrieves tide model parameters for named tide modelsread_tide_model.py
: extract tidal harmonic constants from OTIS tide modelsThis notebook uses Jupyter widgets to set parameters for calculating the tidal maps.
from __future__ import print_function
import os
import numpy as np
import matplotlib.pyplot as plt
import ipywidgets as widgets
import pyTMD.time
import pyTMD.model
import pyTMD.tools
import pyTMD.read_tide_model
# autoreload
%load_ext autoreload
%autoreload 2
# available model list
model_list = sorted(pyTMD.model.ATLAS_compact())
# display widgets for setting directory and model
TMDwidgets = pyTMD.tools.widgets()
TMDwidgets.model.options = model_list
TMDwidgets.model.value = 'TPXO8-atlas'
TMDwidgets.compress.value = False
widgets.VBox([
TMDwidgets.directory,
TMDwidgets.model,
TMDwidgets.compress,
])
# get model parameters
model = pyTMD.model(TMDwidgets.directory.value,
compressed=TMDwidgets.compress.value
).elevation(TMDwidgets.model.value)
# read each constituent
constituents,nc = pyTMD.read_tide_model.read_constituents(model.model_file)
# if reading a global solution with localized solutions
x0,y0,hz0,mz0,iob,dt,pmask,local = pyTMD.read_tide_model.read_atlas_grid(model.grid_file)
xi,yi,hz = pyTMD.read_tide_model.combine_atlas_model(x0,y0,hz0,pmask,local,VARIABLE='depth')
mz = pyTMD.read_tide_model.create_atlas_mask(x0,y0,mz0,local,VARIABLE='depth')
# resample global solution to 2 arc-minute solution
x30,y30,hz30 = pyTMD.read_tide_model.interpolate_atlas_model(x0,y0,hz0)
%matplotlib widget
# plot the ATLAS mask
fig,ax1 = plt.subplots(num=1, figsize=(8.25,5.25), dpi=120)
ax1.imshow(mz, interpolation='nearest',
extent=(xi.min(),xi.max(),yi.min(),yi.max()),
vmin=0, vmax=1, origin='lower', cmap='gray_r', alpha=0.5)
ax1.imshow(pmask, interpolation='nearest',
extent=(x0.min(),x0.max(),y0.min(),y0.max()),
vmin=0, vmax=1, origin='lower', cmap='Purples', alpha=0.5)
# no ticks on the x and y axes
ax1.get_xaxis().set_ticks([])
ax1.get_yaxis().set_ticks([])
# stronger linewidth on frame
[i.set_linewidth(2.0) for i in ax1.spines.values()]
# adjust subplot within figure
fig.subplots_adjust(left=0.02,right=0.98,bottom=0.05,top=0.98)
plt.show()
# percent difference between grids
percent = 100.0*(hz30 - hz)/hz30
# plot the percent difference between ATLAS depth
fig,ax2 = plt.subplots(num=2, figsize=(8.25,5.25), dpi=120)
im = ax2.imshow(percent, interpolation='nearest',
extent=(xi.min(),xi.max(),yi.min(),yi.max()),
vmin=-40, vmax=40, origin='lower', cmap='PRGn')
# Add colorbar and adjust size
# pad = distance from main plot axis
# extend = add extension triangles to upper and lower bounds
# options: neither, both, min, max
# shrink = percent size of colorbar
# aspect = lengthXwidth aspect of colorbar
cbar = plt.colorbar(im, ax=ax2, pad=0.025, extend='both',
extendfrac=0.0375, orientation='horizontal', shrink=0.925,
aspect=22, drawedges=False)
# rasterized colorbar to remove lines
cbar.solids.set_rasterized(True)
# Add label to the colorbar
cbar.ax.set_xlabel('{0} Bathymetry Differences'.format(model.name), fontsize=13)
cbar.ax.set_ylabel('%', fontsize=13, rotation=0)
cbar.ax.yaxis.set_label_coords(1.0325, 0.15)
# ticks lines all the way across
cbar.ax.tick_params(which='both', width=1, length=23,
labelsize=13, direction='in')
# no ticks on the x and y axes
ax2.get_xaxis().set_ticks([])
ax2.get_yaxis().set_ticks([])
# stronger linewidth on frame
[i.set_linewidth(2.0) for i in ax2.spines.values()]
# adjust subplot within figure
fig.subplots_adjust(left=0.02,right=0.98,bottom=0.05,top=0.98)
plt.show()
# total amplitude difference for all constituents
diff = np.zeros_like(hz30)
power = np.zeros_like(hz30)
# for each constituent
for i,c in enumerate(constituents):
# if reading a global solution with localized solutions
z0,zlocal = pyTMD.read_tide_model.read_atlas_elevation(model.model_file,i,c)
xi,yi,z = pyTMD.read_tide_model.combine_atlas_model(x0,y0,z0,pmask,zlocal,VARIABLE='z')
# resample global solution to 2 arc-minute solution
x30,y30,z30 = pyTMD.read_tide_model.interpolate_atlas_model(x0,y0,z0)
# add to total amplitude difference
diff += (z30.real - z.real)**2 + (z30.imag - z.imag)**2
power += z30.real**2 + z30.imag**2
# calculate the percent difference
percent = 100.0*np.sqrt(diff/power)
# plot the percent between ATLAS tidal amplitudes
fig,ax3 = plt.subplots(num=3, figsize=(8.25,5.25), dpi=120)
im = ax3.imshow(percent, interpolation='nearest',
extent=(xi.min(),xi.max(),yi.min(),yi.max()),
vmin=0, vmax=100, origin='lower', cmap='BuPu')
# Add colorbar and adjust size
# pad = distance from main plot axis
# extend = add extension triangles to upper and lower bounds
# options: neither, both, min, max
# shrink = percent size of colorbar
# aspect = lengthXwidth aspect of colorbar
cbar = plt.colorbar(im, ax=ax3, pad=0.025, extend='max',
extendfrac=0.0375, orientation='horizontal', shrink=0.925,
aspect=22, drawedges=False)
# rasterized colorbar to remove lines
cbar.solids.set_rasterized(True)
# Add label to the colorbar
cbar.ax.set_xlabel('{0} Tide Height Differences'.format(model.name), fontsize=13)
cbar.ax.set_ylabel('%', fontsize=13, rotation=0)
cbar.ax.yaxis.set_label_coords(1.0325, 0.15)
# ticks lines all the way across
cbar.ax.tick_params(which='both', width=1, length=23,
labelsize=13, direction='in')
# no ticks on the x and y axes
ax3.get_xaxis().set_ticks([])
ax3.get_yaxis().set_ticks([])
# stronger linewidth on frame
[i.set_linewidth(2.0) for i in ax3.spines.values()]
# adjust subplot within figure
fig.subplots_adjust(left=0.02,right=0.98,bottom=0.05,top=0.98)
plt.show()