From 027a8d67f1395aff7ef5d872d9ed535ed57e596c Mon Sep 17 00:00:00 2001 From: Hamish Graham <hgraham@hpc-201-11-01-a.cr.cnaf.infn.it> Date: Mon, 30 Aug 2021 14:15:52 +0200 Subject: [PATCH] updated pandas_with_bokeh --- examples/hamish_example/pandas_bokeh.py | 55 + examples/hamish_example/pandas_skeleton.py | 104 ++ .../hamish_example/pandas_with_bokeh.ipynb | 1262 +++++++++++++++++ 3 files changed, 1421 insertions(+) create mode 100644 examples/hamish_example/pandas_bokeh.py create mode 100644 examples/hamish_example/pandas_skeleton.py create mode 100644 examples/hamish_example/pandas_with_bokeh.ipynb diff --git a/examples/hamish_example/pandas_bokeh.py b/examples/hamish_example/pandas_bokeh.py new file mode 100644 index 0000000..89d802a --- /dev/null +++ b/examples/hamish_example/pandas_bokeh.py @@ -0,0 +1,55 @@ +import pandas_skeleton as ps +import tree_maker as tm +from pandas import DataFrame + +from bokeh.layouts import column +from bokeh.models import ColumnDataSource, Slider, WheelZoomTool, BoxZoomTool, Button +from bokeh.plotting import figure +from bokeh.themes import Theme +from bokeh.io import show, output_notebook + +output_notebook() + +#root = tm.tree_from_json(filename='/home/HPC/sterbini/DA_study_example/study_000/tree.json') + +def bkapp(doc): + global my_df + global source + + try: + ps.create_tree(root) + except: + raise Exception('Sorry, I need a root of a tree!') + + x_values, y_values, path = ps.create_xypath(root) + my_colors = ps.create_color(root) + angles = ps.create_tree_cartesian(root) + + my_df = ps.create_df(root, path, x_values, y_values, my_colors) + + del my_df['handle'] + + source = ColumnDataSource(data=my_df) + + plot = figure(plot_width=400, plot_height=400, tools="lasso_select", title="Select Here") + plot.circle('x', 'y', source=source, alpha=0.6, color = 'color') + plot.add_tools(BoxZoomTool()) + + def callback(attr, index_list, _): + global my_df + global my_df_selected + source.data = ColumnDataSource.from_df(my_df) + my_df_selected = my_df.loc[index_list] + + def dummyfunction(): + global my_df + my_df = ps.update(my_df, 'completed', 'green') + + source.selected.on_change('indices', callback) + button = Button(label="Update", button_type="success") + + button.on_click(dummyfunction) + + doc.add_root(column(plot, button)) + +show(bkapp, notebook_url='http://localhost:8102', port=8202) # notebook_url="http://localhost:8888" \ No newline at end of file diff --git a/examples/hamish_example/pandas_skeleton.py b/examples/hamish_example/pandas_skeleton.py new file mode 100644 index 0000000..4626973 --- /dev/null +++ b/examples/hamish_example/pandas_skeleton.py @@ -0,0 +1,104 @@ +import tree_maker as tm +import numpy as np +import math +import random +from anytree import AnyNode, RenderTree +import numpy as np +import json +import pandas as pd + +def create_tree(node): + """ + Creates a tree with the shape of a 'flower'. The nodes that have attributes; x, y, ragius, short_path, angle, min_angle, max_angle and color. + """ + if node.is_leaf: + pass + else: + if node.is_root: + node.x = 0 + node.y = 0 + node.radius = 0 + #node.min_x = -2 + #node.max_x = 2 + node.short_path = '/'.join(node.path.split('/')[-3:]) + node.angle = 2 * math.pi + node.min_angle = 0 + node.max_angle = 2 * math.pi + node.color = 'black' + for my_child, my_angle in zip(node.children, np.linspace(node.min_angle, node.max_angle, len(node.children))): + #my_child.min_x = xx - (node.max_x - node.min_x)/len(node.children)/2 + #my_child.max_x = xx + (node.max_x - node.min_x)/len(node.children)/2 + my_child.color = "black" + my_child.short_path = '/'.join(my_child.path.split('/')[-3:]) + my_child.angle = my_angle + my_child.min_angle = my_angle - (node.max_angle - node.min_angle)/len(node.children)/2 + my_child.max_angle = my_angle + (node.max_angle - node.min_angle)/len(node.children)/2 + my_child.radius = node.radius + 1 + my_child.x = my_child.radius * math.cos(my_angle) + my_child.y = my_child.radius * math.sin(my_angle) + create_tree(my_child) + + +def create_xypath(node): + """ + Creates a list for x_values and y_values for the nodes of a tree. + """ + x_values = [node.x] + y_values = [node.y] + path = [node.short_path] + for descendant in node.descendants: + x_values.append(descendant.x) + y_values.append(descendant.y) + path.append(descendant.short_path) + return x_values, y_values, path + +def create_color(node): + """ + Adds colors of nodes to an array. + """ + my_colors = [node.color] + for descendant in node.descendants: + my_colors.append(descendant.color) + return my_colors + +def create_tree_cartesian(node): + """ + Adds the angle attribute to an array. + """ + angles = [node.angle] + for descendant in node.descendants: + angles.append(node.angle) + return angles + +def get_status(handle): + """ + Returns last key, the status of the job, from 'log_file'. Incase of an empty log_file, 'None' is returned. + """ + keys = list(tm.from_json(handle.log_file)) + if len(keys) > 0: + return keys[-1] + else: + return None + +def create_df(node, path, x_values, y_values, my_colors): + """ + Creating a dataframe and its attributes. Here its attributes are; node, path, x_values, y_values and my_colors. + """ + my_df = pd.DataFrame([node]+list(node.descendants), columns=['handle']).copy() + my_df['name'] = my_df['handle'].apply(lambda x:x.name) + my_df['path'] = path + my_df['x'] = x_values # to check the order + my_df['y'] = y_values # to check the order + my_df['status'] = my_df['handle'].apply(get_status) + my_df['color'] = my_colors + return my_df + +def update(my_df, last_key, my_color): + """ + Filtering through the dataframe using the 'last_key'. The color that is connected to this 'last_key', can also be chosen. + """ + new_df1 = my_df[(my_df.status == last_key)].copy() + new_df1['color'] = my_color + new_df2 = my_df[(my_df.status != last_key)].copy() + my_df = pd.concat([new_df1, new_df2]).sort_index() + return my_df \ No newline at end of file diff --git a/examples/hamish_example/pandas_with_bokeh.ipynb b/examples/hamish_example/pandas_with_bokeh.ipynb new file mode 100644 index 0000000..adf98c7 --- /dev/null +++ b/examples/hamish_example/pandas_with_bokeh.ipynb @@ -0,0 +1,1262 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "7f7bb5b9-554d-45b0-b7b5-6e0240c836c5", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + " <div class=\"bk-root\">\n", + " <a href=\"https://bokeh.org\" target=\"_blank\" class=\"bk-logo bk-logo-small bk-logo-notebook\"></a>\n", + " <span id=\"1002\">Loading BokehJS ...</span>\n", + " </div>" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/javascript": [ + "\n", + "(function(root) {\n", + " function now() {\n", + " return new Date();\n", + " }\n", + "\n", + " var force = true;\n", + "\n", + " if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n", + " root._bokeh_onload_callbacks = [];\n", + " root._bokeh_is_loading = undefined;\n", + " }\n", + "\n", + " var JS_MIME_TYPE = 'application/javascript';\n", + " var HTML_MIME_TYPE = 'text/html';\n", + " var EXEC_MIME_TYPE = 'application/vnd.bokehjs_exec.v0+json';\n", + " var CLASS_NAME = 'output_bokeh rendered_html';\n", + "\n", + " /**\n", + " * Render data to the DOM node\n", + " */\n", + " function render(props, node) {\n", + " var script = document.createElement(\"script\");\n", + " node.appendChild(script);\n", + " }\n", + "\n", + " /**\n", + " * Handle when an output is cleared or removed\n", + " */\n", + " function handleClearOutput(event, handle) {\n", + " var cell = handle.cell;\n", + "\n", + " var id = cell.output_area._bokeh_element_id;\n", + " var server_id = cell.output_area._bokeh_server_id;\n", + " // Clean up Bokeh references\n", + " if (id != null && id in Bokeh.index) {\n", + " Bokeh.index[id].model.document.clear();\n", + " delete Bokeh.index[id];\n", + " }\n", + "\n", + " if (server_id !== undefined) {\n", + " // Clean up Bokeh references\n", + " var cmd = \"from bokeh.io.state import curstate; print(curstate().uuid_to_server['\" + server_id + \"'].get_sessions()[0].document.roots[0]._id)\";\n", + " cell.notebook.kernel.execute(cmd, {\n", + " iopub: {\n", + " output: function(msg) {\n", + " var id = msg.content.text.trim();\n", + " if (id in Bokeh.index) {\n", + " Bokeh.index[id].model.document.clear();\n", + " delete Bokeh.index[id];\n", + " }\n", + " }\n", + " }\n", + " });\n", + " // Destroy server and session\n", + " var cmd = \"import bokeh.io.notebook as ion; ion.destroy_server('\" + server_id + \"')\";\n", + " cell.notebook.kernel.execute(cmd);\n", + " }\n", + " }\n", + "\n", + " /**\n", + " * Handle when a new output is added\n", + " */\n", + " function handleAddOutput(event, handle) {\n", + " var output_area = handle.output_area;\n", + " var output = handle.output;\n", + "\n", + " // limit handleAddOutput to display_data with EXEC_MIME_TYPE content only\n", + " if ((output.output_type != \"display_data\") || (!Object.prototype.hasOwnProperty.call(output.data, EXEC_MIME_TYPE))) {\n", + " return\n", + " }\n", + "\n", + " var toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n", + "\n", + " if (output.metadata[EXEC_MIME_TYPE][\"id\"] !== undefined) {\n", + " toinsert[toinsert.length - 1].firstChild.textContent = output.data[JS_MIME_TYPE];\n", + " // store reference to embed id on output_area\n", + " output_area._bokeh_element_id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n", + " }\n", + " if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n", + " 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].firstChild.setAttribute(script_attrs[i].name, script_attrs[i].value);\n", + " toinsert[toinsert.length - 1].firstChild.textContent = bk_div.children[0].textContent\n", + " }\n", + " // store reference to server id on output_area\n", + " output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n", + " }\n", + " }\n", + "\n", + " function register_renderer(events, OutputArea) {\n", + "\n", + " function append_mime(data, metadata, element) {\n", + " // create a DOM node to render to\n", + " 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[toinsert.length - 1]);\n", + " element.append(toinsert);\n", + " return toinsert\n", + " }\n", + "\n", + " /* Handle when an output is cleared or removed */\n", + " events.on('clear_output.CodeCell', handleClearOutput);\n", + " events.on('delete.Cell', handleClearOutput);\n", + "\n", + " /* Handle when a new output is added */\n", + " events.on('output_added.OutputArea', handleAddOutput);\n", + "\n", + " /**\n", + " * Register the mime type and append_mime function with output_area\n", + " */\n", + " OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n", + " /* Is output safe? */\n", + " safe: true,\n", + " /* Index of renderer in `output_area.display_order` */\n", + " index: 0\n", + " });\n", + " }\n", + "\n", + " // register the mime type if in Jupyter Notebook environment and previously unregistered\n", + " if (root.Jupyter !== undefined) {\n", + " var events = require('base/js/events');\n", + " var OutputArea = require('notebook/js/outputarea').OutputArea;\n", + "\n", + " if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n", + " register_renderer(events, OutputArea);\n", + " }\n", + " }\n", + "\n", + " \n", + " if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n", + " root._bokeh_timeout = Date.now() + 5000;\n", + " root._bokeh_failed_load = false;\n", + " }\n", + "\n", + " var NB_LOAD_WARNING = {'data': {'text/html':\n", + " \"<div style='background-color: #fdd'>\\n\"+\n", + " \"<p>\\n\"+\n", + " \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n", + " \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n", + " \"</p>\\n\"+\n", + " \"<ul>\\n\"+\n", + " \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n", + " \"<li>use INLINE resources instead, as so:</li>\\n\"+\n", + " \"</ul>\\n\"+\n", + " \"<code>\\n\"+\n", + " \"from bokeh.resources import INLINE\\n\"+\n", + " \"output_notebook(resources=INLINE)\\n\"+\n", + " \"</code>\\n\"+\n", + " \"</div>\"}};\n", + "\n", + " function display_loaded() {\n", + " var el = document.getElementById(\"1002\");\n", + " if (el != null) {\n", + " el.textContent = \"BokehJS is loading...\";\n", + " }\n", + " if (root.Bokeh !== undefined) {\n", + " if (el != null) {\n", + " el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n", + " }\n", + " } else if (Date.now() < root._bokeh_timeout) {\n", + " setTimeout(display_loaded, 100)\n", + " }\n", + " }\n", + "\n", + "\n", + " function run_callbacks() {\n", + " try {\n", + " root._bokeh_onload_callbacks.forEach(function(callback) {\n", + " if (callback != null)\n", + " callback();\n", + " });\n", + " } finally {\n", + " delete root._bokeh_onload_callbacks\n", + " }\n", + " console.debug(\"Bokeh: all callbacks have finished\");\n", + " }\n", + "\n", + " function load_libs(css_urls, js_urls, callback) {\n", + " if (css_urls == null) css_urls = [];\n", + " if (js_urls == null) js_urls = [];\n", + "\n", + " root._bokeh_onload_callbacks.push(callback);\n", + " if (root._bokeh_is_loading > 0) {\n", + " console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n", + " return null;\n", + " }\n", + " if (js_urls == null || js_urls.length === 0) {\n", + " run_callbacks();\n", + " return null;\n", + " }\n", + " console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n", + " root._bokeh_is_loading = css_urls.length + js_urls.length;\n", + "\n", + " function on_load() {\n", + " root._bokeh_is_loading--;\n", + " if (root._bokeh_is_loading === 0) {\n", + " console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n", + " run_callbacks()\n", + " }\n", + " }\n", + "\n", + " function on_error(url) {\n", + " console.error(\"failed to load \" + url);\n", + " }\n", + "\n", + " for (let i = 0; i < css_urls.length; i++) {\n", + " const url = css_urls[i];\n", + " const element = document.createElement(\"link\");\n", + " element.onload = on_load;\n", + " element.onerror = on_error.bind(null, url);\n", + " element.rel = \"stylesheet\";\n", + " element.type = \"text/css\";\n", + " element.href = url;\n", + " console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n", + " document.body.appendChild(element);\n", + " }\n", + "\n", + " const hashes = {\"https://cdn.bokeh.org/bokeh/release/bokeh-2.3.3.min.js\": \"dM3QQsP+wXdHg42wTqW85BjZQdLNNIXqlPw/BgKoExPmTG7ZLML4EGqLMfqHT6ON\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.3.3.min.js\": \"8x57I4YuIfu8XyZfFo0XVr2WAT8EK4rh/uDe3wF7YuW2FNUSNEpJbsPaB1nJ2fz2\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.3.3.min.js\": \"3QTqdz9LyAm2i0sG5XTePsHec3UHWwVsrOL68SYRoAXsafvfAyqtQ+h440+qIBhS\"};\n", + "\n", + " for (let i = 0; i < js_urls.length; i++) {\n", + " const url = js_urls[i];\n", + " const element = document.createElement('script');\n", + " element.onload = on_load;\n", + " element.onerror = on_error.bind(null, url);\n", + " element.async = false;\n", + " element.src = url;\n", + " if (url in hashes) {\n", + " element.crossOrigin = \"anonymous\";\n", + " element.integrity = \"sha384-\" + hashes[url];\n", + " }\n", + " console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n", + " document.head.appendChild(element);\n", + " }\n", + " };\n", + "\n", + " function inject_raw_css(css) {\n", + " const element = document.createElement(\"style\");\n", + " element.appendChild(document.createTextNode(css));\n", + " document.body.appendChild(element);\n", + " }\n", + "\n", + " \n", + " var js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.3.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.3.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.3.3.min.js\"];\n", + " var css_urls = [];\n", + " \n", + "\n", + " var inline_js = [\n", + " function(Bokeh) {\n", + " Bokeh.set_log_level(\"info\");\n", + " },\n", + " function(Bokeh) {\n", + " \n", + " \n", + " }\n", + " ];\n", + "\n", + " function run_inline_js() {\n", + " \n", + " if (root.Bokeh !== undefined || force === true) {\n", + " \n", + " for (var i = 0; i < inline_js.length; i++) {\n", + " inline_js[i].call(root, root.Bokeh);\n", + " }\n", + " if (force === true) {\n", + " display_loaded();\n", + " }} else if (Date.now() < root._bokeh_timeout) {\n", + " setTimeout(run_inline_js, 100);\n", + " } else if (!root._bokeh_failed_load) {\n", + " console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n", + " root._bokeh_failed_load = true;\n", + " } else if (force !== true) {\n", + " var cell = $(document.getElementById(\"1002\")).parents('.cell').data().cell;\n", + " cell.output_area.append_execute_result(NB_LOAD_WARNING)\n", + " }\n", + "\n", + " }\n", + "\n", + " if (root._bokeh_is_loading === 0) {\n", + " console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n", + " run_inline_js();\n", + " } else {\n", + " load_libs(css_urls, js_urls, function() {\n", + " console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n", + " run_inline_js();\n", + " });\n", + " }\n", + "}(window));" + ], + "application/vnd.bokehjs_load.v0+json": "\n(function(root) {\n function now() {\n return new Date();\n }\n\n var force = true;\n\n if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n root._bokeh_onload_callbacks = [];\n root._bokeh_is_loading = undefined;\n }\n\n \n\n \n if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_failed_load = false;\n }\n\n var NB_LOAD_WARNING = {'data': {'text/html':\n \"<div style='background-color: #fdd'>\\n\"+\n \"<p>\\n\"+\n \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n \"</p>\\n\"+\n \"<ul>\\n\"+\n \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n \"<li>use INLINE resources instead, as so:</li>\\n\"+\n \"</ul>\\n\"+\n \"<code>\\n\"+\n \"from bokeh.resources import INLINE\\n\"+\n \"output_notebook(resources=INLINE)\\n\"+\n \"</code>\\n\"+\n \"</div>\"}};\n\n function display_loaded() {\n var el = document.getElementById(\"1002\");\n if (el != null) {\n el.textContent = \"BokehJS is loading...\";\n }\n if (root.Bokeh !== undefined) {\n if (el != null) {\n el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n }\n } else if (Date.now() < root._bokeh_timeout) {\n setTimeout(display_loaded, 100)\n }\n }\n\n\n function run_callbacks() {\n try {\n root._bokeh_onload_callbacks.forEach(function(callback) {\n if (callback != null)\n callback();\n });\n } finally {\n delete root._bokeh_onload_callbacks\n }\n console.debug(\"Bokeh: all callbacks have finished\");\n }\n\n function load_libs(css_urls, js_urls, callback) {\n if (css_urls == null) css_urls = [];\n if (js_urls == null) js_urls = [];\n\n root._bokeh_onload_callbacks.push(callback);\n if (root._bokeh_is_loading > 0) {\n console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n return null;\n }\n if (js_urls == null || js_urls.length === 0) {\n run_callbacks();\n return null;\n }\n console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n root._bokeh_is_loading = css_urls.length + js_urls.length;\n\n function on_load() {\n root._bokeh_is_loading--;\n if (root._bokeh_is_loading === 0) {\n console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n run_callbacks()\n }\n }\n\n function on_error(url) {\n console.error(\"failed to load \" + url);\n }\n\n for (let i = 0; i < css_urls.length; i++) {\n const url = css_urls[i];\n const element = document.createElement(\"link\");\n element.onload = on_load;\n element.onerror = on_error.bind(null, url);\n element.rel = \"stylesheet\";\n element.type = \"text/css\";\n element.href = url;\n console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n document.body.appendChild(element);\n }\n\n const hashes = {\"https://cdn.bokeh.org/bokeh/release/bokeh-2.3.3.min.js\": \"dM3QQsP+wXdHg42wTqW85BjZQdLNNIXqlPw/BgKoExPmTG7ZLML4EGqLMfqHT6ON\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.3.3.min.js\": \"8x57I4YuIfu8XyZfFo0XVr2WAT8EK4rh/uDe3wF7YuW2FNUSNEpJbsPaB1nJ2fz2\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.3.3.min.js\": \"3QTqdz9LyAm2i0sG5XTePsHec3UHWwVsrOL68SYRoAXsafvfAyqtQ+h440+qIBhS\"};\n\n for (let i = 0; i < js_urls.length; i++) {\n const url = js_urls[i];\n const element = document.createElement('script');\n element.onload = on_load;\n element.onerror = on_error.bind(null, url);\n element.async = false;\n element.src = url;\n if (url in hashes) {\n element.crossOrigin = \"anonymous\";\n element.integrity = \"sha384-\" + hashes[url];\n }\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n document.head.appendChild(element);\n }\n };\n\n function inject_raw_css(css) {\n const element = document.createElement(\"style\");\n element.appendChild(document.createTextNode(css));\n document.body.appendChild(element);\n }\n\n \n var js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.3.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.3.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.3.3.min.js\"];\n var css_urls = [];\n \n\n var inline_js = [\n function(Bokeh) {\n Bokeh.set_log_level(\"info\");\n },\n function(Bokeh) {\n \n \n }\n ];\n\n function run_inline_js() {\n \n if (root.Bokeh !== undefined || force === true) {\n \n for (var i = 0; i < inline_js.length; i++) {\n inline_js[i].call(root, root.Bokeh);\n }\n if (force === true) {\n display_loaded();\n }} else if (Date.now() < root._bokeh_timeout) {\n setTimeout(run_inline_js, 100);\n } else if (!root._bokeh_failed_load) {\n console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n root._bokeh_failed_load = true;\n } else if (force !== true) {\n var cell = $(document.getElementById(\"1002\")).parents('.cell').data().cell;\n cell.output_area.append_execute_result(NB_LOAD_WARNING)\n }\n\n }\n\n if (root._bokeh_is_loading === 0) {\n console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n run_inline_js();\n } else {\n load_libs(css_urls, js_urls, function() {\n console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n run_inline_js();\n });\n }\n}(window));" + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "import pandas_skeleton as ps\n", + "import tree_maker as tm\n", + "from pandas import DataFrame\n", + "\n", + "from bokeh.layouts import column\n", + "from bokeh.models import ColumnDataSource, Slider, WheelZoomTool, BoxZoomTool, Button\n", + "from bokeh.plotting import figure\n", + "from bokeh.themes import Theme\n", + "from bokeh.io import show, output_notebook\n", + "\n", + "output_notebook()" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "68380bba-2edd-4d18-b95d-57819da498b0", + "metadata": {}, + "outputs": [], + "source": [ + "%load_ext autoreload" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "f684f232-914a-4f2e-8835-a5c0b35576f6", + "metadata": {}, + "outputs": [], + "source": [ + "%autoreload 2" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "41e859af-98f5-492e-9c98-ec03cf59294a", + "metadata": {}, + "outputs": [], + "source": [ + "root = tm.tree_from_json(filename='/home/HPC/sterbini/DA_study_example/study_000/tree.json')" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "78cab292-371e-44dd-9d8e-50b6bd4f7b9e", + "metadata": {}, + "outputs": [], + "source": [ + "def bkapp(doc):\n", + " #root = my_root\n", + " \n", + " global my_df\n", + " global source\n", + " ps.create_tree(root)\n", + " \n", + " x_values, y_values, path = ps.create_xypath(root)\n", + " my_colors = ps.create_color(root)\n", + " angles = ps.create_tree_cartesian(root)\n", + " \n", + " my_df = ps.create_df(root, path, x_values, y_values, my_colors)\n", + " \n", + " del my_df['handle']\n", + " \n", + " source = ColumnDataSource(data=my_df)\n", + "\n", + " plot = figure(plot_width=400, plot_height=400, tools=\"lasso_select\", title=\"Select Here\")\n", + " plot.circle('x', 'y', source=source, alpha=0.6, color = 'color')\n", + " plot.add_tools(BoxZoomTool())\n", + " \n", + " def callback(attr, index_list, _):\n", + " global my_df\n", + " global my_df_selected\n", + " source.data = ColumnDataSource.from_df(my_df)\n", + " my_df_selected = my_df.loc[index_list]\n", + "\n", + " def dummyfunction():\n", + " global my_df\n", + " my_df = ps.update(my_df, 'completed', 'green')\n", + "\n", + " source.selected.on_change('indices', callback)\n", + " button = Button(label=\"hello\", button_type=\"success\")\n", + "\n", + " button.on_click(dummyfunction)\n", + "\n", + " doc.add_root(column(plot, button))" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "466ec80a-215a-4969-b876-b96a3ead3994", + "metadata": {}, + "outputs": [ + { + "ename": "OSError", + "evalue": "[Errno 98] Address already in use", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mOSError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/tmp/ipykernel_25955/1803267195.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mshow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbkapp\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnotebook_url\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'http://127.0.0.1:8103'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mport\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m8203\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# notebook_url=\"http://localhost:8888\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m/home/HPC/sterbini/py38/lib/python3.8/site-packages/bokeh/io/showing.py\u001b[0m in \u001b[0;36mshow\u001b[0;34m(obj, browser, new, notebook_handle, notebook_url, **kw)\u001b[0m\n\u001b[1;32m 135\u001b[0m \u001b[0;31m# in Tornado) just in order to show a non-server object\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 136\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mis_application\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0mcallable\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mobj\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 137\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mrun_notebook_hook\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mstate\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnotebook_type\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'app'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mobj\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstate\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnotebook_url\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkw\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 138\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 139\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0m_show_with_state\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mobj\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstate\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbrowser\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnew\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnotebook_handle\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mnotebook_handle\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/home/HPC/sterbini/py38/lib/python3.8/site-packages/bokeh/io/notebook.py\u001b[0m in \u001b[0;36mrun_notebook_hook\u001b[0;34m(notebook_type, action, *args, **kw)\u001b[0m\n\u001b[1;32m 296\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0m_HOOKS\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mnotebook_type\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0maction\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 297\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mRuntimeError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"notebook hook for %r did not install %r action\"\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0mnotebook_type\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0maction\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 298\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0m_HOOKS\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mnotebook_type\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0maction\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkw\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 299\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 300\u001b[0m \u001b[0;31m#-----------------------------------------------------------------------------\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/home/HPC/sterbini/py38/lib/python3.8/site-packages/bokeh/io/notebook.py\u001b[0m in \u001b[0;36mshow_app\u001b[0;34m(app, state, notebook_url, port, **kw)\u001b[0m\n\u001b[1;32m 472\u001b[0m \u001b[0morigin\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_origin_url\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnotebook_url\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 473\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 474\u001b[0;31m \u001b[0mserver\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mServer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m{\u001b[0m\u001b[0;34m\"/\"\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mapp\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mio_loop\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mloop\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mport\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mport\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mallow_websocket_origin\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0morigin\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkw\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 475\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 476\u001b[0m \u001b[0mserver_id\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0muuid4\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhex\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/home/HPC/sterbini/py38/lib/python3.8/site-packages/bokeh/server/server.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, applications, io_loop, http_server_kwargs, **kwargs)\u001b[0m\n\u001b[1;32m 393\u001b[0m \u001b[0mhttp_server_kwargs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'ssl_options'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcontext\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 394\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 395\u001b[0;31m \u001b[0msockets\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_port\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mbind_sockets\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mopts\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0maddress\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mopts\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mport\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 396\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_address\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mopts\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0maddress\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 397\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/home/HPC/sterbini/py38/lib/python3.8/site-packages/bokeh/server/util.py\u001b[0m in \u001b[0;36mbind_sockets\u001b[0;34m(address, port)\u001b[0m\n\u001b[1;32m 58\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 59\u001b[0m '''\n\u001b[0;32m---> 60\u001b[0;31m \u001b[0mss\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnetutil\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbind_sockets\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mport\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mport\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0maddress\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0maddress\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 61\u001b[0m \u001b[0;32massert\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mss\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 62\u001b[0m \u001b[0mports\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0ms\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgetsockname\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0ms\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mss\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/home/HPC/sterbini/py38/lib/python3.8/site-packages/tornado/netutil.py\u001b[0m in \u001b[0;36mbind_sockets\u001b[0;34m(port, address, family, backlog, flags, reuse_port)\u001b[0m\n\u001b[1;32m 159\u001b[0m \u001b[0msock\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msetblocking\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 160\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 161\u001b[0;31m \u001b[0msock\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbind\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msockaddr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 162\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mOSError\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 163\u001b[0m if (\n", + "\u001b[0;31mOSError\u001b[0m: [Errno 98] Address already in use" + ] + } + ], + "source": [ + "show(bkapp, notebook_url='http://127.0.0.1:8103', port=8203) # notebook_url=\"http://localhost:8888\"" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "6a63fe6e-8563-4610-86af-323fa3d94866", + "metadata": {}, + "outputs": [ + { + "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>name</th>\n", + " <th>path</th>\n", + " <th>x</th>\n", + " <th>y</th>\n", + " <th>status</th>\n", + " <th>color</th>\n", + " </tr>\n", + " </thead>\n", + " <tbody>\n", + " <tr>\n", + " <th>0</th>\n", + " <td>root</td>\n", + " <td>sterbini/DA_study_example/study_000</td>\n", + " <td>0.000000</td>\n", + " <td>0.000000</td>\n", + " <td>completed</td>\n", + " <td>black</td>\n", + " </tr>\n", + " <tr>\n", + " <th>1</th>\n", + " <td>000</td>\n", + " <td>DA_study_example/study_000/000</td>\n", + " <td>1.000000</td>\n", + " <td>0.000000</td>\n", + " <td>completed</td>\n", + " <td>black</td>\n", + " </tr>\n", + " <tr>\n", + " <th>2</th>\n", + " <td>000</td>\n", + " <td>study_000/000/000</td>\n", + " <td>1.999949</td>\n", + " <td>-0.014247</td>\n", + " <td>completed</td>\n", + " <td>black</td>\n", + " </tr>\n", + " <tr>\n", + " <th>3</th>\n", + " <td>001</td>\n", + " <td>study_000/000/001</td>\n", + " <td>1.999963</td>\n", + " <td>-0.012212</td>\n", + " <td>completed</td>\n", + " <td>black</td>\n", + " </tr>\n", + " <tr>\n", + " <th>4</th>\n", + " <td>002</td>\n", + " <td>study_000/000/002</td>\n", + " <td>1.999974</td>\n", + " <td>-0.010177</td>\n", + " <td>completed</td>\n", + " <td>black</td>\n", + " </tr>\n", + " <tr>\n", + " <th>...</th>\n", + " <td>...</td>\n", + " <td>...</td>\n", + " <td>...</td>\n", + " <td>...</td>\n", + " <td>...</td>\n", + " <td>...</td>\n", + " </tr>\n", + " <tr>\n", + " <th>7052</th>\n", + " <td>010</td>\n", + " <td>study_000/440/010</td>\n", + " <td>1.999991</td>\n", + " <td>0.006106</td>\n", + " <td>completed</td>\n", + " <td>black</td>\n", + " </tr>\n", + " <tr>\n", + " <th>7053</th>\n", + " <td>011</td>\n", + " <td>study_000/440/011</td>\n", + " <td>1.999983</td>\n", + " <td>0.008141</td>\n", + " <td>completed</td>\n", + " <td>black</td>\n", + " </tr>\n", + " <tr>\n", + " <th>7054</th>\n", + " <td>012</td>\n", + " <td>study_000/440/012</td>\n", + " <td>1.999974</td>\n", + " <td>0.010177</td>\n", + " <td>completed</td>\n", + " <td>black</td>\n", + " </tr>\n", + " <tr>\n", + " <th>7055</th>\n", + " <td>013</td>\n", + " <td>study_000/440/013</td>\n", + " <td>1.999963</td>\n", + " <td>0.012212</td>\n", + " <td>completed</td>\n", + " <td>black</td>\n", + " </tr>\n", + " <tr>\n", + " <th>7056</th>\n", + " <td>014</td>\n", + " <td>study_000/440/014</td>\n", + " <td>1.999949</td>\n", + " <td>0.014247</td>\n", + " <td>completed</td>\n", + " <td>black</td>\n", + " </tr>\n", + " </tbody>\n", + "</table>\n", + "<p>7057 rows × 6 columns</p>\n", + "</div>" + ], + "text/plain": [ + " name path x y \\\n", + "0 root sterbini/DA_study_example/study_000 0.000000 0.000000 \n", + "1 000 DA_study_example/study_000/000 1.000000 0.000000 \n", + "2 000 study_000/000/000 1.999949 -0.014247 \n", + "3 001 study_000/000/001 1.999963 -0.012212 \n", + "4 002 study_000/000/002 1.999974 -0.010177 \n", + "... ... ... ... ... \n", + "7052 010 study_000/440/010 1.999991 0.006106 \n", + "7053 011 study_000/440/011 1.999983 0.008141 \n", + "7054 012 study_000/440/012 1.999974 0.010177 \n", + "7055 013 study_000/440/013 1.999963 0.012212 \n", + "7056 014 study_000/440/014 1.999949 0.014247 \n", + "\n", + " status color \n", + "0 completed black \n", + "1 completed black \n", + "2 completed black \n", + "3 completed black \n", + "4 completed black \n", + "... ... ... \n", + "7052 completed black \n", + "7053 completed black \n", + "7054 completed black \n", + "7055 completed black \n", + "7056 completed black \n", + "\n", + "[7057 rows x 6 columns]" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "my_df" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3019e3dd-557b-427b-8786-d5d538bb7cb8", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "90fabbb9-2053-4326-8b6e-713990517413", + "metadata": {}, + "outputs": [ + { + "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>name</th>\n", + " <th>path</th>\n", + " <th>x</th>\n", + " <th>y</th>\n", + " <th>status</th>\n", + " <th>color</th>\n", + " </tr>\n", + " </thead>\n", + " <tbody>\n", + " <tr>\n", + " <th>849</th>\n", + " <td>053</td>\n", + " <td>DA_study_example/study_000/053</td>\n", + " <td>0.727011</td>\n", + " <td>0.686626</td>\n", + " <td>completed</td>\n", + " <td>green</td>\n", + " </tr>\n", + " <tr>\n", + " <th>865</th>\n", + " <td>054</td>\n", + " <td>DA_study_example/study_000/054</td>\n", + " <td>0.717132</td>\n", + " <td>0.696938</td>\n", + " <td>completed</td>\n", + " <td>green</td>\n", + " </tr>\n", + " <tr>\n", + " <th>881</th>\n", + " <td>055</td>\n", + " <td>DA_study_example/study_000/055</td>\n", + " <td>0.707107</td>\n", + " <td>0.707107</td>\n", + " <td>completed</td>\n", + " <td>green</td>\n", + " </tr>\n", + " <tr>\n", + " <th>897</th>\n", + " <td>056</td>\n", + " <td>DA_study_example/study_000/056</td>\n", + " <td>0.696938</td>\n", + " <td>0.717132</td>\n", + " <td>completed</td>\n", + " <td>green</td>\n", + " </tr>\n", + " <tr>\n", + " <th>913</th>\n", + " <td>057</td>\n", + " <td>DA_study_example/study_000/057</td>\n", + " <td>0.686626</td>\n", + " <td>0.727011</td>\n", + " <td>completed</td>\n", + " <td>green</td>\n", + " </tr>\n", + " <tr>\n", + " <th>929</th>\n", + " <td>058</td>\n", + " <td>DA_study_example/study_000/058</td>\n", + " <td>0.676175</td>\n", + " <td>0.736741</td>\n", + " <td>completed</td>\n", + " <td>green</td>\n", + " </tr>\n", + " <tr>\n", + " <th>945</th>\n", + " <td>059</td>\n", + " <td>DA_study_example/study_000/059</td>\n", + " <td>0.665586</td>\n", + " <td>0.746321</td>\n", + " <td>completed</td>\n", + " <td>green</td>\n", + " </tr>\n", + " <tr>\n", + " <th>961</th>\n", + " <td>060</td>\n", + " <td>DA_study_example/study_000/060</td>\n", + " <td>0.654861</td>\n", + " <td>0.755750</td>\n", + " <td>completed</td>\n", + " <td>green</td>\n", + " </tr>\n", + " <tr>\n", + " <th>977</th>\n", + " <td>061</td>\n", + " <td>DA_study_example/study_000/061</td>\n", + " <td>0.644002</td>\n", + " <td>0.765024</td>\n", + " <td>completed</td>\n", + " <td>green</td>\n", + " </tr>\n", + " <tr>\n", + " <th>993</th>\n", + " <td>062</td>\n", + " <td>DA_study_example/study_000/062</td>\n", + " <td>0.633012</td>\n", + " <td>0.774142</td>\n", + " <td>completed</td>\n", + " <td>green</td>\n", + " </tr>\n", + " <tr>\n", + " <th>1009</th>\n", + " <td>063</td>\n", + " <td>DA_study_example/study_000/063</td>\n", + " <td>0.621894</td>\n", + " <td>0.783102</td>\n", + " <td>completed</td>\n", + " <td>green</td>\n", + " </tr>\n", + " <tr>\n", + " <th>1025</th>\n", + " <td>064</td>\n", + " <td>DA_study_example/study_000/064</td>\n", + " <td>0.610648</td>\n", + " <td>0.791902</td>\n", + " <td>completed</td>\n", + " <td>green</td>\n", + " </tr>\n", + " <tr>\n", + " <th>1041</th>\n", + " <td>065</td>\n", + " <td>DA_study_example/study_000/065</td>\n", + " <td>0.599278</td>\n", + " <td>0.800541</td>\n", + " <td>completed</td>\n", + " <td>green</td>\n", + " </tr>\n", + " <tr>\n", + " <th>1057</th>\n", + " <td>066</td>\n", + " <td>DA_study_example/study_000/066</td>\n", + " <td>0.587785</td>\n", + " <td>0.809017</td>\n", + " <td>completed</td>\n", + " <td>green</td>\n", + " </tr>\n", + " <tr>\n", + " <th>1073</th>\n", + " <td>067</td>\n", + " <td>DA_study_example/study_000/067</td>\n", + " <td>0.576173</td>\n", + " <td>0.817328</td>\n", + " <td>completed</td>\n", + " <td>green</td>\n", + " </tr>\n", + " <tr>\n", + " <th>1089</th>\n", + " <td>068</td>\n", + " <td>DA_study_example/study_000/068</td>\n", + " <td>0.564443</td>\n", + " <td>0.825472</td>\n", + " <td>completed</td>\n", + " <td>green</td>\n", + " </tr>\n", + " </tbody>\n", + "</table>\n", + "</div>" + ], + "text/plain": [ + " name path x y status \\\n", + "849 053 DA_study_example/study_000/053 0.727011 0.686626 completed \n", + "865 054 DA_study_example/study_000/054 0.717132 0.696938 completed \n", + "881 055 DA_study_example/study_000/055 0.707107 0.707107 completed \n", + "897 056 DA_study_example/study_000/056 0.696938 0.717132 completed \n", + "913 057 DA_study_example/study_000/057 0.686626 0.727011 completed \n", + "929 058 DA_study_example/study_000/058 0.676175 0.736741 completed \n", + "945 059 DA_study_example/study_000/059 0.665586 0.746321 completed \n", + "961 060 DA_study_example/study_000/060 0.654861 0.755750 completed \n", + "977 061 DA_study_example/study_000/061 0.644002 0.765024 completed \n", + "993 062 DA_study_example/study_000/062 0.633012 0.774142 completed \n", + "1009 063 DA_study_example/study_000/063 0.621894 0.783102 completed \n", + "1025 064 DA_study_example/study_000/064 0.610648 0.791902 completed \n", + "1041 065 DA_study_example/study_000/065 0.599278 0.800541 completed \n", + "1057 066 DA_study_example/study_000/066 0.587785 0.809017 completed \n", + "1073 067 DA_study_example/study_000/067 0.576173 0.817328 completed \n", + "1089 068 DA_study_example/study_000/068 0.564443 0.825472 completed \n", + "\n", + " color \n", + "849 green \n", + "865 green \n", + "881 green \n", + "897 green \n", + "913 green \n", + "929 green \n", + "945 green \n", + "961 green \n", + "977 green \n", + "993 green \n", + "1009 green \n", + "1025 green \n", + "1041 green \n", + "1057 green \n", + "1073 green \n", + "1089 green " + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "my_df_selected" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "ee617105-b3c8-48d0-9664-4f5fe3bf9664", + "metadata": {}, + "outputs": [ + { + "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>name</th>\n", + " <th>path</th>\n", + " <th>x</th>\n", + " <th>y</th>\n", + " <th>status</th>\n", + " <th>color</th>\n", + " </tr>\n", + " </thead>\n", + " <tbody>\n", + " <tr>\n", + " <th>0</th>\n", + " <td>root</td>\n", + " <td>sterbini/DA_study_example/study_000</td>\n", + " <td>0.000000</td>\n", + " <td>0.000000</td>\n", + " <td>completed</td>\n", + " <td>green</td>\n", + " </tr>\n", + " <tr>\n", + " <th>1</th>\n", + " <td>000</td>\n", + " <td>DA_study_example/study_000/000</td>\n", + " <td>1.000000</td>\n", + " <td>0.000000</td>\n", + " <td>completed</td>\n", + " <td>green</td>\n", + " </tr>\n", + " <tr>\n", + " <th>2</th>\n", + " <td>000</td>\n", + " <td>study_000/000/000</td>\n", + " <td>1.999949</td>\n", + " <td>-0.014247</td>\n", + " <td>completed</td>\n", + " <td>green</td>\n", + " </tr>\n", + " <tr>\n", + " <th>3</th>\n", + " <td>001</td>\n", + " <td>study_000/000/001</td>\n", + " <td>1.999963</td>\n", + " <td>-0.012212</td>\n", + " <td>completed</td>\n", + " <td>green</td>\n", + " </tr>\n", + " <tr>\n", + " <th>4</th>\n", + " <td>002</td>\n", + " <td>study_000/000/002</td>\n", + " <td>1.999974</td>\n", + " <td>-0.010177</td>\n", + " <td>completed</td>\n", + " <td>green</td>\n", + " </tr>\n", + " <tr>\n", + " <th>...</th>\n", + " <td>...</td>\n", + " <td>...</td>\n", + " <td>...</td>\n", + " <td>...</td>\n", + " <td>...</td>\n", + " <td>...</td>\n", + " </tr>\n", + " <tr>\n", + " <th>7052</th>\n", + " <td>010</td>\n", + " <td>study_000/440/010</td>\n", + " <td>1.999991</td>\n", + " <td>0.006106</td>\n", + " <td>completed</td>\n", + " <td>green</td>\n", + " </tr>\n", + " <tr>\n", + " <th>7053</th>\n", + " <td>011</td>\n", + " <td>study_000/440/011</td>\n", + " <td>1.999983</td>\n", + " <td>0.008141</td>\n", + " <td>completed</td>\n", + " <td>green</td>\n", + " </tr>\n", + " <tr>\n", + " <th>7054</th>\n", + " <td>012</td>\n", + " <td>study_000/440/012</td>\n", + " <td>1.999974</td>\n", + " <td>0.010177</td>\n", + " <td>completed</td>\n", + " <td>green</td>\n", + " </tr>\n", + " <tr>\n", + " <th>7055</th>\n", + " <td>013</td>\n", + " <td>study_000/440/013</td>\n", + " <td>1.999963</td>\n", + " <td>0.012212</td>\n", + " <td>completed</td>\n", + " <td>green</td>\n", + " </tr>\n", + " <tr>\n", + " <th>7056</th>\n", + " <td>014</td>\n", + " <td>study_000/440/014</td>\n", + " <td>1.999949</td>\n", + " <td>0.014247</td>\n", + " <td>completed</td>\n", + " <td>green</td>\n", + " </tr>\n", + " </tbody>\n", + "</table>\n", + "<p>7057 rows × 6 columns</p>\n", + "</div>" + ], + "text/plain": [ + " name path x y \\\n", + "0 root sterbini/DA_study_example/study_000 0.000000 0.000000 \n", + "1 000 DA_study_example/study_000/000 1.000000 0.000000 \n", + "2 000 study_000/000/000 1.999949 -0.014247 \n", + "3 001 study_000/000/001 1.999963 -0.012212 \n", + "4 002 study_000/000/002 1.999974 -0.010177 \n", + "... ... ... ... ... \n", + "7052 010 study_000/440/010 1.999991 0.006106 \n", + "7053 011 study_000/440/011 1.999983 0.008141 \n", + "7054 012 study_000/440/012 1.999974 0.010177 \n", + "7055 013 study_000/440/013 1.999963 0.012212 \n", + "7056 014 study_000/440/014 1.999949 0.014247 \n", + "\n", + " status color \n", + "0 completed green \n", + "1 completed green \n", + "2 completed green \n", + "3 completed green \n", + "4 completed green \n", + "... ... ... \n", + "7052 completed green \n", + "7053 completed green \n", + "7054 completed green \n", + "7055 completed green \n", + "7056 completed green \n", + "\n", + "[7057 rows x 6 columns]" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ps.update(my_df, 'completed', 'green')" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "8107481e-f694-4ead-9fdf-d5fbf261da17", + "metadata": {}, + "outputs": [], + "source": [ + "new_df = ps.update(my_df, 'completed', 'green')" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "8108b9ef-9360-4f6d-95b6-204208a31474", + "metadata": {}, + "outputs": [ + { + "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>name</th>\n", + " <th>path</th>\n", + " <th>x</th>\n", + " <th>y</th>\n", + " <th>status</th>\n", + " <th>color</th>\n", + " </tr>\n", + " </thead>\n", + " <tbody>\n", + " <tr>\n", + " <th>0</th>\n", + " <td>root</td>\n", + " <td>sterbini/DA_study_example/study_000</td>\n", + " <td>0.000000</td>\n", + " <td>0.000000</td>\n", + " <td>completed</td>\n", + " <td>green</td>\n", + " </tr>\n", + " <tr>\n", + " <th>1</th>\n", + " <td>000</td>\n", + " <td>DA_study_example/study_000/000</td>\n", + " <td>1.000000</td>\n", + " <td>0.000000</td>\n", + " <td>completed</td>\n", + " <td>green</td>\n", + " </tr>\n", + " <tr>\n", + " <th>2</th>\n", + " <td>000</td>\n", + " <td>study_000/000/000</td>\n", + " <td>1.999949</td>\n", + " <td>-0.014247</td>\n", + " <td>completed</td>\n", + " <td>green</td>\n", + " </tr>\n", + " <tr>\n", + " <th>3</th>\n", + " <td>001</td>\n", + " <td>study_000/000/001</td>\n", + " <td>1.999963</td>\n", + " <td>-0.012212</td>\n", + " <td>completed</td>\n", + " <td>green</td>\n", + " </tr>\n", + " <tr>\n", + " <th>4</th>\n", + " <td>002</td>\n", + " <td>study_000/000/002</td>\n", + " <td>1.999974</td>\n", + " <td>-0.010177</td>\n", + " <td>completed</td>\n", + " <td>green</td>\n", + " </tr>\n", + " <tr>\n", + " <th>...</th>\n", + " <td>...</td>\n", + " <td>...</td>\n", + " <td>...</td>\n", + " <td>...</td>\n", + " <td>...</td>\n", + " <td>...</td>\n", + " </tr>\n", + " <tr>\n", + " <th>7052</th>\n", + " <td>010</td>\n", + " <td>study_000/440/010</td>\n", + " <td>1.999991</td>\n", + " <td>0.006106</td>\n", + " <td>completed</td>\n", + " <td>green</td>\n", + " </tr>\n", + " <tr>\n", + " <th>7053</th>\n", + " <td>011</td>\n", + " <td>study_000/440/011</td>\n", + " <td>1.999983</td>\n", + " <td>0.008141</td>\n", + " <td>completed</td>\n", + " <td>green</td>\n", + " </tr>\n", + " <tr>\n", + " <th>7054</th>\n", + " <td>012</td>\n", + " <td>study_000/440/012</td>\n", + " <td>1.999974</td>\n", + " <td>0.010177</td>\n", + " <td>completed</td>\n", + " <td>green</td>\n", + " </tr>\n", + " <tr>\n", + " <th>7055</th>\n", + " <td>013</td>\n", + " <td>study_000/440/013</td>\n", + " <td>1.999963</td>\n", + " <td>0.012212</td>\n", + " <td>completed</td>\n", + " <td>green</td>\n", + " </tr>\n", + " <tr>\n", + " <th>7056</th>\n", + " <td>014</td>\n", + " <td>study_000/440/014</td>\n", + " <td>1.999949</td>\n", + " <td>0.014247</td>\n", + " <td>completed</td>\n", + " <td>green</td>\n", + " </tr>\n", + " </tbody>\n", + "</table>\n", + "<p>7057 rows × 6 columns</p>\n", + "</div>" + ], + "text/plain": [ + " name path x y \\\n", + "0 root sterbini/DA_study_example/study_000 0.000000 0.000000 \n", + "1 000 DA_study_example/study_000/000 1.000000 0.000000 \n", + "2 000 study_000/000/000 1.999949 -0.014247 \n", + "3 001 study_000/000/001 1.999963 -0.012212 \n", + "4 002 study_000/000/002 1.999974 -0.010177 \n", + "... ... ... ... ... \n", + "7052 010 study_000/440/010 1.999991 0.006106 \n", + "7053 011 study_000/440/011 1.999983 0.008141 \n", + "7054 012 study_000/440/012 1.999974 0.010177 \n", + "7055 013 study_000/440/013 1.999963 0.012212 \n", + "7056 014 study_000/440/014 1.999949 0.014247 \n", + "\n", + " status color \n", + "0 completed green \n", + "1 completed green \n", + "2 completed green \n", + "3 completed green \n", + "4 completed green \n", + "... ... ... \n", + "7052 completed green \n", + "7053 completed green \n", + "7054 completed green \n", + "7055 completed green \n", + "7056 completed green \n", + "\n", + "[7057 rows x 6 columns]" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "new_df" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9357f393-7f52-4dad-a696-0f37d560fb59", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "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.8.5" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} -- GitLab