-
Notifications
You must be signed in to change notification settings - Fork 0
/
predict.py
67 lines (54 loc) · 1.99 KB
/
predict.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from datetime import datetime
from pytides.tide import Tide
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
##Prepare our tide data
station_id = 'Fernandina Beach'
columns = ['time', 'data']
heights = []
t = []
data = pd.read_csv('/Users/anonymous/clawpack_src/clawpack-v5.4.1rc-beta/geoclaw/examples/storm-surge/matthew/detide/data/FernandinaBeach.csv', header=None, names=columns)
for x in data.time:
if (x != 'time'):
datetime_object = datetime.strptime(x, '%x %H:%M')
t.append(datetime_object)
for y in data.data:
if (y != 'data'):
heights.append(float(y))
#print heights
#print t
#For a quicker decomposition, we'll only use hourly readings rather than 6-minutely readings.
# heights = np.array(heights[::10])
# t = np.array(t[::10])
##Prepare a list of datetimes, each 6 minutes apart, for a week.
prediction_t0 = datetime(2016,10,4)
hours = np.arange(6 * 24)
times = Tide._times(prediction_t0, hours)
# print times
##Fit the tidal data to the harmonic model using Pytides
my_tide = Tide.decompose(heights, t)
##Predict the tides using the Pytides model.
my_prediction = my_tide.at(times)
##Prepare NOAA's results
noaa_verified = []
noaa_predicted = []
column = ['time', 'prediction', 'verified']
result = pd.read_csv('/Users/anonymous/clawpack_src/clawpack-v5.4.1rc-beta/geoclaw/examples/storm-surge/matthew/detide/data/FernandinaBeach_noaa.csv', header=None, names=column)
for x in result.prediction:
if (x != 'prediction'):
print x
noaa_predicted.append(float(y))
for y in result.verified:
if (y != 'verified'):
noaa_verified.append(float(y))
#print noaa_predicted
##Plot the results
plt.plot(hours, my_prediction, label="Pytides")
plt.plot(hours, noaa_predicted, label="NOAA Prediction")
plt.plot(hours, noaa_verified, label="NOAA Verified")
plt.legend()
plt.title('Comparison of Pytides and NOAA predictions for Station: ' + str(station_id))
plt.xlabel('Hours since ' + str(prediction_t0) + '(GMT)')
plt.ylabel('Metres')
plt.show()