-
Notifications
You must be signed in to change notification settings - Fork 20
/
fetch_forecast.py
47 lines (40 loc) · 1.65 KB
/
fetch_forecast.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
import matplotlib.pyplot as plt
import surfpy
if __name__=='__main__':
ri_wave_location = surfpy.Location(41.4, -71.45, altitude=30.0, name='Block Island Sound')
ri_wave_location.depth = 30.0
ri_wave_location.angle = 145.0
ri_wave_location.slope = 0.02
ec_wave_model = surfpy.wavemodel.us_east_coast_wave_model()
print('Fetching WW3 Wave Data')
if ec_wave_model.fetch_grib_datas(ri_wave_location, 0, 60):
data = ec_wave_model.to_buoy_data()
else:
print('Failed to fetch wave forecast data')
sys.exit(1)
print('Fetching GFS Weather Data')
ri_wind_location = surfpy.Location(41.6, -71.5, altitude=10.0, name='Narragansett Pier')
gfs_model = surfpy.weathermodel.global_gfs_model()
if gfs_model.fetch_grib_datas(ri_wind_location, 0, 60):
gfs_model.fill_buoy_data(data)
else:
print('Failed to fetch wind forecast data')
#sys.exit(1)
for dat in data:
dat.solve_breaking_wave_heights(ri_wave_location)
dat.change_units(surfpy.units.Units.english)
json_data = surfpy.serialize(data)
with open('forecast.json', 'w') as outfile:
outfile.write(json_data)
maxs =[x.maximum_breaking_height for x in data]
mins = [x.minimum_breaking_height for x in data]
summary = [x.wave_summary.wave_height for x in data]
times = [x.date for x in data]
plt.plot(times, maxs, c='green')
plt.plot(times, mins, c='blue')
plt.plot(times, summary, c='red')
plt.xlabel('Hours')
plt.ylabel('Breaking Wave Height (ft)')
plt.grid(True)
plt.title('WaveWatch III: ' + ec_wave_model.latest_model_time().strftime('%d/%m/%Y %Hz'))
plt.show()