Plot ATLAS Compact
This (notebook
) demonstrates plotting the global and local solutions from an ATLAS compact model
OTIS format tidal solutions provided by Oregon State University and ESR
Python Dependencies
Program Dependencies
io.model.py
: retrieves tide model parameters for named tide modelsio.OTIS.py
: extract tidal harmonic constants from OTIS tide models
This notebook uses Jupyter widgets to set parameters for calculating the tidal maps.
Load modules
from __future__ import print_function
import os
import numpy as np
import matplotlib.pyplot as plt
import pyTMD.tools
import pyTMD.io
# autoreload
%load_ext autoreload
%autoreload 2
Set parameters for program
Model directory
Tide model
# available model list
model_list = sorted(pyTMD.io.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
TMDwidgets.VBox([
TMDwidgets.directory,
TMDwidgets.model,
TMDwidgets.compress,
])
Setup tide model parameters
# get model parameters
model = pyTMD.io.model(TMDwidgets.directory.value,
compressed=TMDwidgets.compress.value
).elevation(TMDwidgets.model.value)
# read each constituent
constituents,nc = pyTMD.io.OTIS.read_constituents(model.model_file)
Read ATLAS Compact model
# if reading a global solution with localized solutions
x0,y0,hz0,mz0,iob,dt,pmask,local = pyTMD.io.OTIS.read_atlas_grid(model.grid_file)
xi,yi,hz = pyTMD.io.OTIS.combine_atlas_model(x0,y0,hz0,pmask,local,variable='depth')
mz = pyTMD.io.OTIS.create_atlas_mask(x0,y0,mz0,local,variable='depth')
# resample global solution to 2 arc-minute solution
x30,y30,hz30 = pyTMD.io.OTIS.interpolate_atlas_model(x0,y0,hz0)
Plot global and local masks
%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()
Plot differences between global and local solutions
# 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_title(f'{model.name} Bathymetry Differences', fontsize=13,
rotation=0, y=-1.4, va='top')
cbar.ax.set_xlabel('%', fontsize=13, rotation=0, va='center')
cbar.ax.xaxis.set_label_coords(1.065, 0.5)
# 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.io.OTIS.read_atlas_elevation(model.model_file,i,c)
xi,yi,z = pyTMD.io.OTIS.combine_atlas_model(x0,y0,z0,pmask,zlocal,variable='z')
# resample global solution to 2 arc-minute solution
x30,y30,z30 = pyTMD.io.OTIS.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_title(f'{model.name} Tide Height Differences', fontsize=13,
rotation=0, y=-1.4, va='top')
cbar.ax.set_xlabel('%', fontsize=13, rotation=0, va='center')
cbar.ax.xaxis.set_label_coords(1.065, 0.5)
# 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()