66This GUI takes data pulled from the National
77Hurricane Center and efficiently sifts through
88the data to plot specific storms and their
9- tracks.
10-
11- This code now creates the GUI
9+ tracks. The GUI runs using ipwidgets, and
10+ is intended to be used as an ipython
11+ notebook.
1212"""
1313import os
1414
2020from siphon .simplewebservice .nhc import nhc
2121
2222class NHC_GUI :
23+ """
24+ Graphic User Interface designed to allow users to access National Hurricane Center data.
25+
26+ This class uses ipython widgets, and the order in which the functions appear in this script
27+ correspond to the order in which the functions and widgets are called/used.
28+ """
29+
2330 def __init__ (self ):
24- self .NHCD = nhc .NHCD ()
31+ """
32+ Create object that references NHC.py and thus the National Hurricane Center.
33+
34+ This initiation creates the National Hurricane Center object and also creates
35+ a widget that allows the user to 1.) select the year in which to find storms,
36+ and 2.) indicate when they have chosen the year and when to continue with parsing
37+ the storm_table.
38+ """
39+ self .NHCD = NHC .NHCD ()
2540 self .storm_table = self .NHCD .storm_table
2641 # Year Slider Widget to select year for which to retrieve storm data.
2742 self .year_slider = widgets .IntSlider (min = 1851 , max = 2019 , value = 2019 ,
@@ -35,24 +50,48 @@ def __init__(self):
3550
3651
3752 def get_storms_slider (self , year_slider ):
53+ """
54+ Take a year chosen by the user, and create a list of all storms during that year.
55+
56+ Parameters
57+ ----------
58+ year_slider: ipywidget
59+ tells value of year chosen by the user
60+ """
3861 self .year = str (year_slider )
3962 self .one_year_table = self .storm_table [self .storm_table .Year == str (year_slider )]
4063 self .storm_names = widgets .Dropdown (options = self .one_year_table ['Name' ],
4164 description = 'Storm Names: ' )
4265 widgets .interact (self .get_name_dropdown , storm_names = self .storm_names )
4366
4467 def get_name_dropdown (self , storm_names ):
68+ """
69+ Take names created by previous function and allow selection of which models to plot.
70+
71+ Parameters
72+ ----------
73+ storm_names: list
74+ all storms in a given year
75+ """
4576 name = self .storm_names .value
4677 one_storm_row = self .one_year_table [self .one_year_table .Name == name ]
4778 self .filename = one_storm_row .Filename
4879 file_name = self .filename .tolist ()
4980 if self .filename .empty is False :
5081 self .filename = file_name [0 ]
5182 elif self .filename .empty is True :
52- print ( ' No file name data for this year.' )
83+ raise Exception ( 'ValueError: No file name data for this year.' )
5384
5485 def get_track (self , track_button ):
55-
86+ """
87+ Query whether track button has been toggled, and create select model widget.
88+
89+ Parameters
90+ ----------
91+ track_button: ipywidget
92+ button that when toggled indicates that user is ready to select the model
93+ tracks for the chosen storm.
94+ """
5695 if self .track_button .value is True :
5796 unique_models = self .NHCD .get_tracks (self .year , self .filename )
5897 self .model_select = widgets .SelectMultiple (options = unique_models ,
@@ -62,20 +101,35 @@ def get_track(self, track_button):
62101 widgets .interact (self .get_models , models = self .model_select )
63102
64103 def get_models (self , models ):
65- """get_models is a function that is linked to the selection widget which allows for
66- multiple models to be selected to plot for a specific hurricane track."""
67-
104+ """
105+ Select models from a list of all models for a given stormself.
106+
107+ Parameters
108+ ----------
109+ models: list
110+ list of ran for a given storm
111+ """
68112 self .NHCD .model_selection_latlon (models )
69113 self .date_times = self .NHCD .date_times
70114 self .plot_slider = widgets .IntSlider (min = 0 , max = (len (self .date_times )- 1 ),
71115 value = 0 , description = 'Tracks Time' ,
72116 disabled = False )
73- widgets .interact (self .plotting , plot_slider = self .plot_slider )
117+ self .play = widgets .Play (interval = 800 , min = 0 , max = (len (self .date_times )- 1 ),
118+ value = 0 , description = 'Tracks Time' )
119+ widgets .jslink ((self .plot_slider , 'value' ), (self .play , 'value' ))
120+ self .box = widgets .HBox ([self .plot_slider , self .play ])
121+ display (self .plot_slider )
122+ widgets .interact (self .plotting , plot_slider = self .play )
74123
75124 def plotting (self , plot_slider ):
76- """plotting is a function that that plots the models tracks and best tracks for all
77- selected models. These tracks are then plotted on the Blue Marble projection. """
78-
125+ """
126+ Plot selected model tracks and best track for given storm.
127+
128+ Parameters
129+ ----------
130+ plot_slider: ipywidget
131+ Widget where assigned value is plot/play widget value
132+ """
79133 if self .plot_slider .disabled is False :
80134
81135 # Identifying the time associated with the models for time text box
@@ -118,8 +172,7 @@ def plotting(self, plot_slider):
118172 if len (lats ) != 0 :
119173 model_list = model_type ['Model' ].tolist ()
120174 self .ax .plot (lons , lats , marker = 'o' , color = next (colors ),
121- label
122- = model_list [0 ])
175+ label = model_list [0 ])
123176
124177 plt .title ('Storm Name: {0} Year: {1}' .format (self .storm_names .value ,
125178 str (self .year_slider .value )))
0 commit comments