# MIMI DICE2013 Climate Impact We're using the [MIMI](https://www.mimiframework.org/Mimi.jl/stable/) framework to create a simple climate impact simulation. We first install all the Julia & Python dependencies in a [Nextjournal runtime](https://nextjournal.com/help/runtimes-environments). This will be backed into a docker container, which can be used in other articles, or downloaded and run locally, with everything installed. [Project.toml][nextjournal#file#107febc3-4539-4309-acec-a1c217e020db] [Manifest.toml][nextjournal#file#c8a12835-0123-47e1-81a6-f33781f6d016] ```bash id=43cef8b3-c869-4b49-a2d4-cafb745dcc0b apt update apt install python3 python3-venv python3-pip pip3 install xlrd ``` ```julia id=6606308b-62b9-4391-be05-bcf362ee202c cp([reference][nextjournal#reference#f31221dd-8ec1-45b7-a950-5f6e446381be], "Manifest.toml") cp([reference][nextjournal#reference#8be52183-9592-4ed3-9e7e-3dd3fdbf42ee], "Project.toml") ENV["PYTHON"] = "python3" # use system python ``` ```julia id=68b735fd-5cd8-4687-a21a-75c9c1616083 ]registry add https://github.com/mimiframework/MimiRegistry.git ``` ```julia id=e84f50aa-9e71-400a-97d2-1bb3d69f0527 ]activate .; instantiate ``` Now, lets create the simulation & interactive visualization in another runtime: ```julia id=40b8b6f6-64dc-488f-b62a-b47756e42789 ]activate . ``` ```julia id=4e4b90cb-61d7-4532-ab0d-6f90e1320c83 using Markdown using Mimi, MimiDICE2013, DataFrames, AbstractPlotting, WGLMakie using Observables, JSServe using JSServe: Application, Slider, styled_slider using JSServe.DOM ``` ```julia id=79a2ce50-ff79-40d6-b949-56cdbc784079 function create_model() # create a dice 2013 model m = MimiDICE2013.get_model() # Use higher climate sensitivity value update_param!(m, :t2xco2, 5) run(m) return m end m_dice1 = create_model() m_dice2 = create_model(); ``` ```julia id=140fd461-6aeb-4d52-83ea-bcf0c29521d4 # Add a better styled slider function JSServe.styled_slider(slider, value) JSServe.rows(DOM.div(slider, class="w-64"), DOM.span(value, class="p-2"), class="p-2 items-center" ) end function run_model(param) update_param!(m_dice2, :MIU, fill(param, 60)) run(m_dice2) something.(m_dice2[:climatedynamics, :TATM], 0.0) end set_theme!(font = "Dejavu Sans", resolution = (500, 400)) function handler(session, request) # get the temperature forecasts: df_dice1 = dropmissing(getdataframe(m_dice1, :climatedynamics, :TATM)) df_dice2 = dropmissing(getdataframe(m_dice2, :climatedynamics, :TATM)) s = JSServe.Slider(range(0, stop=1, step=0.01)) 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 dmg = round(m_dice2[:damages, :DAMAGES][year_idx], digits = 3) return "$(dmg) trillion USD" end year_sel = map(i-> t[i], year) b = DOM.font("● baseline", color = :black) ec = DOM.font("● with emission control", color = :red) styled_s = styled_slider(s, map(x-> round(x, digits = 3), s.value)) styled_damage = styled_slider(year, DOM.div(dmg_estimated)) dom = md""" # Explore Climate Set amount of emission control: $styled_s # Temperature Increase $b $ec $(scene) # Estimated damage in year $(year_sel) $(styled_damage) """ dom = DOM.div(JSServe.MarkdownCSS, JSServe.TailwindCSS, JSServe.Styling, dom, class="w-2/3") # Record all states of the simulation, to have them # available when the julia server is offline: return JSServe.record_state_map(session, dom).dom end JSServe.with_session(handler) ``` [result][nextjournal#output#140fd461-6aeb-4d52-83ea-bcf0c29521d4#result] [__jsserve/core.js][nextjournal#output#140fd461-6aeb-4d52-83ea-bcf0c29521d4#__jsserve/core.js] [__jsserve/tailwind.min.css][nextjournal#output#140fd461-6aeb-4d52-83ea-bcf0c29521d4#__jsserve/tailwind.min.css] [__jsserve/c06ce54b-bf09-44bb-bcaf-73c061ae2ef0.msgpack][nextjournal#output#140fd461-6aeb-4d52-83ea-bcf0c29521d4#__jsserve/c06ce54b-bf09-44bb-bcaf-73c061ae2ef0.msgpack] [__jsserve/styled.css][nextjournal#output#140fd461-6aeb-4d52-83ea-bcf0c29521d4#__jsserve/styled.css] [__jsserve/msgpack.min.js][nextjournal#output#140fd461-6aeb-4d52-83ea-bcf0c29521d4#__jsserve/msgpack.min.js] [__jsserve/wglmakie.js][nextjournal#output#140fd461-6aeb-4d52-83ea-bcf0c29521d4#__jsserve/wglmakie.js] [__jsserve/markdown.css][nextjournal#output#140fd461-6aeb-4d52-83ea-bcf0c29521d4#__jsserve/markdown.css] [nextjournal#file#107febc3-4539-4309-acec-a1c217e020db]: [nextjournal#file#c8a12835-0123-47e1-81a6-f33781f6d016]: [nextjournal#reference#f31221dd-8ec1-45b7-a950-5f6e446381be]: <#nextjournal#reference#f31221dd-8ec1-45b7-a950-5f6e446381be> [nextjournal#reference#8be52183-9592-4ed3-9e7e-3dd3fdbf42ee]: <#nextjournal#reference#8be52183-9592-4ed3-9e7e-3dd3fdbf42ee> [nextjournal#output#140fd461-6aeb-4d52-83ea-bcf0c29521d4#result]: [nextjournal#output#140fd461-6aeb-4d52-83ea-bcf0c29521d4#__jsserve/core.js]: [nextjournal#output#140fd461-6aeb-4d52-83ea-bcf0c29521d4#__jsserve/tailwind.min.css]: [nextjournal#output#140fd461-6aeb-4d52-83ea-bcf0c29521d4#__jsserve/c06ce54b-bf09-44bb-bcaf-73c061ae2ef0.msgpack]: [nextjournal#output#140fd461-6aeb-4d52-83ea-bcf0c29521d4#__jsserve/styled.css]: [nextjournal#output#140fd461-6aeb-4d52-83ea-bcf0c29521d4#__jsserve/msgpack.min.js]: [nextjournal#output#140fd461-6aeb-4d52-83ea-bcf0c29521d4#__jsserve/wglmakie.js]: [nextjournal#output#140fd461-6aeb-4d52-83ea-bcf0c29521d4#__jsserve/markdown.css]:
This notebook was exported from https://nextjournal.com/a/MtSc2b95phrQDSRcexhdh?change-id=Cm41Q7cJq54qWeXfEFrHYm ```edn nextjournal-metadata {:article {:nodes {"107febc3-4539-4309-acec-a1c217e020db" {:id "107febc3-4539-4309-acec-a1c217e020db", :kind "file"}, "140fd461-6aeb-4d52-83ea-bcf0c29521d4" {:compute-ref #uuid "ea95bd57-9716-438b-8846-0f1a20b571e3", :exec-duration 2821, :id "140fd461-6aeb-4d52-83ea-bcf0c29521d4", :kind "code", :output-log-lines {}, :runtime [:runtime "83a46ce4-6614-4363-a265-5153f65323b6"], :stdout-collapsed? true}, "40b8b6f6-64dc-488f-b62a-b47756e42789" {:compute-ref #uuid "84073ab4-074f-4ae5-898a-cfdf284c48ca", :exec-duration 12180, :id "40b8b6f6-64dc-488f-b62a-b47756e42789", :kind "code", :output-log-lines {:stdout 12}, :runtime [:runtime "83a46ce4-6614-4363-a265-5153f65323b6"], :stdout-collapsed? true}, "43cef8b3-c869-4b49-a2d4-cafb745dcc0b" {:compute-ref #uuid "1f020fc0-9d41-4b4d-94bc-3b15a7ff4b65", :exec-duration 19950, :id "43cef8b3-c869-4b49-a2d4-cafb745dcc0b", :kind "code", :locked? true, :output-log-lines {:stdout 98}, :runtime [:runtime "ebad1ac1-d90e-43ea-b615-e88145d99b76"], :stdout-collapsed? true}, "4e4b90cb-61d7-4532-ab0d-6f90e1320c83" {:compute-ref #uuid "44acb33f-1b0a-4098-ae6b-bcc77935b0d2", :exec-duration 98148, :id "4e4b90cb-61d7-4532-ab0d-6f90e1320c83", :kind "code", :output-log-lines {}, :runtime [:runtime "83a46ce4-6614-4363-a265-5153f65323b6"]}, "6606308b-62b9-4391-be05-bcf362ee202c" {:compute-ref #uuid "743000d2-f091-48cc-87eb-a465bdede8bf", :exec-duration 542, :id "6606308b-62b9-4391-be05-bcf362ee202c", :kind "code", :locked? true, :output-log-lines {}, :runtime [:runtime "ebad1ac1-d90e-43ea-b615-e88145d99b76"]}, "68b735fd-5cd8-4687-a21a-75c9c1616083" {:compute-ref #uuid "5fe5272e-8125-45ff-bf19-af4888f2352f", :exec-duration 2377, :id "68b735fd-5cd8-4687-a21a-75c9c1616083", :kind "code", :locked? true, :output-log-lines {:stdout 3}, :runtime [:runtime "ebad1ac1-d90e-43ea-b615-e88145d99b76"], :stdout-collapsed? true}, "79a2ce50-ff79-40d6-b949-56cdbc784079" {:compute-ref #uuid "307ed869-d5a9-4c72-a9c2-bf35af53bd6a", :exec-duration 12174, :id "79a2ce50-ff79-40d6-b949-56cdbc784079", :kind "code", :output-log-lines {}, :runtime [:runtime "83a46ce4-6614-4363-a265-5153f65323b6"]}, "83a46ce4-6614-4363-a265-5153f65323b6" {:environment [:environment "ebad1ac1-d90e-43ea-b615-e88145d99b76"], :id "83a46ce4-6614-4363-a265-5153f65323b6", :kind "runtime", :language "julia", :resources {:machine-type "n1-standard-4"}, :type :nextjournal}, "8be52183-9592-4ed3-9e7e-3dd3fdbf42ee" {:id "8be52183-9592-4ed3-9e7e-3dd3fdbf42ee", :kind "reference", :link [:output "107febc3-4539-4309-acec-a1c217e020db" nil]}, "c8a12835-0123-47e1-81a6-f33781f6d016" {:id "c8a12835-0123-47e1-81a6-f33781f6d016", :kind "file"}, "e84f50aa-9e71-400a-97d2-1bb3d69f0527" {:compute-ref #uuid "6e8f6b41-6ef4-4c22-b4e2-b66acbe630db", :exec-duration 23046, :id "e84f50aa-9e71-400a-97d2-1bb3d69f0527", :kind "code", :locked? true, :output-log-lines {:stdout 2}, :runtime [:runtime "ebad1ac1-d90e-43ea-b615-e88145d99b76"], :stdout-collapsed? true}, "ebad1ac1-d90e-43ea-b615-e88145d99b76" {:environment [:environment {:article/nextjournal.id #uuid "5b460d39-8c57-43a6-8b13-e217642b0146", :change/nextjournal.id #uuid "5f0bd3e3-9a65-4c13-b714-ec3b8370eb8a", :node/id "39e3f06d-60bf-4003-ae1a-62e835085aef"}], :environment? true, :id "ebad1ac1-d90e-43ea-b615-e88145d99b76", :kind "runtime", :language "julia", :name "install", :resources {:machine-type "n1-standard-4"}, :type :nextjournal, :docker/environment-image "docker.nextjournal.com/environment@sha256:071a15e8dde49180984d9775984a0d2e91d21f609edea4153ca7122880bbf130"}, "f31221dd-8ec1-45b7-a950-5f6e446381be" {:id "f31221dd-8ec1-45b7-a950-5f6e446381be", :kind "reference", :link [:output "c8a12835-0123-47e1-81a6-f33781f6d016" nil]}}, :nextjournal/id #uuid "02ea93cb-1d7d-471a-a77a-a20f7df6ff38", :article/change {:nextjournal/id #uuid "5f3b1aac-3146-4fd6-b929-917bda9ae29a"}}} ```