Download and plot gauge time series

Original Author: R.J. LeVeque, Modified by Christopher Liu to also work on Windows.

For data from the paper

"A Source Clustering Approach for Efficient Inundation Modeling and Regional Scale PTHA" by A.L. Williamson, D. Rim, L.M. Adams, R.J. LeVeque, D. Melgar, and F.I. González, Frontiers in Earth Science, 8 (2020) p. 442. [paper and more data].

This illustrates how to download gauge times series results from some of the 2000 GeoClaw fine-grid runs archived at http://krakatoa.uoregon.edu/cascadia_ptha/ground_truth.

The corresponding coarse-grid run results (on a 9 arcsecond grid) are in the directory http://krakatoa.uoregon.edu/cascadia_ptha/coarse_model_runs.

In [1]:
%pylab inline
Populating the interactive namespace from numpy and matplotlib
In [2]:
import os
from urllib.request import urlretrieve
from IPython.display import Image

Location of some gauges near westport

Open the gauges.kml file in Google Earth to see all gauge locations for these runs.

In [3]:
Image('westport_gauges.png', width=600)
Out[3]:

Function to download gauge files for a set of runs

In [4]:
# where to put the files downloaded:
datadir = os.path.join(os.getcwd(), 'westport_data')

def get_gauges_urllib(rnums, gaugenos):
    
    # create directory for data if it does not exist
    if not os.path.isdir(datadir):
        os.mkdir(datadir)
    
    for rnum in rnums:
        url = 'http://krakatoa.uoregon.edu/cascadia_ptha/ground_truth/ptha_%s/' % str(rnum).zfill(6)
        rundir = os.path.join(datadir, 'run%s' % str(rnum).zfill(6))
       
        if not os.path.isdir(rundir):
            os.mkdir(rundir)
        
        print('Data for run %s will go into directory %s' % (rnum, rundir))
        for gaugeno in gaugenos:
            fname = 'gauge%s.txt' % str(gaugeno).zfill(5)
            local_fname = os.path.join(rundir, fname)
            if os.path.isfile(local_fname):
                print('%s has already been downloaded' % fname)
            else:
                remote_fname = url + '/' + fname
                print('Downloading %s from %s' % (fname,url))
                a = urlretrieve(remote_fname, local_fname)
            

For illustration purposes we will just download a few, including the runs used in the paper.

The script download_gauges.py can be used to download all gauges from all 2000 simulations, or whatever subset you want.

In [6]:
get_gauges_urllib([1665,1670,1999],[3,120])
Data for run 1665 will go into directory /Users/rjl/git/Forks/jdf-autoencoder/frontiers2020_westport/westport_data/run001665
gauge00003.txt has already been downloaded
gauge00120.txt has already been downloaded
Data for run 1670 will go into directory /Users/rjl/git/Forks/jdf-autoencoder/frontiers2020_westport/westport_data/run001670
gauge00003.txt has already been downloaded
gauge00120.txt has already been downloaded
Data for run 1999 will go into directory /Users/rjl/git/Forks/jdf-autoencoder/frontiers2020_westport/westport_data/run001999
Downloading gauge00003.txt from http://krakatoa.uoregon.edu/cascadia_ptha/ground_truth/ptha_001999/
Downloading gauge00120.txt from http://krakatoa.uoregon.edu/cascadia_ptha/ground_truth/ptha_001999/
In [7]:
def plot_gauges(rnum, gaugenos):
    rundir = os.path.join(datadir, 'run%s' % str(rnum).zfill(6))
    figure(figsize=(12,5))
    for gaugeno in gaugenos:
        fname = 'gauge%s.txt' % str(gaugeno).zfill(5)
        local_fname = os.path.join(rundir, fname)
        d = loadtxt(local_fname, skiprows=3)
        print('gauge data has shape ',d.shape)
        t = d[:,1]  # time in seconds
        h = d[:,2]  # water depth in meters
        eta = d[:,5]  # surface elevation B+h in meters
        B = eta - h   # topography B in meters
        plot(t/3600., eta, label='Gauge %s' % str(gaugeno).rjust(5))
    grid(True)
    legend(loc='upper right')
    xlim(0,5)
    xlabel('hours')
    ylabel('meters')
    title('Run %s' % rnum);
In [8]:
plot_gauges(1665,[3,120])
gauge data has shape  (12332, 6)
gauge data has shape  (1988, 6)
In [9]:
plot_gauges(1670,[3,120])
gauge data has shape  (12130, 6)
gauge data has shape  (2075, 6)
In [10]:
plot_gauges(1999,[3,120])
gauge data has shape  (12241, 6)
gauge data has shape  (2075, 6)
In [ ]: