{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Opening bottle with sparkling water\n", "\n", "

Written by Svetlana Kyas (ETH Zurich) on Mar 31th, 2022

\n", "\n", "```{attention}\n", "Always make sure you are using the [latest version of Reaktoro](https://anaconda.org/conda-forge/reaktoro). Otherwise, some new features documented on this website will not work on your machine and you may receive unintuitive errors. Follow these [update instructions](updating_reaktoro_via_conda) to get the latest version of Reaktoro!\n", "```\n", "\n", "This tutorial shows how to simulate the solubility of CO2 in water or, more simply, the **effect of the carbon dioxide released when you open the bottle of sparkling water**.\n", "\n", "|![Opening bottle with sparkling water](../../images/applications/opening-bottle-with-soda.jpg)|\n", "|:--:|\n", "|Opening bottle with sparkling water, Source: flavorman.com|\n", "\n", "First, we define the chemical system:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from reaktoro import *\n", "\n", "db = SupcrtDatabase(\"supcrtbl\")\n", "\n", "# Create an aqueous phase automatically selecting all species with provided elements\n", "aqueousphase = AqueousPhase(speciate(\"H O C\"))\n", "aqueousphase.set(ActivityModelPitzer())\n", "\n", "# Create a gaseous phase\n", "gaseousphase = GaseousPhase(\"CO2(g)\")\n", "gaseousphase.set(ActivityModelPengRobinson())\n", "\n", "# Create the chemical system\n", "system = ChemicalSystem(db, aqueousphase, gaseousphase)\n", "\n", "# Create the equilibrium solver\n", "solver = EquilibriumSolver(system)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Then, we define the range of pressures using the `linspace()` function of the **numpy** library. The initial and final pressures correspond to the values in the bubble bottle before and after opening." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "closedP = 3.79 # in bars\n", "openP = 1.01325 # in bars\n", "pressures = np.linspace(openP, closedP, num=100)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "> **Note**: A typical carbonated soft drink contains approximately 3–4 volumes (6–8 g/L) CO2. To obtain the amount of mol of CO2, we need to perform the following calculations: 8 g/L = 8 / 44.01 mol = 0.18 mol, where 44.01 g/mol is the CO2 molar mass.\n", "\n", "Next, we go through the created pressure list and collect the CO2(g) amounts obtained in the equilibrated chemical for a given pressure." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "df = pd.DataFrame(columns=[\"P\", \"amountCO2\"])\n", "\n", "for P in pressures:\n", " state = ChemicalState(system)\n", " state.setTemperature(20.0, \"celsius\")\n", " state.setPressure(P, \"bar\")\n", " state.add(\"H2O(aq)\", 0.5, \"kg\") # add ~ half a liter of water\n", " state.add(\"CO2(g)\", 0.18, \"mol\") # add calculated amount of gas\n", "\n", " res = solver.solve(state)\n", "\n", " df.loc[len(df)] = [P, float(state.speciesAmount(\"CO2(g)\"))]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To visualize the changes in the CO2(g) amount in the bottle, we export [bokeh](https://docs.bokeh.org/en/latest/docs/gallery.html#standalone-examples) python plotting package." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "lines_to_next_cell": 1, "tags": [ "hide_input" ] }, "outputs": [ { "data": { "text/html": [ "
\n", " \n", " Loading BokehJS ...\n", "
\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": "(function(root) {\n function now() {\n return new Date();\n }\n\n const force = true;\n\n if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n root._bokeh_onload_callbacks = [];\n root._bokeh_is_loading = undefined;\n }\n\nconst JS_MIME_TYPE = 'application/javascript';\n const HTML_MIME_TYPE = 'text/html';\n const EXEC_MIME_TYPE = 'application/vnd.bokehjs_exec.v0+json';\n const CLASS_NAME = 'output_bokeh rendered_html';\n\n /**\n * Render data to the DOM node\n */\n function render(props, node) {\n const script = document.createElement(\"script\");\n node.appendChild(script);\n }\n\n /**\n * Handle when an output is cleared or removed\n */\n function handleClearOutput(event, handle) {\n const cell = handle.cell;\n\n const id = cell.output_area._bokeh_element_id;\n const server_id = cell.output_area._bokeh_server_id;\n // Clean up Bokeh references\n if (id != null && id in Bokeh.index) {\n Bokeh.index[id].model.document.clear();\n delete Bokeh.index[id];\n }\n\n if (server_id !== undefined) {\n // Clean up Bokeh references\n const cmd_clean = \"from bokeh.io.state import curstate; print(curstate().uuid_to_server['\" + server_id + \"'].get_sessions()[0].document.roots[0]._id)\";\n cell.notebook.kernel.execute(cmd_clean, {\n iopub: {\n output: function(msg) {\n const id = msg.content.text.trim();\n if (id in Bokeh.index) {\n Bokeh.index[id].model.document.clear();\n delete Bokeh.index[id];\n }\n }\n }\n });\n // Destroy server and session\n const cmd_destroy = \"import bokeh.io.notebook as ion; ion.destroy_server('\" + server_id + \"')\";\n cell.notebook.kernel.execute(cmd_destroy);\n }\n }\n\n /**\n * Handle when a new output is added\n */\n function handleAddOutput(event, handle) {\n const output_area = handle.output_area;\n const output = handle.output;\n\n // limit handleAddOutput to display_data with EXEC_MIME_TYPE content only\n if ((output.output_type != \"display_data\") || (!Object.prototype.hasOwnProperty.call(output.data, EXEC_MIME_TYPE))) {\n return\n }\n\n const toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n\n if (output.metadata[EXEC_MIME_TYPE][\"id\"] !== undefined) {\n toinsert[toinsert.length - 1].firstChild.textContent = output.data[JS_MIME_TYPE];\n // store reference to embed id on output_area\n output_area._bokeh_element_id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n }\n if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n const bk_div = document.createElement(\"div\");\n bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n const script_attrs = bk_div.children[0].attributes;\n for (let i = 0; i < script_attrs.length; i++) {\n toinsert[toinsert.length - 1].firstChild.setAttribute(script_attrs[i].name, script_attrs[i].value);\n toinsert[toinsert.length - 1].firstChild.textContent = bk_div.children[0].textContent\n }\n // store reference to server id on output_area\n output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n }\n }\n\n function register_renderer(events, OutputArea) {\n\n function append_mime(data, metadata, element) {\n // create a DOM node to render to\n const toinsert = this.create_output_subarea(\n metadata,\n CLASS_NAME,\n EXEC_MIME_TYPE\n );\n this.keyboard_manager.register_events(toinsert);\n // Render to node\n const props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n render(props, toinsert[toinsert.length - 1]);\n element.append(toinsert);\n return toinsert\n }\n\n /* Handle when an output is cleared or removed */\n events.on('clear_output.CodeCell', handleClearOutput);\n events.on('delete.Cell', handleClearOutput);\n\n /* Handle when a new output is added */\n events.on('output_added.OutputArea', handleAddOutput);\n\n /**\n * Register the mime type and append_mime function with output_area\n */\n OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n /* Is output safe? */\n safe: true,\n /* Index of renderer in `output_area.display_order` */\n index: 0\n });\n }\n\n // register the mime type if in Jupyter Notebook environment and previously unregistered\n if (root.Jupyter !== undefined) {\n const events = require('base/js/events');\n const OutputArea = require('notebook/js/outputarea').OutputArea;\n\n if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n register_renderer(events, OutputArea);\n }\n }\n if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_failed_load = false;\n }\n\n const NB_LOAD_WARNING = {'data': {'text/html':\n \"
\\n\"+\n \"

\\n\"+\n \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n \"

\\n\"+\n \"\\n\"+\n \"\\n\"+\n \"from bokeh.resources import INLINE\\n\"+\n \"output_notebook(resources=INLINE)\\n\"+\n \"\\n\"+\n \"
\"}};\n\n function display_loaded() {\n const el = document.getElementById(\"1002\");\n if (el != null) {\n el.textContent = \"BokehJS is loading...\";\n }\n if (root.Bokeh !== undefined) {\n if (el != null) {\n el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n }\n } else if (Date.now() < root._bokeh_timeout) {\n setTimeout(display_loaded, 100)\n }\n }\n\n function run_callbacks() {\n try {\n root._bokeh_onload_callbacks.forEach(function(callback) {\n if (callback != null)\n callback();\n });\n } finally {\n delete root._bokeh_onload_callbacks\n }\n console.debug(\"Bokeh: all callbacks have finished\");\n }\n\n function load_libs(css_urls, js_urls, callback) {\n if (css_urls == null) css_urls = [];\n if (js_urls == null) js_urls = [];\n\n root._bokeh_onload_callbacks.push(callback);\n if (root._bokeh_is_loading > 0) {\n console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n return null;\n }\n if (js_urls == null || js_urls.length === 0) {\n run_callbacks();\n return null;\n }\n console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n root._bokeh_is_loading = css_urls.length + js_urls.length;\n\n function on_load() {\n root._bokeh_is_loading--;\n if (root._bokeh_is_loading === 0) {\n console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n run_callbacks()\n }\n }\n\n function on_error(url) {\n console.error(\"failed to load \" + url);\n }\n\n for (let i = 0; i < css_urls.length; i++) {\n const url = css_urls[i];\n const element = document.createElement(\"link\");\n element.onload = on_load;\n element.onerror = on_error.bind(null, url);\n element.rel = \"stylesheet\";\n element.type = \"text/css\";\n element.href = url;\n console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n document.body.appendChild(element);\n }\n\n for (let i = 0; i < js_urls.length; i++) {\n const url = js_urls[i];\n const element = document.createElement('script');\n element.onload = on_load;\n element.onerror = on_error.bind(null, url);\n element.async = false;\n element.src = url;\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n document.head.appendChild(element);\n }\n };\n\n function inject_raw_css(css) {\n const element = document.createElement(\"style\");\n element.appendChild(document.createTextNode(css));\n document.body.appendChild(element);\n }\n\n const js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.4.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.4.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.4.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.4.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-2.4.3.min.js\"];\n const css_urls = [];\n\n const inline_js = [ function(Bokeh) {\n Bokeh.set_log_level(\"info\");\n },\nfunction(Bokeh) {\n }\n ];\n\n function run_inline_js() {\n if (root.Bokeh !== undefined || force === true) {\n for (let i = 0; i < inline_js.length; i++) {\n inline_js[i].call(root, root.Bokeh);\n }\nif (force === true) {\n display_loaded();\n }} else if (Date.now() < root._bokeh_timeout) {\n setTimeout(run_inline_js, 100);\n } else if (!root._bokeh_failed_load) {\n console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n root._bokeh_failed_load = true;\n } else if (force !== true) {\n const cell = $(document.getElementById(\"1002\")).parents('.cell').data().cell;\n cell.output_area.append_execute_result(NB_LOAD_WARNING)\n }\n }\n\n if (root._bokeh_is_loading === 0) {\n console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n run_inline_js();\n } else {\n load_libs(css_urls, js_urls, function() {\n console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n run_inline_js();\n });\n }\n}(window));", "application/vnd.bokehjs_load.v0+json": "" }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": "(function(root) {\n function embed_document(root) {\n const docs_json = {\"a87a471f-8259-4a40-87bf-e72bb9ba7f8f\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1015\"}],\"center\":[{\"id\":\"1018\"},{\"id\":\"1022\"}],\"height\":300,\"left\":[{\"id\":\"1019\"}],\"renderers\":[{\"id\":\"1043\"}],\"sizing_mode\":\"scale_width\",\"title\":{\"id\":\"1005\"},\"toolbar\":{\"id\":\"1030\"},\"x_range\":{\"id\":\"1007\"},\"x_scale\":{\"id\":\"1011\"},\"y_range\":{\"id\":\"1009\"},\"y_scale\":{\"id\":\"1013\"}},\"id\":\"1004\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1013\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1028\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"1007\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1023\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1051\",\"type\":\"AllLabels\"},{\"attributes\":{},\"id\":\"1024\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"axis_label\":\"AMOUNT OF CO2(G) [MOL]\",\"coordinates\":null,\"formatter\":{\"id\":\"1047\"},\"group\":null,\"major_label_policy\":{\"id\":\"1048\"},\"ticker\":{\"id\":\"1020\"}},\"id\":\"1019\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1053\",\"type\":\"Selection\"},{\"attributes\":{\"source\":{\"id\":\"1038\"}},\"id\":\"1044\",\"type\":\"CDSView\"},{\"attributes\":{\"data\":{\"P\":{\"__ndarray__\":\"g8DKoUU28D+Y+AkSKKnwP60wSYIKHPE/wmiI8uyO8T/XoMdizwHyP+zYBtOxdPI/ARFGQ5Tn8j8WSYWzdlrzPyuBxCNZzfM/QLkDlDtA9D9V8UIEHrP0P2opgnQAJvU/f2HB5OKY9T+UmQBVxQv2P6nRP8WnfvY/vgl/NYrx9j/TQb6lbGT3P+h5/RVP1/c//rE8hjFK+D8S6nv2E734Pygiu2b2L/k/PFr61tii+T9SkjlHuxX6P2bKeLediPo/fAK4J4D7+j+QOveXYm77P6ZyNghF4fs/uqp1eCdU/D/Q4rToCcf8P+Qa9FjsOf0/+lIzyc6s/T8Oi3I5sR/+PyTDsamTkv4/OPvwGXYF/z9OMzCKWHj/P2Jrb/o66/8/vFFXtQ4vAEDG7Xbtf2gAQNGJliXxoQBA3CW2XWLbAEDmwdWV0xQBQPBd9c1ETgFA+/kUBraHAUAGljQ+J8EBQBAyVHaY+gFAGs5zrgk0AkAlapPmem0CQDAGsx7spgJAOqLSVl3gAkBEPvKOzhkDQE/aEcc/UwNAWnYx/7CMA0BkElE3IsYDQG6ucG+T/wNAeUqQpwQ5BECE5q/fdXIEQI6CzxfnqwRAmB7vT1jlBECjug6IyR4FQK5WLsA6WAVAuPJN+KuRBUDCjm0wHcsFQM0qjWiOBAZA2MasoP89BkDiYszYcHcGQOz+6xDisAZA95oLSVPqBkACNyuBxCMHQAzTSrk1XQdAFm9q8aaWB0AhC4opGNAHQCynqWGJCQhANkPJmfpCCEBA3+jRa3wIQEx7CArdtQhAVhcoQk7vCEBgs0d6vygJQGpPZ7IwYglAduuG6qGbCUCAh6YiE9UJQIojxlqEDgpAlL/lkvVHCkCgWwXLZoEKQKr3JAPYugpAtJNEO0n0CkC+L2Rzui0LQMrLg6srZwtA1Gej45ygC0DeA8MbDtoLQOif4lN/EwxA9DsCjPBMDED+1yHEYYYMQAh0QfzSvwxAEhBhNET5DEAerIBstTINQChIoKQmbA1AMuS/3JelDUA8gN8UCd8NQEgc/0x6GA5AUrgehetRDkA=\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[100]},\"amountCO2\":{\"__ndarray__\":\"hNzr5op+xD+2Fzu+p2zEP3YNs1/GWsQ/nnlDyuZIxD99iez8CDfEP+B0vfYsJcQ/oQXTtlITxD+KvVY8egHEP6+pfYaj78M/LpWHlM7dwz94Xipl+8vDP73b0fgpusM/o5dSTlqowz9Clw9ljJbDP6r5cjzAhMM/4a7t0/Vywz/+//YqLWHDP+IGDEFmT8M/EUmvFaE9wz/1u2io3SvDP6PXxPgbGsM/PMpUBlwIwz/z0q3QnfbCP9l0aVfh5MI/46UkmibTwj9yHoCYbcHCP6T8H1K2r8I/+i2rxgCewj9vBsz1TIzCP91IL9+aesI/W66Egupowj+7Un7fO1fCP0W20PWORcI/HbAyxeMzwj9DRl1NOiLCP1pNC46SEMI/Fuv5huz+wT9h2+c3SO3BP0W3laCl28E/S97FwATKwT9U9zuYZbjBP1S3vSbIpsE/a98RbCyVwT/gpQBokoPBP3vEUxr6ccE/oyPWgmNgwT/y6FOhzk7BP5hBmnU7PcE/6bB3/6krwT9fubs+GhrBP4vTNjOMCME/Hbi63P/2wD+Euhk7deXAPzhGJ07s08A/vMG3FWXCwD+dE6CR37DAP8petsFbn8A/K03RpdmNwD8ETcg9WXzAP8Olc4naasA/KTSsiF1ZwD+TlEs74kfAPzXnK6FoNsA/uzEouvAkwD9QxBuGehPAP2O14gQGAsA/sFazbCbhvz/7ULs0RL6/PwNMmWFlm78/tOEI84l4vz9xB8josVW/P4HWlELdMr8/l4MuAAwQvz9LGFUhPu2+P0LfyaVzyr4/R3FOjaynvj87b6XX6IS+P2xckoQoYr4/60vZk2s/vj/3VT8Fshy+P/fridj7+b0/OX1/DUnXvT/NDuejmbS9P8sLiJvtkb0/Ljkr9ERvvT9bD5mtn0y9P+Ism8f9Kb0/yvX7QV8HvT/5rYUcxOS8P0DDA1cswrw//71B8ZefvD/QQgzrBn28P+etL0R5Wrw/X4d5/O43vD9Ub7cTaBW8PzvJt4nk8rs/8f1IXmTQuz91XzqR5627P+stWyJui7s/ucl7Efhouz8=\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[100]},\"index\":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99]},\"selected\":{\"id\":\"1053\"},\"selection_policy\":{\"id\":\"1052\"}},\"id\":\"1038\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1011\",\"type\":\"LinearScale\"},{\"attributes\":{\"line_alpha\":0.2,\"line_cap\":\"round\",\"line_color\":\"indigo\",\"line_width\":3,\"x\":{\"field\":\"P\"},\"y\":{\"field\":\"amountCO2\"}},\"id\":\"1042\",\"type\":\"Line\"},{\"attributes\":{},\"id\":\"1026\",\"type\":\"SaveTool\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"amount(CO2) in brine\",\"@amountCO2 mol\"],[\"P\",\"@P\"]]},\"id\":\"1003\",\"type\":\"HoverTool\"},{\"attributes\":{},\"id\":\"1027\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"1048\",\"type\":\"AllLabels\"},{\"attributes\":{\"overlay\":{\"id\":\"1029\"}},\"id\":\"1025\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"tools\":[{\"id\":\"1023\"},{\"id\":\"1024\"},{\"id\":\"1025\"},{\"id\":\"1026\"},{\"id\":\"1027\"},{\"id\":\"1028\"},{\"id\":\"1003\"}]},\"id\":\"1030\",\"type\":\"Toolbar\"},{\"attributes\":{\"axis_label\":\"PRESSURE [BAR]\",\"coordinates\":null,\"formatter\":{\"id\":\"1050\"},\"group\":null,\"major_label_policy\":{\"id\":\"1051\"},\"ticker\":{\"id\":\"1016\"}},\"id\":\"1015\",\"type\":\"LinearAxis\"},{\"attributes\":{\"line_cap\":\"round\",\"line_color\":\"indigo\",\"line_width\":3,\"x\":{\"field\":\"P\"},\"y\":{\"field\":\"amountCO2\"}},\"id\":\"1040\",\"type\":\"Line\"},{\"attributes\":{},\"id\":\"1020\",\"type\":\"BasicTicker\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"1029\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"1038\"},\"glyph\":{\"id\":\"1040\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"1042\"},\"nonselection_glyph\":{\"id\":\"1041\"},\"view\":{\"id\":\"1044\"}},\"id\":\"1043\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"line_alpha\":0.1,\"line_cap\":\"round\",\"line_color\":\"indigo\",\"line_width\":3,\"x\":{\"field\":\"P\"},\"y\":{\"field\":\"amountCO2\"}},\"id\":\"1041\",\"type\":\"Line\"},{\"attributes\":{},\"id\":\"1047\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1052\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"axis\":{\"id\":\"1015\"},\"coordinates\":null,\"group\":null,\"ticker\":null},\"id\":\"1018\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1009\",\"type\":\"DataRange1d\"},{\"attributes\":{\"axis\":{\"id\":\"1019\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"1022\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1016\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1050\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"text\":\"CO2(G) AMOUNT IN SPARKLING WATER BOTTLE BEFORE AND AFTER OPENING\"},\"id\":\"1005\",\"type\":\"Title\"}],\"root_ids\":[\"1004\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.3\"}};\n const render_items = [{\"docid\":\"a87a471f-8259-4a40-87bf-e72bb9ba7f8f\",\"root_ids\":[\"1004\"],\"roots\":{\"1004\":\"ce129d7b-60eb-4fe0-b9c3-7c4586b26415\"}}];\n root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n }\n if (root.Bokeh !== undefined) {\n embed_document(root);\n } else {\n let attempts = 0;\n const timer = setInterval(function(root) {\n if (root.Bokeh !== undefined) {\n clearInterval(timer);\n embed_document(root);\n } else {\n attempts++;\n if (attempts > 100) {\n clearInterval(timer);\n console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n }\n }\n }, 10, root)\n }\n})(window);", "application/vnd.bokehjs_exec.v0+json": "" }, "metadata": { "application/vnd.bokehjs_exec.v0+json": { "id": "1004" } }, "output_type": "display_data" } ], "source": [ "from bokeh.plotting import figure, show\n", "from bokeh.models import HoverTool\n", "from bokeh.io import output_notebook\n", "output_notebook()\n", "\n", "hovertool = HoverTool()\n", "hovertool.tooltips = [(\"amount(CO2) in brine\", \"@amountCO2 mol\"), \n", " (\"P\", \"@P\")]\n", "\n", "p = figure(\n", " title=\"CO2(G) AMOUNT IN SPARKLING WATER BOTTLE BEFORE AND AFTER OPENING\",\n", " x_axis_label=r'PRESSURE [BAR]',\n", " y_axis_label='AMOUNT OF CO2(G) [MOL]',\n", " sizing_mode=\"scale_width\",\n", " height=300)\n", "\n", "p.add_tools(hovertool)\n", "\n", "p.line(\"P\", \"amountCO2\", line_width=3, line_cap=\"round\", line_color='indigo', source=df)\n", "\n", "show(p)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "From the generated plot, it can be seen that reducing the pressure in the bottle (opening the bottle) also reduces the amount of CO2 dissolved in the carbonated beverage, which evaporates as CO2 gas." ] } ], "metadata": { "kernelspec": { "display_name": "reaktoro-jupyter-book", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.5" }, "vscode": { "interpreter": { "hash": "e4e8b2f3ae27709963f14fd23a6560d362beea55eaec742263828e04d814e23c" } } }, "nbformat": 4, "nbformat_minor": 4 }