In [1]:
%matplotlib inline

In [2]:
import os
import tappy
import numpy as np
import matplotlib.pyplot as plt

from datetime import datetime

In [3]:
# Load the time series data from the tests
testfile = os.path.join('tests', 'output_ts', 'outts_original.dat')
timeconvert = lambda x: datetime.strptime(x, '%Y-%m-%dT%H:%M:%S')
dates, elevations = [], []
with open(testfile) as f:
    timeseries = f.readlines()
    for line in timeseries:
        date, elevation = line.strip().split(' ')
        dates.append(timeconvert(date))
        elevations.append(float(elevation))

In [4]:
fig = plt.figure(figsize=(10, 6))
ax = fig.add_subplot(111)
ax.plot_date(dates, elevations, 'g.-')
ax.set_ylabel('Surface elevation (m)')


Out[4]:
<matplotlib.text.Text at 0x7f94ac3587d0>

In [5]:
# Set up the bits needed for TAPPY. This is mostly lifted from
# tappy.py in the baker function "analysis" (around line 1721).
quiet = True
debug = False
outputts = False
outputxml = False
ephemeris = False
rayleigh = 1
print_vau_table = False
missing_data = 'ignore'
linear_trend = False
remove_extreme = False
zero_ts = None
filter = None
pad_filters = None
include_inferred = True
if rayleigh:
    ray = float(rayleigh)

# Make the TAPPY object with the relevant configuration.
x = tappy.tappy(outputts=outputts,
                outputxml=outputxml,
                quiet=quiet,
                debug=debug,
                ephemeris=ephemeris,
                rayleigh=rayleigh,
                print_vau_table=print_vau_table,
                missing_data=missing_data,
                linear_trend=linear_trend,
                remove_extreme=remove_extreme,
                zero_ts=zero_ts,
                filter=filter,
                pad_filters=pad_filters,
                include_inferred=include_inferred)

In [6]:
# Populate the TAPPY object with the data we loaded.
x.dates = dates
x.elevation = elevations
package = x.astronomic(x.dates)
(x.zeta, x.nu, x.nup, x.nupp, x.kap_p, x.ii, x.R, x.Q, x.T, x.jd, x.s, x.h, x.N, x.p, x.p1) = package
(x.speed_dict, x.key_list) = x.which_constituents(len(x.dates), package, rayleigh_comp=ray)

In [7]:
# Perform the analysis
x.constituents()

In [8]:
# Print the M2 phase and amplitude.
print('M2 phase:     {}'.format(x.phase['M2']))
print('M2 amplitude: {}'.format(x.r['M2']))


M2 phase:     22.498501109
M2 amplitude: 0.662085904432

In [16]: