1948 lines
159 KiB
Plaintext
1948 lines
159 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "bb54fa69",
|
|
"metadata": {},
|
|
"source": [
|
|
"# 🌍 Decision Tree Land Classification - ODC Database\n",
|
|
"\n",
|
|
"## 📌 Notebook này chạy trên:\n",
|
|
"- ✅ **Server ODC/JupyterHub** với Dask Gateway\n",
|
|
"- ✅ Load dữ liệu từ **ODC Database** (access nhanh trên server)\n",
|
|
"\n",
|
|
"## 🎯 Nguồn dữ liệu:\n",
|
|
"**ODC Database**\n",
|
|
"- Sentinel-2 L2A (optical) từ ODC\n",
|
|
"- Sentinel-1 RTC (SAR) từ ODC\n",
|
|
"\n",
|
|
"## 🚀 Infrastructure:\n",
|
|
"- **Dask Gateway**: Adaptive scaling (1-10 workers)\n",
|
|
"- **Datacube**: Load data từ ODC database\n",
|
|
"- **S3 Access**: Configured với requester_pays\n",
|
|
"\n",
|
|
"## 🔄 Workflow:\n",
|
|
"1. Load data từ ODC Database (nhanh trên server)\n",
|
|
"2. Preprocessing (cloud mask, NDVI, resampling)\n",
|
|
"3. Train Decision Tree model\n",
|
|
"4. Save model → dùng cho prediction trên Planetary Computer\n",
|
|
"\n",
|
|
"---"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"id": "10e7e875",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<script type=\"esms-options\">{\"shimMode\": true}</script><style>*[data-root-id],\n",
|
|
"*[data-root-id] > * {\n",
|
|
" box-sizing: border-box;\n",
|
|
" font-family: var(--jp-ui-font-family);\n",
|
|
" font-size: var(--jp-ui-font-size1);\n",
|
|
" color: var(--vscode-editor-foreground, var(--jp-ui-font-color1));\n",
|
|
"}\n",
|
|
"\n",
|
|
"/* Override VSCode background color */\n",
|
|
".cell-output-ipywidget-background:has(\n",
|
|
" > .cell-output-ipywidget-background > .lm-Widget > *[data-root-id]\n",
|
|
" ),\n",
|
|
".cell-output-ipywidget-background:has(> .lm-Widget > *[data-root-id]) {\n",
|
|
" background-color: transparent !important;\n",
|
|
"}\n",
|
|
"</style>"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"data": {
|
|
"application/javascript": "(function(root) {\n function now() {\n return new Date();\n }\n\n const force = true;\n const py_version = '3.6.0'.replace('rc', '-rc.').replace('.dev', '-dev.');\n const reloading = false;\n const Bokeh = root.Bokeh;\n\n // Set a timeout for this load but only if we are not already initializing\n if (typeof (root._bokeh_timeout) === \"undefined\" || (force || !root._bokeh_is_initializing)) {\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_failed_load = false;\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, js_modules, js_exports, callback) {\n if (css_urls == null) css_urls = [];\n if (js_urls == null) js_urls = [];\n if (js_modules == null) js_modules = [];\n if (js_exports == null) js_exports = {};\n\n root._bokeh_onload_callbacks.push(callback);\n\n if (root._bokeh_is_loading > 0) {\n // Don't load bokeh if it is still initializing\n console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n return null;\n } else if (js_urls.length === 0 && js_modules.length === 0 && Object.keys(js_exports).length === 0) {\n // There is nothing to load\n run_callbacks();\n return null;\n }\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 window._bokeh_on_load = on_load\n\n function on_error(e) {\n const src_el = e.srcElement\n console.error(\"failed to load \" + (src_el.href || src_el.src));\n }\n\n const skip = [];\n if (window.requirejs) {\n window.requirejs.config({'packages': {}, 'paths': {}, 'shim': {}});\n root._bokeh_is_loading = css_urls.length + 0;\n } else {\n root._bokeh_is_loading = css_urls.length + js_urls.length + js_modules.length + Object.keys(js_exports).length;\n }\n\n const existing_stylesheets = []\n const links = document.getElementsByTagName('link')\n for (let i = 0; i < links.length; i++) {\n const link = links[i]\n if (link.href != null) {\n existing_stylesheets.push(link.href)\n }\n }\n for (let i = 0; i < css_urls.length; i++) {\n const url = css_urls[i];\n const escaped = encodeURI(url)\n if (existing_stylesheets.indexOf(escaped) !== -1) {\n on_load()\n continue;\n }\n const element = document.createElement(\"link\");\n element.onload = on_load;\n element.onerror = on_error;\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 } var existing_scripts = []\n const scripts = document.getElementsByTagName('script')\n for (let i = 0; i < scripts.length; i++) {\n var script = scripts[i]\n if (script.src != null) {\n existing_scripts.push(script.src)\n }\n }\n for (let i = 0; i < js_urls.length; i++) {\n const url = js_urls[i];\n const escaped = encodeURI(url)\n if (skip.indexOf(escaped) !== -1 || existing_scripts.indexOf(escaped) !== -1) {\n if (!window.requirejs) {\n on_load();\n }\n continue;\n }\n const element = document.createElement('script');\n element.onload = on_load;\n element.onerror = on_error;\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 for (let i = 0; i < js_modules.length; i++) {\n const url = js_modules[i];\n const escaped = encodeURI(url)\n if (skip.indexOf(escaped) !== -1 || existing_scripts.indexOf(escaped) !== -1) {\n if (!window.requirejs) {\n on_load();\n }\n continue;\n }\n var element = document.createElement('script');\n element.onload = on_load;\n element.onerror = on_error;\n element.async = false;\n element.src = url;\n element.type = \"module\";\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n document.head.appendChild(element);\n }\n for (const name in js_exports) {\n const url = js_exports[name];\n const escaped = encodeURI(url)\n if (skip.indexOf(escaped) >= 0 || root[name] != null) {\n if (!window.requirejs) {\n on_load();\n }\n continue;\n }\n var element = document.createElement('script');\n element.onerror = on_error;\n element.async = false;\n element.type = \"module\";\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n element.textContent = `\n import ${name} from \"${url}\"\n window.${name} = ${name}\n window._bokeh_on_load()\n `\n document.head.appendChild(element);\n }\n if (!js_urls.length && !js_modules.length) {\n on_load()\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.holoviz.org/panel/1.5.3/dist/bundled/reactiveesm/es-module-shims@^1.10.0/dist/es-module-shims.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-3.6.0.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-3.6.0.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-3.6.0.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-3.6.0.min.js\", \"https://cdn.holoviz.org/panel/1.5.3/dist/panel.min.js\"];\n const js_modules = [];\n const js_exports = {};\n const css_urls = [];\n const inline_js = [ function(Bokeh) {\n Bokeh.set_log_level(\"info\");\n },\nfunction(Bokeh) {} // ensure no trailing comma for IE\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 try {\n inline_js[i].call(root, root.Bokeh);\n } catch(e) {\n if (!reloading) {\n throw e;\n }\n }\n }\n // Cache old bokeh versions\n if (Bokeh != undefined && !reloading) {\n var NewBokeh = root.Bokeh;\n if (Bokeh.versions === undefined) {\n Bokeh.versions = new Map();\n }\n if (NewBokeh.version !== Bokeh.version) {\n Bokeh.versions.set(NewBokeh.version, NewBokeh)\n }\n root.Bokeh = Bokeh;\n }\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 }\n root._bokeh_is_initializing = false\n }\n\n function load_or_wait() {\n // Implement a backoff loop that tries to ensure we do not load multiple\n // versions of Bokeh and its dependencies at the same time.\n // In recent versions we use the root._bokeh_is_initializing flag\n // to determine whether there is an ongoing attempt to initialize\n // bokeh, however for backward compatibility we also try to ensure\n // that we do not start loading a newer (Panel>=1.0 and Bokeh>3) version\n // before older versions are fully initialized.\n if (root._bokeh_is_initializing && Date.now() > root._bokeh_timeout) {\n // If the timeout and bokeh was not successfully loaded we reset\n // everything and try loading again\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_is_initializing = false;\n root._bokeh_onload_callbacks = undefined;\n root._bokeh_is_loading = 0\n console.log(\"Bokeh: BokehJS was loaded multiple times but one version failed to initialize.\");\n load_or_wait();\n } else if (root._bokeh_is_initializing || (typeof root._bokeh_is_initializing === \"undefined\" && root._bokeh_onload_callbacks !== undefined)) {\n setTimeout(load_or_wait, 100);\n } else {\n root._bokeh_is_initializing = true\n root._bokeh_onload_callbacks = []\n const bokeh_loaded = root.Bokeh != null && (root.Bokeh.version === py_version || (root.Bokeh.versions !== undefined && root.Bokeh.versions.has(py_version)));\n if (!reloading && !bokeh_loaded) {\n if (root.Bokeh) {\n root.Bokeh = undefined;\n }\n console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n }\n load_libs(css_urls, js_urls, js_modules, js_exports, function() {\n console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n run_inline_js();\n });\n }\n }\n // Give older versions of the autoload script a head-start to ensure\n // they initialize before we start loading newer version.\n setTimeout(load_or_wait, 100)\n}(window));",
|
|
"application/vnd.holoviews_load.v0+json": ""
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"data": {
|
|
"application/javascript": "\nif ((window.PyViz === undefined) || (window.PyViz instanceof HTMLElement)) {\n window.PyViz = {comms: {}, comm_status:{}, kernels:{}, receivers: {}, plot_index: []}\n}\n\n\n function JupyterCommManager() {\n }\n\n JupyterCommManager.prototype.register_target = function(plot_id, comm_id, msg_handler) {\n if (window.comm_manager || ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel != null))) {\n var comm_manager = window.comm_manager || Jupyter.notebook.kernel.comm_manager;\n comm_manager.register_target(comm_id, function(comm) {\n comm.on_msg(msg_handler);\n });\n } else if ((plot_id in window.PyViz.kernels) && (window.PyViz.kernels[plot_id])) {\n window.PyViz.kernels[plot_id].registerCommTarget(comm_id, function(comm) {\n comm.onMsg = msg_handler;\n });\n } else if (typeof google != 'undefined' && google.colab.kernel != null) {\n google.colab.kernel.comms.registerTarget(comm_id, (comm) => {\n var messages = comm.messages[Symbol.asyncIterator]();\n function processIteratorResult(result) {\n var message = result.value;\n console.log(message)\n var content = {data: message.data, comm_id};\n var buffers = []\n for (var buffer of message.buffers || []) {\n buffers.push(new DataView(buffer))\n }\n var metadata = message.metadata || {};\n var msg = {content, buffers, metadata}\n msg_handler(msg);\n return messages.next().then(processIteratorResult);\n }\n return messages.next().then(processIteratorResult);\n })\n }\n }\n\n JupyterCommManager.prototype.get_client_comm = function(plot_id, comm_id, msg_handler) {\n if (comm_id in window.PyViz.comms) {\n return window.PyViz.comms[comm_id];\n } else if (window.comm_manager || ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel != null))) {\n var comm_manager = window.comm_manager || Jupyter.notebook.kernel.comm_manager;\n var comm = comm_manager.new_comm(comm_id, {}, {}, {}, comm_id);\n if (msg_handler) {\n comm.on_msg(msg_handler);\n }\n } else if ((plot_id in window.PyViz.kernels) && (window.PyViz.kernels[plot_id])) {\n var comm = window.PyViz.kernels[plot_id].connectToComm(comm_id);\n comm.open();\n if (msg_handler) {\n comm.onMsg = msg_handler;\n }\n } else if (typeof google != 'undefined' && google.colab.kernel != null) {\n var comm_promise = google.colab.kernel.comms.open(comm_id)\n comm_promise.then((comm) => {\n window.PyViz.comms[comm_id] = comm;\n if (msg_handler) {\n var messages = comm.messages[Symbol.asyncIterator]();\n function processIteratorResult(result) {\n var message = result.value;\n var content = {data: message.data};\n var metadata = message.metadata || {comm_id};\n var msg = {content, metadata}\n msg_handler(msg);\n return messages.next().then(processIteratorResult);\n }\n return messages.next().then(processIteratorResult);\n }\n }) \n var sendClosure = (data, metadata, buffers, disposeOnDone) => {\n return comm_promise.then((comm) => {\n comm.send(data, metadata, buffers, disposeOnDone);\n });\n };\n var comm = {\n send: sendClosure\n };\n }\n window.PyViz.comms[comm_id] = comm;\n return comm;\n }\n window.PyViz.comm_manager = new JupyterCommManager();\n \n\n\nvar JS_MIME_TYPE = 'application/javascript';\nvar HTML_MIME_TYPE = 'text/html';\nvar EXEC_MIME_TYPE = 'application/vnd.holoviews_exec.v0+json';\nvar CLASS_NAME = 'output';\n\n/**\n * Render data to the DOM node\n */\nfunction render(props, node) {\n var div = document.createElement(\"div\");\n var script = document.createElement(\"script\");\n node.appendChild(div);\n node.appendChild(script);\n}\n\n/**\n * Handle when a new output is added\n */\nfunction handle_add_output(event, handle) {\n var output_area = handle.output_area;\n var output = handle.output;\n if ((output.data == undefined) || (!output.data.hasOwnProperty(EXEC_MIME_TYPE))) {\n return\n }\n var id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n var toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n if (id !== undefined) {\n var nchildren = toinsert.length;\n var html_node = toinsert[nchildren-1].children[0];\n html_node.innerHTML = output.data[HTML_MIME_TYPE];\n var scripts = [];\n var nodelist = html_node.querySelectorAll(\"script\");\n for (var i in nodelist) {\n if (nodelist.hasOwnProperty(i)) {\n scripts.push(nodelist[i])\n }\n }\n\n scripts.forEach( function (oldScript) {\n var newScript = document.createElement(\"script\");\n var attrs = [];\n var nodemap = oldScript.attributes;\n for (var j in nodemap) {\n if (nodemap.hasOwnProperty(j)) {\n attrs.push(nodemap[j])\n }\n }\n attrs.forEach(function(attr) { newScript.setAttribute(attr.name, attr.value) });\n newScript.appendChild(document.createTextNode(oldScript.innerHTML));\n oldScript.parentNode.replaceChild(newScript, oldScript);\n });\n if (JS_MIME_TYPE in output.data) {\n toinsert[nchildren-1].children[1].textContent = output.data[JS_MIME_TYPE];\n }\n output_area._hv_plot_id = id;\n if ((window.Bokeh !== undefined) && (id in Bokeh.index)) {\n window.PyViz.plot_index[id] = Bokeh.index[id];\n } else {\n window.PyViz.plot_index[id] = null;\n }\n } else if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n var bk_div = document.createElement(\"div\");\n bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n var script_attrs = bk_div.children[0].attributes;\n for (var i = 0; i < script_attrs.length; i++) {\n toinsert[toinsert.length - 1].childNodes[1].setAttribute(script_attrs[i].name, script_attrs[i].value);\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/**\n * Handle when an output is cleared or removed\n */\nfunction handle_clear_output(event, handle) {\n var id = handle.cell.output_area._hv_plot_id;\n var server_id = handle.cell.output_area._bokeh_server_id;\n if (((id === undefined) || !(id in PyViz.plot_index)) && (server_id !== undefined)) { return; }\n var comm = window.PyViz.comm_manager.get_client_comm(\"hv-extension-comm\", \"hv-extension-comm\", function () {});\n if (server_id !== null) {\n comm.send({event_type: 'server_delete', 'id': server_id});\n return;\n } else if (comm !== null) {\n comm.send({event_type: 'delete', 'id': id});\n }\n delete PyViz.plot_index[id];\n if ((window.Bokeh !== undefined) & (id in window.Bokeh.index)) {\n var doc = window.Bokeh.index[id].model.document\n doc.clear();\n const i = window.Bokeh.documents.indexOf(doc);\n if (i > -1) {\n window.Bokeh.documents.splice(i, 1);\n }\n }\n}\n\n/**\n * Handle kernel restart event\n */\nfunction handle_kernel_cleanup(event, handle) {\n delete PyViz.comms[\"hv-extension-comm\"];\n window.PyViz.plot_index = {}\n}\n\n/**\n * Handle update_display_data messages\n */\nfunction handle_update_output(event, handle) {\n handle_clear_output(event, {cell: {output_area: handle.output_area}})\n handle_add_output(event, handle)\n}\n\nfunction register_renderer(events, OutputArea) {\n function append_mime(data, metadata, element) {\n // create a DOM node to render to\n var 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 var props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n render(props, toinsert[0]);\n element.append(toinsert);\n return toinsert\n }\n\n events.on('output_added.OutputArea', handle_add_output);\n events.on('output_updated.OutputArea', handle_update_output);\n events.on('clear_output.CodeCell', handle_clear_output);\n events.on('delete.Cell', handle_clear_output);\n events.on('kernel_ready.Kernel', handle_kernel_cleanup);\n\n OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n safe: true,\n index: 0\n });\n}\n\nif (window.Jupyter !== undefined) {\n try {\n var events = require('base/js/events');\n var OutputArea = require('notebook/js/outputarea').OutputArea;\n if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n register_renderer(events, OutputArea);\n }\n } catch(err) {\n }\n}\n",
|
|
"application/vnd.holoviews_load.v0+json": ""
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"data": {
|
|
"application/vnd.holoviews_exec.v0+json": "",
|
|
"text/html": [
|
|
"<div id='p1002'>\n",
|
|
" <div id=\"d75e8a21-4a59-46d1-acde-eb5c0b1672db\" data-root-id=\"p1002\" style=\"display: contents;\"></div>\n",
|
|
"</div>\n",
|
|
"<script type=\"application/javascript\">(function(root) {\n",
|
|
" var docs_json = {\"7a764e1e-4c11-43ce-8d3f-c0bf085ca03d\":{\"version\":\"3.6.0\",\"title\":\"Bokeh Application\",\"roots\":[{\"type\":\"object\",\"name\":\"panel.models.browser.BrowserInfo\",\"id\":\"p1002\"},{\"type\":\"object\",\"name\":\"panel.models.comm_manager.CommManager\",\"id\":\"p1003\",\"attributes\":{\"plot_id\":\"p1002\",\"comm_id\":\"10c9e63460644829b43c3f39dba18e9e\",\"client_comm_id\":\"7ba13fc2238549adb7cb1bce38f44028\"}}],\"defs\":[{\"type\":\"model\",\"name\":\"ReactiveHTML1\"},{\"type\":\"model\",\"name\":\"FlexBox1\",\"properties\":[{\"name\":\"align_content\",\"kind\":\"Any\",\"default\":\"flex-start\"},{\"name\":\"align_items\",\"kind\":\"Any\",\"default\":\"flex-start\"},{\"name\":\"flex_direction\",\"kind\":\"Any\",\"default\":\"row\"},{\"name\":\"flex_wrap\",\"kind\":\"Any\",\"default\":\"wrap\"},{\"name\":\"gap\",\"kind\":\"Any\",\"default\":\"\"},{\"name\":\"justify_content\",\"kind\":\"Any\",\"default\":\"flex-start\"}]},{\"type\":\"model\",\"name\":\"FloatPanel1\",\"properties\":[{\"name\":\"config\",\"kind\":\"Any\",\"default\":{\"type\":\"map\"}},{\"name\":\"contained\",\"kind\":\"Any\",\"default\":true},{\"name\":\"position\",\"kind\":\"Any\",\"default\":\"right-top\"},{\"name\":\"offsetx\",\"kind\":\"Any\",\"default\":null},{\"name\":\"offsety\",\"kind\":\"Any\",\"default\":null},{\"name\":\"theme\",\"kind\":\"Any\",\"default\":\"primary\"},{\"name\":\"status\",\"kind\":\"Any\",\"default\":\"normalized\"}]},{\"type\":\"model\",\"name\":\"GridStack1\",\"properties\":[{\"name\":\"mode\",\"kind\":\"Any\",\"default\":\"warn\"},{\"name\":\"ncols\",\"kind\":\"Any\",\"default\":null},{\"name\":\"nrows\",\"kind\":\"Any\",\"default\":null},{\"name\":\"allow_resize\",\"kind\":\"Any\",\"default\":true},{\"name\":\"allow_drag\",\"kind\":\"Any\",\"default\":true},{\"name\":\"state\",\"kind\":\"Any\",\"default\":[]}]},{\"type\":\"model\",\"name\":\"drag1\",\"properties\":[{\"name\":\"slider_width\",\"kind\":\"Any\",\"default\":5},{\"name\":\"slider_color\",\"kind\":\"Any\",\"default\":\"black\"},{\"name\":\"value\",\"kind\":\"Any\",\"default\":50}]},{\"type\":\"model\",\"name\":\"click1\",\"properties\":[{\"name\":\"terminal_output\",\"kind\":\"Any\",\"default\":\"\"},{\"name\":\"debug_name\",\"kind\":\"Any\",\"default\":\"\"},{\"name\":\"clears\",\"kind\":\"Any\",\"default\":0}]},{\"type\":\"model\",\"name\":\"FastWrapper1\",\"properties\":[{\"name\":\"object\",\"kind\":\"Any\",\"default\":null},{\"name\":\"style\",\"kind\":\"Any\",\"default\":null}]},{\"type\":\"model\",\"name\":\"NotificationAreaBase1\",\"properties\":[{\"name\":\"js_events\",\"kind\":\"Any\",\"default\":{\"type\":\"map\"}},{\"name\":\"position\",\"kind\":\"Any\",\"default\":\"bottom-right\"},{\"name\":\"_clear\",\"kind\":\"Any\",\"default\":0}]},{\"type\":\"model\",\"name\":\"NotificationArea1\",\"properties\":[{\"name\":\"js_events\",\"kind\":\"Any\",\"default\":{\"type\":\"map\"}},{\"name\":\"notifications\",\"kind\":\"Any\",\"default\":[]},{\"name\":\"position\",\"kind\":\"Any\",\"default\":\"bottom-right\"},{\"name\":\"_clear\",\"kind\":\"Any\",\"default\":0},{\"name\":\"types\",\"kind\":\"Any\",\"default\":[{\"type\":\"map\",\"entries\":[[\"type\",\"warning\"],[\"background\",\"#ffc107\"],[\"icon\",{\"type\":\"map\",\"entries\":[[\"className\",\"fas fa-exclamation-triangle\"],[\"tagName\",\"i\"],[\"color\",\"white\"]]}]]},{\"type\":\"map\",\"entries\":[[\"type\",\"info\"],[\"background\",\"#007bff\"],[\"icon\",{\"type\":\"map\",\"entries\":[[\"className\",\"fas fa-info-circle\"],[\"tagName\",\"i\"],[\"color\",\"white\"]]}]]}]}]},{\"type\":\"model\",\"name\":\"Notification\",\"properties\":[{\"name\":\"background\",\"kind\":\"Any\",\"default\":null},{\"name\":\"duration\",\"kind\":\"Any\",\"default\":3000},{\"name\":\"icon\",\"kind\":\"Any\",\"default\":null},{\"name\":\"message\",\"kind\":\"Any\",\"default\":\"\"},{\"name\":\"notification_type\",\"kind\":\"Any\",\"default\":null},{\"name\":\"_destroyed\",\"kind\":\"Any\",\"default\":false}]},{\"type\":\"model\",\"name\":\"TemplateActions1\",\"properties\":[{\"name\":\"open_modal\",\"kind\":\"Any\",\"default\":0},{\"name\":\"close_modal\",\"kind\":\"Any\",\"default\":0}]},{\"type\":\"model\",\"name\":\"BootstrapTemplateActions1\",\"properties\":[{\"name\":\"open_modal\",\"kind\":\"Any\",\"default\":0},{\"name\":\"close_modal\",\"kind\":\"Any\",\"default\":0}]},{\"type\":\"model\",\"name\":\"TemplateEditor1\",\"properties\":[{\"name\":\"layout\",\"kind\":\"Any\",\"default\":[]}]},{\"type\":\"model\",\"name\":\"MaterialTemplateActions1\",\"properties\":[{\"name\":\"open_modal\",\"kind\":\"Any\",\"default\":0},{\"name\":\"close_modal\",\"kind\":\"Any\",\"default\":0}]},{\"type\":\"model\",\"name\":\"ReactiveESM1\"},{\"type\":\"model\",\"name\":\"JSComponent1\"},{\"type\":\"model\",\"name\":\"ReactComponent1\"},{\"type\":\"model\",\"name\":\"AnyWidgetComponent1\"},{\"type\":\"model\",\"name\":\"request_value1\",\"properties\":[{\"name\":\"fill\",\"kind\":\"Any\",\"default\":\"none\"},{\"name\":\"_synced\",\"kind\":\"Any\",\"default\":null},{\"name\":\"_request_sync\",\"kind\":\"Any\",\"default\":0}]}]}};\n",
|
|
" var render_items = [{\"docid\":\"7a764e1e-4c11-43ce-8d3f-c0bf085ca03d\",\"roots\":{\"p1002\":\"d75e8a21-4a59-46d1-acde-eb5c0b1672db\"},\"root_ids\":[\"p1002\"]}];\n",
|
|
" var docs = Object.values(docs_json)\n",
|
|
" if (!docs) {\n",
|
|
" return\n",
|
|
" }\n",
|
|
" const py_version = docs[0].version.replace('rc', '-rc.').replace('.dev', '-dev.')\n",
|
|
" async function embed_document(root) {\n",
|
|
" var Bokeh = get_bokeh(root)\n",
|
|
" await Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
|
|
" for (const render_item of render_items) {\n",
|
|
" for (const root_id of render_item.root_ids) {\n",
|
|
"\tconst id_el = document.getElementById(root_id)\n",
|
|
"\tif (id_el.children.length && id_el.children[0].hasAttribute('data-root-id')) {\n",
|
|
"\t const root_el = id_el.children[0]\n",
|
|
"\t root_el.id = root_el.id + '-rendered'\n",
|
|
"\t for (const child of root_el.children) {\n",
|
|
" // Ensure JupyterLab does not capture keyboard shortcuts\n",
|
|
" // see: https://jupyterlab.readthedocs.io/en/4.1.x/extension/notebook.html#keyboard-interaction-model\n",
|
|
"\t child.setAttribute('data-lm-suppress-shortcuts', 'true')\n",
|
|
"\t }\n",
|
|
"\t}\n",
|
|
" }\n",
|
|
" }\n",
|
|
" }\n",
|
|
" function get_bokeh(root) {\n",
|
|
" if (root.Bokeh === undefined) {\n",
|
|
" return null\n",
|
|
" } else if (root.Bokeh.version !== py_version) {\n",
|
|
" if (root.Bokeh.versions === undefined || !root.Bokeh.versions.has(py_version)) {\n",
|
|
"\treturn null\n",
|
|
" }\n",
|
|
" return root.Bokeh.versions.get(py_version);\n",
|
|
" } else if (root.Bokeh.version === py_version) {\n",
|
|
" return root.Bokeh\n",
|
|
" }\n",
|
|
" return null\n",
|
|
" }\n",
|
|
" function is_loaded(root) {\n",
|
|
" var Bokeh = get_bokeh(root)\n",
|
|
" return (Bokeh != null && Bokeh.Panel !== undefined)\n",
|
|
" }\n",
|
|
" if (is_loaded(root)) {\n",
|
|
" embed_document(root);\n",
|
|
" } else {\n",
|
|
" var attempts = 0;\n",
|
|
" var timer = setInterval(function(root) {\n",
|
|
" if (is_loaded(root)) {\n",
|
|
" clearInterval(timer);\n",
|
|
" embed_document(root);\n",
|
|
" } else if (document.readyState == \"complete\") {\n",
|
|
" attempts++;\n",
|
|
" if (attempts > 200) {\n",
|
|
" clearInterval(timer);\n",
|
|
"\t var Bokeh = get_bokeh(root)\n",
|
|
"\t if (Bokeh == null || Bokeh.Panel == null) {\n",
|
|
" console.warn(\"Panel: ERROR: Unable to run Panel code because Bokeh or Panel library is missing\");\n",
|
|
"\t } else {\n",
|
|
"\t console.warn(\"Panel: WARNING: Attempting to render but not all required libraries could be resolved.\")\n",
|
|
"\t embed_document(root)\n",
|
|
"\t }\n",
|
|
" }\n",
|
|
" }\n",
|
|
" }, 25, root)\n",
|
|
" }\n",
|
|
"})(window);</script>"
|
|
]
|
|
},
|
|
"metadata": {
|
|
"application/vnd.holoviews_exec.v0+json": {
|
|
"id": "p1002"
|
|
}
|
|
},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<script type=\"esms-options\">{\"shimMode\": true}</script><style>*[data-root-id],\n",
|
|
"*[data-root-id] > * {\n",
|
|
" box-sizing: border-box;\n",
|
|
" font-family: var(--jp-ui-font-family);\n",
|
|
" font-size: var(--jp-ui-font-size1);\n",
|
|
" color: var(--vscode-editor-foreground, var(--jp-ui-font-color1));\n",
|
|
"}\n",
|
|
"\n",
|
|
"/* Override VSCode background color */\n",
|
|
".cell-output-ipywidget-background:has(\n",
|
|
" > .cell-output-ipywidget-background > .lm-Widget > *[data-root-id]\n",
|
|
" ),\n",
|
|
".cell-output-ipywidget-background:has(> .lm-Widget > *[data-root-id]) {\n",
|
|
" background-color: transparent !important;\n",
|
|
"}\n",
|
|
"</style>"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"data": {
|
|
"application/javascript": "(function(root) {\n function now() {\n return new Date();\n }\n\n const force = false;\n const py_version = '3.6.0'.replace('rc', '-rc.').replace('.dev', '-dev.');\n const reloading = true;\n const Bokeh = root.Bokeh;\n\n // Set a timeout for this load but only if we are not already initializing\n if (typeof (root._bokeh_timeout) === \"undefined\" || (force || !root._bokeh_is_initializing)) {\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_failed_load = false;\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, js_modules, js_exports, callback) {\n if (css_urls == null) css_urls = [];\n if (js_urls == null) js_urls = [];\n if (js_modules == null) js_modules = [];\n if (js_exports == null) js_exports = {};\n\n root._bokeh_onload_callbacks.push(callback);\n\n if (root._bokeh_is_loading > 0) {\n // Don't load bokeh if it is still initializing\n console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n return null;\n } else if (js_urls.length === 0 && js_modules.length === 0 && Object.keys(js_exports).length === 0) {\n // There is nothing to load\n run_callbacks();\n return null;\n }\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 window._bokeh_on_load = on_load\n\n function on_error(e) {\n const src_el = e.srcElement\n console.error(\"failed to load \" + (src_el.href || src_el.src));\n }\n\n const skip = [];\n if (window.requirejs) {\n window.requirejs.config({'packages': {}, 'paths': {}, 'shim': {}});\n root._bokeh_is_loading = css_urls.length + 0;\n } else {\n root._bokeh_is_loading = css_urls.length + js_urls.length + js_modules.length + Object.keys(js_exports).length;\n }\n\n const existing_stylesheets = []\n const links = document.getElementsByTagName('link')\n for (let i = 0; i < links.length; i++) {\n const link = links[i]\n if (link.href != null) {\n existing_stylesheets.push(link.href)\n }\n }\n for (let i = 0; i < css_urls.length; i++) {\n const url = css_urls[i];\n const escaped = encodeURI(url)\n if (existing_stylesheets.indexOf(escaped) !== -1) {\n on_load()\n continue;\n }\n const element = document.createElement(\"link\");\n element.onload = on_load;\n element.onerror = on_error;\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 } var existing_scripts = []\n const scripts = document.getElementsByTagName('script')\n for (let i = 0; i < scripts.length; i++) {\n var script = scripts[i]\n if (script.src != null) {\n existing_scripts.push(script.src)\n }\n }\n for (let i = 0; i < js_urls.length; i++) {\n const url = js_urls[i];\n const escaped = encodeURI(url)\n if (skip.indexOf(escaped) !== -1 || existing_scripts.indexOf(escaped) !== -1) {\n if (!window.requirejs) {\n on_load();\n }\n continue;\n }\n const element = document.createElement('script');\n element.onload = on_load;\n element.onerror = on_error;\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 for (let i = 0; i < js_modules.length; i++) {\n const url = js_modules[i];\n const escaped = encodeURI(url)\n if (skip.indexOf(escaped) !== -1 || existing_scripts.indexOf(escaped) !== -1) {\n if (!window.requirejs) {\n on_load();\n }\n continue;\n }\n var element = document.createElement('script');\n element.onload = on_load;\n element.onerror = on_error;\n element.async = false;\n element.src = url;\n element.type = \"module\";\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n document.head.appendChild(element);\n }\n for (const name in js_exports) {\n const url = js_exports[name];\n const escaped = encodeURI(url)\n if (skip.indexOf(escaped) >= 0 || root[name] != null) {\n if (!window.requirejs) {\n on_load();\n }\n continue;\n }\n var element = document.createElement('script');\n element.onerror = on_error;\n element.async = false;\n element.type = \"module\";\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n element.textContent = `\n import ${name} from \"${url}\"\n window.${name} = ${name}\n window._bokeh_on_load()\n `\n document.head.appendChild(element);\n }\n if (!js_urls.length && !js_modules.length) {\n on_load()\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.holoviz.org/panel/1.5.3/dist/bundled/reactiveesm/es-module-shims@^1.10.0/dist/es-module-shims.min.js\"];\n const js_modules = [];\n const js_exports = {};\n const css_urls = [];\n const inline_js = [ function(Bokeh) {\n Bokeh.set_log_level(\"info\");\n },\nfunction(Bokeh) {} // ensure no trailing comma for IE\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 try {\n inline_js[i].call(root, root.Bokeh);\n } catch(e) {\n if (!reloading) {\n throw e;\n }\n }\n }\n // Cache old bokeh versions\n if (Bokeh != undefined && !reloading) {\n var NewBokeh = root.Bokeh;\n if (Bokeh.versions === undefined) {\n Bokeh.versions = new Map();\n }\n if (NewBokeh.version !== Bokeh.version) {\n Bokeh.versions.set(NewBokeh.version, NewBokeh)\n }\n root.Bokeh = Bokeh;\n }\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 }\n root._bokeh_is_initializing = false\n }\n\n function load_or_wait() {\n // Implement a backoff loop that tries to ensure we do not load multiple\n // versions of Bokeh and its dependencies at the same time.\n // In recent versions we use the root._bokeh_is_initializing flag\n // to determine whether there is an ongoing attempt to initialize\n // bokeh, however for backward compatibility we also try to ensure\n // that we do not start loading a newer (Panel>=1.0 and Bokeh>3) version\n // before older versions are fully initialized.\n if (root._bokeh_is_initializing && Date.now() > root._bokeh_timeout) {\n // If the timeout and bokeh was not successfully loaded we reset\n // everything and try loading again\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_is_initializing = false;\n root._bokeh_onload_callbacks = undefined;\n root._bokeh_is_loading = 0\n console.log(\"Bokeh: BokehJS was loaded multiple times but one version failed to initialize.\");\n load_or_wait();\n } else if (root._bokeh_is_initializing || (typeof root._bokeh_is_initializing === \"undefined\" && root._bokeh_onload_callbacks !== undefined)) {\n setTimeout(load_or_wait, 100);\n } else {\n root._bokeh_is_initializing = true\n root._bokeh_onload_callbacks = []\n const bokeh_loaded = root.Bokeh != null && (root.Bokeh.version === py_version || (root.Bokeh.versions !== undefined && root.Bokeh.versions.has(py_version)));\n if (!reloading && !bokeh_loaded) {\n if (root.Bokeh) {\n root.Bokeh = undefined;\n }\n console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n }\n load_libs(css_urls, js_urls, js_modules, js_exports, function() {\n console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n run_inline_js();\n });\n }\n }\n // Give older versions of the autoload script a head-start to ensure\n // they initialize before we start loading newer version.\n setTimeout(load_or_wait, 100)\n}(window));",
|
|
"application/vnd.holoviews_load.v0+json": ""
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"data": {
|
|
"application/javascript": "\nif ((window.PyViz === undefined) || (window.PyViz instanceof HTMLElement)) {\n window.PyViz = {comms: {}, comm_status:{}, kernels:{}, receivers: {}, plot_index: []}\n}\n\n\n function JupyterCommManager() {\n }\n\n JupyterCommManager.prototype.register_target = function(plot_id, comm_id, msg_handler) {\n if (window.comm_manager || ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel != null))) {\n var comm_manager = window.comm_manager || Jupyter.notebook.kernel.comm_manager;\n comm_manager.register_target(comm_id, function(comm) {\n comm.on_msg(msg_handler);\n });\n } else if ((plot_id in window.PyViz.kernels) && (window.PyViz.kernels[plot_id])) {\n window.PyViz.kernels[plot_id].registerCommTarget(comm_id, function(comm) {\n comm.onMsg = msg_handler;\n });\n } else if (typeof google != 'undefined' && google.colab.kernel != null) {\n google.colab.kernel.comms.registerTarget(comm_id, (comm) => {\n var messages = comm.messages[Symbol.asyncIterator]();\n function processIteratorResult(result) {\n var message = result.value;\n console.log(message)\n var content = {data: message.data, comm_id};\n var buffers = []\n for (var buffer of message.buffers || []) {\n buffers.push(new DataView(buffer))\n }\n var metadata = message.metadata || {};\n var msg = {content, buffers, metadata}\n msg_handler(msg);\n return messages.next().then(processIteratorResult);\n }\n return messages.next().then(processIteratorResult);\n })\n }\n }\n\n JupyterCommManager.prototype.get_client_comm = function(plot_id, comm_id, msg_handler) {\n if (comm_id in window.PyViz.comms) {\n return window.PyViz.comms[comm_id];\n } else if (window.comm_manager || ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel != null))) {\n var comm_manager = window.comm_manager || Jupyter.notebook.kernel.comm_manager;\n var comm = comm_manager.new_comm(comm_id, {}, {}, {}, comm_id);\n if (msg_handler) {\n comm.on_msg(msg_handler);\n }\n } else if ((plot_id in window.PyViz.kernels) && (window.PyViz.kernels[plot_id])) {\n var comm = window.PyViz.kernels[plot_id].connectToComm(comm_id);\n comm.open();\n if (msg_handler) {\n comm.onMsg = msg_handler;\n }\n } else if (typeof google != 'undefined' && google.colab.kernel != null) {\n var comm_promise = google.colab.kernel.comms.open(comm_id)\n comm_promise.then((comm) => {\n window.PyViz.comms[comm_id] = comm;\n if (msg_handler) {\n var messages = comm.messages[Symbol.asyncIterator]();\n function processIteratorResult(result) {\n var message = result.value;\n var content = {data: message.data};\n var metadata = message.metadata || {comm_id};\n var msg = {content, metadata}\n msg_handler(msg);\n return messages.next().then(processIteratorResult);\n }\n return messages.next().then(processIteratorResult);\n }\n }) \n var sendClosure = (data, metadata, buffers, disposeOnDone) => {\n return comm_promise.then((comm) => {\n comm.send(data, metadata, buffers, disposeOnDone);\n });\n };\n var comm = {\n send: sendClosure\n };\n }\n window.PyViz.comms[comm_id] = comm;\n return comm;\n }\n window.PyViz.comm_manager = new JupyterCommManager();\n \n\n\nvar JS_MIME_TYPE = 'application/javascript';\nvar HTML_MIME_TYPE = 'text/html';\nvar EXEC_MIME_TYPE = 'application/vnd.holoviews_exec.v0+json';\nvar CLASS_NAME = 'output';\n\n/**\n * Render data to the DOM node\n */\nfunction render(props, node) {\n var div = document.createElement(\"div\");\n var script = document.createElement(\"script\");\n node.appendChild(div);\n node.appendChild(script);\n}\n\n/**\n * Handle when a new output is added\n */\nfunction handle_add_output(event, handle) {\n var output_area = handle.output_area;\n var output = handle.output;\n if ((output.data == undefined) || (!output.data.hasOwnProperty(EXEC_MIME_TYPE))) {\n return\n }\n var id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n var toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n if (id !== undefined) {\n var nchildren = toinsert.length;\n var html_node = toinsert[nchildren-1].children[0];\n html_node.innerHTML = output.data[HTML_MIME_TYPE];\n var scripts = [];\n var nodelist = html_node.querySelectorAll(\"script\");\n for (var i in nodelist) {\n if (nodelist.hasOwnProperty(i)) {\n scripts.push(nodelist[i])\n }\n }\n\n scripts.forEach( function (oldScript) {\n var newScript = document.createElement(\"script\");\n var attrs = [];\n var nodemap = oldScript.attributes;\n for (var j in nodemap) {\n if (nodemap.hasOwnProperty(j)) {\n attrs.push(nodemap[j])\n }\n }\n attrs.forEach(function(attr) { newScript.setAttribute(attr.name, attr.value) });\n newScript.appendChild(document.createTextNode(oldScript.innerHTML));\n oldScript.parentNode.replaceChild(newScript, oldScript);\n });\n if (JS_MIME_TYPE in output.data) {\n toinsert[nchildren-1].children[1].textContent = output.data[JS_MIME_TYPE];\n }\n output_area._hv_plot_id = id;\n if ((window.Bokeh !== undefined) && (id in Bokeh.index)) {\n window.PyViz.plot_index[id] = Bokeh.index[id];\n } else {\n window.PyViz.plot_index[id] = null;\n }\n } else if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n var bk_div = document.createElement(\"div\");\n bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n var script_attrs = bk_div.children[0].attributes;\n for (var i = 0; i < script_attrs.length; i++) {\n toinsert[toinsert.length - 1].childNodes[1].setAttribute(script_attrs[i].name, script_attrs[i].value);\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/**\n * Handle when an output is cleared or removed\n */\nfunction handle_clear_output(event, handle) {\n var id = handle.cell.output_area._hv_plot_id;\n var server_id = handle.cell.output_area._bokeh_server_id;\n if (((id === undefined) || !(id in PyViz.plot_index)) && (server_id !== undefined)) { return; }\n var comm = window.PyViz.comm_manager.get_client_comm(\"hv-extension-comm\", \"hv-extension-comm\", function () {});\n if (server_id !== null) {\n comm.send({event_type: 'server_delete', 'id': server_id});\n return;\n } else if (comm !== null) {\n comm.send({event_type: 'delete', 'id': id});\n }\n delete PyViz.plot_index[id];\n if ((window.Bokeh !== undefined) & (id in window.Bokeh.index)) {\n var doc = window.Bokeh.index[id].model.document\n doc.clear();\n const i = window.Bokeh.documents.indexOf(doc);\n if (i > -1) {\n window.Bokeh.documents.splice(i, 1);\n }\n }\n}\n\n/**\n * Handle kernel restart event\n */\nfunction handle_kernel_cleanup(event, handle) {\n delete PyViz.comms[\"hv-extension-comm\"];\n window.PyViz.plot_index = {}\n}\n\n/**\n * Handle update_display_data messages\n */\nfunction handle_update_output(event, handle) {\n handle_clear_output(event, {cell: {output_area: handle.output_area}})\n handle_add_output(event, handle)\n}\n\nfunction register_renderer(events, OutputArea) {\n function append_mime(data, metadata, element) {\n // create a DOM node to render to\n var 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 var props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n render(props, toinsert[0]);\n element.append(toinsert);\n return toinsert\n }\n\n events.on('output_added.OutputArea', handle_add_output);\n events.on('output_updated.OutputArea', handle_update_output);\n events.on('clear_output.CodeCell', handle_clear_output);\n events.on('delete.Cell', handle_clear_output);\n events.on('kernel_ready.Kernel', handle_kernel_cleanup);\n\n OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n safe: true,\n index: 0\n });\n}\n\nif (window.Jupyter !== undefined) {\n try {\n var events = require('base/js/events');\n var OutputArea = require('notebook/js/outputarea').OutputArea;\n if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n register_renderer(events, OutputArea);\n }\n } catch(err) {\n }\n}\n",
|
|
"application/vnd.holoviews_load.v0+json": ""
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<script type=\"esms-options\">{\"shimMode\": true}</script><style>*[data-root-id],\n",
|
|
"*[data-root-id] > * {\n",
|
|
" box-sizing: border-box;\n",
|
|
" font-family: var(--jp-ui-font-family);\n",
|
|
" font-size: var(--jp-ui-font-size1);\n",
|
|
" color: var(--vscode-editor-foreground, var(--jp-ui-font-color1));\n",
|
|
"}\n",
|
|
"\n",
|
|
"/* Override VSCode background color */\n",
|
|
".cell-output-ipywidget-background:has(\n",
|
|
" > .cell-output-ipywidget-background > .lm-Widget > *[data-root-id]\n",
|
|
" ),\n",
|
|
".cell-output-ipywidget-background:has(> .lm-Widget > *[data-root-id]) {\n",
|
|
" background-color: transparent !important;\n",
|
|
"}\n",
|
|
"</style>"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"data": {
|
|
"application/javascript": "(function(root) {\n function now() {\n return new Date();\n }\n\n const force = false;\n const py_version = '3.6.0'.replace('rc', '-rc.').replace('.dev', '-dev.');\n const reloading = true;\n const Bokeh = root.Bokeh;\n\n // Set a timeout for this load but only if we are not already initializing\n if (typeof (root._bokeh_timeout) === \"undefined\" || (force || !root._bokeh_is_initializing)) {\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_failed_load = false;\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, js_modules, js_exports, callback) {\n if (css_urls == null) css_urls = [];\n if (js_urls == null) js_urls = [];\n if (js_modules == null) js_modules = [];\n if (js_exports == null) js_exports = {};\n\n root._bokeh_onload_callbacks.push(callback);\n\n if (root._bokeh_is_loading > 0) {\n // Don't load bokeh if it is still initializing\n console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n return null;\n } else if (js_urls.length === 0 && js_modules.length === 0 && Object.keys(js_exports).length === 0) {\n // There is nothing to load\n run_callbacks();\n return null;\n }\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 window._bokeh_on_load = on_load\n\n function on_error(e) {\n const src_el = e.srcElement\n console.error(\"failed to load \" + (src_el.href || src_el.src));\n }\n\n const skip = [];\n if (window.requirejs) {\n window.requirejs.config({'packages': {}, 'paths': {}, 'shim': {}});\n root._bokeh_is_loading = css_urls.length + 0;\n } else {\n root._bokeh_is_loading = css_urls.length + js_urls.length + js_modules.length + Object.keys(js_exports).length;\n }\n\n const existing_stylesheets = []\n const links = document.getElementsByTagName('link')\n for (let i = 0; i < links.length; i++) {\n const link = links[i]\n if (link.href != null) {\n existing_stylesheets.push(link.href)\n }\n }\n for (let i = 0; i < css_urls.length; i++) {\n const url = css_urls[i];\n const escaped = encodeURI(url)\n if (existing_stylesheets.indexOf(escaped) !== -1) {\n on_load()\n continue;\n }\n const element = document.createElement(\"link\");\n element.onload = on_load;\n element.onerror = on_error;\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 } var existing_scripts = []\n const scripts = document.getElementsByTagName('script')\n for (let i = 0; i < scripts.length; i++) {\n var script = scripts[i]\n if (script.src != null) {\n existing_scripts.push(script.src)\n }\n }\n for (let i = 0; i < js_urls.length; i++) {\n const url = js_urls[i];\n const escaped = encodeURI(url)\n if (skip.indexOf(escaped) !== -1 || existing_scripts.indexOf(escaped) !== -1) {\n if (!window.requirejs) {\n on_load();\n }\n continue;\n }\n const element = document.createElement('script');\n element.onload = on_load;\n element.onerror = on_error;\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 for (let i = 0; i < js_modules.length; i++) {\n const url = js_modules[i];\n const escaped = encodeURI(url)\n if (skip.indexOf(escaped) !== -1 || existing_scripts.indexOf(escaped) !== -1) {\n if (!window.requirejs) {\n on_load();\n }\n continue;\n }\n var element = document.createElement('script');\n element.onload = on_load;\n element.onerror = on_error;\n element.async = false;\n element.src = url;\n element.type = \"module\";\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n document.head.appendChild(element);\n }\n for (const name in js_exports) {\n const url = js_exports[name];\n const escaped = encodeURI(url)\n if (skip.indexOf(escaped) >= 0 || root[name] != null) {\n if (!window.requirejs) {\n on_load();\n }\n continue;\n }\n var element = document.createElement('script');\n element.onerror = on_error;\n element.async = false;\n element.type = \"module\";\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n element.textContent = `\n import ${name} from \"${url}\"\n window.${name} = ${name}\n window._bokeh_on_load()\n `\n document.head.appendChild(element);\n }\n if (!js_urls.length && !js_modules.length) {\n on_load()\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.holoviz.org/panel/1.5.3/dist/bundled/reactiveesm/es-module-shims@^1.10.0/dist/es-module-shims.min.js\"];\n const js_modules = [];\n const js_exports = {};\n const css_urls = [];\n const inline_js = [ function(Bokeh) {\n Bokeh.set_log_level(\"info\");\n },\nfunction(Bokeh) {} // ensure no trailing comma for IE\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 try {\n inline_js[i].call(root, root.Bokeh);\n } catch(e) {\n if (!reloading) {\n throw e;\n }\n }\n }\n // Cache old bokeh versions\n if (Bokeh != undefined && !reloading) {\n var NewBokeh = root.Bokeh;\n if (Bokeh.versions === undefined) {\n Bokeh.versions = new Map();\n }\n if (NewBokeh.version !== Bokeh.version) {\n Bokeh.versions.set(NewBokeh.version, NewBokeh)\n }\n root.Bokeh = Bokeh;\n }\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 }\n root._bokeh_is_initializing = false\n }\n\n function load_or_wait() {\n // Implement a backoff loop that tries to ensure we do not load multiple\n // versions of Bokeh and its dependencies at the same time.\n // In recent versions we use the root._bokeh_is_initializing flag\n // to determine whether there is an ongoing attempt to initialize\n // bokeh, however for backward compatibility we also try to ensure\n // that we do not start loading a newer (Panel>=1.0 and Bokeh>3) version\n // before older versions are fully initialized.\n if (root._bokeh_is_initializing && Date.now() > root._bokeh_timeout) {\n // If the timeout and bokeh was not successfully loaded we reset\n // everything and try loading again\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_is_initializing = false;\n root._bokeh_onload_callbacks = undefined;\n root._bokeh_is_loading = 0\n console.log(\"Bokeh: BokehJS was loaded multiple times but one version failed to initialize.\");\n load_or_wait();\n } else if (root._bokeh_is_initializing || (typeof root._bokeh_is_initializing === \"undefined\" && root._bokeh_onload_callbacks !== undefined)) {\n setTimeout(load_or_wait, 100);\n } else {\n root._bokeh_is_initializing = true\n root._bokeh_onload_callbacks = []\n const bokeh_loaded = root.Bokeh != null && (root.Bokeh.version === py_version || (root.Bokeh.versions !== undefined && root.Bokeh.versions.has(py_version)));\n if (!reloading && !bokeh_loaded) {\n if (root.Bokeh) {\n root.Bokeh = undefined;\n }\n console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n }\n load_libs(css_urls, js_urls, js_modules, js_exports, function() {\n console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n run_inline_js();\n });\n }\n }\n // Give older versions of the autoload script a head-start to ensure\n // they initialize before we start loading newer version.\n setTimeout(load_or_wait, 100)\n}(window));",
|
|
"application/vnd.holoviews_load.v0+json": ""
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"data": {
|
|
"application/javascript": "\nif ((window.PyViz === undefined) || (window.PyViz instanceof HTMLElement)) {\n window.PyViz = {comms: {}, comm_status:{}, kernels:{}, receivers: {}, plot_index: []}\n}\n\n\n function JupyterCommManager() {\n }\n\n JupyterCommManager.prototype.register_target = function(plot_id, comm_id, msg_handler) {\n if (window.comm_manager || ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel != null))) {\n var comm_manager = window.comm_manager || Jupyter.notebook.kernel.comm_manager;\n comm_manager.register_target(comm_id, function(comm) {\n comm.on_msg(msg_handler);\n });\n } else if ((plot_id in window.PyViz.kernels) && (window.PyViz.kernels[plot_id])) {\n window.PyViz.kernels[plot_id].registerCommTarget(comm_id, function(comm) {\n comm.onMsg = msg_handler;\n });\n } else if (typeof google != 'undefined' && google.colab.kernel != null) {\n google.colab.kernel.comms.registerTarget(comm_id, (comm) => {\n var messages = comm.messages[Symbol.asyncIterator]();\n function processIteratorResult(result) {\n var message = result.value;\n console.log(message)\n var content = {data: message.data, comm_id};\n var buffers = []\n for (var buffer of message.buffers || []) {\n buffers.push(new DataView(buffer))\n }\n var metadata = message.metadata || {};\n var msg = {content, buffers, metadata}\n msg_handler(msg);\n return messages.next().then(processIteratorResult);\n }\n return messages.next().then(processIteratorResult);\n })\n }\n }\n\n JupyterCommManager.prototype.get_client_comm = function(plot_id, comm_id, msg_handler) {\n if (comm_id in window.PyViz.comms) {\n return window.PyViz.comms[comm_id];\n } else if (window.comm_manager || ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel != null))) {\n var comm_manager = window.comm_manager || Jupyter.notebook.kernel.comm_manager;\n var comm = comm_manager.new_comm(comm_id, {}, {}, {}, comm_id);\n if (msg_handler) {\n comm.on_msg(msg_handler);\n }\n } else if ((plot_id in window.PyViz.kernels) && (window.PyViz.kernels[plot_id])) {\n var comm = window.PyViz.kernels[plot_id].connectToComm(comm_id);\n comm.open();\n if (msg_handler) {\n comm.onMsg = msg_handler;\n }\n } else if (typeof google != 'undefined' && google.colab.kernel != null) {\n var comm_promise = google.colab.kernel.comms.open(comm_id)\n comm_promise.then((comm) => {\n window.PyViz.comms[comm_id] = comm;\n if (msg_handler) {\n var messages = comm.messages[Symbol.asyncIterator]();\n function processIteratorResult(result) {\n var message = result.value;\n var content = {data: message.data};\n var metadata = message.metadata || {comm_id};\n var msg = {content, metadata}\n msg_handler(msg);\n return messages.next().then(processIteratorResult);\n }\n return messages.next().then(processIteratorResult);\n }\n }) \n var sendClosure = (data, metadata, buffers, disposeOnDone) => {\n return comm_promise.then((comm) => {\n comm.send(data, metadata, buffers, disposeOnDone);\n });\n };\n var comm = {\n send: sendClosure\n };\n }\n window.PyViz.comms[comm_id] = comm;\n return comm;\n }\n window.PyViz.comm_manager = new JupyterCommManager();\n \n\n\nvar JS_MIME_TYPE = 'application/javascript';\nvar HTML_MIME_TYPE = 'text/html';\nvar EXEC_MIME_TYPE = 'application/vnd.holoviews_exec.v0+json';\nvar CLASS_NAME = 'output';\n\n/**\n * Render data to the DOM node\n */\nfunction render(props, node) {\n var div = document.createElement(\"div\");\n var script = document.createElement(\"script\");\n node.appendChild(div);\n node.appendChild(script);\n}\n\n/**\n * Handle when a new output is added\n */\nfunction handle_add_output(event, handle) {\n var output_area = handle.output_area;\n var output = handle.output;\n if ((output.data == undefined) || (!output.data.hasOwnProperty(EXEC_MIME_TYPE))) {\n return\n }\n var id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n var toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n if (id !== undefined) {\n var nchildren = toinsert.length;\n var html_node = toinsert[nchildren-1].children[0];\n html_node.innerHTML = output.data[HTML_MIME_TYPE];\n var scripts = [];\n var nodelist = html_node.querySelectorAll(\"script\");\n for (var i in nodelist) {\n if (nodelist.hasOwnProperty(i)) {\n scripts.push(nodelist[i])\n }\n }\n\n scripts.forEach( function (oldScript) {\n var newScript = document.createElement(\"script\");\n var attrs = [];\n var nodemap = oldScript.attributes;\n for (var j in nodemap) {\n if (nodemap.hasOwnProperty(j)) {\n attrs.push(nodemap[j])\n }\n }\n attrs.forEach(function(attr) { newScript.setAttribute(attr.name, attr.value) });\n newScript.appendChild(document.createTextNode(oldScript.innerHTML));\n oldScript.parentNode.replaceChild(newScript, oldScript);\n });\n if (JS_MIME_TYPE in output.data) {\n toinsert[nchildren-1].children[1].textContent = output.data[JS_MIME_TYPE];\n }\n output_area._hv_plot_id = id;\n if ((window.Bokeh !== undefined) && (id in Bokeh.index)) {\n window.PyViz.plot_index[id] = Bokeh.index[id];\n } else {\n window.PyViz.plot_index[id] = null;\n }\n } else if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n var bk_div = document.createElement(\"div\");\n bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n var script_attrs = bk_div.children[0].attributes;\n for (var i = 0; i < script_attrs.length; i++) {\n toinsert[toinsert.length - 1].childNodes[1].setAttribute(script_attrs[i].name, script_attrs[i].value);\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/**\n * Handle when an output is cleared or removed\n */\nfunction handle_clear_output(event, handle) {\n var id = handle.cell.output_area._hv_plot_id;\n var server_id = handle.cell.output_area._bokeh_server_id;\n if (((id === undefined) || !(id in PyViz.plot_index)) && (server_id !== undefined)) { return; }\n var comm = window.PyViz.comm_manager.get_client_comm(\"hv-extension-comm\", \"hv-extension-comm\", function () {});\n if (server_id !== null) {\n comm.send({event_type: 'server_delete', 'id': server_id});\n return;\n } else if (comm !== null) {\n comm.send({event_type: 'delete', 'id': id});\n }\n delete PyViz.plot_index[id];\n if ((window.Bokeh !== undefined) & (id in window.Bokeh.index)) {\n var doc = window.Bokeh.index[id].model.document\n doc.clear();\n const i = window.Bokeh.documents.indexOf(doc);\n if (i > -1) {\n window.Bokeh.documents.splice(i, 1);\n }\n }\n}\n\n/**\n * Handle kernel restart event\n */\nfunction handle_kernel_cleanup(event, handle) {\n delete PyViz.comms[\"hv-extension-comm\"];\n window.PyViz.plot_index = {}\n}\n\n/**\n * Handle update_display_data messages\n */\nfunction handle_update_output(event, handle) {\n handle_clear_output(event, {cell: {output_area: handle.output_area}})\n handle_add_output(event, handle)\n}\n\nfunction register_renderer(events, OutputArea) {\n function append_mime(data, metadata, element) {\n // create a DOM node to render to\n var 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 var props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n render(props, toinsert[0]);\n element.append(toinsert);\n return toinsert\n }\n\n events.on('output_added.OutputArea', handle_add_output);\n events.on('output_updated.OutputArea', handle_update_output);\n events.on('clear_output.CodeCell', handle_clear_output);\n events.on('delete.Cell', handle_clear_output);\n events.on('kernel_ready.Kernel', handle_kernel_cleanup);\n\n OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n safe: true,\n index: 0\n });\n}\n\nif (window.Jupyter !== undefined) {\n try {\n var events = require('base/js/events');\n var OutputArea = require('notebook/js/outputarea').OutputArea;\n if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n register_renderer(events, OutputArea);\n }\n } catch(err) {\n }\n}\n",
|
|
"application/vnd.holoviews_load.v0+json": ""
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<script type=\"esms-options\">{\"shimMode\": true}</script><style>*[data-root-id],\n",
|
|
"*[data-root-id] > * {\n",
|
|
" box-sizing: border-box;\n",
|
|
" font-family: var(--jp-ui-font-family);\n",
|
|
" font-size: var(--jp-ui-font-size1);\n",
|
|
" color: var(--vscode-editor-foreground, var(--jp-ui-font-color1));\n",
|
|
"}\n",
|
|
"\n",
|
|
"/* Override VSCode background color */\n",
|
|
".cell-output-ipywidget-background:has(\n",
|
|
" > .cell-output-ipywidget-background > .lm-Widget > *[data-root-id]\n",
|
|
" ),\n",
|
|
".cell-output-ipywidget-background:has(> .lm-Widget > *[data-root-id]) {\n",
|
|
" background-color: transparent !important;\n",
|
|
"}\n",
|
|
"</style>"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"data": {
|
|
"application/javascript": "(function(root) {\n function now() {\n return new Date();\n }\n\n const force = false;\n const py_version = '3.6.0'.replace('rc', '-rc.').replace('.dev', '-dev.');\n const reloading = true;\n const Bokeh = root.Bokeh;\n\n // Set a timeout for this load but only if we are not already initializing\n if (typeof (root._bokeh_timeout) === \"undefined\" || (force || !root._bokeh_is_initializing)) {\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_failed_load = false;\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, js_modules, js_exports, callback) {\n if (css_urls == null) css_urls = [];\n if (js_urls == null) js_urls = [];\n if (js_modules == null) js_modules = [];\n if (js_exports == null) js_exports = {};\n\n root._bokeh_onload_callbacks.push(callback);\n\n if (root._bokeh_is_loading > 0) {\n // Don't load bokeh if it is still initializing\n console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n return null;\n } else if (js_urls.length === 0 && js_modules.length === 0 && Object.keys(js_exports).length === 0) {\n // There is nothing to load\n run_callbacks();\n return null;\n }\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 window._bokeh_on_load = on_load\n\n function on_error(e) {\n const src_el = e.srcElement\n console.error(\"failed to load \" + (src_el.href || src_el.src));\n }\n\n const skip = [];\n if (window.requirejs) {\n window.requirejs.config({'packages': {}, 'paths': {}, 'shim': {}});\n root._bokeh_is_loading = css_urls.length + 0;\n } else {\n root._bokeh_is_loading = css_urls.length + js_urls.length + js_modules.length + Object.keys(js_exports).length;\n }\n\n const existing_stylesheets = []\n const links = document.getElementsByTagName('link')\n for (let i = 0; i < links.length; i++) {\n const link = links[i]\n if (link.href != null) {\n existing_stylesheets.push(link.href)\n }\n }\n for (let i = 0; i < css_urls.length; i++) {\n const url = css_urls[i];\n const escaped = encodeURI(url)\n if (existing_stylesheets.indexOf(escaped) !== -1) {\n on_load()\n continue;\n }\n const element = document.createElement(\"link\");\n element.onload = on_load;\n element.onerror = on_error;\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 } var existing_scripts = []\n const scripts = document.getElementsByTagName('script')\n for (let i = 0; i < scripts.length; i++) {\n var script = scripts[i]\n if (script.src != null) {\n existing_scripts.push(script.src)\n }\n }\n for (let i = 0; i < js_urls.length; i++) {\n const url = js_urls[i];\n const escaped = encodeURI(url)\n if (skip.indexOf(escaped) !== -1 || existing_scripts.indexOf(escaped) !== -1) {\n if (!window.requirejs) {\n on_load();\n }\n continue;\n }\n const element = document.createElement('script');\n element.onload = on_load;\n element.onerror = on_error;\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 for (let i = 0; i < js_modules.length; i++) {\n const url = js_modules[i];\n const escaped = encodeURI(url)\n if (skip.indexOf(escaped) !== -1 || existing_scripts.indexOf(escaped) !== -1) {\n if (!window.requirejs) {\n on_load();\n }\n continue;\n }\n var element = document.createElement('script');\n element.onload = on_load;\n element.onerror = on_error;\n element.async = false;\n element.src = url;\n element.type = \"module\";\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n document.head.appendChild(element);\n }\n for (const name in js_exports) {\n const url = js_exports[name];\n const escaped = encodeURI(url)\n if (skip.indexOf(escaped) >= 0 || root[name] != null) {\n if (!window.requirejs) {\n on_load();\n }\n continue;\n }\n var element = document.createElement('script');\n element.onerror = on_error;\n element.async = false;\n element.type = \"module\";\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n element.textContent = `\n import ${name} from \"${url}\"\n window.${name} = ${name}\n window._bokeh_on_load()\n `\n document.head.appendChild(element);\n }\n if (!js_urls.length && !js_modules.length) {\n on_load()\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.holoviz.org/panel/1.5.3/dist/bundled/reactiveesm/es-module-shims@^1.10.0/dist/es-module-shims.min.js\"];\n const js_modules = [];\n const js_exports = {};\n const css_urls = [];\n const inline_js = [ function(Bokeh) {\n Bokeh.set_log_level(\"info\");\n },\nfunction(Bokeh) {} // ensure no trailing comma for IE\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 try {\n inline_js[i].call(root, root.Bokeh);\n } catch(e) {\n if (!reloading) {\n throw e;\n }\n }\n }\n // Cache old bokeh versions\n if (Bokeh != undefined && !reloading) {\n var NewBokeh = root.Bokeh;\n if (Bokeh.versions === undefined) {\n Bokeh.versions = new Map();\n }\n if (NewBokeh.version !== Bokeh.version) {\n Bokeh.versions.set(NewBokeh.version, NewBokeh)\n }\n root.Bokeh = Bokeh;\n }\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 }\n root._bokeh_is_initializing = false\n }\n\n function load_or_wait() {\n // Implement a backoff loop that tries to ensure we do not load multiple\n // versions of Bokeh and its dependencies at the same time.\n // In recent versions we use the root._bokeh_is_initializing flag\n // to determine whether there is an ongoing attempt to initialize\n // bokeh, however for backward compatibility we also try to ensure\n // that we do not start loading a newer (Panel>=1.0 and Bokeh>3) version\n // before older versions are fully initialized.\n if (root._bokeh_is_initializing && Date.now() > root._bokeh_timeout) {\n // If the timeout and bokeh was not successfully loaded we reset\n // everything and try loading again\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_is_initializing = false;\n root._bokeh_onload_callbacks = undefined;\n root._bokeh_is_loading = 0\n console.log(\"Bokeh: BokehJS was loaded multiple times but one version failed to initialize.\");\n load_or_wait();\n } else if (root._bokeh_is_initializing || (typeof root._bokeh_is_initializing === \"undefined\" && root._bokeh_onload_callbacks !== undefined)) {\n setTimeout(load_or_wait, 100);\n } else {\n root._bokeh_is_initializing = true\n root._bokeh_onload_callbacks = []\n const bokeh_loaded = root.Bokeh != null && (root.Bokeh.version === py_version || (root.Bokeh.versions !== undefined && root.Bokeh.versions.has(py_version)));\n if (!reloading && !bokeh_loaded) {\n if (root.Bokeh) {\n root.Bokeh = undefined;\n }\n console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n }\n load_libs(css_urls, js_urls, js_modules, js_exports, function() {\n console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n run_inline_js();\n });\n }\n }\n // Give older versions of the autoload script a head-start to ensure\n // they initialize before we start loading newer version.\n setTimeout(load_or_wait, 100)\n}(window));",
|
|
"application/vnd.holoviews_load.v0+json": ""
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"data": {
|
|
"application/javascript": "\nif ((window.PyViz === undefined) || (window.PyViz instanceof HTMLElement)) {\n window.PyViz = {comms: {}, comm_status:{}, kernels:{}, receivers: {}, plot_index: []}\n}\n\n\n function JupyterCommManager() {\n }\n\n JupyterCommManager.prototype.register_target = function(plot_id, comm_id, msg_handler) {\n if (window.comm_manager || ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel != null))) {\n var comm_manager = window.comm_manager || Jupyter.notebook.kernel.comm_manager;\n comm_manager.register_target(comm_id, function(comm) {\n comm.on_msg(msg_handler);\n });\n } else if ((plot_id in window.PyViz.kernels) && (window.PyViz.kernels[plot_id])) {\n window.PyViz.kernels[plot_id].registerCommTarget(comm_id, function(comm) {\n comm.onMsg = msg_handler;\n });\n } else if (typeof google != 'undefined' && google.colab.kernel != null) {\n google.colab.kernel.comms.registerTarget(comm_id, (comm) => {\n var messages = comm.messages[Symbol.asyncIterator]();\n function processIteratorResult(result) {\n var message = result.value;\n console.log(message)\n var content = {data: message.data, comm_id};\n var buffers = []\n for (var buffer of message.buffers || []) {\n buffers.push(new DataView(buffer))\n }\n var metadata = message.metadata || {};\n var msg = {content, buffers, metadata}\n msg_handler(msg);\n return messages.next().then(processIteratorResult);\n }\n return messages.next().then(processIteratorResult);\n })\n }\n }\n\n JupyterCommManager.prototype.get_client_comm = function(plot_id, comm_id, msg_handler) {\n if (comm_id in window.PyViz.comms) {\n return window.PyViz.comms[comm_id];\n } else if (window.comm_manager || ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel != null))) {\n var comm_manager = window.comm_manager || Jupyter.notebook.kernel.comm_manager;\n var comm = comm_manager.new_comm(comm_id, {}, {}, {}, comm_id);\n if (msg_handler) {\n comm.on_msg(msg_handler);\n }\n } else if ((plot_id in window.PyViz.kernels) && (window.PyViz.kernels[plot_id])) {\n var comm = window.PyViz.kernels[plot_id].connectToComm(comm_id);\n comm.open();\n if (msg_handler) {\n comm.onMsg = msg_handler;\n }\n } else if (typeof google != 'undefined' && google.colab.kernel != null) {\n var comm_promise = google.colab.kernel.comms.open(comm_id)\n comm_promise.then((comm) => {\n window.PyViz.comms[comm_id] = comm;\n if (msg_handler) {\n var messages = comm.messages[Symbol.asyncIterator]();\n function processIteratorResult(result) {\n var message = result.value;\n var content = {data: message.data};\n var metadata = message.metadata || {comm_id};\n var msg = {content, metadata}\n msg_handler(msg);\n return messages.next().then(processIteratorResult);\n }\n return messages.next().then(processIteratorResult);\n }\n }) \n var sendClosure = (data, metadata, buffers, disposeOnDone) => {\n return comm_promise.then((comm) => {\n comm.send(data, metadata, buffers, disposeOnDone);\n });\n };\n var comm = {\n send: sendClosure\n };\n }\n window.PyViz.comms[comm_id] = comm;\n return comm;\n }\n window.PyViz.comm_manager = new JupyterCommManager();\n \n\n\nvar JS_MIME_TYPE = 'application/javascript';\nvar HTML_MIME_TYPE = 'text/html';\nvar EXEC_MIME_TYPE = 'application/vnd.holoviews_exec.v0+json';\nvar CLASS_NAME = 'output';\n\n/**\n * Render data to the DOM node\n */\nfunction render(props, node) {\n var div = document.createElement(\"div\");\n var script = document.createElement(\"script\");\n node.appendChild(div);\n node.appendChild(script);\n}\n\n/**\n * Handle when a new output is added\n */\nfunction handle_add_output(event, handle) {\n var output_area = handle.output_area;\n var output = handle.output;\n if ((output.data == undefined) || (!output.data.hasOwnProperty(EXEC_MIME_TYPE))) {\n return\n }\n var id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n var toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n if (id !== undefined) {\n var nchildren = toinsert.length;\n var html_node = toinsert[nchildren-1].children[0];\n html_node.innerHTML = output.data[HTML_MIME_TYPE];\n var scripts = [];\n var nodelist = html_node.querySelectorAll(\"script\");\n for (var i in nodelist) {\n if (nodelist.hasOwnProperty(i)) {\n scripts.push(nodelist[i])\n }\n }\n\n scripts.forEach( function (oldScript) {\n var newScript = document.createElement(\"script\");\n var attrs = [];\n var nodemap = oldScript.attributes;\n for (var j in nodemap) {\n if (nodemap.hasOwnProperty(j)) {\n attrs.push(nodemap[j])\n }\n }\n attrs.forEach(function(attr) { newScript.setAttribute(attr.name, attr.value) });\n newScript.appendChild(document.createTextNode(oldScript.innerHTML));\n oldScript.parentNode.replaceChild(newScript, oldScript);\n });\n if (JS_MIME_TYPE in output.data) {\n toinsert[nchildren-1].children[1].textContent = output.data[JS_MIME_TYPE];\n }\n output_area._hv_plot_id = id;\n if ((window.Bokeh !== undefined) && (id in Bokeh.index)) {\n window.PyViz.plot_index[id] = Bokeh.index[id];\n } else {\n window.PyViz.plot_index[id] = null;\n }\n } else if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n var bk_div = document.createElement(\"div\");\n bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n var script_attrs = bk_div.children[0].attributes;\n for (var i = 0; i < script_attrs.length; i++) {\n toinsert[toinsert.length - 1].childNodes[1].setAttribute(script_attrs[i].name, script_attrs[i].value);\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/**\n * Handle when an output is cleared or removed\n */\nfunction handle_clear_output(event, handle) {\n var id = handle.cell.output_area._hv_plot_id;\n var server_id = handle.cell.output_area._bokeh_server_id;\n if (((id === undefined) || !(id in PyViz.plot_index)) && (server_id !== undefined)) { return; }\n var comm = window.PyViz.comm_manager.get_client_comm(\"hv-extension-comm\", \"hv-extension-comm\", function () {});\n if (server_id !== null) {\n comm.send({event_type: 'server_delete', 'id': server_id});\n return;\n } else if (comm !== null) {\n comm.send({event_type: 'delete', 'id': id});\n }\n delete PyViz.plot_index[id];\n if ((window.Bokeh !== undefined) & (id in window.Bokeh.index)) {\n var doc = window.Bokeh.index[id].model.document\n doc.clear();\n const i = window.Bokeh.documents.indexOf(doc);\n if (i > -1) {\n window.Bokeh.documents.splice(i, 1);\n }\n }\n}\n\n/**\n * Handle kernel restart event\n */\nfunction handle_kernel_cleanup(event, handle) {\n delete PyViz.comms[\"hv-extension-comm\"];\n window.PyViz.plot_index = {}\n}\n\n/**\n * Handle update_display_data messages\n */\nfunction handle_update_output(event, handle) {\n handle_clear_output(event, {cell: {output_area: handle.output_area}})\n handle_add_output(event, handle)\n}\n\nfunction register_renderer(events, OutputArea) {\n function append_mime(data, metadata, element) {\n // create a DOM node to render to\n var 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 var props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n render(props, toinsert[0]);\n element.append(toinsert);\n return toinsert\n }\n\n events.on('output_added.OutputArea', handle_add_output);\n events.on('output_updated.OutputArea', handle_update_output);\n events.on('clear_output.CodeCell', handle_clear_output);\n events.on('delete.Cell', handle_clear_output);\n events.on('kernel_ready.Kernel', handle_kernel_cleanup);\n\n OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n safe: true,\n index: 0\n });\n}\n\nif (window.Jupyter !== undefined) {\n try {\n var events = require('base/js/events');\n var OutputArea = require('notebook/js/outputarea').OutputArea;\n if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n register_renderer(events, OutputArea);\n }\n } catch(err) {\n }\n}\n",
|
|
"application/vnd.holoviews_load.v0+json": ""
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"✅ All modules loaded successfully!\n",
|
|
"📡 Data source: ODC Database\n",
|
|
"🚀 Infrastructure: Dask Gateway + ODC\n",
|
|
"CPU times: user 20 s, sys: 3.44 s, total: 23.4 s\n",
|
|
"Wall time: 15 s\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"%%time\n",
|
|
"%matplotlib inline\n",
|
|
"\n",
|
|
"import sys\n",
|
|
"import os\n",
|
|
"sys.path.insert(0, '/home/jovyan/remote-sensing')\n",
|
|
"\n",
|
|
"# Import ODC modules\n",
|
|
"import datacube\n",
|
|
"from easi_tools import notebook_utils\n",
|
|
"from datacube.utils.rio import configure_s3_access\n",
|
|
"\n",
|
|
"# Import ODC data loading functions\n",
|
|
"import importlib\n",
|
|
"import new_import_ODC\n",
|
|
"importlib.reload(new_import_ODC)\n",
|
|
"from new_import_ODC import *\n",
|
|
"\n",
|
|
"# Standard imports\n",
|
|
"import numpy as np\n",
|
|
"import pandas as pd\n",
|
|
"import xarray as xr\n",
|
|
"import matplotlib.pyplot as plt\n",
|
|
"import seaborn as sns\n",
|
|
"sns.set_style('whitegrid')\n",
|
|
"\n",
|
|
"# ML imports\n",
|
|
"from sklearn.tree import DecisionTreeClassifier\n",
|
|
"from sklearn.model_selection import train_test_split\n",
|
|
"from sklearn.metrics import classification_report, confusion_matrix, accuracy_score\n",
|
|
"import joblib\n",
|
|
"import json\n",
|
|
"from datetime import datetime\n",
|
|
"\n",
|
|
"print(\"✅ All modules loaded successfully!\")\n",
|
|
"print(\"📡 Data source: ODC Database\")\n",
|
|
"print(\"🚀 Infrastructure: Dask Gateway + ODC\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "0ad19235",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 🚀 Step 1: Initialize Dask Gateway + Datacube\n",
|
|
"\n",
|
|
"Khởi tạo Dask Gateway với adaptive scaling và kết nối tới ODC Database"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"id": "5d894cbd",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"🚀 Step 1: Dask Gateway + Datacube Initialization\n",
|
|
"======================================================================\n",
|
|
"Starting new cluster\n",
|
|
"\n",
|
|
"✅ Dask Gateway + Datacube + S3 ready!\n",
|
|
" Dask dashboard: https://hub.asia.easi-eo.solutions/services/dask-gateway/clusters/easihub.9d312633e3034586b37988a836a53a1d/status\n",
|
|
" Workers: Adaptive scaling (1-10)\n",
|
|
" ODC products available: 31\n",
|
|
"======================================================================\n",
|
|
"CPU times: user 1.3 s, sys: 33.3 ms, total: 1.33 s\n",
|
|
"Wall time: 3min 33s\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"%%time\n",
|
|
"\n",
|
|
"print(\"🚀 Step 1: Dask Gateway + Datacube Initialization\")\n",
|
|
"print(\"=\" * 70)\n",
|
|
"\n",
|
|
"# Cấu hình Dask Gateway\n",
|
|
"cluster, client = notebook_utils.initialize_dask(use_gateway=True, workers=(1, 10))\n",
|
|
"\n",
|
|
"# Khai báo Datacube - kết nối tới ODC Database\n",
|
|
"dc = datacube.Datacube()\n",
|
|
"\n",
|
|
"# Cấu hình truy cập dịch vụ S3\n",
|
|
"configure_s3_access(aws_unsigned=False, requester_pays=True, client=client)\n",
|
|
"\n",
|
|
"print(f\"\\n✅ Dask Gateway + Datacube + S3 ready!\")\n",
|
|
"print(f\" Dask dashboard: {client.dashboard_link}\")\n",
|
|
"print(f\" Workers: Adaptive scaling (1-10)\")\n",
|
|
"print(f\" ODC products available: {len(dc.list_products())}\")\n",
|
|
"print(\"=\" * 70)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "d96f19e5",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 📍 Step 2: Define Area of Interest (AOI)\n",
|
|
"\n",
|
|
"Định nghĩa vùng nghiên cứu và khoảng thời gian"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"id": "98046ea8",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"📍 Area of Interest:\n",
|
|
" Longitude range: 105.5 to 106.4\n",
|
|
" Latitude range: 9.2 to 10.0\n",
|
|
" Date range: 2022-09-01 to 2023-10-01\n",
|
|
"======================================================================\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"# Cấu hình vùng và thời gian\n",
|
|
"date_range = (\"2022-09-01\", \"2023-10-01\")\n",
|
|
"\n",
|
|
"# Coordinates: (lon_min, lon_max), (lat_min, lat_max)\n",
|
|
"longitude_range = (105.5, 106.4) # Khu vực Mekong Delta\n",
|
|
"latitude_range = (9.2, 10.0)\n",
|
|
"\n",
|
|
"print(\"📍 Area of Interest:\")\n",
|
|
"print(f\" Longitude range: {longitude_range[0]} to {longitude_range[1]}\")\n",
|
|
"print(f\" Latitude range: {latitude_range[0]} to {latitude_range[1]}\")\n",
|
|
"print(f\" Date range: {date_range[0]} to {date_range[1]}\")\n",
|
|
"print(\"=\" * 70)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "79d37cff",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 📥 Step 3: Load Sentinel-2 Data from ODC\n",
|
|
"\n",
|
|
"Load dữ liệu Sentinel-2 L2A từ ODC Database"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"id": "3e8b535d",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"📥 Loading Sentinel-2 data from ODC Database...\n",
|
|
"----------------------------------------------------------------------\n",
|
|
"Most common native CRS: EPSG:32648\n",
|
|
"No datasets require offset correction\n",
|
|
"The valid_data_mask and scale (no offset) have been applied to the reflectance bands\n",
|
|
"\n",
|
|
"✅ Sentinel-2 data loaded from ODC!\n",
|
|
" Dimensions: {'time': 151, 'y': 8874, 'x': 9902}\n",
|
|
" Variables: ['red', 'nir', 'scl']\n",
|
|
" Time steps: 151\n",
|
|
"\n",
|
|
"🔧 Applying cloud mask...\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"<timed exec>:9: FutureWarning: The return type of `Dataset.dims` will be changed to return a set of dimension names in future, in order to be more consistent with `DataArray.dims`. To access a mapping from dimension names to lengths, please use `Dataset.sizes`.\n"
|
|
]
|
|
},
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<div>\n",
|
|
"<style scoped>\n",
|
|
" .dataframe tbody tr th:only-of-type {\n",
|
|
" vertical-align: middle;\n",
|
|
" }\n",
|
|
"\n",
|
|
" .dataframe tbody tr th {\n",
|
|
" vertical-align: top;\n",
|
|
" }\n",
|
|
"\n",
|
|
" .dataframe thead th {\n",
|
|
" text-align: right;\n",
|
|
" }\n",
|
|
"</style>\n",
|
|
"<table border=\"1\" class=\"dataframe\">\n",
|
|
" <thead>\n",
|
|
" <tr style=\"text-align: right;\">\n",
|
|
" <th></th>\n",
|
|
" <th>bits</th>\n",
|
|
" <th>values</th>\n",
|
|
" <th>description</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>qa</th>\n",
|
|
" <td>[0, 1, 2, 3, 4, 5, 6, 7]</td>\n",
|
|
" <td>{'0': 'no data', '1': 'saturated or defective'...</td>\n",
|
|
" <td>Sen2Cor Scene Classification</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" bits \\\n",
|
|
"qa [0, 1, 2, 3, 4, 5, 6, 7] \n",
|
|
"\n",
|
|
" values \\\n",
|
|
"qa {'0': 'no data', '1': 'saturated or defective'... \n",
|
|
"\n",
|
|
" description \n",
|
|
"qa Sen2Cor Scene Classification "
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"{'0': 'no data',\n",
|
|
" '1': 'saturated or defective',\n",
|
|
" '2': 'dark area pixels',\n",
|
|
" '3': 'cloud shadows',\n",
|
|
" '4': 'vegetation',\n",
|
|
" '5': 'bare soils',\n",
|
|
" '6': 'water',\n",
|
|
" '7': 'unclassified',\n",
|
|
" '8': 'cloud medium probability',\n",
|
|
" '9': 'cloud high probability',\n",
|
|
" '10': 'thin cirrus',\n",
|
|
" '11': 'snow or ice'}"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"📊 Calculating NDVI...\n",
|
|
"📅 Resampling to monthly averages...\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"/env/lib/python3.12/site-packages/xarray/groupers.py:392: FutureWarning: 'M' is deprecated and will be removed in a future version, please use 'ME' instead.\n",
|
|
" self.index_grouper = pd.Grouper(\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"\n",
|
|
"✅ Sentinel-2 monthly data ready!\n",
|
|
" ✓ Cloud masked\n",
|
|
" ✓ NDVI calculated\n",
|
|
" ✓ Monthly resampled\n",
|
|
" ✓ Loaded into memory\n",
|
|
"CPU times: user 11.5 s, sys: 6.48 s, total: 18 s\n",
|
|
"Wall time: 4min 40s\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"%%time\n",
|
|
"\n",
|
|
"print(\"📥 Loading Sentinel-2 data from ODC Database...\")\n",
|
|
"print(\"-\" * 70)\n",
|
|
"\n",
|
|
"# Load Sentinel-2 từ ODC\n",
|
|
"data_sen2 = load_data(dc, date_range, longitude_range, latitude_range)\n",
|
|
"\n",
|
|
"if data_sen2 is not None:\n",
|
|
" print(f\"\\n✅ Sentinel-2 data loaded from ODC!\")\n",
|
|
" print(f\" Dimensions: {dict(data_sen2.dims)}\")\n",
|
|
" print(f\" Variables: {list(data_sen2.data_vars)}\")\n",
|
|
" print(f\" Time steps: {len(data_sen2.time)}\")\n",
|
|
" \n",
|
|
" # Apply cloud masking\n",
|
|
" print(\"\\n🔧 Applying cloud mask...\")\n",
|
|
" data_sen2_clean = mask_clean(data_sen2)\n",
|
|
" \n",
|
|
" # Calculate NDVI manually\n",
|
|
" print(\"📊 Calculating NDVI...\")\n",
|
|
" ndvi = (data_sen2_clean.nir - data_sen2_clean.red) / (data_sen2_clean.nir + data_sen2_clean.red)\n",
|
|
" \n",
|
|
" # Resample to monthly\n",
|
|
" print(\"📅 Resampling to monthly averages...\")\n",
|
|
" data_sen2_monthly = calculate_average(ndvi, time_pattern='1M')\n",
|
|
" \n",
|
|
" # Compute to load into memory\n",
|
|
" data_sen2_monthly = data_sen2_monthly.compute()\n",
|
|
" print(f\"\\n✅ Sentinel-2 monthly data ready!\")\n",
|
|
" print(f\" ✓ Cloud masked\")\n",
|
|
" print(f\" ✓ NDVI calculated\")\n",
|
|
" print(f\" ✓ Monthly resampled\")\n",
|
|
" print(f\" ✓ Loaded into memory\")\n",
|
|
"else:\n",
|
|
" print(\"❌ Failed to load Sentinel-2 data\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "d0c0f672",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 📥 Step 4: Load Sentinel-1 Data from ODC\n",
|
|
"\n",
|
|
"Load dữ liệu Sentinel-1 RTC (SAR) từ ODC Database"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "1e629839",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"📥 Loading Sentinel-1 data from ODC Database...\n",
|
|
"----------------------------------------------------------------------\n"
|
|
]
|
|
},
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<h4>Dataset size: 21.60 GB</h4>"
|
|
],
|
|
"text/plain": [
|
|
"<IPython.core.display.HTML object>"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<div><svg style=\"position: absolute; width: 0; height: 0; overflow: hidden\">\n",
|
|
"<defs>\n",
|
|
"<symbol id=\"icon-database\" viewBox=\"0 0 32 32\">\n",
|
|
"<path d=\"M16 0c-8.837 0-16 2.239-16 5v4c0 2.761 7.163 5 16 5s16-2.239 16-5v-4c0-2.761-7.163-5-16-5z\"></path>\n",
|
|
"<path d=\"M16 17c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n",
|
|
"<path d=\"M16 26c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n",
|
|
"</symbol>\n",
|
|
"<symbol id=\"icon-file-text2\" viewBox=\"0 0 32 32\">\n",
|
|
"<path d=\"M28.681 7.159c-0.694-0.947-1.662-2.053-2.724-3.116s-2.169-2.030-3.116-2.724c-1.612-1.182-2.393-1.319-2.841-1.319h-15.5c-1.378 0-2.5 1.121-2.5 2.5v27c0 1.378 1.122 2.5 2.5 2.5h23c1.378 0 2.5-1.122 2.5-2.5v-19.5c0-0.448-0.137-1.23-1.319-2.841zM24.543 5.457c0.959 0.959 1.712 1.825 2.268 2.543h-4.811v-4.811c0.718 0.556 1.584 1.309 2.543 2.268zM28 29.5c0 0.271-0.229 0.5-0.5 0.5h-23c-0.271 0-0.5-0.229-0.5-0.5v-27c0-0.271 0.229-0.5 0.5-0.5 0 0 15.499-0 15.5 0v7c0 0.552 0.448 1 1 1h7v19.5z\"></path>\n",
|
|
"<path d=\"M23 26h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
|
|
"<path d=\"M23 22h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
|
|
"<path d=\"M23 18h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
|
|
"</symbol>\n",
|
|
"</defs>\n",
|
|
"</svg>\n",
|
|
"<style>/* CSS stylesheet for displaying xarray objects in jupyterlab.\n",
|
|
" *\n",
|
|
" */\n",
|
|
"\n",
|
|
":root {\n",
|
|
" --xr-font-color0: var(--jp-content-font-color0, rgba(0, 0, 0, 1));\n",
|
|
" --xr-font-color2: var(--jp-content-font-color2, rgba(0, 0, 0, 0.54));\n",
|
|
" --xr-font-color3: var(--jp-content-font-color3, rgba(0, 0, 0, 0.38));\n",
|
|
" --xr-border-color: var(--jp-border-color2, #e0e0e0);\n",
|
|
" --xr-disabled-color: var(--jp-layout-color3, #bdbdbd);\n",
|
|
" --xr-background-color: var(--jp-layout-color0, white);\n",
|
|
" --xr-background-color-row-even: var(--jp-layout-color1, white);\n",
|
|
" --xr-background-color-row-odd: var(--jp-layout-color2, #eeeeee);\n",
|
|
"}\n",
|
|
"\n",
|
|
"html[theme=dark],\n",
|
|
"html[data-theme=dark],\n",
|
|
"body[data-theme=dark],\n",
|
|
"body.vscode-dark {\n",
|
|
" --xr-font-color0: rgba(255, 255, 255, 1);\n",
|
|
" --xr-font-color2: rgba(255, 255, 255, 0.54);\n",
|
|
" --xr-font-color3: rgba(255, 255, 255, 0.38);\n",
|
|
" --xr-border-color: #1F1F1F;\n",
|
|
" --xr-disabled-color: #515151;\n",
|
|
" --xr-background-color: #111111;\n",
|
|
" --xr-background-color-row-even: #111111;\n",
|
|
" --xr-background-color-row-odd: #313131;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-wrap {\n",
|
|
" display: block !important;\n",
|
|
" min-width: 300px;\n",
|
|
" max-width: 700px;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-text-repr-fallback {\n",
|
|
" /* fallback to plain text repr when CSS is not injected (untrusted notebook) */\n",
|
|
" display: none;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-header {\n",
|
|
" padding-top: 6px;\n",
|
|
" padding-bottom: 6px;\n",
|
|
" margin-bottom: 4px;\n",
|
|
" border-bottom: solid 1px var(--xr-border-color);\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-header > div,\n",
|
|
".xr-header > ul {\n",
|
|
" display: inline;\n",
|
|
" margin-top: 0;\n",
|
|
" margin-bottom: 0;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-obj-type,\n",
|
|
".xr-array-name {\n",
|
|
" margin-left: 2px;\n",
|
|
" margin-right: 10px;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-obj-type {\n",
|
|
" color: var(--xr-font-color2);\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-sections {\n",
|
|
" padding-left: 0 !important;\n",
|
|
" display: grid;\n",
|
|
" grid-template-columns: 150px auto auto 1fr 0 20px 0 20px;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-section-item {\n",
|
|
" display: contents;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-section-item input {\n",
|
|
" display: inline-block;\n",
|
|
" opacity: 0;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-section-item input + label {\n",
|
|
" color: var(--xr-disabled-color);\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-section-item input:enabled + label {\n",
|
|
" cursor: pointer;\n",
|
|
" color: var(--xr-font-color2);\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-section-item input:focus + label {\n",
|
|
" border: 2px solid var(--xr-font-color0);\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-section-item input:enabled + label:hover {\n",
|
|
" color: var(--xr-font-color0);\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-section-summary {\n",
|
|
" grid-column: 1;\n",
|
|
" color: var(--xr-font-color2);\n",
|
|
" font-weight: 500;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-section-summary > span {\n",
|
|
" display: inline-block;\n",
|
|
" padding-left: 0.5em;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-section-summary-in:disabled + label {\n",
|
|
" color: var(--xr-font-color2);\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-section-summary-in + label:before {\n",
|
|
" display: inline-block;\n",
|
|
" content: '►';\n",
|
|
" font-size: 11px;\n",
|
|
" width: 15px;\n",
|
|
" text-align: center;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-section-summary-in:disabled + label:before {\n",
|
|
" color: var(--xr-disabled-color);\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-section-summary-in:checked + label:before {\n",
|
|
" content: '▼';\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-section-summary-in:checked + label > span {\n",
|
|
" display: none;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-section-summary,\n",
|
|
".xr-section-inline-details {\n",
|
|
" padding-top: 4px;\n",
|
|
" padding-bottom: 4px;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-section-inline-details {\n",
|
|
" grid-column: 2 / -1;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-section-details {\n",
|
|
" display: none;\n",
|
|
" grid-column: 1 / -1;\n",
|
|
" margin-bottom: 5px;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-section-summary-in:checked ~ .xr-section-details {\n",
|
|
" display: contents;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-array-wrap {\n",
|
|
" grid-column: 1 / -1;\n",
|
|
" display: grid;\n",
|
|
" grid-template-columns: 20px auto;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-array-wrap > label {\n",
|
|
" grid-column: 1;\n",
|
|
" vertical-align: top;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-preview {\n",
|
|
" color: var(--xr-font-color3);\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-array-preview,\n",
|
|
".xr-array-data {\n",
|
|
" padding: 0 5px !important;\n",
|
|
" grid-column: 2;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-array-data,\n",
|
|
".xr-array-in:checked ~ .xr-array-preview {\n",
|
|
" display: none;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-array-in:checked ~ .xr-array-data,\n",
|
|
".xr-array-preview {\n",
|
|
" display: inline-block;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-dim-list {\n",
|
|
" display: inline-block !important;\n",
|
|
" list-style: none;\n",
|
|
" padding: 0 !important;\n",
|
|
" margin: 0;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-dim-list li {\n",
|
|
" display: inline-block;\n",
|
|
" padding: 0;\n",
|
|
" margin: 0;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-dim-list:before {\n",
|
|
" content: '(';\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-dim-list:after {\n",
|
|
" content: ')';\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-dim-list li:not(:last-child):after {\n",
|
|
" content: ',';\n",
|
|
" padding-right: 5px;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-has-index {\n",
|
|
" font-weight: bold;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-var-list,\n",
|
|
".xr-var-item {\n",
|
|
" display: contents;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-var-item > div,\n",
|
|
".xr-var-item label,\n",
|
|
".xr-var-item > .xr-var-name span {\n",
|
|
" background-color: var(--xr-background-color-row-even);\n",
|
|
" margin-bottom: 0;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-var-item > .xr-var-name:hover span {\n",
|
|
" padding-right: 5px;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-var-list > li:nth-child(odd) > div,\n",
|
|
".xr-var-list > li:nth-child(odd) > label,\n",
|
|
".xr-var-list > li:nth-child(odd) > .xr-var-name span {\n",
|
|
" background-color: var(--xr-background-color-row-odd);\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-var-name {\n",
|
|
" grid-column: 1;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-var-dims {\n",
|
|
" grid-column: 2;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-var-dtype {\n",
|
|
" grid-column: 3;\n",
|
|
" text-align: right;\n",
|
|
" color: var(--xr-font-color2);\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-var-preview {\n",
|
|
" grid-column: 4;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-index-preview {\n",
|
|
" grid-column: 2 / 5;\n",
|
|
" color: var(--xr-font-color2);\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-var-name,\n",
|
|
".xr-var-dims,\n",
|
|
".xr-var-dtype,\n",
|
|
".xr-preview,\n",
|
|
".xr-attrs dt {\n",
|
|
" white-space: nowrap;\n",
|
|
" overflow: hidden;\n",
|
|
" text-overflow: ellipsis;\n",
|
|
" padding-right: 10px;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-var-name:hover,\n",
|
|
".xr-var-dims:hover,\n",
|
|
".xr-var-dtype:hover,\n",
|
|
".xr-attrs dt:hover {\n",
|
|
" overflow: visible;\n",
|
|
" width: auto;\n",
|
|
" z-index: 1;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-var-attrs,\n",
|
|
".xr-var-data,\n",
|
|
".xr-index-data {\n",
|
|
" display: none;\n",
|
|
" background-color: var(--xr-background-color) !important;\n",
|
|
" padding-bottom: 5px !important;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-var-attrs-in:checked ~ .xr-var-attrs,\n",
|
|
".xr-var-data-in:checked ~ .xr-var-data,\n",
|
|
".xr-index-data-in:checked ~ .xr-index-data {\n",
|
|
" display: block;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-var-data > table {\n",
|
|
" float: right;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-var-name span,\n",
|
|
".xr-var-data,\n",
|
|
".xr-index-name div,\n",
|
|
".xr-index-data,\n",
|
|
".xr-attrs {\n",
|
|
" padding-left: 25px !important;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-attrs,\n",
|
|
".xr-var-attrs,\n",
|
|
".xr-var-data,\n",
|
|
".xr-index-data {\n",
|
|
" grid-column: 1 / -1;\n",
|
|
"}\n",
|
|
"\n",
|
|
"dl.xr-attrs {\n",
|
|
" padding: 0;\n",
|
|
" margin: 0;\n",
|
|
" display: grid;\n",
|
|
" grid-template-columns: 125px auto;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-attrs dt,\n",
|
|
".xr-attrs dd {\n",
|
|
" padding: 0;\n",
|
|
" margin: 0;\n",
|
|
" float: left;\n",
|
|
" padding-right: 10px;\n",
|
|
" width: auto;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-attrs dt {\n",
|
|
" font-weight: normal;\n",
|
|
" grid-column: 1;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-attrs dt:hover span {\n",
|
|
" display: inline-block;\n",
|
|
" background: var(--xr-background-color);\n",
|
|
" padding-right: 10px;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-attrs dd {\n",
|
|
" grid-column: 2;\n",
|
|
" white-space: pre-wrap;\n",
|
|
" word-break: break-all;\n",
|
|
"}\n",
|
|
"\n",
|
|
".xr-icon-database,\n",
|
|
".xr-icon-file-text2,\n",
|
|
".xr-no-icon {\n",
|
|
" display: inline-block;\n",
|
|
" vertical-align: middle;\n",
|
|
" width: 1em;\n",
|
|
" height: 1.5em !important;\n",
|
|
" stroke-width: 0;\n",
|
|
" stroke: currentColor;\n",
|
|
" fill: currentColor;\n",
|
|
"}\n",
|
|
"</style><pre class='xr-text-repr-fallback'><xarray.Dataset> Size: 23GB\n",
|
|
"Dimensions: (time: 33, y: 8874, x: 9902)\n",
|
|
"Coordinates:\n",
|
|
" * time (time) datetime64[ns] 264B 2022-09-06T22:46:14.500000 ... 20...\n",
|
|
" * y (y) float64 71kB 1.106e+06 1.106e+06 ... 1.017e+06 1.017e+06\n",
|
|
" * x (x) float64 79kB 5.548e+05 5.548e+05 ... 6.538e+05 6.538e+05\n",
|
|
" spatial_ref int32 4B 32648\n",
|
|
"Data variables:\n",
|
|
" vv (time, y, x) float32 12GB dask.array<chunksize=(1, 2048, 2048), meta=np.ndarray>\n",
|
|
" vh (time, y, x) float32 12GB dask.array<chunksize=(1, 2048, 2048), meta=np.ndarray>\n",
|
|
"Attributes:\n",
|
|
" crs: EPSG:32648\n",
|
|
" grid_mapping: spatial_ref</pre><div class='xr-wrap' style='display:none'><div class='xr-header'><div class='xr-obj-type'>xarray.Dataset</div></div><ul class='xr-sections'><li class='xr-section-item'><input id='section-6c153c81-e84a-4625-b5d6-43d4d93af738' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-6c153c81-e84a-4625-b5d6-43d4d93af738' class='xr-section-summary' title='Expand/collapse section'>Dimensions:</label><div class='xr-section-inline-details'><ul class='xr-dim-list'><li><span class='xr-has-index'>time</span>: 33</li><li><span class='xr-has-index'>y</span>: 8874</li><li><span class='xr-has-index'>x</span>: 9902</li></ul></div><div class='xr-section-details'></div></li><li class='xr-section-item'><input id='section-54bc589f-0c35-4a98-b0b2-67d68832a4e2' class='xr-section-summary-in' type='checkbox' checked><label for='section-54bc589f-0c35-4a98-b0b2-67d68832a4e2' class='xr-section-summary' >Coordinates: <span>(4)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>time</span></div><div class='xr-var-dims'>(time)</div><div class='xr-var-dtype'>datetime64[ns]</div><div class='xr-var-preview xr-preview'>2022-09-06T22:46:14.500000 ... 2...</div><input id='attrs-95850d5f-4a0b-4192-a3c2-d71d3ef0002e' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-95850d5f-4a0b-4192-a3c2-d71d3ef0002e' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-a057e45c-8e76-4592-a583-7913d9e50a27' class='xr-var-data-in' type='checkbox'><label for='data-a057e45c-8e76-4592-a583-7913d9e50a27' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>units :</span></dt><dd>seconds since 1970-01-01 00:00:00</dd></dl></div><div class='xr-var-data'><pre>array(['2022-09-06T22:46:14.500000000', '2022-09-18T22:46:13.500000000',\n",
|
|
" '2022-09-30T22:46:14.500000000', '2022-10-12T22:46:14.500000000',\n",
|
|
" '2022-10-24T22:46:14.500000000', '2022-11-05T22:46:14.500000000',\n",
|
|
" '2022-11-17T22:46:13.500000000', '2022-11-29T22:46:13.500000000',\n",
|
|
" '2022-12-11T22:46:13.500000000', '2022-12-23T22:46:12.500000000',\n",
|
|
" '2023-01-04T22:46:11.500000000', '2023-01-16T22:46:10.500000000',\n",
|
|
" '2023-01-28T22:46:11.500000000', '2023-02-09T22:46:10.500000000',\n",
|
|
" '2023-02-21T22:46:09.500000000', '2023-03-05T22:46:10.500000000',\n",
|
|
" '2023-03-17T22:46:10.500000000', '2023-03-29T22:46:10.500000000',\n",
|
|
" '2023-04-10T22:46:11.500000000', '2023-04-22T22:46:11.500000000',\n",
|
|
" '2023-05-04T22:46:11.500000000', '2023-05-17T11:11:32.500000000',\n",
|
|
" '2023-05-29T11:11:32.500000000', '2023-06-10T11:11:28.500000000',\n",
|
|
" '2023-06-21T22:46:13.500000000', '2023-07-04T11:11:34.500000000',\n",
|
|
" '2023-07-16T11:11:35.500000000', '2023-07-28T11:11:36.500000000',\n",
|
|
" '2023-08-08T22:46:16.500000000', '2023-08-20T22:46:17.500000000',\n",
|
|
" '2023-09-01T22:46:18.500000000', '2023-09-13T22:46:18.500000000',\n",
|
|
" '2023-09-25T22:46:19.500000000'], dtype='datetime64[ns]')</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>y</span></div><div class='xr-var-dims'>(y)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>1.106e+06 1.106e+06 ... 1.017e+06</div><input id='attrs-f36ad6d7-6685-4e2a-a8d3-2f8cd26a6664' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-f36ad6d7-6685-4e2a-a8d3-2f8cd26a6664' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-db09617d-eafc-424e-b044-b4e712a83f56' class='xr-var-data-in' type='checkbox'><label for='data-db09617d-eafc-424e-b044-b4e712a83f56' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>units :</span></dt><dd>metre</dd><dt><span>resolution :</span></dt><dd>-10.0</dd><dt><span>crs :</span></dt><dd>EPSG:32648</dd></dl></div><div class='xr-var-data'><pre>array([1105735., 1105725., 1105715., ..., 1017025., 1017015., 1017005.])</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>x</span></div><div class='xr-var-dims'>(x)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>5.548e+05 5.548e+05 ... 6.538e+05</div><input id='attrs-386894ad-9c38-4af8-8447-10eddc9a42bf' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-386894ad-9c38-4af8-8447-10eddc9a42bf' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-d93cfb9f-bb28-49b3-938a-a4a53062c2c0' class='xr-var-data-in' type='checkbox'><label for='data-d93cfb9f-bb28-49b3-938a-a4a53062c2c0' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>units :</span></dt><dd>metre</dd><dt><span>resolution :</span></dt><dd>10.0</dd><dt><span>crs :</span></dt><dd>EPSG:32648</dd></dl></div><div class='xr-var-data'><pre>array([554795., 554805., 554815., ..., 653785., 653795., 653805.])</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>spatial_ref</span></div><div class='xr-var-dims'>()</div><div class='xr-var-dtype'>int32</div><div class='xr-var-preview xr-preview'>32648</div><input id='attrs-1b1a1cb9-473d-4764-a2be-979f30e8a23b' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-1b1a1cb9-473d-4764-a2be-979f30e8a23b' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-9cd597e6-7000-49a8-8cd4-07e2786e5d4d' class='xr-var-data-in' type='checkbox'><label for='data-9cd597e6-7000-49a8-8cd4-07e2786e5d4d' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>spatial_ref :</span></dt><dd>PROJCS["WGS 84 / UTM zone 48N",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",105],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","32648"]]</dd><dt><span>grid_mapping_name :</span></dt><dd>transverse_mercator</dd></dl></div><div class='xr-var-data'><pre>array(32648, dtype=int32)</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-dbb7b89a-988d-41df-a841-3aed359b57c2' class='xr-section-summary-in' type='checkbox' checked><label for='section-dbb7b89a-988d-41df-a841-3aed359b57c2' class='xr-section-summary' >Data variables: <span>(2)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-var-name'><span>vv</span></div><div class='xr-var-dims'>(time, y, x)</div><div class='xr-var-dtype'>float32</div><div class='xr-var-preview xr-preview'>dask.array<chunksize=(1, 2048, 2048), meta=np.ndarray></div><input id='attrs-e3bc6265-bbe2-4559-be9b-10eca9adb438' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-e3bc6265-bbe2-4559-be9b-10eca9adb438' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-b7a5f379-2b66-4a13-babe-0fbc5f83f148' class='xr-var-data-in' type='checkbox'><label for='data-b7a5f379-2b66-4a13-babe-0fbc5f83f148' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>units :</span></dt><dd>intensity</dd><dt><span>nodata :</span></dt><dd>nan</dd><dt><span>crs :</span></dt><dd>EPSG:32648</dd><dt><span>grid_mapping :</span></dt><dd>spatial_ref</dd></dl></div><div class='xr-var-data'><table>\n",
|
|
" <tr>\n",
|
|
" <td>\n",
|
|
" <table style=\"border-collapse: collapse;\">\n",
|
|
" <thead>\n",
|
|
" <tr>\n",
|
|
" <td> </td>\n",
|
|
" <th> Array </th>\n",
|
|
" <th> Chunk </th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" \n",
|
|
" <tr>\n",
|
|
" <th> Bytes </th>\n",
|
|
" <td> 10.80 GiB </td>\n",
|
|
" <td> 16.00 MiB </td>\n",
|
|
" </tr>\n",
|
|
" \n",
|
|
" <tr>\n",
|
|
" <th> Shape </th>\n",
|
|
" <td> (33, 8874, 9902) </td>\n",
|
|
" <td> (1, 2048, 2048) </td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th> Dask graph </th>\n",
|
|
" <td colspan=\"2\"> 825 chunks in 1 graph layer </td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th> Data type </th>\n",
|
|
" <td colspan=\"2\"> float32 numpy.ndarray </td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
" </table>\n",
|
|
" </td>\n",
|
|
" <td>\n",
|
|
" <svg width=\"194\" height=\"172\" style=\"stroke:rgb(0,0,0);stroke-width:1\" >\n",
|
|
"\n",
|
|
" <!-- Horizontal lines -->\n",
|
|
" <line x1=\"10\" y1=\"0\" x2=\"24\" y2=\"14\" style=\"stroke-width:2\" />\n",
|
|
" <line x1=\"10\" y1=\"24\" x2=\"24\" y2=\"39\" />\n",
|
|
" <line x1=\"10\" y1=\"49\" x2=\"24\" y2=\"64\" />\n",
|
|
" <line x1=\"10\" y1=\"74\" x2=\"24\" y2=\"89\" />\n",
|
|
" <line x1=\"10\" y1=\"99\" x2=\"24\" y2=\"114\" />\n",
|
|
" <line x1=\"10\" y1=\"107\" x2=\"24\" y2=\"122\" style=\"stroke-width:2\" />\n",
|
|
"\n",
|
|
" <!-- Vertical lines -->\n",
|
|
" <line x1=\"10\" y1=\"0\" x2=\"10\" y2=\"107\" style=\"stroke-width:2\" />\n",
|
|
" <line x1=\"10\" y1=\"0\" x2=\"10\" y2=\"107\" />\n",
|
|
" <line x1=\"11\" y1=\"1\" x2=\"11\" y2=\"108\" />\n",
|
|
" <line x1=\"12\" y1=\"2\" x2=\"12\" y2=\"109\" />\n",
|
|
" <line x1=\"12\" y1=\"2\" x2=\"12\" y2=\"110\" />\n",
|
|
" <line x1=\"13\" y1=\"3\" x2=\"13\" y2=\"111\" />\n",
|
|
" <line x1=\"14\" y1=\"4\" x2=\"14\" y2=\"112\" />\n",
|
|
" <line x1=\"15\" y1=\"5\" x2=\"15\" y2=\"112\" />\n",
|
|
" <line x1=\"15\" y1=\"5\" x2=\"15\" y2=\"113\" />\n",
|
|
" <line x1=\"16\" y1=\"6\" x2=\"16\" y2=\"114\" />\n",
|
|
" <line x1=\"17\" y1=\"7\" x2=\"17\" y2=\"115\" />\n",
|
|
" <line x1=\"18\" y1=\"8\" x2=\"18\" y2=\"116\" />\n",
|
|
" <line x1=\"19\" y1=\"9\" x2=\"19\" y2=\"116\" />\n",
|
|
" <line x1=\"19\" y1=\"9\" x2=\"19\" y2=\"117\" />\n",
|
|
" <line x1=\"20\" y1=\"10\" x2=\"20\" y2=\"118\" />\n",
|
|
" <line x1=\"21\" y1=\"11\" x2=\"21\" y2=\"119\" />\n",
|
|
" <line x1=\"22\" y1=\"12\" x2=\"22\" y2=\"119\" />\n",
|
|
" <line x1=\"23\" y1=\"13\" x2=\"23\" y2=\"120\" />\n",
|
|
" <line x1=\"24\" y1=\"14\" x2=\"24\" y2=\"121\" />\n",
|
|
" <line x1=\"24\" y1=\"14\" x2=\"24\" y2=\"122\" style=\"stroke-width:2\" />\n",
|
|
"\n",
|
|
" <!-- Colored Rectangle -->\n",
|
|
" <polygon points=\"10.0,0.0 24.9485979497544,14.948597949754403 24.9485979497544,122.49050867486044 10.0,107.54191072510604\" style=\"fill:#8B4903A0;stroke-width:0\"/>\n",
|
|
"\n",
|
|
" <!-- Horizontal lines -->\n",
|
|
" <line x1=\"10\" y1=\"0\" x2=\"130\" y2=\"0\" style=\"stroke-width:2\" />\n",
|
|
" <line x1=\"10\" y1=\"0\" x2=\"130\" y2=\"0\" />\n",
|
|
" <line x1=\"11\" y1=\"1\" x2=\"131\" y2=\"1\" />\n",
|
|
" <line x1=\"12\" y1=\"2\" x2=\"132\" y2=\"2\" />\n",
|
|
" <line x1=\"12\" y1=\"2\" x2=\"132\" y2=\"2\" />\n",
|
|
" <line x1=\"13\" y1=\"3\" x2=\"133\" y2=\"3\" />\n",
|
|
" <line x1=\"14\" y1=\"4\" x2=\"134\" y2=\"4\" />\n",
|
|
" <line x1=\"15\" y1=\"5\" x2=\"135\" y2=\"5\" />\n",
|
|
" <line x1=\"15\" y1=\"5\" x2=\"135\" y2=\"5\" />\n",
|
|
" <line x1=\"16\" y1=\"6\" x2=\"136\" y2=\"6\" />\n",
|
|
" <line x1=\"17\" y1=\"7\" x2=\"137\" y2=\"7\" />\n",
|
|
" <line x1=\"18\" y1=\"8\" x2=\"138\" y2=\"8\" />\n",
|
|
" <line x1=\"19\" y1=\"9\" x2=\"139\" y2=\"9\" />\n",
|
|
" <line x1=\"19\" y1=\"9\" x2=\"139\" y2=\"9\" />\n",
|
|
" <line x1=\"20\" y1=\"10\" x2=\"140\" y2=\"10\" />\n",
|
|
" <line x1=\"21\" y1=\"11\" x2=\"141\" y2=\"11\" />\n",
|
|
" <line x1=\"22\" y1=\"12\" x2=\"142\" y2=\"12\" />\n",
|
|
" <line x1=\"23\" y1=\"13\" x2=\"143\" y2=\"13\" />\n",
|
|
" <line x1=\"24\" y1=\"14\" x2=\"144\" y2=\"14\" />\n",
|
|
" <line x1=\"24\" y1=\"14\" x2=\"144\" y2=\"14\" style=\"stroke-width:2\" />\n",
|
|
"\n",
|
|
" <!-- Vertical lines -->\n",
|
|
" <line x1=\"10\" y1=\"0\" x2=\"24\" y2=\"14\" style=\"stroke-width:2\" />\n",
|
|
" <line x1=\"34\" y1=\"0\" x2=\"49\" y2=\"14\" />\n",
|
|
" <line x1=\"59\" y1=\"0\" x2=\"74\" y2=\"14\" />\n",
|
|
" <line x1=\"84\" y1=\"0\" x2=\"99\" y2=\"14\" />\n",
|
|
" <line x1=\"109\" y1=\"0\" x2=\"124\" y2=\"14\" />\n",
|
|
" <line x1=\"130\" y1=\"0\" x2=\"144\" y2=\"14\" style=\"stroke-width:2\" />\n",
|
|
"\n",
|
|
" <!-- Colored Rectangle -->\n",
|
|
" <polygon points=\"10.0,0.0 130.0,0.0 144.9485979497544,14.948597949754403 24.9485979497544,14.948597949754403\" style=\"fill:#8B4903A0;stroke-width:0\"/>\n",
|
|
"\n",
|
|
" <!-- Horizontal lines -->\n",
|
|
" <line x1=\"24\" y1=\"14\" x2=\"144\" y2=\"14\" style=\"stroke-width:2\" />\n",
|
|
" <line x1=\"24\" y1=\"39\" x2=\"144\" y2=\"39\" />\n",
|
|
" <line x1=\"24\" y1=\"64\" x2=\"144\" y2=\"64\" />\n",
|
|
" <line x1=\"24\" y1=\"89\" x2=\"144\" y2=\"89\" />\n",
|
|
" <line x1=\"24\" y1=\"114\" x2=\"144\" y2=\"114\" />\n",
|
|
" <line x1=\"24\" y1=\"122\" x2=\"144\" y2=\"122\" style=\"stroke-width:2\" />\n",
|
|
"\n",
|
|
" <!-- Vertical lines -->\n",
|
|
" <line x1=\"24\" y1=\"14\" x2=\"24\" y2=\"122\" style=\"stroke-width:2\" />\n",
|
|
" <line x1=\"49\" y1=\"14\" x2=\"49\" y2=\"122\" />\n",
|
|
" <line x1=\"74\" y1=\"14\" x2=\"74\" y2=\"122\" />\n",
|
|
" <line x1=\"99\" y1=\"14\" x2=\"99\" y2=\"122\" />\n",
|
|
" <line x1=\"124\" y1=\"14\" x2=\"124\" y2=\"122\" />\n",
|
|
" <line x1=\"144\" y1=\"14\" x2=\"144\" y2=\"122\" style=\"stroke-width:2\" />\n",
|
|
"\n",
|
|
" <!-- Colored Rectangle -->\n",
|
|
" <polygon points=\"24.9485979497544,14.948597949754403 144.9485979497544,14.948597949754403 144.9485979497544,122.49050867486044 24.9485979497544,122.49050867486044\" style=\"fill:#ECB172A0;stroke-width:0\"/>\n",
|
|
"\n",
|
|
" <!-- Text -->\n",
|
|
" <text x=\"84.948598\" y=\"142.490509\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" >9902</text>\n",
|
|
" <text x=\"164.948598\" y=\"68.719553\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" transform=\"rotate(-90,164.948598,68.719553)\">8874</text>\n",
|
|
" <text x=\"7.474299\" y=\"135.016210\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" transform=\"rotate(45,7.474299,135.016210)\">33</text>\n",
|
|
"</svg>\n",
|
|
" </td>\n",
|
|
" </tr>\n",
|
|
"</table></div></li><li class='xr-var-item'><div class='xr-var-name'><span>vh</span></div><div class='xr-var-dims'>(time, y, x)</div><div class='xr-var-dtype'>float32</div><div class='xr-var-preview xr-preview'>dask.array<chunksize=(1, 2048, 2048), meta=np.ndarray></div><input id='attrs-ca46d2fa-b1a4-40da-aa7a-6c8ae9614330' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-ca46d2fa-b1a4-40da-aa7a-6c8ae9614330' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-a4a515be-de8e-4c86-9a54-19f0cc1ce2a5' class='xr-var-data-in' type='checkbox'><label for='data-a4a515be-de8e-4c86-9a54-19f0cc1ce2a5' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>units :</span></dt><dd>intensity</dd><dt><span>nodata :</span></dt><dd>nan</dd><dt><span>crs :</span></dt><dd>EPSG:32648</dd><dt><span>grid_mapping :</span></dt><dd>spatial_ref</dd></dl></div><div class='xr-var-data'><table>\n",
|
|
" <tr>\n",
|
|
" <td>\n",
|
|
" <table style=\"border-collapse: collapse;\">\n",
|
|
" <thead>\n",
|
|
" <tr>\n",
|
|
" <td> </td>\n",
|
|
" <th> Array </th>\n",
|
|
" <th> Chunk </th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" \n",
|
|
" <tr>\n",
|
|
" <th> Bytes </th>\n",
|
|
" <td> 10.80 GiB </td>\n",
|
|
" <td> 16.00 MiB </td>\n",
|
|
" </tr>\n",
|
|
" \n",
|
|
" <tr>\n",
|
|
" <th> Shape </th>\n",
|
|
" <td> (33, 8874, 9902) </td>\n",
|
|
" <td> (1, 2048, 2048) </td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th> Dask graph </th>\n",
|
|
" <td colspan=\"2\"> 825 chunks in 1 graph layer </td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th> Data type </th>\n",
|
|
" <td colspan=\"2\"> float32 numpy.ndarray </td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
" </table>\n",
|
|
" </td>\n",
|
|
" <td>\n",
|
|
" <svg width=\"194\" height=\"172\" style=\"stroke:rgb(0,0,0);stroke-width:1\" >\n",
|
|
"\n",
|
|
" <!-- Horizontal lines -->\n",
|
|
" <line x1=\"10\" y1=\"0\" x2=\"24\" y2=\"14\" style=\"stroke-width:2\" />\n",
|
|
" <line x1=\"10\" y1=\"24\" x2=\"24\" y2=\"39\" />\n",
|
|
" <line x1=\"10\" y1=\"49\" x2=\"24\" y2=\"64\" />\n",
|
|
" <line x1=\"10\" y1=\"74\" x2=\"24\" y2=\"89\" />\n",
|
|
" <line x1=\"10\" y1=\"99\" x2=\"24\" y2=\"114\" />\n",
|
|
" <line x1=\"10\" y1=\"107\" x2=\"24\" y2=\"122\" style=\"stroke-width:2\" />\n",
|
|
"\n",
|
|
" <!-- Vertical lines -->\n",
|
|
" <line x1=\"10\" y1=\"0\" x2=\"10\" y2=\"107\" style=\"stroke-width:2\" />\n",
|
|
" <line x1=\"10\" y1=\"0\" x2=\"10\" y2=\"107\" />\n",
|
|
" <line x1=\"11\" y1=\"1\" x2=\"11\" y2=\"108\" />\n",
|
|
" <line x1=\"12\" y1=\"2\" x2=\"12\" y2=\"109\" />\n",
|
|
" <line x1=\"12\" y1=\"2\" x2=\"12\" y2=\"110\" />\n",
|
|
" <line x1=\"13\" y1=\"3\" x2=\"13\" y2=\"111\" />\n",
|
|
" <line x1=\"14\" y1=\"4\" x2=\"14\" y2=\"112\" />\n",
|
|
" <line x1=\"15\" y1=\"5\" x2=\"15\" y2=\"112\" />\n",
|
|
" <line x1=\"15\" y1=\"5\" x2=\"15\" y2=\"113\" />\n",
|
|
" <line x1=\"16\" y1=\"6\" x2=\"16\" y2=\"114\" />\n",
|
|
" <line x1=\"17\" y1=\"7\" x2=\"17\" y2=\"115\" />\n",
|
|
" <line x1=\"18\" y1=\"8\" x2=\"18\" y2=\"116\" />\n",
|
|
" <line x1=\"19\" y1=\"9\" x2=\"19\" y2=\"116\" />\n",
|
|
" <line x1=\"19\" y1=\"9\" x2=\"19\" y2=\"117\" />\n",
|
|
" <line x1=\"20\" y1=\"10\" x2=\"20\" y2=\"118\" />\n",
|
|
" <line x1=\"21\" y1=\"11\" x2=\"21\" y2=\"119\" />\n",
|
|
" <line x1=\"22\" y1=\"12\" x2=\"22\" y2=\"119\" />\n",
|
|
" <line x1=\"23\" y1=\"13\" x2=\"23\" y2=\"120\" />\n",
|
|
" <line x1=\"24\" y1=\"14\" x2=\"24\" y2=\"121\" />\n",
|
|
" <line x1=\"24\" y1=\"14\" x2=\"24\" y2=\"122\" style=\"stroke-width:2\" />\n",
|
|
"\n",
|
|
" <!-- Colored Rectangle -->\n",
|
|
" <polygon points=\"10.0,0.0 24.9485979497544,14.948597949754403 24.9485979497544,122.49050867486044 10.0,107.54191072510604\" style=\"fill:#8B4903A0;stroke-width:0\"/>\n",
|
|
"\n",
|
|
" <!-- Horizontal lines -->\n",
|
|
" <line x1=\"10\" y1=\"0\" x2=\"130\" y2=\"0\" style=\"stroke-width:2\" />\n",
|
|
" <line x1=\"10\" y1=\"0\" x2=\"130\" y2=\"0\" />\n",
|
|
" <line x1=\"11\" y1=\"1\" x2=\"131\" y2=\"1\" />\n",
|
|
" <line x1=\"12\" y1=\"2\" x2=\"132\" y2=\"2\" />\n",
|
|
" <line x1=\"12\" y1=\"2\" x2=\"132\" y2=\"2\" />\n",
|
|
" <line x1=\"13\" y1=\"3\" x2=\"133\" y2=\"3\" />\n",
|
|
" <line x1=\"14\" y1=\"4\" x2=\"134\" y2=\"4\" />\n",
|
|
" <line x1=\"15\" y1=\"5\" x2=\"135\" y2=\"5\" />\n",
|
|
" <line x1=\"15\" y1=\"5\" x2=\"135\" y2=\"5\" />\n",
|
|
" <line x1=\"16\" y1=\"6\" x2=\"136\" y2=\"6\" />\n",
|
|
" <line x1=\"17\" y1=\"7\" x2=\"137\" y2=\"7\" />\n",
|
|
" <line x1=\"18\" y1=\"8\" x2=\"138\" y2=\"8\" />\n",
|
|
" <line x1=\"19\" y1=\"9\" x2=\"139\" y2=\"9\" />\n",
|
|
" <line x1=\"19\" y1=\"9\" x2=\"139\" y2=\"9\" />\n",
|
|
" <line x1=\"20\" y1=\"10\" x2=\"140\" y2=\"10\" />\n",
|
|
" <line x1=\"21\" y1=\"11\" x2=\"141\" y2=\"11\" />\n",
|
|
" <line x1=\"22\" y1=\"12\" x2=\"142\" y2=\"12\" />\n",
|
|
" <line x1=\"23\" y1=\"13\" x2=\"143\" y2=\"13\" />\n",
|
|
" <line x1=\"24\" y1=\"14\" x2=\"144\" y2=\"14\" />\n",
|
|
" <line x1=\"24\" y1=\"14\" x2=\"144\" y2=\"14\" style=\"stroke-width:2\" />\n",
|
|
"\n",
|
|
" <!-- Vertical lines -->\n",
|
|
" <line x1=\"10\" y1=\"0\" x2=\"24\" y2=\"14\" style=\"stroke-width:2\" />\n",
|
|
" <line x1=\"34\" y1=\"0\" x2=\"49\" y2=\"14\" />\n",
|
|
" <line x1=\"59\" y1=\"0\" x2=\"74\" y2=\"14\" />\n",
|
|
" <line x1=\"84\" y1=\"0\" x2=\"99\" y2=\"14\" />\n",
|
|
" <line x1=\"109\" y1=\"0\" x2=\"124\" y2=\"14\" />\n",
|
|
" <line x1=\"130\" y1=\"0\" x2=\"144\" y2=\"14\" style=\"stroke-width:2\" />\n",
|
|
"\n",
|
|
" <!-- Colored Rectangle -->\n",
|
|
" <polygon points=\"10.0,0.0 130.0,0.0 144.9485979497544,14.948597949754403 24.9485979497544,14.948597949754403\" style=\"fill:#8B4903A0;stroke-width:0\"/>\n",
|
|
"\n",
|
|
" <!-- Horizontal lines -->\n",
|
|
" <line x1=\"24\" y1=\"14\" x2=\"144\" y2=\"14\" style=\"stroke-width:2\" />\n",
|
|
" <line x1=\"24\" y1=\"39\" x2=\"144\" y2=\"39\" />\n",
|
|
" <line x1=\"24\" y1=\"64\" x2=\"144\" y2=\"64\" />\n",
|
|
" <line x1=\"24\" y1=\"89\" x2=\"144\" y2=\"89\" />\n",
|
|
" <line x1=\"24\" y1=\"114\" x2=\"144\" y2=\"114\" />\n",
|
|
" <line x1=\"24\" y1=\"122\" x2=\"144\" y2=\"122\" style=\"stroke-width:2\" />\n",
|
|
"\n",
|
|
" <!-- Vertical lines -->\n",
|
|
" <line x1=\"24\" y1=\"14\" x2=\"24\" y2=\"122\" style=\"stroke-width:2\" />\n",
|
|
" <line x1=\"49\" y1=\"14\" x2=\"49\" y2=\"122\" />\n",
|
|
" <line x1=\"74\" y1=\"14\" x2=\"74\" y2=\"122\" />\n",
|
|
" <line x1=\"99\" y1=\"14\" x2=\"99\" y2=\"122\" />\n",
|
|
" <line x1=\"124\" y1=\"14\" x2=\"124\" y2=\"122\" />\n",
|
|
" <line x1=\"144\" y1=\"14\" x2=\"144\" y2=\"122\" style=\"stroke-width:2\" />\n",
|
|
"\n",
|
|
" <!-- Colored Rectangle -->\n",
|
|
" <polygon points=\"24.9485979497544,14.948597949754403 144.9485979497544,14.948597949754403 144.9485979497544,122.49050867486044 24.9485979497544,122.49050867486044\" style=\"fill:#ECB172A0;stroke-width:0\"/>\n",
|
|
"\n",
|
|
" <!-- Text -->\n",
|
|
" <text x=\"84.948598\" y=\"142.490509\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" >9902</text>\n",
|
|
" <text x=\"164.948598\" y=\"68.719553\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" transform=\"rotate(-90,164.948598,68.719553)\">8874</text>\n",
|
|
" <text x=\"7.474299\" y=\"135.016210\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" transform=\"rotate(45,7.474299,135.016210)\">33</text>\n",
|
|
"</svg>\n",
|
|
" </td>\n",
|
|
" </tr>\n",
|
|
"</table></div></li></ul></div></li><li class='xr-section-item'><input id='section-1b8412bb-3703-4bb8-bd2a-eba4770c03dd' class='xr-section-summary-in' type='checkbox' ><label for='section-1b8412bb-3703-4bb8-bd2a-eba4770c03dd' class='xr-section-summary' >Indexes: <span>(3)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-index-name'><div>time</div></div><div class='xr-index-preview'>PandasIndex</div><div></div><input id='index-d6b76182-2d0f-4721-91ca-5834ae6c63c2' class='xr-index-data-in' type='checkbox'/><label for='index-d6b76182-2d0f-4721-91ca-5834ae6c63c2' title='Show/Hide index repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-index-data'><pre>PandasIndex(DatetimeIndex(['2022-09-06 22:46:14.500000', '2022-09-18 22:46:13.500000',\n",
|
|
" '2022-09-30 22:46:14.500000', '2022-10-12 22:46:14.500000',\n",
|
|
" '2022-10-24 22:46:14.500000', '2022-11-05 22:46:14.500000',\n",
|
|
" '2022-11-17 22:46:13.500000', '2022-11-29 22:46:13.500000',\n",
|
|
" '2022-12-11 22:46:13.500000', '2022-12-23 22:46:12.500000',\n",
|
|
" '2023-01-04 22:46:11.500000', '2023-01-16 22:46:10.500000',\n",
|
|
" '2023-01-28 22:46:11.500000', '2023-02-09 22:46:10.500000',\n",
|
|
" '2023-02-21 22:46:09.500000', '2023-03-05 22:46:10.500000',\n",
|
|
" '2023-03-17 22:46:10.500000', '2023-03-29 22:46:10.500000',\n",
|
|
" '2023-04-10 22:46:11.500000', '2023-04-22 22:46:11.500000',\n",
|
|
" '2023-05-04 22:46:11.500000', '2023-05-17 11:11:32.500000',\n",
|
|
" '2023-05-29 11:11:32.500000', '2023-06-10 11:11:28.500000',\n",
|
|
" '2023-06-21 22:46:13.500000', '2023-07-04 11:11:34.500000',\n",
|
|
" '2023-07-16 11:11:35.500000', '2023-07-28 11:11:36.500000',\n",
|
|
" '2023-08-08 22:46:16.500000', '2023-08-20 22:46:17.500000',\n",
|
|
" '2023-09-01 22:46:18.500000', '2023-09-13 22:46:18.500000',\n",
|
|
" '2023-09-25 22:46:19.500000'],\n",
|
|
" dtype='datetime64[ns]', name='time', freq=None))</pre></div></li><li class='xr-var-item'><div class='xr-index-name'><div>y</div></div><div class='xr-index-preview'>PandasIndex</div><div></div><input id='index-ba517615-93c0-4193-84fd-b0d6bddc9d6d' class='xr-index-data-in' type='checkbox'/><label for='index-ba517615-93c0-4193-84fd-b0d6bddc9d6d' title='Show/Hide index repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-index-data'><pre>PandasIndex(Index([1105735.0, 1105725.0, 1105715.0, 1105705.0, 1105695.0, 1105685.0,\n",
|
|
" 1105675.0, 1105665.0, 1105655.0, 1105645.0,\n",
|
|
" ...\n",
|
|
" 1017095.0, 1017085.0, 1017075.0, 1017065.0, 1017055.0, 1017045.0,\n",
|
|
" 1017035.0, 1017025.0, 1017015.0, 1017005.0],\n",
|
|
" dtype='float64', name='y', length=8874))</pre></div></li><li class='xr-var-item'><div class='xr-index-name'><div>x</div></div><div class='xr-index-preview'>PandasIndex</div><div></div><input id='index-baa8ef93-0dff-4ccb-a0b9-41c3b1343fcf' class='xr-index-data-in' type='checkbox'/><label for='index-baa8ef93-0dff-4ccb-a0b9-41c3b1343fcf' title='Show/Hide index repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-index-data'><pre>PandasIndex(Index([554795.0, 554805.0, 554815.0, 554825.0, 554835.0, 554845.0, 554855.0,\n",
|
|
" 554865.0, 554875.0, 554885.0,\n",
|
|
" ...\n",
|
|
" 653715.0, 653725.0, 653735.0, 653745.0, 653755.0, 653765.0, 653775.0,\n",
|
|
" 653785.0, 653795.0, 653805.0],\n",
|
|
" dtype='float64', name='x', length=9902))</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-5f2dfaed-ef51-44aa-9556-739ddaf18a65' class='xr-section-summary-in' type='checkbox' checked><label for='section-5f2dfaed-ef51-44aa-9556-739ddaf18a65' class='xr-section-summary' >Attributes: <span>(2)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'><dt><span>crs :</span></dt><dd>EPSG:32648</dd><dt><span>grid_mapping :</span></dt><dd>spatial_ref</dd></dl></div></li></ul></div></div>"
|
|
],
|
|
"text/plain": [
|
|
"<xarray.Dataset> Size: 23GB\n",
|
|
"Dimensions: (time: 33, y: 8874, x: 9902)\n",
|
|
"Coordinates:\n",
|
|
" * time (time) datetime64[ns] 264B 2022-09-06T22:46:14.500000 ... 20...\n",
|
|
" * y (y) float64 71kB 1.106e+06 1.106e+06 ... 1.017e+06 1.017e+06\n",
|
|
" * x (x) float64 79kB 5.548e+05 5.548e+05 ... 6.538e+05 6.538e+05\n",
|
|
" spatial_ref int32 4B 32648\n",
|
|
"Data variables:\n",
|
|
" vv (time, y, x) float32 12GB dask.array<chunksize=(1, 2048, 2048), meta=np.ndarray>\n",
|
|
" vh (time, y, x) float32 12GB dask.array<chunksize=(1, 2048, 2048), meta=np.ndarray>\n",
|
|
"Attributes:\n",
|
|
" crs: EPSG:32648\n",
|
|
" grid_mapping: spatial_ref"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"\n",
|
|
"✅ Sentinel-1 data loaded from ODC!\n"
|
|
]
|
|
},
|
|
{
|
|
"ename": "ValueError",
|
|
"evalue": "dictionary update sequence element #0 has length 4; 2 is required",
|
|
"output_type": "error",
|
|
"traceback": [
|
|
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
|
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
|
|
"File \u001b[0;32m<timed exec>:12\u001b[0m\n",
|
|
"\u001b[0;31mValueError\u001b[0m: dictionary update sequence element #0 has length 4; 2 is required"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"%%time\n",
|
|
"\n",
|
|
"print(\"📥 Loading Sentinel-1 data from ODC Database...\")\n",
|
|
"print(\"-\" * 70)\n",
|
|
"\n",
|
|
"# Initialize to None\n",
|
|
"dsvh_monthly = None\n",
|
|
"dsvv_monthly = None\n",
|
|
"\n",
|
|
"try:\n",
|
|
" # Load Sentinel-1 từ ODC\n",
|
|
" # Note: load_data_sen1 returns (dsvh, dsvv) - 2 separate DataArrays\n",
|
|
" coordinates = (longitude_range, latitude_range)\n",
|
|
" \n",
|
|
" dsvh, dsvv = load_data_sen1(dc, date_range, coordinates)\n",
|
|
" \n",
|
|
" if dsvh is not None and dsvv is not None and len(dsvh.time) > 0:\n",
|
|
" print(f\"\\n✅ Sentinel-1 data loaded from ODC!\")\n",
|
|
" print(f\" VH dimensions: {dict(dsvh.dims)}\")\n",
|
|
" print(f\" VV dimensions: {dict(dsvv.dims)}\")\n",
|
|
" print(f\" Time steps: {len(dsvh.time)}\")\n",
|
|
" \n",
|
|
" # Resample to monthly\n",
|
|
" print(\"\\n📅 Resampling to monthly averages...\")\n",
|
|
" dsvh_monthly = calculate_average(dsvh, time_pattern='1M')\n",
|
|
" dsvv_monthly = calculate_average(dsvv, time_pattern='1M')\n",
|
|
" \n",
|
|
" # Compute to load into memory\n",
|
|
" dsvh_monthly = dsvh_monthly.compute()\n",
|
|
" dsvv_monthly = dsvv_monthly.compute()\n",
|
|
" print(f\"\\n✅ Sentinel-1 monthly data ready!\")\n",
|
|
" print(f\" ✓ Monthly resampled\")\n",
|
|
" print(f\" ✓ Loaded into memory\")\n",
|
|
" else:\n",
|
|
" print(\"⚠️ Sentinel-1 data returned but empty\")\n",
|
|
" dsvh_monthly = None\n",
|
|
" dsvv_monthly = None\n",
|
|
" \n",
|
|
"except Exception as e:\n",
|
|
" print(f\"❌ Failed to load Sentinel-1 data: {e}\")\n",
|
|
" dsvh_monthly = None\n",
|
|
" dsvv_monthly = None\n",
|
|
"\n",
|
|
"if dsvh_monthly is None or dsvv_monthly is None:\n",
|
|
" print(\"\\n⚠️ Sentinel-1 NOT available - will train with Sentinel-2 (NDVI) only\")\n",
|
|
" print(\" This may reduce model accuracy but allows training to proceed.\")\n",
|
|
"else:\n",
|
|
" print(\"\\n✅ Sentinel-1 available - will use both S1 and S2 data\")\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "40a2ffe6",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 🎯 Step 5: Load Training Data\n",
|
|
"\n",
|
|
"Load dữ liệu mẫu huấn luyện (training samples)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 6,
|
|
"id": "9be070b8",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"🎯 Label mapping:\n",
|
|
" 0: Lua tom\n",
|
|
" 1: Lua\n",
|
|
" 2: CHN\n",
|
|
" 3: CLN\n",
|
|
" 4: TS\n",
|
|
" 5: Song\n",
|
|
" 6: Dat xay dung\n",
|
|
" 7: Rung\n",
|
|
"\n",
|
|
"📂 Loading training data from: /home/jovyan/remote-sensing/train/ST_training_data_updated_1130points_new.shp\n",
|
|
"\n",
|
|
"✅ Training data loaded successfully!\n",
|
|
" Total points: 1130\n",
|
|
" CRS: EPSG:32648\n",
|
|
" Columns: ['No', 'X', 'Y', 'LU2022', 'Hientrang', 'HT_code', 'geometry']\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"# Ánh xạ nhãn lớp đất\n",
|
|
"label_mapping = {\n",
|
|
" \"Lua tom\": 0,\n",
|
|
" \"Lua\": 1,\n",
|
|
" \"CHN\": 2,\n",
|
|
" \"CLN\": 3,\n",
|
|
" \"TS\": 4,\n",
|
|
" \"Song\": 5,\n",
|
|
" \"Dat xay dung\": 6,\n",
|
|
" \"Rung\": 7,\n",
|
|
"}\n",
|
|
"\n",
|
|
"print(\"🎯 Label mapping:\")\n",
|
|
"for label, idx in label_mapping.items():\n",
|
|
" print(f\" {idx}: {label}\")\n",
|
|
"\n",
|
|
"# Load training data with absolute path\n",
|
|
"train_path = \"/home/jovyan/remote-sensing/train/ST_training_data_updated_1130points_new.shp\"\n",
|
|
"\n",
|
|
"print(f\"\\n📂 Loading training data from: {train_path}\")\n",
|
|
"train_data = load_train_data(train_path)\n",
|
|
"\n",
|
|
"if train_data is not None:\n",
|
|
" print(f\"\\n✅ Training data loaded successfully!\")\n",
|
|
" print(f\" Total points: {len(train_data)}\")\n",
|
|
" print(f\" CRS: {train_data.crs}\")\n",
|
|
" print(f\" Columns: {list(train_data.columns)}\")\n",
|
|
"else:\n",
|
|
" print(\"❌ Failed to load training data\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "b371c97f",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 🔧 Step 6: Extract Features\n",
|
|
"\n",
|
|
"Trích xuất features từ Sentinel-1 và Sentinel-2 tại các điểm mẫu"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "7d6c117d",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"🔧 Extracting features from satellite data...\n",
|
|
"----------------------------------------------------------------------\n",
|
|
"❌ Missing data: Please check training data or satellite data\n",
|
|
" train_data: ✓\n",
|
|
" data_sen2_monthly: ✓\n",
|
|
" dsvh_monthly: ✗\n",
|
|
" dsvv_monthly: ✗\n",
|
|
"CPU times: user 148 μs, sys: 43 μs, total: 191 μs\n",
|
|
"Wall time: 160 μs\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"%%time\n",
|
|
"\n",
|
|
"print(\"🔧 Extracting features from satellite data...\")\n",
|
|
"print(\"-\" * 70)\n",
|
|
"\n",
|
|
"if train_data is not None and 'data_sen2_monthly' in locals():\n",
|
|
" \n",
|
|
" # Check if we have Sentinel-1 data\n",
|
|
" has_sentinel1 = ('dsvh_monthly' in locals() and \n",
|
|
" 'dsvv_monthly' in locals() and \n",
|
|
" dsvh_monthly is not None and \n",
|
|
" dsvv_monthly is not None)\n",
|
|
" \n",
|
|
" if has_sentinel1:\n",
|
|
" print(\"📡 Using Sentinel-1 + Sentinel-2 data\")\n",
|
|
" # Extract features using ODC function with S1 and S2\n",
|
|
" datasets = get_data_sen1_and_sen2(\n",
|
|
" train_data, \n",
|
|
" data_sen2_monthly, # NDVI monthly average\n",
|
|
" dsvh_monthly, # VH monthly average\n",
|
|
" dsvv_monthly # VV monthly average\n",
|
|
" )\n",
|
|
" else:\n",
|
|
" print(\"📡 Using Sentinel-2 (NDVI) only - Sentinel-1 not available\")\n",
|
|
" # Extract features from S2 only\n",
|
|
" datasets = {}\n",
|
|
" for idx, point in train_data.iterrows():\n",
|
|
" try:\n",
|
|
" # Extract NDVI time series at point\n",
|
|
" ndvi_data = data_sen2_monthly.sel(\n",
|
|
" x=point.geometry.x, \n",
|
|
" y=point.geometry.y, \n",
|
|
" method='nearest'\n",
|
|
" ).values\n",
|
|
" \n",
|
|
" # Flatten to 1D array\n",
|
|
" ndvi_flat = ndvi_data.flatten()\n",
|
|
" \n",
|
|
" # Store if valid\n",
|
|
" if not np.all(np.isnan(ndvi_flat)):\n",
|
|
" datasets[idx] = {\n",
|
|
" 'data': ndvi_flat,\n",
|
|
" 'label': point['id_4']\n",
|
|
" }\n",
|
|
" except Exception as e:\n",
|
|
" print(f\" Warning: Failed to extract features for point {idx}: {e}\")\n",
|
|
" continue\n",
|
|
" \n",
|
|
" print(f\"\\n✅ Feature extraction complete!\")\n",
|
|
" print(f\" Total datasets: {len(datasets)}\")\n",
|
|
" \n",
|
|
" # Display statistics\n",
|
|
" valid_datasets = [v for v in datasets.values() if v is not None]\n",
|
|
" if valid_datasets:\n",
|
|
" sample_data = valid_datasets[0]['data']\n",
|
|
" print(f\" Feature dimension: {len(sample_data)}\")\n",
|
|
" print(f\" Valid samples: {len(valid_datasets)}\")\n",
|
|
" print(f\" Data source: {'S1+S2' if has_sentinel1 else 'S2 only (NDVI)'}\")\n",
|
|
" \n",
|
|
" # Count labels\n",
|
|
" labels = [d['label'] for d in valid_datasets]\n",
|
|
" label_counts = pd.Series(labels).value_counts().sort_index()\n",
|
|
" print(f\"\\n Label distribution:\")\n",
|
|
" for label_id, count in label_counts.items():\n",
|
|
" print(f\" {label_id}: {count} samples ({count/len(labels)*100:.1f}%)\")\n",
|
|
" \n",
|
|
"else:\n",
|
|
" print(\"❌ Missing data: Please check training data or satellite data\")\n",
|
|
" print(f\" train_data: {'✓' if train_data is not None else '✗'}\")\n",
|
|
" print(f\" data_sen2_monthly: {'✓' if 'data_sen2_monthly' in locals() else '✗'}\")\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "b485ba1b",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 📊 Step 7: Split Data\n",
|
|
"\n",
|
|
"Chia dữ liệu thành train/val/test sets"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 8,
|
|
"id": "29726670",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"❌ Features not extracted yet. Please run Step 6 first.\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"if 'datasets' in locals():\n",
|
|
" # Split data using ODC function\n",
|
|
" X_train, X_val, X_test, y_train, y_val, y_test = split_train_data(\n",
|
|
" train_data, \n",
|
|
" label_mapping, \n",
|
|
" datasets\n",
|
|
" )\n",
|
|
" \n",
|
|
" # Combine train + val for final model training\n",
|
|
" X_fit = X_train + X_val\n",
|
|
" y_fit = y_train + y_val\n",
|
|
" \n",
|
|
" print(f\"\\n✅ Data split complete:\")\n",
|
|
" print(f\" Training samples: {len(X_train)}\")\n",
|
|
" print(f\" Validation samples: {len(X_val)}\")\n",
|
|
" print(f\" Test samples: {len(X_test)}\")\n",
|
|
" print(f\"\\n Combined train+val: {len(X_fit)} samples\")\n",
|
|
" \n",
|
|
"else:\n",
|
|
" print(\"❌ Features not extracted yet. Please run Step 6 first.\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "3966ba86",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 🌲 Step 8: Train Decision Tree Model\n",
|
|
"\n",
|
|
"Huấn luyện mô hình Decision Tree"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 9,
|
|
"id": "2fc1c3da",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"❌ Data not ready. Please run Step 7 first.\n",
|
|
"CPU times: user 57 μs, sys: 0 ns, total: 57 μs\n",
|
|
"Wall time: 66.5 μs\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"%%time\n",
|
|
"\n",
|
|
"if 'X_fit' in locals() and 'y_fit' in locals():\n",
|
|
" \n",
|
|
" print(\"🚀 Training Decision Tree model...\")\n",
|
|
" print(\"-\" * 70)\n",
|
|
" \n",
|
|
" # Train Decision Tree with tuned hyperparameters\n",
|
|
" model = DecisionTreeClassifier(\n",
|
|
" max_depth=30,\n",
|
|
" min_samples_leaf=2,\n",
|
|
" min_samples_split=5,\n",
|
|
" class_weight=\"balanced\",\n",
|
|
" random_state=42,\n",
|
|
" )\n",
|
|
" \n",
|
|
" model.fit(X_fit, y_fit)\n",
|
|
" \n",
|
|
" # Evaluate on validation set\n",
|
|
" val_acc = model.score(X_val, y_val)\n",
|
|
" \n",
|
|
" print(f\"\\n✅ Training complete!\")\n",
|
|
" print(f\" Model: Decision Tree\")\n",
|
|
" print(f\" Tree depth: {model.get_depth()}\")\n",
|
|
" print(f\" Number of leaves: {model.get_n_leaves()}\")\n",
|
|
" print(f\" Training samples: {len(X_fit)}\")\n",
|
|
" print(f\" Validation accuracy: {val_acc:.4f} ({val_acc*100:.2f}%)\")\n",
|
|
" \n",
|
|
"else:\n",
|
|
" print(\"❌ Data not ready. Please run Step 7 first.\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "b244cc21",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 📊 Step 9: Evaluate Model\n",
|
|
"\n",
|
|
"Đánh giá mô hình trên tập test"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 10,
|
|
"id": "4c50781e",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"❌ Model not trained yet. Please run Step 8 first.\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"if 'model' in locals() and 'X_test' in locals():\n",
|
|
" \n",
|
|
" print(\"📊 Evaluating model on test set...\")\n",
|
|
" print(\"-\" * 70)\n",
|
|
" \n",
|
|
" # Make predictions\n",
|
|
" y_pred = model.predict(X_test)\n",
|
|
" acc = accuracy_score(y_test, y_pred)\n",
|
|
" \n",
|
|
" print(f\"\\n🎯 Test Accuracy: {acc:.4f} ({acc*100:.2f}%)\\n\")\n",
|
|
" print(\"📋 Classification Report:\")\n",
|
|
" print(classification_report(y_test, y_pred, digits=4))\n",
|
|
" \n",
|
|
" # Confusion Matrix\n",
|
|
" class_names = list(label_mapping.keys())\n",
|
|
" cm = confusion_matrix(y_test, y_pred)\n",
|
|
" \n",
|
|
" plt.figure(figsize=(10, 8))\n",
|
|
" sns.heatmap(cm, annot=True, fmt='d', cmap='Blues',\n",
|
|
" xticklabels=class_names, yticklabels=class_names,\n",
|
|
" cbar_kws={'label': 'Count'})\n",
|
|
" plt.xlabel('Predicted Label', fontsize=12)\n",
|
|
" plt.ylabel('True Label', fontsize=12)\n",
|
|
" plt.title('Confusion Matrix — Decision Tree (Test Set)', fontsize=14, fontweight='bold')\n",
|
|
" plt.tight_layout()\n",
|
|
" plt.show()\n",
|
|
" \n",
|
|
"else:\n",
|
|
" print(\"❌ Model not trained yet. Please run Step 8 first.\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "3db1ed05",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 💾 Step 10: Save Model\n",
|
|
"\n",
|
|
"Lưu mô hình để dùng cho prediction trên Planetary Computer"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 11,
|
|
"id": "11e9ac2d",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"❌ Model not trained yet or evaluation not complete.\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"if 'model' in locals() and 'acc' in locals():\n",
|
|
" \n",
|
|
" print(\"💾 Saving model and metadata...\")\n",
|
|
" print(\"-\" * 70)\n",
|
|
" \n",
|
|
" # Save model\n",
|
|
" model_path = \"model_decision_tree_odc.joblib\"\n",
|
|
" joblib.dump(model, model_path)\n",
|
|
" print(f\"✅ Model saved → {model_path}\")\n",
|
|
" \n",
|
|
" # Create metadata\n",
|
|
" info = {\n",
|
|
" \"model_type\": \"DecisionTree\",\n",
|
|
" \"data_source\": \"ODC Database\",\n",
|
|
" \"training_data\": train_path,\n",
|
|
" \"max_depth\": int(model.get_depth()),\n",
|
|
" \"n_leaves\": int(model.get_n_leaves()),\n",
|
|
" \"n_features\": len(X_fit[0]) if X_fit else 0,\n",
|
|
" \"label_mapping\": label_mapping,\n",
|
|
" \"test_accuracy\": float(acc),\n",
|
|
" \"train_samples\": int(len(X_fit)),\n",
|
|
" \"val_samples\": int(len(X_val)),\n",
|
|
" \"test_samples\": int(len(X_test)),\n",
|
|
" \"longitude_range\": list(longitude_range),\n",
|
|
" \"latitude_range\": list(latitude_range),\n",
|
|
" \"date_range\": list(date_range),\n",
|
|
" \"saved_at\": datetime.now().isoformat(),\n",
|
|
" \"hyperparameters\": {\n",
|
|
" \"max_depth\": 30,\n",
|
|
" \"min_samples_leaf\": 2,\n",
|
|
" \"min_samples_split\": 5,\n",
|
|
" \"class_weight\": \"balanced\",\n",
|
|
" \"random_state\": 42\n",
|
|
" },\n",
|
|
" \"note\": \"Model trained on ODC data, can be used for prediction on Planetary Computer\"\n",
|
|
" }\n",
|
|
" \n",
|
|
" # Save metadata\n",
|
|
" info_path = \"model_decision_tree_odc_info.json\"\n",
|
|
" with open(info_path, \"w\") as f:\n",
|
|
" json.dump(info, f, indent=2, ensure_ascii=False)\n",
|
|
" \n",
|
|
" print(f\"✅ Metadata saved → {info_path}\")\n",
|
|
" print(\"\\n📋 Model Info:\")\n",
|
|
" print(json.dumps(info, indent=2, ensure_ascii=False))\n",
|
|
" print(\"\\n💡 Model này có thể dùng cho prediction trên Planetary Computer!\")\n",
|
|
" \n",
|
|
"else:\n",
|
|
" print(\"❌ Model not trained yet or evaluation not complete.\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "8280de27",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 🧹 Step 11: Cleanup\n",
|
|
"\n",
|
|
"Đóng Dask cluster"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 12,
|
|
"id": "3ffe4f8a",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"✅ Dask Gateway cluster closed.\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"# Close Dask Gateway cluster\n",
|
|
"try:\n",
|
|
" client.close()\n",
|
|
" cluster.close()\n",
|
|
" print(\"✅ Dask Gateway cluster closed.\")\n",
|
|
"except Exception as e:\n",
|
|
" print(f\"⚠ Error closing cluster: {e}\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "382428e1",
|
|
"metadata": {},
|
|
"source": [
|
|
"---\n",
|
|
"\n",
|
|
"## ✅ Summary\n",
|
|
"\n",
|
|
"### Notebook này:\n",
|
|
"- ✅ Chạy trên **Server ODC/JupyterHub** với **Dask Gateway**\n",
|
|
"- ✅ Load dữ liệu từ **ODC Database** (rất nhanh trên server)\n",
|
|
"- ✅ Train model với dữ liệu từ ODC\n",
|
|
"- ✅ Save model để dùng cho prediction\n",
|
|
"\n",
|
|
"### Ưu điểm của approach này:\n",
|
|
"1. **Speed**: ODC Database truy cập cực nhanh trên server\n",
|
|
"2. **Scalability**: Dask Gateway adaptive scaling (1-10 workers)\n",
|
|
"3. **Compatibility**: Model có thể dùng trên Planetary Computer\n",
|
|
"\n",
|
|
"### Workflow hoàn chỉnh:\n",
|
|
"```\n",
|
|
"┌─────────────────────────────────────┐\n",
|
|
"│ TRAINING (ODC Server) │\n",
|
|
"│ ✅ Load từ ODC Database (FAST) │\n",
|
|
"│ ✅ Dask Gateway (1-10 workers) │\n",
|
|
"│ ✅ Train Decision Tree │\n",
|
|
"│ → Model: .joblib │\n",
|
|
"└─────────────────────────────────────┘\n",
|
|
" ↓\n",
|
|
"┌─────────────────────────────────────┐\n",
|
|
"│ PREDICTION (Local Machine) │\n",
|
|
"│ ✅ Load từ Planetary Computer │\n",
|
|
"│ ✅ Use trained model │\n",
|
|
"│ ✅ No VPN/ODC access needed │\n",
|
|
"│ → GeoTIFF output │\n",
|
|
"└─────────────────────────────────────┘\n",
|
|
"```\n",
|
|
"\n",
|
|
"### Prediction API:\n",
|
|
"- Máy local không cần truy cập ODC\n",
|
|
"- Load data từ Planetary Computer (public)\n",
|
|
"- Sử dụng model đã train từ ODC\n",
|
|
"- Kết quả prediction giống nhau!\n",
|
|
"\n",
|
|
"---"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3 (ipykernel)",
|
|
"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.12.3"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|