Simon Danisch / Sep 25 2019

Mimi Reactive Image

apt update
apt install python3 python3-venv python3-pip
pip3 install xlrd
ENV["PYTHON"] = "python3"
pkg"up; add PyCall Hyperscript https://github.com/SimonDanisch/JSServe.jl.git GeometryTypes https://github.com/SimonDanisch/ReactiveRuntime.jl.git Observables#sd-extensions https://github.com/JuliaPlots/WGLMakie.jl#sd-jsserve AbstractPlotting"
pkg"registry add https://github.com/mimiframework/MimiRegistry.git; add Mimi MimiDICE2013"
using Mimi, MimiDICE2013, DataFrames, AbstractPlotting, WGLMakie
using Observables, Hyperscript, JSServe
using JSServe: with_session, Slider
using JSServe.DOM
# get model instances
m_dice1 = MimiDICE2013.get_model()
m_dice2 = MimiDICE2013.get_model()
3.1s
Julia
Reactive
using Markdown

using Mimi, MimiDICE2013, DataFrames, AbstractPlotting, WGLMakie
using Observables, Hyperscript, JSServe
using JSServe: with_session, Slider
using JSServe.DOM
# get model instances
m_dice1 = MimiDICE2013.get_model()
m_dice2 = MimiDICE2013.get_model()
run(m_dice1)
run(m_dice2)
function run_model(param)
	set_param!(m_dice2, :emissions, :MIU, fill(param, 60))
	run(m_dice2)
  something.(m_dice2[:climatedynamics, :TATM], 0.0)
end
set_theme!(font = "Dejavu Sans", resolution = (500, 400))
with_session() do session
  df_dice1 = dropmissing(getdataframe(m_dice1, :climatedynamics, :TATM))
	df_dice2 = dropmissing(getdataframe(m_dice2, :climatedynamics, :TATM))
  s = JSServe.Slider(LinRange(0, 1, 100))
  data = map(run_model, s)
  scene = scatter(df_dice1.time, df_dice1.TATM, markersize = 5)
  scatter!(df_dice2.time, data, color = :red, markersize = 5)
  scene[Axis].names.axisnames = ("Year", "Temperature Increase")
  scene[Axis].names.textsize = (8, 8)
  t = df_dice2.time
  year = JSServe.Slider(1:length(t))
  dmg_estimated = map(year, s) do year_idx, s
    round(m_dice2[:damages, :DAMAGES][year_idx], digits = 4)
  end
	year_sel = map(i-> t[i], year)
  b = DOM.font("● baseline", color = :black)
  ec = DOM.font("● with emission control", color = :red)
  markdown = md"
  # Explore Climate
  
  Set amount of emission control: $(s) $(map(x-> round(x, digits = 3), s.value))
  # Temperature Increase
  
  $b | $ec
  
  $(scene)
  
  # Estimated damage in year $(year_sel)
  
  $(year)
  
  
  $(dmg_estimated) trillion USD per year.
  "
end

Without running this Notebook in the cloud, you won't be able to interact with the Parameters, since the simulation can't run in the browser. For this we will need to cache the results of the simulation. Here is a preview of how it looks when running this notebook: