diff --git a/docs/workshop-5/module-1-xarray.ipynb b/docs/workshop-5/module-1-xarray.ipynb index a299f09..a871a35 100644 --- a/docs/workshop-5/module-1-xarray.ipynb +++ b/docs/workshop-5/module-1-xarray.ipynb @@ -140,18 +140,26 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 3, "metadata": { "id": "DowTxcfD2Oxd" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Note: you may need to restart the kernel to use updated packages.\n" + ] + } + ], "source": [ - "!pip install -q --no-warn-conflicts malariagen_data rioxarray" + "%pip install -q --no-warn-conflicts malariagen_data rioxarray" ] }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 4, "metadata": { "id": "bQw97PEh2RDq" }, @@ -160,9 +168,11 @@ "import malariagen_data\n", "import xarray as xr\n", "import numpy as np\n", + "import warnings\n", "# configure plotting with matplotlib\n", "%matplotlib inline\n", - "%config InlineBackend.figure_format = \"retina\"" + "%config InlineBackend.figure_format = \"retina\"\n", + "warnings.simplefilter(action='ignore', category=FutureWarning)" ] }, { @@ -172,9 +182,16 @@ "Configure access to the MalariaGEN Ag3 data resource." ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Note that authentication is required to access data through the package, please follow the instructions [here](https://malariagen.github.io/vector-data/vobs/vobs-data-access.html)." + ] + }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 5, "metadata": { "id": "7lSms3Hn2SFR" }, @@ -182,6 +199,7 @@ { "data": { "application/javascript": [ + "'use strict';\n", "(function(root) {\n", " function now() {\n", " return new Date();\n", @@ -211,14 +229,22 @@ " * Handle when an output is cleared or removed\n", " */\n", " function handleClearOutput(event, handle) {\n", + " function drop(id) {\n", + " const view = Bokeh.index.get_by_id(id)\n", + " if (view != null) {\n", + " view.model.document.clear()\n", + " Bokeh.index.delete(view)\n", + " }\n", + " }\n", + "\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", + "\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", + " if (id != null) {\n", + " drop(id)\n", " }\n", "\n", " if (server_id !== undefined) {\n", @@ -227,11 +253,8 @@ " 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", + " const id = msg.content.text.trim()\n", + " drop(id)\n", " }\n", " }\n", " });\n", @@ -338,17 +361,42 @@ " \"\\n\"+\n", " \"\"}};\n", "\n", - " function display_loaded() {\n", + " function display_loaded(error = null) {\n", " const el = document.getElementById(null);\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", + " const html = (() => {\n", + " if (typeof root.Bokeh === \"undefined\") {\n", + " if (error == null) {\n", + " return \"BokehJS is loading ...\";\n", + " } else {\n", + " return \"BokehJS failed to load.\";\n", + " }\n", + " } else {\n", + " const prefix = `BokehJS ${root.Bokeh.version}`;\n", + " if (error == null) {\n", + " return `${prefix} successfully loaded.`;\n", + " } else {\n", + " return `${prefix} encountered errors while loading and may not function as expected.`;\n", + " }\n", + " }\n", + " })();\n", + " el.innerHTML = html;\n", + "\n", + " if (error != null) {\n", + " const wrapper = document.createElement(\"div\");\n", + " wrapper.style.overflow = \"auto\";\n", + " wrapper.style.height = \"5em\";\n", + " wrapper.style.resize = \"vertical\";\n", + " const content = document.createElement(\"div\");\n", + " content.style.fontFamily = \"monospace\";\n", + " content.style.whiteSpace = \"pre-wrap\";\n", + " content.style.backgroundColor = \"rgb(255, 221, 221)\";\n", + " content.textContent = error.stack ?? error.toString();\n", + " wrapper.append(content);\n", + " el.append(wrapper);\n", " }\n", " } else if (Date.now() < root._bokeh_timeout) {\n", - " setTimeout(display_loaded, 100)\n", + " setTimeout(() => display_loaded(error), 100);\n", " }\n", " }\n", "\n", @@ -422,7 +470,7 @@ " document.body.appendChild(element);\n", " }\n", "\n", - " const js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-3.2.0.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-3.2.0.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-3.2.0.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-3.2.0.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-3.2.0.min.js\"];\n", + " const js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-3.4.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-3.4.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-3.4.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-3.4.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-3.4.1.min.js\"];\n", " const css_urls = [];\n", "\n", " const inline_js = [ function(Bokeh) {\n", @@ -434,10 +482,13 @@ "\n", " function run_inline_js() {\n", " if (root.Bokeh !== undefined || force === true) {\n", - " for (let i = 0; i < inline_js.length; i++) {\n", + " try {\n", + " for (let i = 0; i < inline_js.length; i++) {\n", " inline_js[i].call(root, root.Bokeh);\n", " }\n", - "} else if (Date.now() < root._bokeh_timeout) {\n", + "\n", + " } catch (error) {throw error;\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", @@ -459,7 +510,7 @@ " }\n", "}(window));" ], - "application/vnd.bokehjs_load.v0+json": "(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\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 \"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 \"from bokeh.resources import INLINE\\n\"+\n \"output_notebook(resources=INLINE)\\n\"+\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 \"from bokeh.resources import INLINE\\n\"+\n \"output_notebook(resources=INLINE)\\n\"+\n \"
\\n\"+\n \"<xarray.Dataset>\n", + "<xarray.Dataset> Size: 983MB\n", "Dimensions: (lon: 1681, lat: 1741, year: 21)\n", "Coordinates:\n", - " * lon (lon) float64 -17.98 -17.94 -17.9 ... 51.94 51.98 52.02\n", - " * lat (lat) float64 37.52 37.48 37.44 ... -34.9 -34.94 -34.98\n", - " * year (year) int64 2000 2001 2002 2003 ... 2018 2019 2020\n", + " * lon (lon) float64 13kB -17.98 -17.94 -17.9 ... 51.98 52.02\n", + " * lat (lat) float64 14kB 37.52 37.48 37.44 ... -34.94 -34.98\n", + " * year (year) int64 168B 2000 2001 2002 ... 2018 2019 2020\n", "Data variables:\n", - " itn_access_mean (year, lat, lon) float32 dask.array<chunksize=(1, 1741, 1681), meta=np.ndarray>\n", - " itn_per_capita_mean (year, lat, lon) float32 dask.array<chunksize=(1, 1741, 1681), meta=np.ndarray>\n", - " itn_use_mean (year, lat, lon) float32 dask.array<chunksize=(1, 1741, 1681), meta=np.ndarray>\n", - " itn_use_rate_mean (year, lat, lon) float32 dask.array<chunksize=(1, 1741, 1681), meta=np.ndarray>\n", + " itn_access_mean (year, lat, lon) float32 246MB dask.array<chunksize=(1, 1741, 1681), meta=np.ndarray>\n", + " itn_per_capita_mean (year, lat, lon) float32 246MB dask.array<chunksize=(1, 1741, 1681), meta=np.ndarray>\n", + " itn_use_mean (year, lat, lon) float32 246MB dask.array<chunksize=(1, 1741, 1681), meta=np.ndarray>\n", + " itn_use_rate_mean (year, lat, lon) float32 246MB dask.array<chunksize=(1, 1741, 1681), meta=np.ndarray>\n", "Attributes:\n", " title: Maps and metrics of insecticide-treated net access, use, and...\n", " creator: The Malaria Atlas Project\n", - " references: https://malariaatlas.org/research-project/metrics-of-insecti...