-
Notifications
You must be signed in to change notification settings - Fork 0
/
parameterwidgets.py
237 lines (205 loc) · 8.5 KB
/
parameterwidgets.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Oct 14 22:04:54 2018
@author: skoebric
"""
import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
import ipywidgets as widgets
import powerplantmapper as ppm
import matplotlib.pyplot as plt
from IPython.core.display import display, HTML
display(HTML("<style>.container { width:85% !important; }</style>"))
style = {'description_width': 'initial'}
countrynamewidget = widgets.Text(
value='India',
placeholder='Type a country name',
description='Country Name:',
disabled=False,
style = style
)
simplifiedwidget = widgets.ToggleButtons(
options=['Simple', 'Mixed', 'Complex'],
value = 'Mixed',
description='Simplification Level:',
disabled=False,
button_style='',
tooltips=['Renewables, Fossil, and Nuclear',
'Solar, Wind, Hydro, Geothermal,Biomass, Wave and Tidal,\n Storage, Fossil, Nuclear',
'Solar, Wind, Hydro, Geothermal,Biomass, Wave and Tidal,\n Storage, Fossil, Nuclear, Coal, Gas, Oil, Waste, Cogeneration'],
style = style)
precursorwidget = widgets.Text(
value='',
placeholder='Precursor to Country Name',
description='Country Precursor:',
disabled=False,
style = style
)
coordswidget = widgets.Text(
value='spherical',
placeholder='Type something',
description='Coordinate System:',
disabled=False,
style = style
)
legendcolumnswidget = widgets.IntSlider(
value=1,
min=1,
max=3,
step=1,
description='Number of Legend Columns:',
disabled=False,
continuous_update=False,
orientation='horizontal',
readout=True,
readout_format='d',
style = style
)
legendsortingwidget = widgets.Dropdown(
options=['capacity', 'alphabetical'],
value='capacity',
description='Sort Legend By:',
disabled=False,
style = style
)
zoomwidget = widgets.FloatSlider(
value=1,
min=0.5,
max=3,
step=0.1,
description='Zoom Level:',
disabled=False,
continuous_update=False,
orientation='horizontal',
readout=True,
readout_format='.1f',
style = style
)
islandthreshwidget = widgets.Text(
value='5000',
placeholder='Type a island thresh',
description='Island Size Thresh:',
disabled=False,
style = style
)
popplaceswidget = widgets.Text(
value='False',
placeholder='Type something',
description='Show Populated Places:',
disabled=False,
style = style
)
bubbleopacitywidget = widgets.FloatSlider(
value=0.5,
min=0,
max=1,
step=0.1,
description='Bubble Opacity:',
disabled=False,
continuous_update=False,
orientation='horizontal',
readout=True,
readout_format='.1f',
style = style
)
pathwidget = widgets.Text(
value='/Users/skoebric/Downloads/XYZ.png',
placeholder='Type the complete path to save to',
description='Path to save to:',
disabled=False,
style = style
)
dpiwidget = widgets.IntSlider(
value=300,
min=100,
max=500,
step=1,
description='DPI (resolution):',
disabled=False,
continuous_update=False,
orientation='horizontal',
readout=True,
readout_format='d',
style = style
)
dpiwidget = widgets.IntSlider(
value=300,
min=100,
max=500,
step=1,
description='DPI (resolution):',
disabled=False,
continuous_update=False,
orientation='horizontal',
readout=True,
readout_format='d',
style = style
)
titlewidget = widgets.RadioButtons(
options=[True, False],
value= True,
description='Title On:',
disabled=False
)
sourcewidget = widgets.RadioButtons(
options=[True, False],
value= True,
description='Source On:',
disabled=False
)
disputedwidget = widgets.RadioButtons(
options=[True, False],
value= True,
description='Include Disputed Territories:',
disabled=False
)
def showbasicwidgets():
global countrynamewidget, simplifiedwidget
display(countrynamewidget)
display(simplifiedwidget)
def showadvancedwidgets():
global precursorwidget, coordswidget, legendcolumnswidget, legendsortingwidget, zoomwidget, islandthreshwidget, popplaceswidget, bubbleopacitywidget
display(coordswidget)
display(legendcolumnswidget)
display(legendsortingwidget)
display(zoomwidget)
display(islandthreshwidget)
display(popplaceswidget)
display(bubbleopacitywidget)
display(precursorwidget)
display(titlewidget)
display(sourcewidget)
display(disputedwidget)
def createplot():
initial = ppm.CountryPowerPlantMapper(countryname = countrynamewidget.value, zoom = zoomwidget.value,
coords = coordswidget.value, legend_columns = legendcolumnswidget.value,
legend_sorting = legendsortingwidget.value, precursor = precursorwidget.value,
island_thresh = islandthreshwidget.value, additional_powerplants_csv = None,
populated_places = popplaceswidget.value, urban_areas = None,
bubble_opacity = bubbleopacitywidget.value, simplified = simplifiedwidget.value,
title = titlewidget.value, source = sourcewidget.value, disputed = disputedwidget.value)
initial.mapper()
def updateplot():
from IPython.display import clear_output
mapwidget = widgets.Button(
description='Update Plot',
disabled=False,
button_style='', # 'success', 'info', 'warning', 'danger' or ''
tooltip='Update Plot',
icon='check',
layout=widgets.Layout(width='70%', height='80px'))
def on_button_clicked(b):
clear_output()
display(mapwidget)
u = ppm.CountryPowerPlantMapper(countryname = countrynamewidget.value, zoom = zoomwidget.value,
coords = coordswidget.value, legend_columns = legendcolumnswidget.value,
legend_sorting = legendsortingwidget.value, precursor = precursorwidget.value,
island_thresh = islandthreshwidget.value, additional_powerplants_csv = None,
populated_places = popplaceswidget.value, urban_areas = None,
bubble_opacity = bubbleopacitywidget.value, simplified = simplifiedwidget.value,
title = titlewidget.value, source = sourcewidget.value, disputed = disputedwidget.value)
u.mapper()
mapwidget.on_click(on_button_clicked)
display(mapwidget)
createplot()