|
| 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