Skip to content

Commit 3ed2c61

Browse files
committed
add widgets_playground notebook
1 parent dac1a7b commit 3ed2c61

File tree

2 files changed

+221
-12
lines changed

2 files changed

+221
-12
lines changed

examples/condense.ipynb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
{
1313
"cell_type": "code",
14-
"execution_count": 12,
14+
"execution_count": 1,
1515
"metadata": {},
1616
"outputs": [],
1717
"source": [
@@ -25,7 +25,7 @@
2525
},
2626
{
2727
"cell_type": "code",
28-
"execution_count": 1,
28+
"execution_count": 2,
2929
"metadata": {},
3030
"outputs": [],
3131
"source": [
@@ -36,7 +36,7 @@
3636
},
3737
{
3838
"cell_type": "code",
39-
"execution_count": 2,
39+
"execution_count": 3,
4040
"metadata": {},
4141
"outputs": [],
4242
"source": [
@@ -46,7 +46,7 @@
4646
},
4747
{
4848
"cell_type": "code",
49-
"execution_count": 3,
49+
"execution_count": 4,
5050
"metadata": {},
5151
"outputs": [],
5252
"source": [
@@ -57,7 +57,7 @@
5757
},
5858
{
5959
"cell_type": "code",
60-
"execution_count": 4,
60+
"execution_count": 5,
6161
"metadata": {},
6262
"outputs": [],
6363
"source": [
@@ -73,7 +73,7 @@
7373
},
7474
{
7575
"cell_type": "code",
76-
"execution_count": 5,
76+
"execution_count": 6,
7777
"metadata": {},
7878
"outputs": [],
7979
"source": [
@@ -105,7 +105,7 @@
105105
},
106106
{
107107
"cell_type": "code",
108-
"execution_count": 6,
108+
"execution_count": 7,
109109
"metadata": {},
110110
"outputs": [],
111111
"source": [
@@ -115,7 +115,7 @@
115115
},
116116
{
117117
"cell_type": "code",
118-
"execution_count": 7,
118+
"execution_count": 8,
119119
"metadata": {},
120120
"outputs": [],
121121
"source": [
@@ -124,7 +124,7 @@
124124
},
125125
{
126126
"cell_type": "code",
127-
"execution_count": 8,
127+
"execution_count": 9,
128128
"metadata": {},
129129
"outputs": [],
130130
"source": [
@@ -159,7 +159,7 @@
159159
},
160160
{
161161
"cell_type": "code",
162-
"execution_count": 9,
162+
"execution_count": 10,
163163
"metadata": {},
164164
"outputs": [],
165165
"source": [
@@ -177,7 +177,7 @@
177177
},
178178
{
179179
"cell_type": "code",
180-
"execution_count": 10,
180+
"execution_count": 11,
181181
"metadata": {},
182182
"outputs": [],
183183
"source": [
@@ -186,7 +186,7 @@
186186
},
187187
{
188188
"cell_type": "code",
189-
"execution_count": 11,
189+
"execution_count": 12,
190190
"metadata": {},
191191
"outputs": [],
192192
"source": [

examples/widgets_playground.ipynb

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"import sys\n",
10+
"if 'google.colab' in sys.modules:\n",
11+
" !pip --quiet install git+https://github.com/open-atmos/PyPartMC.git"
12+
]
13+
},
14+
{
15+
"cell_type": "code",
16+
"execution_count": 2,
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"!pip install --quiet ipywidgets"
21+
]
22+
},
23+
{
24+
"cell_type": "code",
25+
"execution_count": 3,
26+
"metadata": {},
27+
"outputs": [],
28+
"source": [
29+
"import PyPartMC as ppmc\n",
30+
"from ipywidgets import Tab, SelectMultiple, IntSlider, FloatSlider, HTML, HBox, VBox, Output\n",
31+
"from matplotlib import pyplot\n",
32+
"from IPython.display import display, clear_output\n",
33+
"\n",
34+
"%matplotlib widget"
35+
]
36+
},
37+
{
38+
"cell_type": "code",
39+
"execution_count": 4,
40+
"metadata": {},
41+
"outputs": [],
42+
"source": [
43+
"if \"google.colab\" in sys.modules:\n",
44+
" hack = (\n",
45+
" \"<link\"\n",
46+
" ' rel=\"stylesheet\"'\n",
47+
" ' href=\"https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css\"'\n",
48+
" \"> \"\n",
49+
" )\n",
50+
" display(HTML(hack))"
51+
]
52+
},
53+
{
54+
"cell_type": "code",
55+
"execution_count": 5,
56+
"metadata": {},
57+
"outputs": [],
58+
"source": [
59+
"gas_data_widget = SelectMultiple(options=(\"H2SO4\", \"HNO3\", \"HCl\", \"NH3\", \"NO\", \"NO2\"))\n",
60+
"gas_data_widget.value = gas_data_widget.options"
61+
]
62+
},
63+
{
64+
"cell_type": "code",
65+
"execution_count": 6,
66+
"metadata": {},
67+
"outputs": [],
68+
"source": [
69+
"humidity_widget = FloatSlider(description='RH [%]', min=90, max=100)"
70+
]
71+
},
72+
{
73+
"cell_type": "code",
74+
"execution_count": 7,
75+
"metadata": {},
76+
"outputs": [],
77+
"source": [
78+
"param_x_widget = IntSlider(description='x [1]', min=1, max=9, value=2)\n",
79+
"param_y_widget = IntSlider(description='y [1]', min=0, max=3, value=2)"
80+
]
81+
},
82+
{
83+
"cell_type": "code",
84+
"execution_count": 8,
85+
"metadata": {},
86+
"outputs": [],
87+
"source": [
88+
"preview_output = Output()\n",
89+
"with preview_output:\n",
90+
" fig, ax = pyplot.subplots(1, 1)\n",
91+
" ax.set_xlim(param_x_widget.min, param_x_widget.max)\n",
92+
" ax.set_ylim(param_y_widget.min, param_y_widget.max)\n",
93+
" line_x = ax.plot([param_x_widget.value]*2, ax.get_ylim())\n",
94+
" line_y = ax.plot(ax.get_xlim(), [param_y_widget.value]*2)\n",
95+
"\n",
96+
"param_x_widget.observe(lambda change: line_x[0].set_xdata([change.new]*2), 'value')\n",
97+
"param_y_widget.observe(lambda change: line_y[0].set_ydata([change.new]*2), 'value')"
98+
]
99+
},
100+
{
101+
"cell_type": "code",
102+
"execution_count": 9,
103+
"metadata": {},
104+
"outputs": [],
105+
"source": [
106+
"tabs = Tab(\n",
107+
" children=(\n",
108+
" gas_data_widget,\n",
109+
" humidity_widget,\n",
110+
" VBox((\n",
111+
" HBox((param_x_widget, param_y_widget)),\n",
112+
" preview_output\n",
113+
" ))\n",
114+
" )\n",
115+
")\n",
116+
"tabs.set_title(0, \"GasData\")\n",
117+
"tabs.set_title(1, \"Scenario\")\n",
118+
"tabs.set_title(2, \"AeroState\")"
119+
]
120+
},
121+
{
122+
"cell_type": "code",
123+
"execution_count": 10,
124+
"metadata": {},
125+
"outputs": [
126+
{
127+
"data": {
128+
"application/vnd.jupyter.widget-view+json": {
129+
"model_id": "1eeaf25a187441b0a2d4ff0e16158319",
130+
"version_major": 2,
131+
"version_minor": 0
132+
},
133+
"text/plain": [
134+
"Tab(children=(SelectMultiple(index=(0, 1, 2, 3, 4, 5), options=('H2SO4', 'HNO3', 'HCl', 'NH3', 'NO', 'NO2'), v…"
135+
]
136+
},
137+
"metadata": {},
138+
"output_type": "display_data"
139+
}
140+
],
141+
"source": [
142+
"display(tabs)"
143+
]
144+
},
145+
{
146+
"cell_type": "code",
147+
"execution_count": 11,
148+
"metadata": {},
149+
"outputs": [
150+
{
151+
"name": "stdout",
152+
"output_type": "stream",
153+
"text": [
154+
"2 , 2\n"
155+
]
156+
}
157+
],
158+
"source": [
159+
"print(param_x_widget.value, \",\", param_y_widget.value)"
160+
]
161+
},
162+
{
163+
"cell_type": "code",
164+
"execution_count": 13,
165+
"metadata": {},
166+
"outputs": [
167+
{
168+
"name": "stdout",
169+
"output_type": "stream",
170+
"text": [
171+
"[\"H2SO4\",\"HNO3\",\"HCl\",\"NO\",\"NO2\"]\n"
172+
]
173+
}
174+
],
175+
"source": [
176+
"gas_data = ppmc.GasData(gas_data_widget.value)\n",
177+
"print(gas_data)"
178+
]
179+
},
180+
{
181+
"cell_type": "code",
182+
"execution_count": null,
183+
"metadata": {},
184+
"outputs": [],
185+
"source": []
186+
}
187+
],
188+
"metadata": {
189+
"kernelspec": {
190+
"display_name": "Python 3",
191+
"language": "python",
192+
"name": "python3"
193+
},
194+
"language_info": {
195+
"codemirror_mode": {
196+
"name": "ipython",
197+
"version": 3
198+
},
199+
"file_extension": ".py",
200+
"mimetype": "text/x-python",
201+
"name": "python",
202+
"nbconvert_exporter": "python",
203+
"pygments_lexer": "ipython3",
204+
"version": "3.8.7"
205+
}
206+
},
207+
"nbformat": 4,
208+
"nbformat_minor": 4
209+
}

0 commit comments

Comments
 (0)