{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [],
   "source": [
    "from mpes import fprocessing as fp, visualization as vis\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "import glob as g"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.1 Loading data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "fpath = r'../data/data_114_parts/data_114_split_1.h5'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "hp = fp.hdf5Processor(fpath)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.2 Binning data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "axes = ['X', 'Y', 't']\n",
    "bins = [100, 100, 200]\n",
    "ranges = [(300, 1800), (200, 1800), (68000, 90000)]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 2.2.1 Local binning"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [],
   "source": [
    "resdict = hp.localBinning_numba(axes=axes, nbins=bins, ranges=ranges)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_keys(['binned', 'X', 'Y', 't'])"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "resdict.keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 307.5,  322.5,  337.5,  352.5,  367.5,  382.5,  397.5,  412.5,\n",
       "        427.5,  442.5,  457.5,  472.5,  487.5,  502.5,  517.5,  532.5,\n",
       "        547.5,  562.5,  577.5,  592.5,  607.5,  622.5,  637.5,  652.5,\n",
       "        667.5,  682.5,  697.5,  712.5,  727.5,  742.5,  757.5,  772.5,\n",
       "        787.5,  802.5,  817.5,  832.5,  847.5,  862.5,  877.5,  892.5,\n",
       "        907.5,  922.5,  937.5,  952.5,  967.5,  982.5,  997.5, 1012.5,\n",
       "       1027.5, 1042.5, 1057.5, 1072.5, 1087.5, 1102.5, 1117.5, 1132.5,\n",
       "       1147.5, 1162.5, 1177.5, 1192.5, 1207.5, 1222.5, 1237.5, 1252.5,\n",
       "       1267.5, 1282.5, 1297.5, 1312.5, 1327.5, 1342.5, 1357.5, 1372.5,\n",
       "       1387.5, 1402.5, 1417.5, 1432.5, 1447.5, 1462.5, 1477.5, 1492.5,\n",
       "       1507.5, 1522.5, 1537.5, 1552.5, 1567.5, 1582.5, 1597.5, 1612.5,\n",
       "       1627.5, 1642.5, 1657.5, 1672.5, 1687.5, 1702.5, 1717.5, 1732.5,\n",
       "       1747.5, 1762.5, 1777.5, 1792.5])"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "resdict['X']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 2.2.2 Parallel binning using split HDF5 files\n",
    "Retrieve split files"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "splits_folder = r'../data/data_114_parts'\n",
    "parp = fp.parallelHDF5Processor(folder=splits_folder)\n",
    "parp.gather(identifier=r'/data*h5')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "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\") || (!output.data.hasOwnProperty(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",
       "      }\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(null);\n",
       "    if (el != null) {\n",
       "      el.textContent = \"BokehJS is loading...\";\n",
       "    }\n",
       "    if (root.Bokeh !== undefined) {\n",
       "      if (el != null) {\n",
       "        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n",
       "      }\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() {\n",
       "      console.error(\"failed to load \" + url);\n",
       "    }\n",
       "\n",
       "    for (var i = 0; i < css_urls.length; i++) {\n",
       "      var url = css_urls[i];\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",
       "    }\n",
       "\n",
       "    for (var i = 0; i < js_urls.length; i++) {\n",
       "      var url = js_urls[i];\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",
       "      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",
       "  var js_urls = [\"https://cdn.pydata.org/bokeh/release/bokeh-1.3.4.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-widgets-1.3.4.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-tables-1.3.4.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-gl-1.3.4.min.js\"];\n",
       "  var css_urls = [];\n",
       "\n",
       "  var inline_js = [\n",
       "    function(Bokeh) {\n",
       "      Bokeh.set_log_level(\"info\");\n",
       "    },\n",
       "    \n",
       "    function(Bokeh) {\n",
       "      \n",
       "    },\n",
       "    function(Bokeh) {} // ensure no trailing comma for IE\n",
       "  ];\n",
       "\n",
       "  function run_inline_js() {\n",
       "    \n",
       "    if ((root.Bokeh !== undefined) || (force === true)) {\n",
       "      for (var i = 0; i < inline_js.length; i++) {\n",
       "        inline_js[i].call(root, root.Bokeh);\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(null)).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(null);\n    if (el != null) {\n      el.textContent = \"BokehJS is loading...\";\n    }\n    if (root.Bokeh !== undefined) {\n      if (el != null) {\n        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n      }\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() {\n      console.error(\"failed to load \" + url);\n    }\n\n    for (var i = 0; i < css_urls.length; i++) {\n      var url = css_urls[i];\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    }\n\n    for (var i = 0; i < js_urls.length; i++) {\n      var url = js_urls[i];\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      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  var js_urls = [\"https://cdn.pydata.org/bokeh/release/bokeh-1.3.4.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-widgets-1.3.4.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-tables-1.3.4.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-gl-1.3.4.min.js\"];\n  var css_urls = [];\n\n  var inline_js = [\n    function(Bokeh) {\n      Bokeh.set_log_level(\"info\");\n    },\n    \n    function(Bokeh) {\n      \n    },\n    function(Bokeh) {} // ensure no trailing comma for IE\n  ];\n\n  function run_inline_js() {\n    \n    if ((root.Bokeh !== undefined) || (force === true)) {\n      for (var i = 0; i < inline_js.length; i++) {\n        inline_js[i].call(root, root.Bokeh);\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(null)).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"
    },
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"55a486aa-9b5a-4bc3-8958-341dcc223d09\" data-root-id=\"1724\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"3f620ef4-32e8-4b21-be38-bbef781a5bab\":{\"roots\":{\"references\":[{\"attributes\":{\"children\":[{\"id\":\"1723\",\"type\":\"ToolbarBox\"},{\"id\":\"1721\",\"type\":\"GridBox\"}]},\"id\":\"1724\",\"type\":\"Column\"},{\"attributes\":{\"formatter\":{\"id\":\"1580\",\"type\":\"BasicTickFormatter\"},\"ticker\":{\"id\":\"1547\",\"type\":\"BasicTicker\"}},\"id\":\"1546\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1689\",\"type\":\"Selection\"},{\"attributes\":{\"source\":{\"id\":\"1523\",\"type\":\"ColumnDataSource\"}},\"id\":\"1527\",\"type\":\"CDSView\"},{\"attributes\":{\"bottom\":{\"value\":0},\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"left\":{\"field\":\"left\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"right\":{\"field\":\"right\"},\"top\":{\"field\":\"top\"}},\"id\":\"1669\",\"type\":\"Quad\"},{\"attributes\":{},\"id\":\"1698\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"text\":\"\"},\"id\":\"1529\",\"type\":\"Title\"},{\"attributes\":{\"bottom\":{\"value\":0},\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"left\":{\"field\":\"left\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"right\":{\"field\":\"right\"},\"top\":{\"field\":\"top\"}},\"id\":\"1621\",\"type\":\"Quad\"},{\"attributes\":{\"bottom\":{\"value\":0},\"fill_alpha\":{\"value\":0.8},\"fill_color\":{\"value\":\"#1f77b4\"},\"left\":{\"field\":\"left\"},\"line_alpha\":{\"value\":0.8},\"line_color\":{\"value\":\"white\"},\"right\":{\"field\":\"right\"},\"top\":{\"field\":\"top\"}},\"id\":\"1668\",\"type\":\"Quad\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1652\",\"type\":\"PanTool\"},{\"id\":\"1653\",\"type\":\"WheelZoomTool\"},{\"id\":\"1654\",\"type\":\"BoxZoomTool\"},{\"id\":\"1655\",\"type\":\"SaveTool\"},{\"id\":\"1656\",\"type\":\"ResetTool\"},{\"id\":\"1657\",\"type\":\"HelpTool\"},{\"id\":\"1658\",\"type\":\"HoverTool\"}]},\"id\":\"1659\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1530\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1699\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1708\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"data_source\":{\"id\":\"1523\",\"type\":\"ColumnDataSource\"},\"glyph\":{\"id\":\"1524\",\"type\":\"Quad\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1525\",\"type\":\"Quad\"},\"selection_glyph\":null,\"view\":{\"id\":\"1527\",\"type\":\"CDSView\"}},\"id\":\"1526\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1719\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1638\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1547\",\"type\":\"BasicTicker\"},{\"attributes\":{\"bottom\":{\"value\":0},\"fill_alpha\":{\"value\":0.8},\"fill_color\":{\"value\":\"#1f77b4\"},\"left\":{\"field\":\"left\"},\"line_alpha\":{\"value\":0.8},\"line_color\":{\"value\":\"white\"},\"right\":{\"field\":\"right\"},\"top\":{\"field\":\"top\"}},\"id\":\"1620\",\"type\":\"Quad\"},{\"attributes\":{},\"id\":\"1652\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1653\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"items\":[{\"id\":\"1584\",\"type\":\"LegendItem\"}]},\"id\":\"1583\",\"type\":\"Legend\"},{\"attributes\":{},\"id\":\"1532\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1640\",\"type\":\"LinearScale\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":{\"value\":0.5},\"fill_color\":{\"value\":\"lightgrey\"},\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":{\"value\":1.0},\"line_color\":{\"value\":\"black\"},\"line_dash\":[4,4],\"line_width\":{\"value\":2},\"render_mode\":\"css\",\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1534\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"label\":{\"value\":\"Y\"},\"renderers\":[{\"id\":\"1574\",\"type\":\"GlyphRenderer\"}]},\"id\":\"1584\",\"type\":\"LegendItem\"},{\"attributes\":{\"background_fill_color\":{\"value\":\"white\"},\"below\":[{\"id\":\"1642\",\"type\":\"LinearAxis\"}],\"center\":[{\"id\":\"1646\",\"type\":\"Grid\"},{\"id\":\"1651\",\"type\":\"Grid\"},{\"id\":\"1679\",\"type\":\"Legend\"}],\"left\":[{\"id\":\"1647\",\"type\":\"LinearAxis\"}],\"plot_height\":224,\"plot_width\":420,\"renderers\":[{\"id\":\"1670\",\"type\":\"GlyphRenderer\"}],\"title\":{\"id\":\"1673\",\"type\":\"Title\"},\"toolbar\":{\"id\":\"1659\",\"type\":\"Toolbar\"},\"toolbar_location\":null,\"x_range\":{\"id\":\"1634\",\"type\":\"DataRange1d\"},\"x_scale\":{\"id\":\"1638\",\"type\":\"LinearScale\"},\"y_range\":{\"id\":\"1636\",\"type\":\"DataRange1d\"},\"y_scale\":{\"id\":\"1640\",\"type\":\"LinearScale\"}},\"id\":\"1633\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"callback\":null,\"data\":{\"left\":{\"__ndarray__\":\"AAAAAACa8EAAAAAAsJ7wQAAAAABgo/BAAAAAABCo8EAAAAAAwKzwQAAAAABwsfBAAAAAACC28EAAAAAA0LrwQAAAAACAv/BAAAAAADDE8EAAAAAA4MjwQAAAAACQzfBAAAAAAEDS8EAAAAAA8NbwQAAAAACg2/BAAAAAAFDg8EAAAAAAAOXwQAAAAACw6fBAAAAAAGDu8EAAAAAAEPPwQAAAAADA9/BAAAAAAHD88EAAAAAAIAHxQAAAAADQBfFAAAAAAIAK8UAAAAAAMA/xQAAAAADgE/FAAAAAAJAY8UAAAAAAQB3xQAAAAADwIfFAAAAAAKAm8UAAAAAAUCvxQAAAAAAAMPFAAAAAALA08UAAAAAAYDnxQAAAAAAQPvFAAAAAAMBC8UAAAAAAcEfxQAAAAAAgTPFAAAAAANBQ8UAAAAAAgFXxQAAAAAAwWvFAAAAAAOBe8UAAAAAAkGPxQAAAAABAaPFAAAAAAPBs8UAAAAAAoHHxQAAAAABQdvFAAAAAAAB78UAAAAAAsH/xQAAAAABghPFAAAAAABCJ8UAAAAAAwI3xQAAAAABwkvFAAAAAACCX8UAAAAAA0JvxQAAAAACAoPFAAAAAADCl8UAAAAAA4KnxQAAAAACQrvFAAAAAAECz8UAAAAAA8LfxQAAAAACgvPFAAAAAAFDB8UAAAAAAAMbxQAAAAACwyvFAAAAAAGDP8UAAAAAAENTxQAAAAADA2PFAAAAAAHDd8UAAAAAAIOLxQAAAAADQ5vFAAAAAAIDr8UAAAAAAMPDxQAAAAADg9PFAAAAAAJD58UAAAAAAQP7xQAAAAADwAvJAAAAAAKAH8kAAAAAAUAzyQA==\",\"dtype\":\"float64\",\"shape\":[80]},\"right\":{\"__ndarray__\":\"AAAAALCe8EAAAAAAYKPwQAAAAAAQqPBAAAAAAMCs8EAAAAAAcLHwQAAAAAAgtvBAAAAAANC68EAAAAAAgL/wQAAAAAAwxPBAAAAAAODI8EAAAAAAkM3wQAAAAABA0vBAAAAAAPDW8EAAAAAAoNvwQAAAAABQ4PBAAAAAAADl8EAAAAAAsOnwQAAAAABg7vBAAAAAABDz8EAAAAAAwPfwQAAAAABw/PBAAAAAACAB8UAAAAAA0AXxQAAAAACACvFAAAAAADAP8UAAAAAA4BPxQAAAAACQGPFAAAAAAEAd8UAAAAAA8CHxQAAAAACgJvFAAAAAAFAr8UAAAAAAADDxQAAAAACwNPFAAAAAAGA58UAAAAAAED7xQAAAAADAQvFAAAAAAHBH8UAAAAAAIEzxQAAAAADQUPFAAAAAAIBV8UAAAAAAMFrxQAAAAADgXvFAAAAAAJBj8UAAAAAAQGjxQAAAAADwbPFAAAAAAKBx8UAAAAAAUHbxQAAAAAAAe/FAAAAAALB/8UAAAAAAYITxQAAAAAAQifFAAAAAAMCN8UAAAAAAcJLxQAAAAAAgl/FAAAAAANCb8UAAAAAAgKDxQAAAAAAwpfFAAAAAAOCp8UAAAAAAkK7xQAAAAABAs/FAAAAAAPC38UAAAAAAoLzxQAAAAABQwfFAAAAAAADG8UAAAAAAsMrxQAAAAABgz/FAAAAAABDU8UAAAAAAwNjxQAAAAABw3fFAAAAAACDi8UAAAAAA0ObxQAAAAACA6/FAAAAAADDw8UAAAAAA4PTxQAAAAACQ+fFAAAAAAED+8UAAAAAA8ALyQAAAAACgB/JAAAAAAFAM8kAAAAAAABHyQA==\",\"dtype\":\"float64\",\"shape\":[80]},\"top\":[2,1,3,5,3,3,4,62,244,241,107,31,17,33,27,31,96,743,4952,16139,31646,54658,92875,146932,201845,229555,238386,231033,193030,145767,121841,121722,128640,137755,147899,165306,182627,198400,207276,205400,185960,148751,112832,94812,92083,96493,102932,108066,109229,107708,104334,102363,102059,103118,107872,115212,122742,129403,128830,122889,112497,103482,96245,91280,89760,90441,91322,92671,94425,94136,93053,91861,90046,87639,84405,80866,77112,72930,69550,66970]},\"selected\":{\"id\":\"1709\",\"type\":\"Selection\"},\"selection_policy\":{\"id\":\"1708\",\"type\":\"UnionRenderers\"}},\"id\":\"1619\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1709\",\"type\":\"Selection\"},{\"attributes\":{\"grid_line_color\":\"lightgrey\",\"ticker\":{\"id\":\"1547\",\"type\":\"BasicTicker\"}},\"id\":\"1550\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1718\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"formatter\":{\"id\":\"1676\",\"type\":\"BasicTickFormatter\"},\"ticker\":{\"id\":\"1643\",\"type\":\"BasicTicker\"}},\"id\":\"1642\",\"type\":\"LinearAxis\"},{\"attributes\":{\"callback\":null},\"id\":\"1586\",\"type\":\"DataRange1d\"},{\"attributes\":{\"overlay\":{\"id\":\"1678\",\"type\":\"BoxAnnotation\"}},\"id\":\"1654\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"callback\":null,\"start\":0},\"id\":\"1588\",\"type\":\"DataRange1d\"},{\"attributes\":{\"bottom\":{\"value\":0},\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"left\":{\"field\":\"left\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"right\":{\"field\":\"right\"},\"top\":{\"field\":\"top\"}},\"id\":\"1525\",\"type\":\"Quad\"},{\"attributes\":{},\"id\":\"1643\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1655\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1590\",\"type\":\"LinearScale\"},{\"attributes\":{\"tools\":[{\"id\":\"1508\",\"type\":\"PanTool\"},{\"id\":\"1509\",\"type\":\"WheelZoomTool\"},{\"id\":\"1510\",\"type\":\"BoxZoomTool\"},{\"id\":\"1511\",\"type\":\"SaveTool\"},{\"id\":\"1512\",\"type\":\"ResetTool\"},{\"id\":\"1513\",\"type\":\"HelpTool\"},{\"id\":\"1514\",\"type\":\"HoverTool\"},{\"id\":\"1556\",\"type\":\"PanTool\"},{\"id\":\"1557\",\"type\":\"WheelZoomTool\"},{\"id\":\"1558\",\"type\":\"BoxZoomTool\"},{\"id\":\"1559\",\"type\":\"SaveTool\"},{\"id\":\"1560\",\"type\":\"ResetTool\"},{\"id\":\"1561\",\"type\":\"HelpTool\"},{\"id\":\"1562\",\"type\":\"HoverTool\"},{\"id\":\"1604\",\"type\":\"PanTool\"},{\"id\":\"1605\",\"type\":\"WheelZoomTool\"},{\"id\":\"1606\",\"type\":\"BoxZoomTool\"},{\"id\":\"1607\",\"type\":\"SaveTool\"},{\"id\":\"1608\",\"type\":\"ResetTool\"},{\"id\":\"1609\",\"type\":\"HelpTool\"},{\"id\":\"1610\",\"type\":\"HoverTool\"},{\"id\":\"1652\",\"type\":\"PanTool\"},{\"id\":\"1653\",\"type\":\"WheelZoomTool\"},{\"id\":\"1654\",\"type\":\"BoxZoomTool\"},{\"id\":\"1655\",\"type\":\"SaveTool\"},{\"id\":\"1656\",\"type\":\"ResetTool\"},{\"id\":\"1657\",\"type\":\"HelpTool\"},{\"id\":\"1658\",\"type\":\"HoverTool\"}]},\"id\":\"1722\",\"type\":\"ProxyToolbar\"},{\"attributes\":{},\"id\":\"1656\",\"type\":\"ResetTool\"},{\"attributes\":{\"formatter\":{\"id\":\"1578\",\"type\":\"BasicTickFormatter\"},\"ticker\":{\"id\":\"1552\",\"type\":\"BasicTicker\"}},\"id\":\"1551\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1592\",\"type\":\"LinearScale\"},{\"attributes\":{\"background_fill_color\":{\"value\":\"white\"},\"below\":[{\"id\":\"1498\",\"type\":\"LinearAxis\"}],\"center\":[{\"id\":\"1502\",\"type\":\"Grid\"},{\"id\":\"1507\",\"type\":\"Grid\"},{\"id\":\"1535\",\"type\":\"Legend\"}],\"left\":[{\"id\":\"1503\",\"type\":\"LinearAxis\"}],\"plot_height\":224,\"plot_width\":420,\"renderers\":[{\"id\":\"1526\",\"type\":\"GlyphRenderer\"}],\"title\":{\"id\":\"1529\",\"type\":\"Title\"},\"toolbar\":{\"id\":\"1515\",\"type\":\"Toolbar\"},\"toolbar_location\":null,\"x_range\":{\"id\":\"1490\",\"type\":\"DataRange1d\"},\"x_scale\":{\"id\":\"1494\",\"type\":\"LinearScale\"},\"y_range\":{\"id\":\"1492\",\"type\":\"DataRange1d\"},\"y_scale\":{\"id\":\"1496\",\"type\":\"LinearScale\"}},\"id\":\"1489\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"background_fill_color\":{\"value\":\"white\"},\"below\":[{\"id\":\"1546\",\"type\":\"LinearAxis\"}],\"center\":[{\"id\":\"1550\",\"type\":\"Grid\"},{\"id\":\"1555\",\"type\":\"Grid\"},{\"id\":\"1583\",\"type\":\"Legend\"}],\"left\":[{\"id\":\"1551\",\"type\":\"LinearAxis\"}],\"plot_height\":224,\"plot_width\":420,\"renderers\":[{\"id\":\"1574\",\"type\":\"GlyphRenderer\"}],\"title\":{\"id\":\"1577\",\"type\":\"Title\"},\"toolbar\":{\"id\":\"1563\",\"type\":\"Toolbar\"},\"toolbar_location\":null,\"x_range\":{\"id\":\"1538\",\"type\":\"DataRange1d\"},\"x_scale\":{\"id\":\"1542\",\"type\":\"LinearScale\"},\"y_range\":{\"id\":\"1540\",\"type\":\"DataRange1d\"},\"y_scale\":{\"id\":\"1544\",\"type\":\"LinearScale\"}},\"id\":\"1537\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1657\",\"type\":\"HelpTool\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"(x, y)\",\"($x, $y)\"]]},\"id\":\"1658\",\"type\":\"HoverTool\"},{\"attributes\":{\"items\":[{\"id\":\"1536\",\"type\":\"LegendItem\"}]},\"id\":\"1535\",\"type\":\"Legend\"},{\"attributes\":{},\"id\":\"1604\",\"type\":\"PanTool\"},{\"attributes\":{\"label\":{\"value\":\"X\"},\"renderers\":[{\"id\":\"1526\",\"type\":\"GlyphRenderer\"}]},\"id\":\"1536\",\"type\":\"LegendItem\"},{\"attributes\":{\"background_fill_color\":{\"value\":\"white\"},\"below\":[{\"id\":\"1594\",\"type\":\"LinearAxis\"}],\"center\":[{\"id\":\"1598\",\"type\":\"Grid\"},{\"id\":\"1603\",\"type\":\"Grid\"},{\"id\":\"1631\",\"type\":\"Legend\"}],\"left\":[{\"id\":\"1599\",\"type\":\"LinearAxis\"}],\"plot_height\":224,\"plot_width\":420,\"renderers\":[{\"id\":\"1622\",\"type\":\"GlyphRenderer\"}],\"title\":{\"id\":\"1625\",\"type\":\"Title\"},\"toolbar\":{\"id\":\"1611\",\"type\":\"Toolbar\"},\"toolbar_location\":null,\"x_range\":{\"id\":\"1586\",\"type\":\"DataRange1d\"},\"x_scale\":{\"id\":\"1590\",\"type\":\"LinearScale\"},\"y_range\":{\"id\":\"1588\",\"type\":\"DataRange1d\"},\"y_scale\":{\"id\":\"1592\",\"type\":\"LinearScale\"}},\"id\":\"1585\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1688\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"callback\":null},\"id\":\"1490\",\"type\":\"DataRange1d\"},{\"attributes\":{\"grid_line_color\":\"lightgrey\",\"ticker\":{\"id\":\"1643\",\"type\":\"BasicTicker\"}},\"id\":\"1646\",\"type\":\"Grid\"},{\"attributes\":{\"callback\":null,\"start\":0},\"id\":\"1492\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1494\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1552\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1605\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"toolbar\":{\"id\":\"1722\",\"type\":\"ProxyToolbar\"},\"toolbar_location\":\"above\"},\"id\":\"1723\",\"type\":\"ToolbarBox\"},{\"attributes\":{\"callback\":null},\"id\":\"1538\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1607\",\"type\":\"SaveTool\"},{\"attributes\":{\"callback\":null,\"start\":0},\"id\":\"1540\",\"type\":\"DataRange1d\"},{\"attributes\":{\"dimension\":1,\"grid_line_color\":\"lightgrey\",\"ticker\":{\"id\":\"1552\",\"type\":\"BasicTicker\"}},\"id\":\"1555\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1542\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1544\",\"type\":\"LinearScale\"},{\"attributes\":{\"overlay\":{\"id\":\"1630\",\"type\":\"BoxAnnotation\"}},\"id\":\"1606\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":{\"value\":0.5},\"fill_color\":{\"value\":\"lightgrey\"},\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":{\"value\":1.0},\"line_color\":{\"value\":\"black\"},\"line_dash\":[4,4],\"line_width\":{\"value\":2},\"render_mode\":\"css\",\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1582\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"children\":[[{\"id\":\"1489\",\"subtype\":\"Figure\",\"type\":\"Plot\"},0,0],[{\"id\":\"1537\",\"subtype\":\"Figure\",\"type\":\"Plot\"},0,1],[{\"id\":\"1585\",\"subtype\":\"Figure\",\"type\":\"Plot\"},1,0],[{\"id\":\"1633\",\"subtype\":\"Figure\",\"type\":\"Plot\"},1,1]]},\"id\":\"1721\",\"type\":\"GridBox\"},{\"attributes\":{\"formatter\":{\"id\":\"1674\",\"type\":\"BasicTickFormatter\"},\"ticker\":{\"id\":\"1648\",\"type\":\"BasicTicker\"}},\"id\":\"1647\",\"type\":\"LinearAxis\"},{\"attributes\":{\"formatter\":{\"id\":\"1626\",\"type\":\"BasicTickFormatter\"},\"ticker\":{\"id\":\"1600\",\"type\":\"BasicTicker\"}},\"id\":\"1599\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1600\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1496\",\"type\":\"LinearScale\"},{\"attributes\":{\"callback\":null,\"data\":{\"left\":{\"__ndarray__\":\"AAAAAAAAtEEAADRCAACHQgAAtEIAAOFCAAAHQwCAHUMAADRDAIBKQwAAYUMAgHdDAACHQwBAkkMAgJ1DAMCoQwAAtEMAQL9DAIDKQwDA1UMAAOFDAEDsQwCA90MAYAFEAAAHRACgDEQAQBJEAOAXRACAHUQAICNEAMAoRABgLkQAADREAKA5RABAP0QA4EREAIBKRAAgUEQAwFVEAGBbRAAAYUQAoGZEAEBsRADgcUQAgHdEACB9RABggUQAMIREAACHRADQiUQAoIxEAHCPRABAkkQAEJVEAOCXRACwmkQAgJ1EAFCgRAAgo0QA8KVEAMCoRACQq0QAYK5EADCxRAAAtEQA0LZEAKC5RABwvEQAQL9EABDCRADgxEQAsMdEAIDKRABQzUQAINBEAPDSRADA1UQAkNhEAGDbRAAw3kQ=\",\"dtype\":\"float32\",\"shape\":[80]},\"right\":{\"__ndarray__\":\"AAC0QQAANEIAAIdCAAC0QgAA4UIAAAdDAIAdQwAANEMAgEpDAABhQwCAd0MAAIdDAECSQwCAnUMAwKhDAAC0QwBAv0MAgMpDAMDVQwAA4UMAQOxDAID3QwBgAUQAAAdEAKAMRABAEkQA4BdEAIAdRAAgI0QAwChEAGAuRAAANEQAoDlEAEA/RADgREQAgEpEACBQRADAVUQAYFtEAABhRACgZkQAQGxEAOBxRACAd0QAIH1EAGCBRAAwhEQAAIdEANCJRACgjEQAcI9EAECSRAAQlUQA4JdEALCaRACAnUQAUKBEACCjRADwpUQAwKhEAJCrRABgrkQAMLFEAAC0RADQtkQAoLlEAHC8RABAv0QAEMJEAODERACwx0QAgMpEAFDNRAAg0EQA8NJEAMDVRACQ2EQAYNtEADDeRAAA4UQ=\",\"dtype\":\"float32\",\"shape\":[80]},\"top\":[8971,3354,3790,3580,3829,3454,3875,3544,3751,3570,3865,3537,3567,3430,4819,5491,6799,8916,14466,21183,31563,38850,51506,61289,79329,93716,122557,142806,176417,195528,240564,259734,305286,325667,378327,395801,438798,439506,484496,485570,534437,520748,578698,565749,595773,576060,621912,613327,635642,599917,609164,554543,555280,499179,478766,406178,379308,321048,300709,255879,236026,193589,168505,129636,104195,74741,57281,37641,25531,15965,11000,7579,6713,5620,5187,4300,3230,2317,2471,2503]},\"selected\":{\"id\":\"1699\",\"type\":\"Selection\"},\"selection_policy\":{\"id\":\"1698\",\"type\":\"UnionRenderers\"}},\"id\":\"1571\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1559\",\"type\":\"SaveTool\"},{\"attributes\":{\"formatter\":{\"id\":\"1532\",\"type\":\"BasicTickFormatter\"},\"ticker\":{\"id\":\"1499\",\"type\":\"BasicTicker\"}},\"id\":\"1498\",\"type\":\"LinearAxis\"},{\"attributes\":{\"dimension\":1,\"grid_line_color\":\"lightgrey\",\"ticker\":{\"id\":\"1600\",\"type\":\"BasicTicker\"}},\"id\":\"1603\",\"type\":\"Grid\"},{\"attributes\":{\"formatter\":{\"id\":\"1628\",\"type\":\"BasicTickFormatter\"},\"ticker\":{\"id\":\"1595\",\"type\":\"BasicTicker\"}},\"id\":\"1594\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1499\",\"type\":\"BasicTicker\"},{\"attributes\":{\"grid_line_color\":\"lightgrey\",\"ticker\":{\"id\":\"1499\",\"type\":\"BasicTicker\"}},\"id\":\"1502\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1595\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1648\",\"type\":\"BasicTicker\"},{\"attributes\":{\"grid_line_color\":\"lightgrey\",\"ticker\":{\"id\":\"1595\",\"type\":\"BasicTicker\"}},\"id\":\"1598\",\"type\":\"Grid\"},{\"attributes\":{\"formatter\":{\"id\":\"1530\",\"type\":\"BasicTickFormatter\"},\"ticker\":{\"id\":\"1504\",\"type\":\"BasicTicker\"}},\"id\":\"1503\",\"type\":\"LinearAxis\"},{\"attributes\":{\"dimension\":1,\"grid_line_color\":\"lightgrey\",\"ticker\":{\"id\":\"1648\",\"type\":\"BasicTicker\"}},\"id\":\"1651\",\"type\":\"Grid\"},{\"attributes\":{\"source\":{\"id\":\"1619\",\"type\":\"ColumnDataSource\"}},\"id\":\"1623\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1509\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1556\",\"type\":\"PanTool\"},{\"id\":\"1557\",\"type\":\"WheelZoomTool\"},{\"id\":\"1558\",\"type\":\"BoxZoomTool\"},{\"id\":\"1559\",\"type\":\"SaveTool\"},{\"id\":\"1560\",\"type\":\"ResetTool\"},{\"id\":\"1561\",\"type\":\"HelpTool\"},{\"id\":\"1562\",\"type\":\"HoverTool\"}]},\"id\":\"1563\",\"type\":\"Toolbar\"},{\"attributes\":{\"text\":\"\"},\"id\":\"1625\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"1561\",\"type\":\"HelpTool\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"(x, y)\",\"($x, $y)\"]]},\"id\":\"1562\",\"type\":\"HoverTool\"},{\"attributes\":{},\"id\":\"1626\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"data_source\":{\"id\":\"1667\",\"type\":\"ColumnDataSource\"},\"glyph\":{\"id\":\"1668\",\"type\":\"Quad\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1669\",\"type\":\"Quad\"},\"selection_glyph\":null,\"view\":{\"id\":\"1671\",\"type\":\"CDSView\"}},\"id\":\"1670\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"bottom\":{\"value\":0},\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"left\":{\"field\":\"left\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"right\":{\"field\":\"right\"},\"top\":{\"field\":\"top\"}},\"id\":\"1573\",\"type\":\"Quad\"},{\"attributes\":{},\"id\":\"1628\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":{\"value\":0.5},\"fill_color\":{\"value\":\"lightgrey\"},\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":{\"value\":1.0},\"line_color\":{\"value\":\"black\"},\"line_dash\":[4,4],\"line_width\":{\"value\":2},\"render_mode\":\"css\",\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1630\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"bottom\":{\"value\":0},\"fill_alpha\":{\"value\":0.8},\"fill_color\":{\"value\":\"#1f77b4\"},\"left\":{\"field\":\"left\"},\"line_alpha\":{\"value\":0.8},\"line_color\":{\"value\":\"white\"},\"right\":{\"field\":\"right\"},\"top\":{\"field\":\"top\"}},\"id\":\"1572\",\"type\":\"Quad\"},{\"attributes\":{},\"id\":\"1560\",\"type\":\"ResetTool\"},{\"attributes\":{\"overlay\":{\"id\":\"1534\",\"type\":\"BoxAnnotation\"}},\"id\":\"1510\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"items\":[{\"id\":\"1632\",\"type\":\"LegendItem\"}]},\"id\":\"1631\",\"type\":\"Legend\"},{\"attributes\":{},\"id\":\"1556\",\"type\":\"PanTool\"},{\"attributes\":{\"source\":{\"id\":\"1667\",\"type\":\"ColumnDataSource\"}},\"id\":\"1671\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1504\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1557\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"1608\",\"type\":\"ResetTool\"},{\"attributes\":{\"overlay\":{\"id\":\"1582\",\"type\":\"BoxAnnotation\"}},\"id\":\"1558\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"data_source\":{\"id\":\"1571\",\"type\":\"ColumnDataSource\"},\"glyph\":{\"id\":\"1572\",\"type\":\"Quad\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1573\",\"type\":\"Quad\"},\"selection_glyph\":null,\"view\":{\"id\":\"1575\",\"type\":\"CDSView\"}},\"id\":\"1574\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1511\",\"type\":\"SaveTool\"},{\"attributes\":{\"text\":\"\"},\"id\":\"1673\",\"type\":\"Title\"},{\"attributes\":{\"source\":{\"id\":\"1571\",\"type\":\"ColumnDataSource\"}},\"id\":\"1575\",\"type\":\"CDSView\"},{\"attributes\":{\"text\":\"\"},\"id\":\"1577\",\"type\":\"Title\"},{\"attributes\":{\"label\":{\"value\":\"t\"},\"renderers\":[{\"id\":\"1622\",\"type\":\"GlyphRenderer\"}]},\"id\":\"1632\",\"type\":\"LegendItem\"},{\"attributes\":{\"dimension\":1,\"grid_line_color\":\"lightgrey\",\"ticker\":{\"id\":\"1504\",\"type\":\"BasicTicker\"}},\"id\":\"1507\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1512\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"1513\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"1609\",\"type\":\"HelpTool\"},{\"attributes\":{\"bottom\":{\"value\":0},\"fill_alpha\":{\"value\":0.8},\"fill_color\":{\"value\":\"#1f77b4\"},\"left\":{\"field\":\"left\"},\"line_alpha\":{\"value\":0.8},\"line_color\":{\"value\":\"white\"},\"right\":{\"field\":\"right\"},\"top\":{\"field\":\"top\"}},\"id\":\"1524\",\"type\":\"Quad\"},{\"attributes\":{},\"id\":\"1674\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1578\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1580\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"(x, y)\",\"($x, $y)\"]]},\"id\":\"1610\",\"type\":\"HoverTool\"},{\"attributes\":{\"callback\":null,\"data\":{\"left\":{\"__ndarray__\":\"AAAAAAAAtEEAADRCAACHQgAAtEIAAOFCAAAHQwCAHUMAADRDAIBKQwAAYUMAgHdDAACHQwBAkkMAgJ1DAMCoQwAAtEMAQL9DAIDKQwDA1UMAAOFDAEDsQwCA90MAYAFEAAAHRACgDEQAQBJEAOAXRACAHUQAICNEAMAoRABgLkQAADREAKA5RABAP0QA4EREAIBKRAAgUEQAwFVEAGBbRAAAYUQAoGZEAEBsRADgcUQAgHdEACB9RABggUQAMIREAACHRADQiUQAoIxEAHCPRABAkkQAEJVEAOCXRACwmkQAgJ1EAFCgRAAgo0QA8KVEAMCoRACQq0QAYK5EADCxRAAAtEQA0LZEAKC5RABwvEQAQL9EABDCRADgxEQAsMdEAIDKRABQzUQAINBEAPDSRADA1UQAkNhEAGDbRAAw3kQ=\",\"dtype\":\"float32\",\"shape\":[80]},\"right\":{\"__ndarray__\":\"AAC0QQAANEIAAIdCAAC0QgAA4UIAAAdDAIAdQwAANEMAgEpDAABhQwCAd0MAAIdDAECSQwCAnUMAwKhDAAC0QwBAv0MAgMpDAMDVQwAA4UMAQOxDAID3QwBgAUQAAAdEAKAMRABAEkQA4BdEAIAdRAAgI0QAwChEAGAuRAAANEQAoDlEAEA/RADgREQAgEpEACBQRADAVUQAYFtEAABhRACgZkQAQGxEAOBxRACAd0QAIH1EAGCBRAAwhEQAAIdEANCJRACgjEQAcI9EAECSRAAQlUQA4JdEALCaRACAnUQAUKBEACCjRADwpUQAwKhEAJCrRABgrkQAMLFEAAC0RADQtkQAoLlEAHC8RABAv0QAEMJEAODERACwx0QAgMpEAFDNRAAg0EQA8NJEAMDVRACQ2EQAYNtEADDeRAAA4UQ=\",\"dtype\":\"float32\",\"shape\":[80]},\"top\":[12121,6366,6482,6381,4876,4509,4620,4383,4219,4095,4213,3817,4093,4022,4487,6478,30052,45303,66204,84456,117589,147845,193583,220262,261616,283462,340696,375526,436493,454775,508299,505504,540529,523510,551941,523061,530585,481200,492694,457892,469907,442100,456558,434477,447596,425603,433830,398631,388489,341665,324031,281322,270641,242202,238390,218139,220445,209654,218844,205345,209207,187659,182407,154529,134026,104448,83124,59326,39812,20915,10651,7414,7126,6494,6478,5786,5546,4676,3929,2724]},\"selected\":{\"id\":\"1689\",\"type\":\"Selection\"},\"selection_policy\":{\"id\":\"1688\",\"type\":\"UnionRenderers\"}},\"id\":\"1523\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1676\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"(x, y)\",\"($x, $y)\"]]},\"id\":\"1514\",\"type\":\"HoverTool\"},{\"attributes\":{\"callback\":null,\"data\":{\"left\":{\"__ndarray__\":\"AAAAAAAAyEAAAEhBAACWQQAAyEEAAPpBAAAWQgAAL0IAAEhCAABhQgAAekIAgIlCAACWQgCAokIAAK9CAIC7QgAAyEIAgNRCAADhQgCA7UIAAPpCAEADQwCACUMAwA9DAAAWQwBAHEMAgCJDAMAoQwAAL0MAQDVDAIA7QwDAQUMAAEhDAEBOQwCAVEMAwFpDAABhQwBAZ0MAgG1DAMBzQwAAekMAIIBDAECDQwBghkMAgIlDAKCMQwDAj0MA4JJDAACWQwAgmUMAQJxDAGCfQwCAokMAoKVDAMCoQwDgq0MAAK9DACCyQwBAtUMAYLhDAIC7QwCgvkMAwMFDAODEQwAAyEMAIMtDAEDOQwBg0UMAgNRDAKDXQwDA2kMA4N1DAADhQwAg5EMAQOdDAGDqQwCA7UMAoPBDAMDzQwDg9kM=\",\"dtype\":\"float32\",\"shape\":[80]},\"right\":{\"__ndarray__\":\"AADIQAAASEEAAJZBAADIQQAA+kEAABZCAAAvQgAASEIAAGFCAAB6QgCAiUIAAJZCAICiQgAAr0IAgLtCAADIQgCA1EIAAOFCAIDtQgAA+kIAQANDAIAJQwDAD0MAABZDAEAcQwCAIkMAwChDAAAvQwBANUMAgDtDAMBBQwAASEMAQE5DAIBUQwDAWkMAAGFDAEBnQwCAbUMAwHNDAAB6QwAggEMAQINDAGCGQwCAiUMAoIxDAMCPQwDgkkMAAJZDACCZQwBAnEMAYJ9DAICiQwCgpUMAwKhDAOCrQwAAr0MAILJDAEC1QwBguEMAgLtDAKC+QwDAwUMA4MRDAADIQwAgy0MAQM5DAGDRQwCA1EMAoNdDAMDaQwDg3UMAAOFDACDkQwBA50MAYOpDAIDtQwCg8EMAwPNDAOD2QwAA+kM=\",\"dtype\":\"float32\",\"shape\":[80]},\"top\":[5166,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},\"selected\":{\"id\":\"1719\",\"type\":\"Selection\"},\"selection_policy\":{\"id\":\"1718\",\"type\":\"UnionRenderers\"}},\"id\":\"1667\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"callback\":null},\"id\":\"1634\",\"type\":\"DataRange1d\"},{\"attributes\":{\"callback\":null,\"start\":0},\"id\":\"1636\",\"type\":\"DataRange1d\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":{\"value\":0.5},\"fill_color\":{\"value\":\"lightgrey\"},\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":{\"value\":1.0},\"line_color\":{\"value\":\"black\"},\"line_dash\":[4,4],\"line_width\":{\"value\":2},\"render_mode\":\"css\",\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1678\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1604\",\"type\":\"PanTool\"},{\"id\":\"1605\",\"type\":\"WheelZoomTool\"},{\"id\":\"1606\",\"type\":\"BoxZoomTool\"},{\"id\":\"1607\",\"type\":\"SaveTool\"},{\"id\":\"1608\",\"type\":\"ResetTool\"},{\"id\":\"1609\",\"type\":\"HelpTool\"},{\"id\":\"1610\",\"type\":\"HoverTool\"}]},\"id\":\"1611\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1508\",\"type\":\"PanTool\"},{\"attributes\":{\"data_source\":{\"id\":\"1619\",\"type\":\"ColumnDataSource\"},\"glyph\":{\"id\":\"1620\",\"type\":\"Quad\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1621\",\"type\":\"Quad\"},\"selection_glyph\":null,\"view\":{\"id\":\"1623\",\"type\":\"CDSView\"}},\"id\":\"1622\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1508\",\"type\":\"PanTool\"},{\"id\":\"1509\",\"type\":\"WheelZoomTool\"},{\"id\":\"1510\",\"type\":\"BoxZoomTool\"},{\"id\":\"1511\",\"type\":\"SaveTool\"},{\"id\":\"1512\",\"type\":\"ResetTool\"},{\"id\":\"1513\",\"type\":\"HelpTool\"},{\"id\":\"1514\",\"type\":\"HoverTool\"}]},\"id\":\"1515\",\"type\":\"Toolbar\"},{\"attributes\":{\"items\":[{\"id\":\"1680\",\"type\":\"LegendItem\"}]},\"id\":\"1679\",\"type\":\"Legend\"},{\"attributes\":{\"label\":{\"value\":\"ADC\"},\"renderers\":[{\"id\":\"1670\",\"type\":\"GlyphRenderer\"}]},\"id\":\"1680\",\"type\":\"LegendItem\"}],\"root_ids\":[\"1724\"]},\"title\":\"Bokeh Application\",\"version\":\"1.3.4\"}};\n",
       "  var render_items = [{\"docid\":\"3f620ef4-32e8-4b21-be38-bbef781a5bab\",\"roots\":{\"1724\":\"55a486aa-9b5a-4bc3-8958-341dcc223d09\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        embed_document(root);\n",
       "        clearInterval(timer);\n",
       "      }\n",
       "      attempts++;\n",
       "      if (attempts > 100) {\n",
       "        console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        clearInterval(timer);\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1724"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "parp.viewEventHistogram(fid=0, ncol=2, backend='bokeh')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Rearrange file by the numbering using regular expression pattern matching (optional step)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "from time import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 3/3 [01:16<00:00, 25.55s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Binning took about 76 s.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "tstart = time()\n",
    "parp.parallelBinning(axes=axes, nbins=bins, ranges=ranges, scheduler='threads', \\\n",
    "                     binning_kwds={'jittered':True}, ret=False)\n",
    "tend = time()\n",
    "print('Binning took about {} s.'.format(int(tend - tstart)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'binned': array([[[0., 0., 0., ..., 0., 0., 0.],\n",
       "         [0., 0., 0., ..., 0., 0., 0.],\n",
       "         [0., 0., 0., ..., 0., 0., 0.],\n",
       "         ...,\n",
       "         [0., 0., 0., ..., 0., 0., 0.],\n",
       "         [0., 0., 0., ..., 0., 0., 0.],\n",
       "         [0., 0., 0., ..., 0., 0., 0.]],\n",
       " \n",
       "        [[0., 0., 0., ..., 0., 0., 0.],\n",
       "         [0., 0., 0., ..., 0., 0., 0.],\n",
       "         [0., 0., 0., ..., 0., 0., 0.],\n",
       "         ...,\n",
       "         [0., 0., 0., ..., 0., 0., 0.],\n",
       "         [0., 0., 0., ..., 0., 0., 0.],\n",
       "         [0., 0., 0., ..., 0., 0., 0.]],\n",
       " \n",
       "        [[0., 0., 0., ..., 0., 0., 0.],\n",
       "         [0., 0., 0., ..., 0., 0., 0.],\n",
       "         [0., 0., 0., ..., 0., 0., 0.],\n",
       "         ...,\n",
       "         [0., 0., 0., ..., 0., 0., 0.],\n",
       "         [0., 0., 0., ..., 0., 0., 0.],\n",
       "         [0., 0., 0., ..., 0., 0., 0.]],\n",
       " \n",
       "        ...,\n",
       " \n",
       "        [[0., 0., 0., ..., 0., 0., 0.],\n",
       "         [0., 0., 0., ..., 0., 0., 1.],\n",
       "         [0., 0., 0., ..., 0., 0., 0.],\n",
       "         ...,\n",
       "         [0., 0., 0., ..., 0., 0., 0.],\n",
       "         [0., 0., 0., ..., 0., 0., 0.],\n",
       "         [0., 0., 0., ..., 0., 0., 0.]],\n",
       " \n",
       "        [[0., 0., 0., ..., 0., 0., 0.],\n",
       "         [0., 0., 0., ..., 0., 0., 0.],\n",
       "         [0., 0., 0., ..., 0., 0., 0.],\n",
       "         ...,\n",
       "         [0., 0., 0., ..., 0., 0., 0.],\n",
       "         [0., 0., 0., ..., 0., 0., 0.],\n",
       "         [0., 0., 0., ..., 0., 0., 0.]],\n",
       " \n",
       "        [[0., 0., 0., ..., 0., 0., 0.],\n",
       "         [0., 0., 0., ..., 0., 0., 0.],\n",
       "         [0., 0., 0., ..., 0., 0., 0.],\n",
       "         ...,\n",
       "         [0., 0., 0., ..., 0., 1., 0.],\n",
       "         [0., 0., 0., ..., 0., 0., 0.],\n",
       "         [0., 0., 0., ..., 0., 0., 0.]]]),\n",
       " 'X': array([ 307.5,  322.5,  337.5,  352.5,  367.5,  382.5,  397.5,  412.5,\n",
       "         427.5,  442.5,  457.5,  472.5,  487.5,  502.5,  517.5,  532.5,\n",
       "         547.5,  562.5,  577.5,  592.5,  607.5,  622.5,  637.5,  652.5,\n",
       "         667.5,  682.5,  697.5,  712.5,  727.5,  742.5,  757.5,  772.5,\n",
       "         787.5,  802.5,  817.5,  832.5,  847.5,  862.5,  877.5,  892.5,\n",
       "         907.5,  922.5,  937.5,  952.5,  967.5,  982.5,  997.5, 1012.5,\n",
       "        1027.5, 1042.5, 1057.5, 1072.5, 1087.5, 1102.5, 1117.5, 1132.5,\n",
       "        1147.5, 1162.5, 1177.5, 1192.5, 1207.5, 1222.5, 1237.5, 1252.5,\n",
       "        1267.5, 1282.5, 1297.5, 1312.5, 1327.5, 1342.5, 1357.5, 1372.5,\n",
       "        1387.5, 1402.5, 1417.5, 1432.5, 1447.5, 1462.5, 1477.5, 1492.5,\n",
       "        1507.5, 1522.5, 1537.5, 1552.5, 1567.5, 1582.5, 1597.5, 1612.5,\n",
       "        1627.5, 1642.5, 1657.5, 1672.5, 1687.5, 1702.5, 1717.5, 1732.5,\n",
       "        1747.5, 1762.5, 1777.5, 1792.5]),\n",
       " 'Y': array([ 208.,  224.,  240.,  256.,  272.,  288.,  304.,  320.,  336.,\n",
       "         352.,  368.,  384.,  400.,  416.,  432.,  448.,  464.,  480.,\n",
       "         496.,  512.,  528.,  544.,  560.,  576.,  592.,  608.,  624.,\n",
       "         640.,  656.,  672.,  688.,  704.,  720.,  736.,  752.,  768.,\n",
       "         784.,  800.,  816.,  832.,  848.,  864.,  880.,  896.,  912.,\n",
       "         928.,  944.,  960.,  976.,  992., 1008., 1024., 1040., 1056.,\n",
       "        1072., 1088., 1104., 1120., 1136., 1152., 1168., 1184., 1200.,\n",
       "        1216., 1232., 1248., 1264., 1280., 1296., 1312., 1328., 1344.,\n",
       "        1360., 1376., 1392., 1408., 1424., 1440., 1456., 1472., 1488.,\n",
       "        1504., 1520., 1536., 1552., 1568., 1584., 1600., 1616., 1632.,\n",
       "        1648., 1664., 1680., 1696., 1712., 1728., 1744., 1760., 1776.,\n",
       "        1792.]),\n",
       " 't': array([68055., 68165., 68275., 68385., 68495., 68605., 68715., 68825.,\n",
       "        68935., 69045., 69155., 69265., 69375., 69485., 69595., 69705.,\n",
       "        69815., 69925., 70035., 70145., 70255., 70365., 70475., 70585.,\n",
       "        70695., 70805., 70915., 71025., 71135., 71245., 71355., 71465.,\n",
       "        71575., 71685., 71795., 71905., 72015., 72125., 72235., 72345.,\n",
       "        72455., 72565., 72675., 72785., 72895., 73005., 73115., 73225.,\n",
       "        73335., 73445., 73555., 73665., 73775., 73885., 73995., 74105.,\n",
       "        74215., 74325., 74435., 74545., 74655., 74765., 74875., 74985.,\n",
       "        75095., 75205., 75315., 75425., 75535., 75645., 75755., 75865.,\n",
       "        75975., 76085., 76195., 76305., 76415., 76525., 76635., 76745.,\n",
       "        76855., 76965., 77075., 77185., 77295., 77405., 77515., 77625.,\n",
       "        77735., 77845., 77955., 78065., 78175., 78285., 78395., 78505.,\n",
       "        78615., 78725., 78835., 78945., 79055., 79165., 79275., 79385.,\n",
       "        79495., 79605., 79715., 79825., 79935., 80045., 80155., 80265.,\n",
       "        80375., 80485., 80595., 80705., 80815., 80925., 81035., 81145.,\n",
       "        81255., 81365., 81475., 81585., 81695., 81805., 81915., 82025.,\n",
       "        82135., 82245., 82355., 82465., 82575., 82685., 82795., 82905.,\n",
       "        83015., 83125., 83235., 83345., 83455., 83565., 83675., 83785.,\n",
       "        83895., 84005., 84115., 84225., 84335., 84445., 84555., 84665.,\n",
       "        84775., 84885., 84995., 85105., 85215., 85325., 85435., 85545.,\n",
       "        85655., 85765., 85875., 85985., 86095., 86205., 86315., 86425.,\n",
       "        86535., 86645., 86755., 86865., 86975., 87085., 87195., 87305.,\n",
       "        87415., 87525., 87635., 87745., 87855., 87965., 88075., 88185.,\n",
       "        88295., 88405., 88515., 88625., 88735., 88845., 88955., 89065.,\n",
       "        89175., 89285., 89395., 89505., 89615., 89725., 89835., 89945.])}"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "parp.combinedresult"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "parp.saveHistogram(form='h5', save_addr='./parbin_result')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 2.2.3 Binning of selected events (within a single file)\n",
    "Example using decay of WSe2 band structure"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [],
   "source": [
    "fpath = r'../data/data_20180605_114.h5'\n",
    "hp = fp.hdf5Processor(fpath)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [],
   "source": [
    "axes = ['t']\n",
    "bins = [200]\n",
    "ranges = [(68000, 90000)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [],
   "source": [
    "hp.localBinning(axes=axes, nbins=bins, ranges=ranges, amin=0, amax=10000, ret=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x7f0a806e4c50>]"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 19816 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(hp.histdict['binned'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 2.2.4 Binning files by the portion (from a collection of files)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "splits_folder = r'../data/data_114_parts'\n",
    "parp = fp.parallelHDF5Processor(folder=splits_folder)\n",
    "parp.gather(identifier=r'/data*.h5', file_sorting=True)\n",
    "portion = 10\n",
    "npart = parp.nfiles // portion"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 1/1 [00:15<00:00, 15.16s/it]\n",
      "100%|██████████| 1/1 [00:14<00:00, 14.45s/it]\n",
      "100%|██████████| 1/1 [00:14<00:00, 14.24s/it]\n",
      "100%|██████████| 1/1 [00:14<00:00, 14.65s/it]\n",
      "100%|██████████| 1/1 [00:14<00:00, 14.83s/it]\n"
     ]
    }
   ],
   "source": [
    "for i in range(0, npart):\n",
    "    parp.gather(identifier=r'/data*.h5', f_start=i*portion, f_end=(i+1)*portion, f_step=1, file_sorting=True)\n",
    "    parp.parallelBinning(axes=axes, nbins=bins, ranges=ranges, scheduler='threads', combine=True,\n",
    "                         binning_kwds={'jittered':True}, ret=False)\n",
    "    # parp.saveHistogram(...) # For saving results (see example earlier in this notebook)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.3 Plotting the binning results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 2466848 characters]\n",
      "text/plain": [
       "<Figure size 1440x2880 with 200 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "vis.sliceview3d(parp.combinedresult['binned'], axis=2, ncol=10, colormap='terrain_r');"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.4 Update the binning results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(100, 100, 200)"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "parp.combinedresult['binned'].shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "parp.updateHistogram(axes=['X','Y'], sliceranges=[(0, 80), (10, 90)])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(80, 80, 200)"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "parp.combinedresult['binned'].shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.5 Saving the binning results\n",
    "Save the histogram and axes in HDF5 (h5), Matlab (mat), image (only histogram) such as tiff (3D/4D) or png (2D slices of 3D) formats."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "hp.saveHistogram(save_addr='../binres_114', form='h5', dtyp='float32')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "hp.saveHistogram(save_addr='../binres_114', form='mat', mat_compression=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "hp.saveHistogram(save_addr='../binres_114', form='tiff', dtyp='float32')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "hp.saveHistogram(save_addr='../binres_114', form='png', cutaxis=2)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
