import sys
import subprocess
if 'google.colab' in sys.modules:
packages = ('PyPartMC',)
else:
packages = ()
for package in packages:
subprocess.check_call([
sys.executable, "-m", "pip", "install", "--quiet", package
])
WARNING: You are using pip version 21.2.3; however, version 22.1.2 is available. You should consider upgrading via the '/usr/local/bin/python3 -m pip install --upgrade pip' command. WARNING: You are using pip version 21.2.3; however, version 22.1.2 is available. You should consider upgrading via the '/usr/local/bin/python3 -m pip install --upgrade pip' command.
from ipywidgets import Tab, SelectMultiple, IntSlider, FloatSlider, HBox, VBox, Output, Button
from matplotlib import pyplot
from IPython.display import display, clear_output
import PyPartMC as ppmc
gas_data_widget = SelectMultiple(options=("H2SO4", "HNO3", "HCl", "NH3", "NO", "NO2"))
gas_data_widget.value = gas_data_widget.options
humidity_widget = FloatSlider(description='RH [%]', min=90, max=100)
param_x_widget = IntSlider(description='x [1]', min=1, max=9, value=2)
param_y_widget = IntSlider(description='y [1]', min=0, max=3, value=2)
button = Button(description= 'Run')
output = Output()
preview_output = Output()
with preview_output:
fig, ax = pyplot.subplots(1, 1)
ax.set_xlim(param_x_widget.min, param_x_widget.max)
ax.set_ylim(param_y_widget.min, param_y_widget.max)
line_x = ax.plot([param_x_widget.value]*2, ax.get_ylim())
line_y = ax.plot(ax.get_xlim(), [param_y_widget.value]*2)
pyplot.show()
def plot_update():
with preview_output:
clear_output(wait=True)
display(fig)
param_x_widget.observe(lambda change: line_x[0].set_xdata([change.new]*2) or plot_update(), 'value')
param_y_widget.observe(lambda change: line_y[0].set_ydata([change.new]*2) or plot_update(), 'value')
tabs = Tab(
children=(
gas_data_widget,
humidity_widget,
VBox((
HBox((param_x_widget, param_y_widget)),
preview_output
))
)
)
tabs.set_title(0, "GasData")
tabs.set_title(1, "Scenario")
tabs.set_title(2, "AeroState")
gui = VBox((tabs,button,output))
def action(_):
with output:
clear_output(wait=True)
print(param_x_widget.value, ",", param_y_widget.value)
gas_data = ppmc.GasData(gas_data_widget.value)
print(gas_data)
button.on_click(action)
display(gui)
VBox(children=(Tab(children=(SelectMultiple(index=(1,), options=('H2SO4', 'HNO3', 'HCl', 'NH3', 'NO', 'NO2'), …