1212from jinja2 import Environment , PackageLoader , select_autoescape
1313from tqdm import tqdm
1414
15+ import wavey
1516from wavey .common import DATETIME_FORMAT , FEET_PER_METER , TZ_PACIFIC , TZ_UTC , setup_logging
1617from wavey .grib import NUM_DATA_POINTS , ForecastType , read_forecast_data
1718from wavey .map import DEFAULT_ARROW_LENGTH , RESOLUTION , Map
@@ -85,8 +86,6 @@ def main(
8586 if resolution != "f" :
8687 LOG .warning ("Not drawing full resolution coastlines. Use the flag '--resolution f'" )
8788
88- out_dir .mkdir (parents = True , exist_ok = True )
89-
9089 # Download data, if needed
9190
9291 if grib_path is None :
@@ -116,9 +115,9 @@ def main(
116115 mon_wave_heights_ft = wave_height_ft [..., MONASTERY_LAT_IDX , MONASTERY_LON_IDX ]
117116 assert not np .ma .is_masked (mon_wave_heights_ft ), "Unexpected: Monastery data contains masked points"
118117
119- # Draw Breakwater graph
118+ # Plotting swell graph
120119
121- LOG .info ("Drawing swell graph" )
120+ LOG .info ("Plotting swell graph" )
122121 fig , ax = plt .subplots (figsize = (9 , 3 ), dpi = DPI )
123122
124123 # NOTE: need to erase timezone info for mlpd3 to plot local times correctly
@@ -136,7 +135,7 @@ def main(
136135 plt .tight_layout ()
137136 fig_div = mpld3 .fig_to_html (fig )
138137
139- # Draw figure
138+ # Draw maps
140139
141140 fig = plt .figure (figsize = (8 , 10 ), dpi = DPI )
142141 gs = fig .add_gridspec (2 , 2 , height_ratios = [3 , 1 ])
@@ -195,6 +194,7 @@ def main(
195194 plt .tight_layout ()
196195 plt .colorbar (map_main .img , orientation = "vertical" , label = "(ft)" , shrink = 0.8 )
197196
197+ LOG .info ("Creating colormap frames" )
198198 plot_dir = out_dir / "plots"
199199 plot_dir .mkdir (parents = True , exist_ok = True )
200200 for hour_i in tqdm (range (NUM_DATA_POINTS )):
@@ -208,22 +208,26 @@ def main(
208208 ax_main .set_title (f"Significant wave height (ft) and wave direction\n Hour { hour_i :03} -- { pacific_time_str } " )
209209 savefig (plot_dir / f"{ hour_i } .png" )
210210
211- # Get current time
211+ # Get current time and version
212212
213213 now_utc = datetime .datetime .now (tz = TZ_UTC )
214214 now_pacific = now_utc .astimezone (tz = TZ_PACIFIC )
215215 now_pacific_str = now_pacific .strftime (DATETIME_FORMAT )
216216
217+ version = wavey .__version__
218+
217219 # Export HTML
218220
219- LOG .info (f"Saving webpage to '{ out_dir } '" )
221+ out_html_path = out_dir / "index.html"
222+ LOG .info (f"Saving webpage to '{ out_html_path } '" )
220223 env = Environment (loader = PackageLoader ("wavey" ), autoescape = select_autoescape ())
221224 template_html = env .get_template ("index.html.j2" )
222225 out_html = template_html .render (
223226 swell_graph = fig_div ,
224227 last_updated = now_pacific_str ,
228+ version = version ,
225229 )
226- ( out_dir / "index.html" ) .write_text (out_html )
230+ out_html_path .write_text (out_html )
227231
228232
229233if __name__ == "__main__" :
0 commit comments