Skip to content

Commit 5ebad49

Browse files
authored
Feat: Add tide chart (#20)
1 parent 1b8f0ab commit 5ebad49

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

wavey/__main__.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,12 @@ def main(
9999
wave_height_forecast = read_forecast_data(grbs, ForecastType.WaveHeight)
100100
wave_direction_forecast = read_forecast_data(grbs, ForecastType.WaveDirection)
101101
wave_period_forecast = read_forecast_data(grbs, ForecastType.WavePeriod)
102+
tide_height_forecast = read_forecast_data(grbs, ForecastType.SeaSurfaceHeight)
102103

103104
wave_height_ft = wave_height_forecast.data * FEET_PER_METER
104105
wave_direction_rad = wave_direction_forecast.data * np.pi / 180
105106
wave_period_sec = wave_period_forecast.data
107+
tide_height_ft = tide_height_forecast.data * FEET_PER_METER
106108
lats = wave_height_forecast.lats
107109
lons = wave_height_forecast.lons
108110
analysis_date_pacific = utc_to_pt(wave_height_forecast.analysis_date_utc)
@@ -123,11 +125,16 @@ def main(
123125
"Unexpected: Monastery data contains masked points"
124126
)
125127

126-
# Plotting swell and period graph
128+
# Get tide height. We measure at Breakwater for simplicity.
127129

128-
LOG.info("Plotting swell and period graph")
129-
fig, (ax_height, ax_period) = plt.subplots(
130-
2, 1, figsize=(9, 6), sharex=True, gridspec_kw={"height_ratios": [2, 1]}, dpi=DPI
130+
tide_height_ft = tide_height_ft[..., BREAKWATER_LAT_IDX, BREAKWATER_LON_IDX]
131+
assert not np.ma.is_masked(tide_height_ft), "Unexpected: sea level data contains masked points"
132+
133+
# Plotting graph
134+
135+
LOG.info("Plotting graph")
136+
fig, (ax_height, ax_period, ax_tide) = plt.subplots(
137+
3, 1, figsize=(8, 8), sharex=True, gridspec_kw={"height_ratios": [2, 1, 1]}, dpi=DPI
131138
)
132139

133140
# NOTE: need to erase timezone info for mlpd3 to plot local times correctly
@@ -151,11 +158,18 @@ def main(
151158
ax_period.plot(times, y, label=labels[i], color=colors[i]) # type: ignore[arg-type]
152159

153160
ax_period.set_ylabel("Primary wave period (sec)")
154-
ax_period.set_xlabel("Time (Pacific)")
155161
ax_period.yaxis.label.set_fontsize(14)
162+
ax_period.xaxis.set_ticks_position("bottom")
156163
ax_period.legend(loc="upper right")
157164
ax_period.grid(True, linestyle=":", alpha=0.7)
158165

166+
ax_tide.plot(times, tide_height_ft, color="black")
167+
168+
ax_tide.set_ylabel("Tide height (ft)")
169+
ax_tide.yaxis.label.set_fontsize(14)
170+
ax_tide.set_xlabel("Time (Pacific)")
171+
ax_tide.grid(True, linestyle=":", alpha=0.7)
172+
159173
plt.tight_layout()
160174
fig_div = mpld3.fig_to_html(fig)
161175

0 commit comments

Comments
 (0)