44By: Aodhan Sweeney
55
66This GUI takes data pulled from the National
7- Hurricane Center and efficiently sifts through
8- the data to plot specific storms and their
9- tracks. The GUI runs using ipwidgets, and
10- is intended to be used as an ipython
11- notebook.
7+ Hurricane Center and plots specific storms and
8+ their tracks. The GUI runs using ipwidgets, and
9+ is intended to be used as an ipython notebook.
1210"""
13- import os
1411
1512import cartopy .crs as ccrs
1613import ipywidgets as widgets
1714import matplotlib .pyplot as plt
1815import numpy as np
1916from pandas import DataFrame
20- from siphon .simplewebservice . nhc import nhc
17+ from siphon .simplewebservice import nhc
2118
2219class NHC_GUI :
2320 """
@@ -36,7 +33,7 @@ def __init__(self):
3633 and 2.) indicate when they have chosen the year and when to continue with parsing
3734 the storm_table.
3835 """
39- self .NHCD = NHC .NHCD ()
36+ self .NHCD = nhc .NHCD ()
4037 self .storm_table = self .NHCD .storm_table
4138 # Year Slider Widget to select year for which to retrieve storm data.
4239 self .year_slider = widgets .IntSlider (min = 1851 , max = 2019 , value = 2019 ,
@@ -59,7 +56,7 @@ def get_storms_slider(self, year_slider):
5956 tells value of year chosen by the user
6057 """
6158 self .year = str (year_slider )
62- self .one_year_table = self .storm_table [self .storm_table .Year == str ( year_slider ) ]
59+ self .one_year_table = self .storm_table [self .storm_table .Year == year_slider ]
6360 self .storm_names = widgets .Dropdown (options = self .one_year_table ['Name' ],
6461 description = 'Storm Names: ' )
6562 widgets .interact (self .get_name_dropdown , storm_names = self .storm_names )
@@ -110,7 +107,7 @@ def get_models(self, models):
110107 list of ran for a given storm
111108 """
112109 self .NHCD .model_selection_latlon (models )
113- self .date_times = self .NHCD .date_times
110+ self .date_times = self .NHCD .date_times . tolist ()
114111 self .plot_slider = widgets .IntSlider (min = 0 , max = (len (self .date_times )- 1 ),
115112 value = 0 , description = 'Tracks Time' ,
116113 disabled = False )
@@ -137,7 +134,7 @@ def plotting(self, plot_slider):
137134 month = self .date_times [plot_slider ][4 : 6 ]
138135 day = self .date_times [plot_slider ][6 : 8 ]
139136 hour = self .date_times [plot_slider ][8 : 10 ]
140- time_string = 'Date: {0}/{1}/{2} \n Hour : {3}' .format (month , day , year , hour )
137+ time_string = 'Date: {0}/{1}/{2} \n Hour : {3}' .format (month , day , year , hour )
141138
142139 # Finding data for best track, and extremes for which to base axis extent on
143140 self .best_lats = np .array (self .NHCD .best_track_coordinates [0 ])
@@ -147,16 +144,20 @@ def plotting(self, plot_slider):
147144 min_best_lon = min (self .best_lons )
148145 max_best_lon = max (self .best_lons )
149146
147+
150148 #Plotting the tracks on top of a cartopy stock image projection
151149 self .fig = plt .figure (figsize = (14 , 11 ))
152150 self .ax = self .fig .add_subplot (1 , 1 , 1 , projection = ccrs .PlateCarree ())
153151 self .ax .stock_img ()
154152 self .data_projection = ccrs .PlateCarree ()
155153 self .ax .plot (self .best_lons , self .best_lats , marker = 'o' , color = 'white' ,
156154 label = 'Best Track' , transform = self .data_projection )
155+
157156 self .ax .set_extent ([(min_best_lon - 40 ), (max_best_lon + 40 ),
158157 (min_best_lat - 40 ), (max_best_lat + 40 )])
159158
159+
160+
160161 jet = plt .get_cmap ('jet' )
161162 colors = iter (jet (np .linspace (0.2 , 1 , (len (self .model_select .value )+ 1 ))))
162163 left = .1
@@ -165,17 +166,15 @@ def plotting(self, plot_slider):
165166 fontsize = 14 , color = 'black' )
166167
167168 for model_type in self .NHCD .model_table :
168- one_model_time = model_type [model_type ['WarnDT' ] ==
169- self .date_times [plot_slider ]]
169+ one_model_time = model_type [model_type ['WarnDT' ] == self .date_times [plot_slider ]]
170170 lats = one_model_time ['Lat' ].tolist ()
171171 lons = one_model_time ['Lon' ].tolist ()
172172 if len (lats ) != 0 :
173173 model_list = model_type ['Model' ].tolist ()
174174 self .ax .plot (lons , lats , marker = 'o' , color = next (colors ),
175175 label = model_list [0 ])
176-
177176 plt .title ('Storm Name: {0} Year: {1}' .format (self .storm_names .value ,
178- str ( self .year_slider . value ) ))
177+ self .year ))
179178 plt .legend ()
180179
181180######################################################################
0 commit comments