Created
September 30, 2020 18:21
-
-
Save shoyer/6d6c82bbf383fb717cc8631869678737 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 14, | |
"metadata": { | |
"id": "pRDJrkjEC3Re" | |
}, | |
"outputs": [], | |
"source": [ | |
"# Copyright 2020 Google LLC.\n", | |
"# SPDX-License-Identifier: Apache-2.0\n", | |
"\n", | |
"import numpy as np\n", | |
"import pandas as pd\n", | |
"import xarray\n", | |
"import numpy_groupies\n", | |
"\n", | |
"def _binned_agg(\n", | |
" array: np.ndarray,\n", | |
" indices: np.ndarray,\n", | |
" num_bins: int,\n", | |
" *,\n", | |
" func,\n", | |
" fill_value,\n", | |
" dtype,\n", | |
") -> np.ndarray:\n", | |
" \"\"\"NumPy helper function for aggregating over bins.\"\"\"\n", | |
" mask = np.logical_not(np.isnan(indices))\n", | |
" int_indices = indices[mask].astype(int)\n", | |
" shape = array.shape[:-indices.ndim] + (num_bins,)\n", | |
" result = numpy_groupies.aggregate(\n", | |
" int_indices, array[..., mask],\n", | |
" func=func,\n", | |
" size=num_bins,\n", | |
" fill_value=fill_value,\n", | |
" dtype=dtype,\n", | |
" axis=-1,\n", | |
" )\n", | |
" return result\n", | |
"\n", | |
"def groupby_bins_agg(\n", | |
" array: xarray.DataArray,\n", | |
" group: xarray.DataArray,\n", | |
" bins,\n", | |
" func='sum',\n", | |
" fill_value=0,\n", | |
" dtype=None,\n", | |
" **cut_kwargs,\n", | |
") -> xarray.DataArray:\n", | |
" \"\"\"Faster equivalent of Xarray's groupby_bins(...).sum().\"\"\"\n", | |
" # TODO: implement this upstream in xarray:\n", | |
" # https://github.com/pydata/xarray/issues/4473\n", | |
" binned = pd.cut(np.ravel(group), bins, **cut_kwargs)\n", | |
" new_dim_name = group.name + \"_bins\"\n", | |
" indices = group.copy(data=binned.codes.reshape(group.shape))\n", | |
"\n", | |
" result = xarray.apply_ufunc(\n", | |
" _binned_agg, array, indices,\n", | |
" input_core_dims=[indices.dims, indices.dims],\n", | |
" output_core_dims=[[new_dim_name]],\n", | |
" output_dtypes=[array.dtype],\n", | |
" dask_gufunc_kwargs=dict(\n", | |
" output_sizes={new_dim_name: binned.categories.size},\n", | |
" ),\n", | |
" kwargs={\n", | |
" 'num_bins': binned.categories.size,\n", | |
" 'func': func,\n", | |
" 'fill_value': fill_value,\n", | |
" 'dtype': dtype,\n", | |
" },\n", | |
" dask='parallelized',\n", | |
" )\n", | |
" result.coords[new_dim_name] = binned.categories\n", | |
" return result\n", | |
"\n", | |
"def make_test_data(t, x, y, seed=0):\n", | |
" signal = xarray.DataArray(\n", | |
" np.random.RandomState(seed).rand(t, x, y),\n", | |
" dims=['time', 'y', 'x'],\n", | |
" coords={\n", | |
" 'time': np.arange(t),\n", | |
" 'y': np.arange(x),\n", | |
" 'x': np.arange(y),\n", | |
" },\n", | |
" name='signal')\n", | |
" distance = ((signal.x ** 2 + signal.y ** 2) ** 0.5).rename('distance')\n", | |
" return signal, distance" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "r0Jp6XRmIoNU" | |
}, | |
"source": [ | |
"# unit test" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 25, | |
"metadata": { | |
"id": "Qa6NH3WGEFyC" | |
}, | |
"outputs": [], | |
"source": [ | |
"signal, distance = make_test_data(t=2, x=50, y=50)\n", | |
"bins = 10" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 29, | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 219 | |
}, | |
"id": "hz1ikpo3Ik-j", | |
"outputId": "f88ae860-c056-424c-94b4-c52608951631" | |
}, | |
"outputs": [], | |
"source": [ | |
"actual = groupby_bins_agg(signal, distance, bins, func='mean')\n", | |
"expected = signal.groupby_bins(distance, bins=10).mean()\n", | |
"xarray.testing.assert_allclose(actual, expected)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 30, | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 219 | |
}, | |
"id": "6FIRcPRzImDV", | |
"outputId": "dc0741f1-44b4-437c-b577-d8e4785c54b8" | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div><svg style=\"position: absolute; width: 0; height: 0; overflow: hidden\">\n", | |
"<defs>\n", | |
"<symbol id=\"icon-database\" viewBox=\"0 0 32 32\">\n", | |
"<path d=\"M16 0c-8.837 0-16 2.239-16 5v4c0 2.761 7.163 5 16 5s16-2.239 16-5v-4c0-2.761-7.163-5-16-5z\"></path>\n", | |
"<path d=\"M16 17c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n", | |
"<path d=\"M16 26c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n", | |
"</symbol>\n", | |
"<symbol id=\"icon-file-text2\" viewBox=\"0 0 32 32\">\n", | |
"<path d=\"M28.681 7.159c-0.694-0.947-1.662-2.053-2.724-3.116s-2.169-2.030-3.116-2.724c-1.612-1.182-2.393-1.319-2.841-1.319h-15.5c-1.378 0-2.5 1.121-2.5 2.5v27c0 1.378 1.122 2.5 2.5 2.5h23c1.378 0 2.5-1.122 2.5-2.5v-19.5c0-0.448-0.137-1.23-1.319-2.841zM24.543 5.457c0.959 0.959 1.712 1.825 2.268 2.543h-4.811v-4.811c0.718 0.556 1.584 1.309 2.543 2.268zM28 29.5c0 0.271-0.229 0.5-0.5 0.5h-23c-0.271 0-0.5-0.229-0.5-0.5v-27c0-0.271 0.229-0.5 0.5-0.5 0 0 15.499-0 15.5 0v7c0 0.552 0.448 1 1 1h7v19.5z\"></path>\n", | |
"<path d=\"M23 26h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n", | |
"<path d=\"M23 22h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n", | |
"<path d=\"M23 18h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n", | |
"</symbol>\n", | |
"</defs>\n", | |
"</svg>\n", | |
"<style>/* CSS stylesheet for displaying xarray objects in jupyterlab.\n", | |
" *\n", | |
" */\n", | |
"\n", | |
":root {\n", | |
" --xr-font-color0: var(--jp-content-font-color0, rgba(0, 0, 0, 1));\n", | |
" --xr-font-color2: var(--jp-content-font-color2, rgba(0, 0, 0, 0.54));\n", | |
" --xr-font-color3: var(--jp-content-font-color3, rgba(0, 0, 0, 0.38));\n", | |
" --xr-border-color: var(--jp-border-color2, #e0e0e0);\n", | |
" --xr-disabled-color: var(--jp-layout-color3, #bdbdbd);\n", | |
" --xr-background-color: var(--jp-layout-color0, white);\n", | |
" --xr-background-color-row-even: var(--jp-layout-color1, white);\n", | |
" --xr-background-color-row-odd: var(--jp-layout-color2, #eeeeee);\n", | |
"}\n", | |
"\n", | |
"html[theme=dark],\n", | |
"body.vscode-dark {\n", | |
" --xr-font-color0: rgba(255, 255, 255, 1);\n", | |
" --xr-font-color2: rgba(255, 255, 255, 0.54);\n", | |
" --xr-font-color3: rgba(255, 255, 255, 0.38);\n", | |
" --xr-border-color: #1F1F1F;\n", | |
" --xr-disabled-color: #515151;\n", | |
" --xr-background-color: #111111;\n", | |
" --xr-background-color-row-even: #111111;\n", | |
" --xr-background-color-row-odd: #313131;\n", | |
"}\n", | |
"\n", | |
".xr-wrap {\n", | |
" display: block;\n", | |
" min-width: 300px;\n", | |
" max-width: 700px;\n", | |
"}\n", | |
"\n", | |
".xr-text-repr-fallback {\n", | |
" /* fallback to plain text repr when CSS is not injected (untrusted notebook) */\n", | |
" display: none;\n", | |
"}\n", | |
"\n", | |
".xr-header {\n", | |
" padding-top: 6px;\n", | |
" padding-bottom: 6px;\n", | |
" margin-bottom: 4px;\n", | |
" border-bottom: solid 1px var(--xr-border-color);\n", | |
"}\n", | |
"\n", | |
".xr-header > div,\n", | |
".xr-header > ul {\n", | |
" display: inline;\n", | |
" margin-top: 0;\n", | |
" margin-bottom: 0;\n", | |
"}\n", | |
"\n", | |
".xr-obj-type,\n", | |
".xr-array-name {\n", | |
" margin-left: 2px;\n", | |
" margin-right: 10px;\n", | |
"}\n", | |
"\n", | |
".xr-obj-type {\n", | |
" color: var(--xr-font-color2);\n", | |
"}\n", | |
"\n", | |
".xr-sections {\n", | |
" padding-left: 0 !important;\n", | |
" display: grid;\n", | |
" grid-template-columns: 150px auto auto 1fr 20px 20px;\n", | |
"}\n", | |
"\n", | |
".xr-section-item {\n", | |
" display: contents;\n", | |
"}\n", | |
"\n", | |
".xr-section-item input {\n", | |
" display: none;\n", | |
"}\n", | |
"\n", | |
".xr-section-item input + label {\n", | |
" color: var(--xr-disabled-color);\n", | |
"}\n", | |
"\n", | |
".xr-section-item input:enabled + label {\n", | |
" cursor: pointer;\n", | |
" color: var(--xr-font-color2);\n", | |
"}\n", | |
"\n", | |
".xr-section-item input:enabled + label:hover {\n", | |
" color: var(--xr-font-color0);\n", | |
"}\n", | |
"\n", | |
".xr-section-summary {\n", | |
" grid-column: 1;\n", | |
" color: var(--xr-font-color2);\n", | |
" font-weight: 500;\n", | |
"}\n", | |
"\n", | |
".xr-section-summary > span {\n", | |
" display: inline-block;\n", | |
" padding-left: 0.5em;\n", | |
"}\n", | |
"\n", | |
".xr-section-summary-in:disabled + label {\n", | |
" color: var(--xr-font-color2);\n", | |
"}\n", | |
"\n", | |
".xr-section-summary-in + label:before {\n", | |
" display: inline-block;\n", | |
" content: '►';\n", | |
" font-size: 11px;\n", | |
" width: 15px;\n", | |
" text-align: center;\n", | |
"}\n", | |
"\n", | |
".xr-section-summary-in:disabled + label:before {\n", | |
" color: var(--xr-disabled-color);\n", | |
"}\n", | |
"\n", | |
".xr-section-summary-in:checked + label:before {\n", | |
" content: '▼';\n", | |
"}\n", | |
"\n", | |
".xr-section-summary-in:checked + label > span {\n", | |
" display: none;\n", | |
"}\n", | |
"\n", | |
".xr-section-summary,\n", | |
".xr-section-inline-details {\n", | |
" padding-top: 4px;\n", | |
" padding-bottom: 4px;\n", | |
"}\n", | |
"\n", | |
".xr-section-inline-details {\n", | |
" grid-column: 2 / -1;\n", | |
"}\n", | |
"\n", | |
".xr-section-details {\n", | |
" display: none;\n", | |
" grid-column: 1 / -1;\n", | |
" margin-bottom: 5px;\n", | |
"}\n", | |
"\n", | |
".xr-section-summary-in:checked ~ .xr-section-details {\n", | |
" display: contents;\n", | |
"}\n", | |
"\n", | |
".xr-array-wrap {\n", | |
" grid-column: 1 / -1;\n", | |
" display: grid;\n", | |
" grid-template-columns: 20px auto;\n", | |
"}\n", | |
"\n", | |
".xr-array-wrap > label {\n", | |
" grid-column: 1;\n", | |
" vertical-align: top;\n", | |
"}\n", | |
"\n", | |
".xr-preview {\n", | |
" color: var(--xr-font-color3);\n", | |
"}\n", | |
"\n", | |
".xr-array-preview,\n", | |
".xr-array-data {\n", | |
" padding: 0 5px !important;\n", | |
" grid-column: 2;\n", | |
"}\n", | |
"\n", | |
".xr-array-data,\n", | |
".xr-array-in:checked ~ .xr-array-preview {\n", | |
" display: none;\n", | |
"}\n", | |
"\n", | |
".xr-array-in:checked ~ .xr-array-data,\n", | |
".xr-array-preview {\n", | |
" display: inline-block;\n", | |
"}\n", | |
"\n", | |
".xr-dim-list {\n", | |
" display: inline-block !important;\n", | |
" list-style: none;\n", | |
" padding: 0 !important;\n", | |
" margin: 0;\n", | |
"}\n", | |
"\n", | |
".xr-dim-list li {\n", | |
" display: inline-block;\n", | |
" padding: 0;\n", | |
" margin: 0;\n", | |
"}\n", | |
"\n", | |
".xr-dim-list:before {\n", | |
" content: '(';\n", | |
"}\n", | |
"\n", | |
".xr-dim-list:after {\n", | |
" content: ')';\n", | |
"}\n", | |
"\n", | |
".xr-dim-list li:not(:last-child):after {\n", | |
" content: ',';\n", | |
" padding-right: 5px;\n", | |
"}\n", | |
"\n", | |
".xr-has-index {\n", | |
" font-weight: bold;\n", | |
"}\n", | |
"\n", | |
".xr-var-list,\n", | |
".xr-var-item {\n", | |
" display: contents;\n", | |
"}\n", | |
"\n", | |
".xr-var-item > div,\n", | |
".xr-var-item label,\n", | |
".xr-var-item > .xr-var-name span {\n", | |
" background-color: var(--xr-background-color-row-even);\n", | |
" margin-bottom: 0;\n", | |
"}\n", | |
"\n", | |
".xr-var-item > .xr-var-name:hover span {\n", | |
" padding-right: 5px;\n", | |
"}\n", | |
"\n", | |
".xr-var-list > li:nth-child(odd) > div,\n", | |
".xr-var-list > li:nth-child(odd) > label,\n", | |
".xr-var-list > li:nth-child(odd) > .xr-var-name span {\n", | |
" background-color: var(--xr-background-color-row-odd);\n", | |
"}\n", | |
"\n", | |
".xr-var-name {\n", | |
" grid-column: 1;\n", | |
"}\n", | |
"\n", | |
".xr-var-dims {\n", | |
" grid-column: 2;\n", | |
"}\n", | |
"\n", | |
".xr-var-dtype {\n", | |
" grid-column: 3;\n", | |
" text-align: right;\n", | |
" color: var(--xr-font-color2);\n", | |
"}\n", | |
"\n", | |
".xr-var-preview {\n", | |
" grid-column: 4;\n", | |
"}\n", | |
"\n", | |
".xr-var-name,\n", | |
".xr-var-dims,\n", | |
".xr-var-dtype,\n", | |
".xr-preview,\n", | |
".xr-attrs dt {\n", | |
" white-space: nowrap;\n", | |
" overflow: hidden;\n", | |
" text-overflow: ellipsis;\n", | |
" padding-right: 10px;\n", | |
"}\n", | |
"\n", | |
".xr-var-name:hover,\n", | |
".xr-var-dims:hover,\n", | |
".xr-var-dtype:hover,\n", | |
".xr-attrs dt:hover {\n", | |
" overflow: visible;\n", | |
" width: auto;\n", | |
" z-index: 1;\n", | |
"}\n", | |
"\n", | |
".xr-var-attrs,\n", | |
".xr-var-data {\n", | |
" display: none;\n", | |
" background-color: var(--xr-background-color) !important;\n", | |
" padding-bottom: 5px !important;\n", | |
"}\n", | |
"\n", | |
".xr-var-attrs-in:checked ~ .xr-var-attrs,\n", | |
".xr-var-data-in:checked ~ .xr-var-data {\n", | |
" display: block;\n", | |
"}\n", | |
"\n", | |
".xr-var-data > table {\n", | |
" float: right;\n", | |
"}\n", | |
"\n", | |
".xr-var-name span,\n", | |
".xr-var-data,\n", | |
".xr-attrs {\n", | |
" padding-left: 25px !important;\n", | |
"}\n", | |
"\n", | |
".xr-attrs,\n", | |
".xr-var-attrs,\n", | |
".xr-var-data {\n", | |
" grid-column: 1 / -1;\n", | |
"}\n", | |
"\n", | |
"dl.xr-attrs {\n", | |
" padding: 0;\n", | |
" margin: 0;\n", | |
" display: grid;\n", | |
" grid-template-columns: 125px auto;\n", | |
"}\n", | |
"\n", | |
".xr-attrs dt, dd {\n", | |
" padding: 0;\n", | |
" margin: 0;\n", | |
" float: left;\n", | |
" padding-right: 10px;\n", | |
" width: auto;\n", | |
"}\n", | |
"\n", | |
".xr-attrs dt {\n", | |
" font-weight: normal;\n", | |
" grid-column: 1;\n", | |
"}\n", | |
"\n", | |
".xr-attrs dt:hover span {\n", | |
" display: inline-block;\n", | |
" background: var(--xr-background-color);\n", | |
" padding-right: 10px;\n", | |
"}\n", | |
"\n", | |
".xr-attrs dd {\n", | |
" grid-column: 2;\n", | |
" white-space: pre-wrap;\n", | |
" word-break: break-all;\n", | |
"}\n", | |
"\n", | |
".xr-icon-database,\n", | |
".xr-icon-file-text2 {\n", | |
" display: inline-block;\n", | |
" vertical-align: middle;\n", | |
" width: 1em;\n", | |
" height: 1.5em !important;\n", | |
" stroke-width: 0;\n", | |
" stroke: currentColor;\n", | |
" fill: currentColor;\n", | |
"}\n", | |
"</style><pre class='xr-text-repr-fallback'><xarray.DataArray (time: 2, distance_bins: 10)>\n", | |
"array([[0.51498271, 0.46370372, 0.48996133, 0.51069211, 0.5302821 ,\n", | |
" 0.50000696, 0.48753868, 0.52151072, 0.48915714, 0.51292164],\n", | |
" [0.53229943, 0.52167522, 0.45915308, 0.5293949 , 0.47742068,\n", | |
" 0.48900111, 0.48465034, 0.47729889, 0.5059115 , 0.50237199]])\n", | |
"Coordinates:\n", | |
" * time (time) int64 0 1\n", | |
" * distance_bins (distance_bins) object (-0.0693, 6.93] ... (62.367, 69.296]</pre><div class='xr-wrap' hidden><div class='xr-header'><div class='xr-obj-type'>xarray.DataArray</div><div class='xr-array-name'></div><ul class='xr-dim-list'><li><span class='xr-has-index'>time</span>: 2</li><li><span class='xr-has-index'>distance_bins</span>: 10</li></ul></div><ul class='xr-sections'><li class='xr-section-item'><div class='xr-array-wrap'><input id='section-5a1ec1d2-af31-4586-a084-270660896406' class='xr-array-in' type='checkbox' checked><label for='section-5a1ec1d2-af31-4586-a084-270660896406' title='Show/hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-array-preview xr-preview'><span>0.515 0.4637 0.49 0.5107 0.5303 ... 0.489 0.4847 0.4773 0.5059 0.5024</span></div><div class='xr-array-data'><pre>array([[0.51498271, 0.46370372, 0.48996133, 0.51069211, 0.5302821 ,\n", | |
" 0.50000696, 0.48753868, 0.52151072, 0.48915714, 0.51292164],\n", | |
" [0.53229943, 0.52167522, 0.45915308, 0.5293949 , 0.47742068,\n", | |
" 0.48900111, 0.48465034, 0.47729889, 0.5059115 , 0.50237199]])</pre></div></div></li><li class='xr-section-item'><input id='section-879f3941-9725-4ac0-9687-71059b7110b7' class='xr-section-summary-in' type='checkbox' checked><label for='section-879f3941-9725-4ac0-9687-71059b7110b7' class='xr-section-summary' >Coordinates: <span>(2)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>time</span></div><div class='xr-var-dims'>(time)</div><div class='xr-var-dtype'>int64</div><div class='xr-var-preview xr-preview'>0 1</div><input id='attrs-e960390c-489e-4a09-add3-4aea5f8b93a9' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-e960390c-489e-4a09-add3-4aea5f8b93a9' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-c552075e-15c9-440a-b3b2-9ea25112fa6d' class='xr-var-data-in' type='checkbox'><label for='data-c552075e-15c9-440a-b3b2-9ea25112fa6d' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([0, 1])</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>distance_bins</span></div><div class='xr-var-dims'>(distance_bins)</div><div class='xr-var-dtype'>object</div><div class='xr-var-preview xr-preview'>(-0.0693, 6.93] ... (62.367, 69....</div><input id='attrs-393b3da5-fccf-47df-a8f3-5ca6c71d2413' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-393b3da5-fccf-47df-a8f3-5ca6c71d2413' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-41f2f687-1deb-4da3-976f-2c8bd1d80e2e' class='xr-var-data-in' type='checkbox'><label for='data-41f2f687-1deb-4da3-976f-2c8bd1d80e2e' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([Interval(-0.0693, 6.93, closed='right'),\n", | |
" Interval(6.93, 13.859, closed='right'),\n", | |
" Interval(13.859, 20.789, closed='right'),\n", | |
" Interval(20.789, 27.719, closed='right'),\n", | |
" Interval(27.719, 34.648, closed='right'),\n", | |
" Interval(34.648, 41.578, closed='right'),\n", | |
" Interval(41.578, 48.508, closed='right'),\n", | |
" Interval(48.508, 55.437, closed='right'),\n", | |
" Interval(55.437, 62.367, closed='right'),\n", | |
" Interval(62.367, 69.296, closed='right')], dtype=object)</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-b8935a87-0ab2-458c-866d-f20825843947' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-b8935a87-0ab2-458c-866d-f20825843947' class='xr-section-summary' title='Expand/collapse section'>Attributes: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'></dl></div></li></ul></div></div>" | |
], | |
"text/plain": [ | |
"<xarray.DataArray (time: 2, distance_bins: 10)>\n", | |
"array([[0.51498271, 0.46370372, 0.48996133, 0.51069211, 0.5302821 ,\n", | |
" 0.50000696, 0.48753868, 0.52151072, 0.48915714, 0.51292164],\n", | |
" [0.53229943, 0.52167522, 0.45915308, 0.5293949 , 0.47742068,\n", | |
" 0.48900111, 0.48465034, 0.47729889, 0.5059115 , 0.50237199]])\n", | |
"Coordinates:\n", | |
" * time (time) int64 0 1\n", | |
" * distance_bins (distance_bins) object (-0.0693, 6.93] ... (62.367, 69.296]" | |
] | |
}, | |
"execution_count": 30, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"actual" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "FP84FGufIrJV" | |
}, | |
"source": [ | |
"# Speed tests" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 57, | |
"metadata": { | |
"id": "AoEU13x4IqzO" | |
}, | |
"outputs": [], | |
"source": [ | |
"signal, distance = make_test_data(t=20, x=1000, y=1000)\n", | |
"bins = 50" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 58, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"160.0" | |
] | |
}, | |
"execution_count": 58, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"signal.nbytes / 1e6" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "OpDWpcNcJpG_" | |
}, | |
"source": [ | |
"## numpy speed test" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 60, | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "ya0e9MVDE5NS", | |
"outputId": "21a7dbc0-0692-4e8f-98f9-f1e1dd1252b9" | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"CPU times: user 8.52 s, sys: 674 ms, total: 9.19 s\n", | |
"Wall time: 10.3 s\n" | |
] | |
} | |
], | |
"source": [ | |
"%time _ = signal.groupby_bins(distance, bins).mean()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 61, | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "-ywMYaSCGaYl", | |
"outputId": "e5e61066-6819-40b9-a061-74badb248001" | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"CPU times: user 909 ms, sys: 290 ms, total: 1.2 s\n", | |
"Wall time: 1.3 s\n" | |
] | |
} | |
], | |
"source": [ | |
"%time _ = groupby_bins_agg(signal, distance, bins, func='mean')" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "Fzrbi2JQJqjH" | |
}, | |
"source": [ | |
"## dask speed test" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 77, | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "uJkGMSk_JCcU", | |
"outputId": "15989c46-55dc-45db-a24b-159fff0b3f12" | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div><svg style=\"position: absolute; width: 0; height: 0; overflow: hidden\">\n", | |
"<defs>\n", | |
"<symbol id=\"icon-database\" viewBox=\"0 0 32 32\">\n", | |
"<path d=\"M16 0c-8.837 0-16 2.239-16 5v4c0 2.761 7.163 5 16 5s16-2.239 16-5v-4c0-2.761-7.163-5-16-5z\"></path>\n", | |
"<path d=\"M16 17c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n", | |
"<path d=\"M16 26c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n", | |
"</symbol>\n", | |
"<symbol id=\"icon-file-text2\" viewBox=\"0 0 32 32\">\n", | |
"<path d=\"M28.681 7.159c-0.694-0.947-1.662-2.053-2.724-3.116s-2.169-2.030-3.116-2.724c-1.612-1.182-2.393-1.319-2.841-1.319h-15.5c-1.378 0-2.5 1.121-2.5 2.5v27c0 1.378 1.122 2.5 2.5 2.5h23c1.378 0 2.5-1.122 2.5-2.5v-19.5c0-0.448-0.137-1.23-1.319-2.841zM24.543 5.457c0.959 0.959 1.712 1.825 2.268 2.543h-4.811v-4.811c0.718 0.556 1.584 1.309 2.543 2.268zM28 29.5c0 0.271-0.229 0.5-0.5 0.5h-23c-0.271 0-0.5-0.229-0.5-0.5v-27c0-0.271 0.229-0.5 0.5-0.5 0 0 15.499-0 15.5 0v7c0 0.552 0.448 1 1 1h7v19.5z\"></path>\n", | |
"<path d=\"M23 26h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n", | |
"<path d=\"M23 22h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n", | |
"<path d=\"M23 18h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n", | |
"</symbol>\n", | |
"</defs>\n", | |
"</svg>\n", | |
"<style>/* CSS stylesheet for displaying xarray objects in jupyterlab.\n", | |
" *\n", | |
" */\n", | |
"\n", | |
":root {\n", | |
" --xr-font-color0: var(--jp-content-font-color0, rgba(0, 0, 0, 1));\n", | |
" --xr-font-color2: var(--jp-content-font-color2, rgba(0, 0, 0, 0.54));\n", | |
" --xr-font-color3: var(--jp-content-font-color3, rgba(0, 0, 0, 0.38));\n", | |
" --xr-border-color: var(--jp-border-color2, #e0e0e0);\n", | |
" --xr-disabled-color: var(--jp-layout-color3, #bdbdbd);\n", | |
" --xr-background-color: var(--jp-layout-color0, white);\n", | |
" --xr-background-color-row-even: var(--jp-layout-color1, white);\n", | |
" --xr-background-color-row-odd: var(--jp-layout-color2, #eeeeee);\n", | |
"}\n", | |
"\n", | |
"html[theme=dark],\n", | |
"body.vscode-dark {\n", | |
" --xr-font-color0: rgba(255, 255, 255, 1);\n", | |
" --xr-font-color2: rgba(255, 255, 255, 0.54);\n", | |
" --xr-font-color3: rgba(255, 255, 255, 0.38);\n", | |
" --xr-border-color: #1F1F1F;\n", | |
" --xr-disabled-color: #515151;\n", | |
" --xr-background-color: #111111;\n", | |
" --xr-background-color-row-even: #111111;\n", | |
" --xr-background-color-row-odd: #313131;\n", | |
"}\n", | |
"\n", | |
".xr-wrap {\n", | |
" display: block;\n", | |
" min-width: 300px;\n", | |
" max-width: 700px;\n", | |
"}\n", | |
"\n", | |
".xr-text-repr-fallback {\n", | |
" /* fallback to plain text repr when CSS is not injected (untrusted notebook) */\n", | |
" display: none;\n", | |
"}\n", | |
"\n", | |
".xr-header {\n", | |
" padding-top: 6px;\n", | |
" padding-bottom: 6px;\n", | |
" margin-bottom: 4px;\n", | |
" border-bottom: solid 1px var(--xr-border-color);\n", | |
"}\n", | |
"\n", | |
".xr-header > div,\n", | |
".xr-header > ul {\n", | |
" display: inline;\n", | |
" margin-top: 0;\n", | |
" margin-bottom: 0;\n", | |
"}\n", | |
"\n", | |
".xr-obj-type,\n", | |
".xr-array-name {\n", | |
" margin-left: 2px;\n", | |
" margin-right: 10px;\n", | |
"}\n", | |
"\n", | |
".xr-obj-type {\n", | |
" color: var(--xr-font-color2);\n", | |
"}\n", | |
"\n", | |
".xr-sections {\n", | |
" padding-left: 0 !important;\n", | |
" display: grid;\n", | |
" grid-template-columns: 150px auto auto 1fr 20px 20px;\n", | |
"}\n", | |
"\n", | |
".xr-section-item {\n", | |
" display: contents;\n", | |
"}\n", | |
"\n", | |
".xr-section-item input {\n", | |
" display: none;\n", | |
"}\n", | |
"\n", | |
".xr-section-item input + label {\n", | |
" color: var(--xr-disabled-color);\n", | |
"}\n", | |
"\n", | |
".xr-section-item input:enabled + label {\n", | |
" cursor: pointer;\n", | |
" color: var(--xr-font-color2);\n", | |
"}\n", | |
"\n", | |
".xr-section-item input:enabled + label:hover {\n", | |
" color: var(--xr-font-color0);\n", | |
"}\n", | |
"\n", | |
".xr-section-summary {\n", | |
" grid-column: 1;\n", | |
" color: var(--xr-font-color2);\n", | |
" font-weight: 500;\n", | |
"}\n", | |
"\n", | |
".xr-section-summary > span {\n", | |
" display: inline-block;\n", | |
" padding-left: 0.5em;\n", | |
"}\n", | |
"\n", | |
".xr-section-summary-in:disabled + label {\n", | |
" color: var(--xr-font-color2);\n", | |
"}\n", | |
"\n", | |
".xr-section-summary-in + label:before {\n", | |
" display: inline-block;\n", | |
" content: '►';\n", | |
" font-size: 11px;\n", | |
" width: 15px;\n", | |
" text-align: center;\n", | |
"}\n", | |
"\n", | |
".xr-section-summary-in:disabled + label:before {\n", | |
" color: var(--xr-disabled-color);\n", | |
"}\n", | |
"\n", | |
".xr-section-summary-in:checked + label:before {\n", | |
" content: '▼';\n", | |
"}\n", | |
"\n", | |
".xr-section-summary-in:checked + label > span {\n", | |
" display: none;\n", | |
"}\n", | |
"\n", | |
".xr-section-summary,\n", | |
".xr-section-inline-details {\n", | |
" padding-top: 4px;\n", | |
" padding-bottom: 4px;\n", | |
"}\n", | |
"\n", | |
".xr-section-inline-details {\n", | |
" grid-column: 2 / -1;\n", | |
"}\n", | |
"\n", | |
".xr-section-details {\n", | |
" display: none;\n", | |
" grid-column: 1 / -1;\n", | |
" margin-bottom: 5px;\n", | |
"}\n", | |
"\n", | |
".xr-section-summary-in:checked ~ .xr-section-details {\n", | |
" display: contents;\n", | |
"}\n", | |
"\n", | |
".xr-array-wrap {\n", | |
" grid-column: 1 / -1;\n", | |
" display: grid;\n", | |
" grid-template-columns: 20px auto;\n", | |
"}\n", | |
"\n", | |
".xr-array-wrap > label {\n", | |
" grid-column: 1;\n", | |
" vertical-align: top;\n", | |
"}\n", | |
"\n", | |
".xr-preview {\n", | |
" color: var(--xr-font-color3);\n", | |
"}\n", | |
"\n", | |
".xr-array-preview,\n", | |
".xr-array-data {\n", | |
" padding: 0 5px !important;\n", | |
" grid-column: 2;\n", | |
"}\n", | |
"\n", | |
".xr-array-data,\n", | |
".xr-array-in:checked ~ .xr-array-preview {\n", | |
" display: none;\n", | |
"}\n", | |
"\n", | |
".xr-array-in:checked ~ .xr-array-data,\n", | |
".xr-array-preview {\n", | |
" display: inline-block;\n", | |
"}\n", | |
"\n", | |
".xr-dim-list {\n", | |
" display: inline-block !important;\n", | |
" list-style: none;\n", | |
" padding: 0 !important;\n", | |
" margin: 0;\n", | |
"}\n", | |
"\n", | |
".xr-dim-list li {\n", | |
" display: inline-block;\n", | |
" padding: 0;\n", | |
" margin: 0;\n", | |
"}\n", | |
"\n", | |
".xr-dim-list:before {\n", | |
" content: '(';\n", | |
"}\n", | |
"\n", | |
".xr-dim-list:after {\n", | |
" content: ')';\n", | |
"}\n", | |
"\n", | |
".xr-dim-list li:not(:last-child):after {\n", | |
" content: ',';\n", | |
" padding-right: 5px;\n", | |
"}\n", | |
"\n", | |
".xr-has-index {\n", | |
" font-weight: bold;\n", | |
"}\n", | |
"\n", | |
".xr-var-list,\n", | |
".xr-var-item {\n", | |
" display: contents;\n", | |
"}\n", | |
"\n", | |
".xr-var-item > div,\n", | |
".xr-var-item label,\n", | |
".xr-var-item > .xr-var-name span {\n", | |
" background-color: var(--xr-background-color-row-even);\n", | |
" margin-bottom: 0;\n", | |
"}\n", | |
"\n", | |
".xr-var-item > .xr-var-name:hover span {\n", | |
" padding-right: 5px;\n", | |
"}\n", | |
"\n", | |
".xr-var-list > li:nth-child(odd) > div,\n", | |
".xr-var-list > li:nth-child(odd) > label,\n", | |
".xr-var-list > li:nth-child(odd) > .xr-var-name span {\n", | |
" background-color: var(--xr-background-color-row-odd);\n", | |
"}\n", | |
"\n", | |
".xr-var-name {\n", | |
" grid-column: 1;\n", | |
"}\n", | |
"\n", | |
".xr-var-dims {\n", | |
" grid-column: 2;\n", | |
"}\n", | |
"\n", | |
".xr-var-dtype {\n", | |
" grid-column: 3;\n", | |
" text-align: right;\n", | |
" color: var(--xr-font-color2);\n", | |
"}\n", | |
"\n", | |
".xr-var-preview {\n", | |
" grid-column: 4;\n", | |
"}\n", | |
"\n", | |
".xr-var-name,\n", | |
".xr-var-dims,\n", | |
".xr-var-dtype,\n", | |
".xr-preview,\n", | |
".xr-attrs dt {\n", | |
" white-space: nowrap;\n", | |
" overflow: hidden;\n", | |
" text-overflow: ellipsis;\n", | |
" padding-right: 10px;\n", | |
"}\n", | |
"\n", | |
".xr-var-name:hover,\n", | |
".xr-var-dims:hover,\n", | |
".xr-var-dtype:hover,\n", | |
".xr-attrs dt:hover {\n", | |
" overflow: visible;\n", | |
" width: auto;\n", | |
" z-index: 1;\n", | |
"}\n", | |
"\n", | |
".xr-var-attrs,\n", | |
".xr-var-data {\n", | |
" display: none;\n", | |
" background-color: var(--xr-background-color) !important;\n", | |
" padding-bottom: 5px !important;\n", | |
"}\n", | |
"\n", | |
".xr-var-attrs-in:checked ~ .xr-var-attrs,\n", | |
".xr-var-data-in:checked ~ .xr-var-data {\n", | |
" display: block;\n", | |
"}\n", | |
"\n", | |
".xr-var-data > table {\n", | |
" float: right;\n", | |
"}\n", | |
"\n", | |
".xr-var-name span,\n", | |
".xr-var-data,\n", | |
".xr-attrs {\n", | |
" padding-left: 25px !important;\n", | |
"}\n", | |
"\n", | |
".xr-attrs,\n", | |
".xr-var-attrs,\n", | |
".xr-var-data {\n", | |
" grid-column: 1 / -1;\n", | |
"}\n", | |
"\n", | |
"dl.xr-attrs {\n", | |
" padding: 0;\n", | |
" margin: 0;\n", | |
" display: grid;\n", | |
" grid-template-columns: 125px auto;\n", | |
"}\n", | |
"\n", | |
".xr-attrs dt, dd {\n", | |
" padding: 0;\n", | |
" margin: 0;\n", | |
" float: left;\n", | |
" padding-right: 10px;\n", | |
" width: auto;\n", | |
"}\n", | |
"\n", | |
".xr-attrs dt {\n", | |
" font-weight: normal;\n", | |
" grid-column: 1;\n", | |
"}\n", | |
"\n", | |
".xr-attrs dt:hover span {\n", | |
" display: inline-block;\n", | |
" background: var(--xr-background-color);\n", | |
" padding-right: 10px;\n", | |
"}\n", | |
"\n", | |
".xr-attrs dd {\n", | |
" grid-column: 2;\n", | |
" white-space: pre-wrap;\n", | |
" word-break: break-all;\n", | |
"}\n", | |
"\n", | |
".xr-icon-database,\n", | |
".xr-icon-file-text2 {\n", | |
" display: inline-block;\n", | |
" vertical-align: middle;\n", | |
" width: 1em;\n", | |
" height: 1.5em !important;\n", | |
" stroke-width: 0;\n", | |
" stroke: currentColor;\n", | |
" fill: currentColor;\n", | |
"}\n", | |
"</style><pre class='xr-text-repr-fallback'><xarray.DataArray 'signal' (time: 20, y: 1000, x: 1000)>\n", | |
"dask.array<xarray-<this-array>, shape=(20, 1000, 1000), dtype=float64, chunksize=(1, 1000, 1000), chunktype=numpy.ndarray>\n", | |
"Coordinates:\n", | |
" * time (time) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19\n", | |
" * y (y) int64 0 1 2 3 4 5 6 7 8 ... 991 992 993 994 995 996 997 998 999\n", | |
" * x (x) int64 0 1 2 3 4 5 6 7 8 ... 991 992 993 994 995 996 997 998 999</pre><div class='xr-wrap' hidden><div class='xr-header'><div class='xr-obj-type'>xarray.DataArray</div><div class='xr-array-name'>'signal'</div><ul class='xr-dim-list'><li><span class='xr-has-index'>time</span>: 20</li><li><span class='xr-has-index'>y</span>: 1000</li><li><span class='xr-has-index'>x</span>: 1000</li></ul></div><ul class='xr-sections'><li class='xr-section-item'><div class='xr-array-wrap'><input id='section-b21f31c5-7528-4ab1-8376-90a23a97c42b' class='xr-array-in' type='checkbox' checked><label for='section-b21f31c5-7528-4ab1-8376-90a23a97c42b' title='Show/hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-array-preview xr-preview'><span>dask.array<chunksize=(1, 1000, 1000), meta=np.ndarray></span></div><div class='xr-array-data'><table>\n", | |
"<tr>\n", | |
"<td>\n", | |
"<table>\n", | |
" <thead>\n", | |
" <tr><td> </td><th> Array </th><th> Chunk </th></tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr><th> Bytes </th><td> 160.00 MB </td> <td> 8.00 MB </td></tr>\n", | |
" <tr><th> Shape </th><td> (20, 1000, 1000) </td> <td> (1, 1000, 1000) </td></tr>\n", | |
" <tr><th> Count </th><td> 20 Tasks </td><td> 20 Chunks </td></tr>\n", | |
" <tr><th> Type </th><td> float64 </td><td> numpy.ndarray </td></tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</td>\n", | |
"<td>\n", | |
"<svg width=\"197\" height=\"187\" style=\"stroke:rgb(0,0,0);stroke-width:1\" >\n", | |
"\n", | |
" <!-- Horizontal lines -->\n", | |
" <line x1=\"10\" y1=\"0\" x2=\"27\" y2=\"17\" style=\"stroke-width:2\" />\n", | |
" <line x1=\"10\" y1=\"120\" x2=\"27\" y2=\"137\" style=\"stroke-width:2\" />\n", | |
"\n", | |
" <!-- Vertical lines -->\n", | |
" <line x1=\"10\" y1=\"0\" x2=\"10\" y2=\"120\" style=\"stroke-width:2\" />\n", | |
" <line x1=\"10\" y1=\"0\" x2=\"10\" y2=\"120\" />\n", | |
" <line x1=\"11\" y1=\"1\" x2=\"11\" y2=\"121\" />\n", | |
" <line x1=\"12\" y1=\"2\" x2=\"12\" y2=\"122\" />\n", | |
" <line x1=\"13\" y1=\"3\" x2=\"13\" y2=\"123\" />\n", | |
" <line x1=\"14\" y1=\"4\" x2=\"14\" y2=\"124\" />\n", | |
" <line x1=\"15\" y1=\"5\" x2=\"15\" y2=\"125\" />\n", | |
" <line x1=\"15\" y1=\"5\" x2=\"15\" y2=\"125\" />\n", | |
" <line x1=\"16\" y1=\"6\" x2=\"16\" y2=\"126\" />\n", | |
" <line x1=\"17\" y1=\"7\" x2=\"17\" y2=\"127\" />\n", | |
" <line x1=\"18\" y1=\"8\" x2=\"18\" y2=\"128\" />\n", | |
" <line x1=\"19\" y1=\"9\" x2=\"19\" y2=\"129\" />\n", | |
" <line x1=\"20\" y1=\"10\" x2=\"20\" y2=\"130\" />\n", | |
" <line x1=\"21\" y1=\"11\" x2=\"21\" y2=\"131\" />\n", | |
" <line x1=\"21\" y1=\"11\" x2=\"21\" y2=\"131\" />\n", | |
" <line x1=\"22\" y1=\"12\" x2=\"22\" y2=\"132\" />\n", | |
" <line x1=\"23\" y1=\"13\" x2=\"23\" y2=\"133\" />\n", | |
" <line x1=\"24\" y1=\"14\" x2=\"24\" y2=\"134\" />\n", | |
" <line x1=\"25\" y1=\"15\" x2=\"25\" y2=\"135\" />\n", | |
" <line x1=\"26\" y1=\"16\" x2=\"26\" y2=\"136\" />\n", | |
" <line x1=\"27\" y1=\"17\" x2=\"27\" y2=\"137\" style=\"stroke-width:2\" />\n", | |
"\n", | |
" <!-- Colored Rectangle -->\n", | |
" <polygon points=\"10.000000,0.000000 27.076841,17.076841 27.076841,137.076841 10.000000,120.000000\" style=\"fill:#ECB172A0;stroke-width:0\"/>\n", | |
"\n", | |
" <!-- Horizontal lines -->\n", | |
" <line x1=\"10\" y1=\"0\" x2=\"130\" y2=\"0\" style=\"stroke-width:2\" />\n", | |
" <line x1=\"10\" y1=\"0\" x2=\"130\" y2=\"0\" />\n", | |
" <line x1=\"11\" y1=\"1\" x2=\"131\" y2=\"1\" />\n", | |
" <line x1=\"12\" y1=\"2\" x2=\"132\" y2=\"2\" />\n", | |
" <line x1=\"13\" y1=\"3\" x2=\"133\" y2=\"3\" />\n", | |
" <line x1=\"14\" y1=\"4\" x2=\"134\" y2=\"4\" />\n", | |
" <line x1=\"15\" y1=\"5\" x2=\"135\" y2=\"5\" />\n", | |
" <line x1=\"15\" y1=\"5\" x2=\"135\" y2=\"5\" />\n", | |
" <line x1=\"16\" y1=\"6\" x2=\"136\" y2=\"6\" />\n", | |
" <line x1=\"17\" y1=\"7\" x2=\"137\" y2=\"7\" />\n", | |
" <line x1=\"18\" y1=\"8\" x2=\"138\" y2=\"8\" />\n", | |
" <line x1=\"19\" y1=\"9\" x2=\"139\" y2=\"9\" />\n", | |
" <line x1=\"20\" y1=\"10\" x2=\"140\" y2=\"10\" />\n", | |
" <line x1=\"21\" y1=\"11\" x2=\"141\" y2=\"11\" />\n", | |
" <line x1=\"21\" y1=\"11\" x2=\"141\" y2=\"11\" />\n", | |
" <line x1=\"22\" y1=\"12\" x2=\"142\" y2=\"12\" />\n", | |
" <line x1=\"23\" y1=\"13\" x2=\"143\" y2=\"13\" />\n", | |
" <line x1=\"24\" y1=\"14\" x2=\"144\" y2=\"14\" />\n", | |
" <line x1=\"25\" y1=\"15\" x2=\"145\" y2=\"15\" />\n", | |
" <line x1=\"26\" y1=\"16\" x2=\"146\" y2=\"16\" />\n", | |
" <line x1=\"27\" y1=\"17\" x2=\"147\" y2=\"17\" style=\"stroke-width:2\" />\n", | |
"\n", | |
" <!-- Vertical lines -->\n", | |
" <line x1=\"10\" y1=\"0\" x2=\"27\" y2=\"17\" style=\"stroke-width:2\" />\n", | |
" <line x1=\"130\" y1=\"0\" x2=\"147\" y2=\"17\" style=\"stroke-width:2\" />\n", | |
"\n", | |
" <!-- Colored Rectangle -->\n", | |
" <polygon points=\"10.000000,0.000000 130.000000,0.000000 147.076841,17.076841 27.076841,17.076841\" style=\"fill:#ECB172A0;stroke-width:0\"/>\n", | |
"\n", | |
" <!-- Horizontal lines -->\n", | |
" <line x1=\"27\" y1=\"17\" x2=\"147\" y2=\"17\" style=\"stroke-width:2\" />\n", | |
" <line x1=\"27\" y1=\"137\" x2=\"147\" y2=\"137\" style=\"stroke-width:2\" />\n", | |
"\n", | |
" <!-- Vertical lines -->\n", | |
" <line x1=\"27\" y1=\"17\" x2=\"27\" y2=\"137\" style=\"stroke-width:2\" />\n", | |
" <line x1=\"147\" y1=\"17\" x2=\"147\" y2=\"137\" style=\"stroke-width:2\" />\n", | |
"\n", | |
" <!-- Colored Rectangle -->\n", | |
" <polygon points=\"27.076841,17.076841 147.076841,17.076841 147.076841,137.076841 27.076841,137.076841\" style=\"fill:#ECB172A0;stroke-width:0\"/>\n", | |
"\n", | |
" <!-- Text -->\n", | |
" <text x=\"87.076841\" y=\"157.076841\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" >1000</text>\n", | |
" <text x=\"167.076841\" y=\"77.076841\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" transform=\"rotate(-90,167.076841,77.076841)\">1000</text>\n", | |
" <text x=\"8.538420\" y=\"148.538420\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" transform=\"rotate(45,8.538420,148.538420)\">20</text>\n", | |
"</svg>\n", | |
"</td>\n", | |
"</tr>\n", | |
"</table></div></div></li><li class='xr-section-item'><input id='section-627c500e-5b3c-4232-8161-42b550651a17' class='xr-section-summary-in' type='checkbox' checked><label for='section-627c500e-5b3c-4232-8161-42b550651a17' class='xr-section-summary' >Coordinates: <span>(3)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>time</span></div><div class='xr-var-dims'>(time)</div><div class='xr-var-dtype'>int64</div><div class='xr-var-preview xr-preview'>0 1 2 3 4 5 6 ... 14 15 16 17 18 19</div><input id='attrs-ac8436a2-d7cf-4e86-99f3-797c12e0bfaf' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-ac8436a2-d7cf-4e86-99f3-797c12e0bfaf' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-e16c40d3-360d-4463-a955-4730ddbeabec' class='xr-var-data-in' type='checkbox'><label for='data-e16c40d3-360d-4463-a955-4730ddbeabec' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,\n", | |
" 18, 19])</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>y</span></div><div class='xr-var-dims'>(y)</div><div class='xr-var-dtype'>int64</div><div class='xr-var-preview xr-preview'>0 1 2 3 4 5 ... 995 996 997 998 999</div><input id='attrs-256049c9-f9a9-4eae-9d19-1435d60bd3a6' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-256049c9-f9a9-4eae-9d19-1435d60bd3a6' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-e2cdc7bb-16d2-4830-802f-e2ad6a0c952f' class='xr-var-data-in' type='checkbox'><label for='data-e2cdc7bb-16d2-4830-802f-e2ad6a0c952f' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([ 0, 1, 2, ..., 997, 998, 999])</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>x</span></div><div class='xr-var-dims'>(x)</div><div class='xr-var-dtype'>int64</div><div class='xr-var-preview xr-preview'>0 1 2 3 4 5 ... 995 996 997 998 999</div><input id='attrs-dd3cb2c2-dce6-4901-985d-5bab68078a19' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-dd3cb2c2-dce6-4901-985d-5bab68078a19' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-6a638f93-8013-4ec4-8321-69a13104ac75' class='xr-var-data-in' type='checkbox'><label for='data-6a638f93-8013-4ec4-8321-69a13104ac75' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([ 0, 1, 2, ..., 997, 998, 999])</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-9aa2aa82-f09d-43e5-add1-195302cf4199' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-9aa2aa82-f09d-43e5-add1-195302cf4199' class='xr-section-summary' title='Expand/collapse section'>Attributes: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'></dl></div></li></ul></div></div>" | |
], | |
"text/plain": [ | |
"<xarray.DataArray 'signal' (time: 20, y: 1000, x: 1000)>\n", | |
"dask.array<xarray-<this-array>, shape=(20, 1000, 1000), dtype=float64, chunksize=(1, 1000, 1000), chunktype=numpy.ndarray>\n", | |
"Coordinates:\n", | |
" * time (time) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19\n", | |
" * y (y) int64 0 1 2 3 4 5 6 7 8 ... 991 992 993 994 995 996 997 998 999\n", | |
" * x (x) int64 0 1 2 3 4 5 6 7 8 ... 991 992 993 994 995 996 997 998 999" | |
] | |
}, | |
"execution_count": 77, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"import dask\n", | |
"dask_signal = signal.chunk({'time': 1})\n", | |
"dask.config.set(num_workers=4)\n", | |
"dask_signal" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 85, | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "Ibm73W1IJXmE", | |
"outputId": "287be907-ec7d-4f77-de0e-c60043c1087f" | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"CPU times: user 8.13 s, sys: 365 ms, total: 8.49 s\n", | |
"Wall time: 8.87 s\n", | |
"CPU times: user 1.12 s, sys: 332 ms, total: 1.45 s\n", | |
"Wall time: 967 ms\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/html": [ | |
"<div><svg style=\"position: absolute; width: 0; height: 0; overflow: hidden\">\n", | |
"<defs>\n", | |
"<symbol id=\"icon-database\" viewBox=\"0 0 32 32\">\n", | |
"<path d=\"M16 0c-8.837 0-16 2.239-16 5v4c0 2.761 7.163 5 16 5s16-2.239 16-5v-4c0-2.761-7.163-5-16-5z\"></path>\n", | |
"<path d=\"M16 17c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n", | |
"<path d=\"M16 26c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n", | |
"</symbol>\n", | |
"<symbol id=\"icon-file-text2\" viewBox=\"0 0 32 32\">\n", | |
"<path d=\"M28.681 7.159c-0.694-0.947-1.662-2.053-2.724-3.116s-2.169-2.030-3.116-2.724c-1.612-1.182-2.393-1.319-2.841-1.319h-15.5c-1.378 0-2.5 1.121-2.5 2.5v27c0 1.378 1.122 2.5 2.5 2.5h23c1.378 0 2.5-1.122 2.5-2.5v-19.5c0-0.448-0.137-1.23-1.319-2.841zM24.543 5.457c0.959 0.959 1.712 1.825 2.268 2.543h-4.811v-4.811c0.718 0.556 1.584 1.309 2.543 2.268zM28 29.5c0 0.271-0.229 0.5-0.5 0.5h-23c-0.271 0-0.5-0.229-0.5-0.5v-27c0-0.271 0.229-0.5 0.5-0.5 0 0 15.499-0 15.5 0v7c0 0.552 0.448 1 1 1h7v19.5z\"></path>\n", | |
"<path d=\"M23 26h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n", | |
"<path d=\"M23 22h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n", | |
"<path d=\"M23 18h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n", | |
"</symbol>\n", | |
"</defs>\n", | |
"</svg>\n", | |
"<style>/* CSS stylesheet for displaying xarray objects in jupyterlab.\n", | |
" *\n", | |
" */\n", | |
"\n", | |
":root {\n", | |
" --xr-font-color0: var(--jp-content-font-color0, rgba(0, 0, 0, 1));\n", | |
" --xr-font-color2: var(--jp-content-font-color2, rgba(0, 0, 0, 0.54));\n", | |
" --xr-font-color3: var(--jp-content-font-color3, rgba(0, 0, 0, 0.38));\n", | |
" --xr-border-color: var(--jp-border-color2, #e0e0e0);\n", | |
" --xr-disabled-color: var(--jp-layout-color3, #bdbdbd);\n", | |
" --xr-background-color: var(--jp-layout-color0, white);\n", | |
" --xr-background-color-row-even: var(--jp-layout-color1, white);\n", | |
" --xr-background-color-row-odd: var(--jp-layout-color2, #eeeeee);\n", | |
"}\n", | |
"\n", | |
"html[theme=dark],\n", | |
"body.vscode-dark {\n", | |
" --xr-font-color0: rgba(255, 255, 255, 1);\n", | |
" --xr-font-color2: rgba(255, 255, 255, 0.54);\n", | |
" --xr-font-color3: rgba(255, 255, 255, 0.38);\n", | |
" --xr-border-color: #1F1F1F;\n", | |
" --xr-disabled-color: #515151;\n", | |
" --xr-background-color: #111111;\n", | |
" --xr-background-color-row-even: #111111;\n", | |
" --xr-background-color-row-odd: #313131;\n", | |
"}\n", | |
"\n", | |
".xr-wrap {\n", | |
" display: block;\n", | |
" min-width: 300px;\n", | |
" max-width: 700px;\n", | |
"}\n", | |
"\n", | |
".xr-text-repr-fallback {\n", | |
" /* fallback to plain text repr when CSS is not injected (untrusted notebook) */\n", | |
" display: none;\n", | |
"}\n", | |
"\n", | |
".xr-header {\n", | |
" padding-top: 6px;\n", | |
" padding-bottom: 6px;\n", | |
" margin-bottom: 4px;\n", | |
" border-bottom: solid 1px var(--xr-border-color);\n", | |
"}\n", | |
"\n", | |
".xr-header > div,\n", | |
".xr-header > ul {\n", | |
" display: inline;\n", | |
" margin-top: 0;\n", | |
" margin-bottom: 0;\n", | |
"}\n", | |
"\n", | |
".xr-obj-type,\n", | |
".xr-array-name {\n", | |
" margin-left: 2px;\n", | |
" margin-right: 10px;\n", | |
"}\n", | |
"\n", | |
".xr-obj-type {\n", | |
" color: var(--xr-font-color2);\n", | |
"}\n", | |
"\n", | |
".xr-sections {\n", | |
" padding-left: 0 !important;\n", | |
" display: grid;\n", | |
" grid-template-columns: 150px auto auto 1fr 20px 20px;\n", | |
"}\n", | |
"\n", | |
".xr-section-item {\n", | |
" display: contents;\n", | |
"}\n", | |
"\n", | |
".xr-section-item input {\n", | |
" display: none;\n", | |
"}\n", | |
"\n", | |
".xr-section-item input + label {\n", | |
" color: var(--xr-disabled-color);\n", | |
"}\n", | |
"\n", | |
".xr-section-item input:enabled + label {\n", | |
" cursor: pointer;\n", | |
" color: var(--xr-font-color2);\n", | |
"}\n", | |
"\n", | |
".xr-section-item input:enabled + label:hover {\n", | |
" color: var(--xr-font-color0);\n", | |
"}\n", | |
"\n", | |
".xr-section-summary {\n", | |
" grid-column: 1;\n", | |
" color: var(--xr-font-color2);\n", | |
" font-weight: 500;\n", | |
"}\n", | |
"\n", | |
".xr-section-summary > span {\n", | |
" display: inline-block;\n", | |
" padding-left: 0.5em;\n", | |
"}\n", | |
"\n", | |
".xr-section-summary-in:disabled + label {\n", | |
" color: var(--xr-font-color2);\n", | |
"}\n", | |
"\n", | |
".xr-section-summary-in + label:before {\n", | |
" display: inline-block;\n", | |
" content: '►';\n", | |
" font-size: 11px;\n", | |
" width: 15px;\n", | |
" text-align: center;\n", | |
"}\n", | |
"\n", | |
".xr-section-summary-in:disabled + label:before {\n", | |
" color: var(--xr-disabled-color);\n", | |
"}\n", | |
"\n", | |
".xr-section-summary-in:checked + label:before {\n", | |
" content: '▼';\n", | |
"}\n", | |
"\n", | |
".xr-section-summary-in:checked + label > span {\n", | |
" display: none;\n", | |
"}\n", | |
"\n", | |
".xr-section-summary,\n", | |
".xr-section-inline-details {\n", | |
" padding-top: 4px;\n", | |
" padding-bottom: 4px;\n", | |
"}\n", | |
"\n", | |
".xr-section-inline-details {\n", | |
" grid-column: 2 / -1;\n", | |
"}\n", | |
"\n", | |
".xr-section-details {\n", | |
" display: none;\n", | |
" grid-column: 1 / -1;\n", | |
" margin-bottom: 5px;\n", | |
"}\n", | |
"\n", | |
".xr-section-summary-in:checked ~ .xr-section-details {\n", | |
" display: contents;\n", | |
"}\n", | |
"\n", | |
".xr-array-wrap {\n", | |
" grid-column: 1 / -1;\n", | |
" display: grid;\n", | |
" grid-template-columns: 20px auto;\n", | |
"}\n", | |
"\n", | |
".xr-array-wrap > label {\n", | |
" grid-column: 1;\n", | |
" vertical-align: top;\n", | |
"}\n", | |
"\n", | |
".xr-preview {\n", | |
" color: var(--xr-font-color3);\n", | |
"}\n", | |
"\n", | |
".xr-array-preview,\n", | |
".xr-array-data {\n", | |
" padding: 0 5px !important;\n", | |
" grid-column: 2;\n", | |
"}\n", | |
"\n", | |
".xr-array-data,\n", | |
".xr-array-in:checked ~ .xr-array-preview {\n", | |
" display: none;\n", | |
"}\n", | |
"\n", | |
".xr-array-in:checked ~ .xr-array-data,\n", | |
".xr-array-preview {\n", | |
" display: inline-block;\n", | |
"}\n", | |
"\n", | |
".xr-dim-list {\n", | |
" display: inline-block !important;\n", | |
" list-style: none;\n", | |
" padding: 0 !important;\n", | |
" margin: 0;\n", | |
"}\n", | |
"\n", | |
".xr-dim-list li {\n", | |
" display: inline-block;\n", | |
" padding: 0;\n", | |
" margin: 0;\n", | |
"}\n", | |
"\n", | |
".xr-dim-list:before {\n", | |
" content: '(';\n", | |
"}\n", | |
"\n", | |
".xr-dim-list:after {\n", | |
" content: ')';\n", | |
"}\n", | |
"\n", | |
".xr-dim-list li:not(:last-child):after {\n", | |
" content: ',';\n", | |
" padding-right: 5px;\n", | |
"}\n", | |
"\n", | |
".xr-has-index {\n", | |
" font-weight: bold;\n", | |
"}\n", | |
"\n", | |
".xr-var-list,\n", | |
".xr-var-item {\n", | |
" display: contents;\n", | |
"}\n", | |
"\n", | |
".xr-var-item > div,\n", | |
".xr-var-item label,\n", | |
".xr-var-item > .xr-var-name span {\n", | |
" background-color: var(--xr-background-color-row-even);\n", | |
" margin-bottom: 0;\n", | |
"}\n", | |
"\n", | |
".xr-var-item > .xr-var-name:hover span {\n", | |
" padding-right: 5px;\n", | |
"}\n", | |
"\n", | |
".xr-var-list > li:nth-child(odd) > div,\n", | |
".xr-var-list > li:nth-child(odd) > label,\n", | |
".xr-var-list > li:nth-child(odd) > .xr-var-name span {\n", | |
" background-color: var(--xr-background-color-row-odd);\n", | |
"}\n", | |
"\n", | |
".xr-var-name {\n", | |
" grid-column: 1;\n", | |
"}\n", | |
"\n", | |
".xr-var-dims {\n", | |
" grid-column: 2;\n", | |
"}\n", | |
"\n", | |
".xr-var-dtype {\n", | |
" grid-column: 3;\n", | |
" text-align: right;\n", | |
" color: var(--xr-font-color2);\n", | |
"}\n", | |
"\n", | |
".xr-var-preview {\n", | |
" grid-column: 4;\n", | |
"}\n", | |
"\n", | |
".xr-var-name,\n", | |
".xr-var-dims,\n", | |
".xr-var-dtype,\n", | |
".xr-preview,\n", | |
".xr-attrs dt {\n", | |
" white-space: nowrap;\n", | |
" overflow: hidden;\n", | |
" text-overflow: ellipsis;\n", | |
" padding-right: 10px;\n", | |
"}\n", | |
"\n", | |
".xr-var-name:hover,\n", | |
".xr-var-dims:hover,\n", | |
".xr-var-dtype:hover,\n", | |
".xr-attrs dt:hover {\n", | |
" overflow: visible;\n", | |
" width: auto;\n", | |
" z-index: 1;\n", | |
"}\n", | |
"\n", | |
".xr-var-attrs,\n", | |
".xr-var-data {\n", | |
" display: none;\n", | |
" background-color: var(--xr-background-color) !important;\n", | |
" padding-bottom: 5px !important;\n", | |
"}\n", | |
"\n", | |
".xr-var-attrs-in:checked ~ .xr-var-attrs,\n", | |
".xr-var-data-in:checked ~ .xr-var-data {\n", | |
" display: block;\n", | |
"}\n", | |
"\n", | |
".xr-var-data > table {\n", | |
" float: right;\n", | |
"}\n", | |
"\n", | |
".xr-var-name span,\n", | |
".xr-var-data,\n", | |
".xr-attrs {\n", | |
" padding-left: 25px !important;\n", | |
"}\n", | |
"\n", | |
".xr-attrs,\n", | |
".xr-var-attrs,\n", | |
".xr-var-data {\n", | |
" grid-column: 1 / -1;\n", | |
"}\n", | |
"\n", | |
"dl.xr-attrs {\n", | |
" padding: 0;\n", | |
" margin: 0;\n", | |
" display: grid;\n", | |
" grid-template-columns: 125px auto;\n", | |
"}\n", | |
"\n", | |
".xr-attrs dt, dd {\n", | |
" padding: 0;\n", | |
" margin: 0;\n", | |
" float: left;\n", | |
" padding-right: 10px;\n", | |
" width: auto;\n", | |
"}\n", | |
"\n", | |
".xr-attrs dt {\n", | |
" font-weight: normal;\n", | |
" grid-column: 1;\n", | |
"}\n", | |
"\n", | |
".xr-attrs dt:hover span {\n", | |
" display: inline-block;\n", | |
" background: var(--xr-background-color);\n", | |
" padding-right: 10px;\n", | |
"}\n", | |
"\n", | |
".xr-attrs dd {\n", | |
" grid-column: 2;\n", | |
" white-space: pre-wrap;\n", | |
" word-break: break-all;\n", | |
"}\n", | |
"\n", | |
".xr-icon-database,\n", | |
".xr-icon-file-text2 {\n", | |
" display: inline-block;\n", | |
" vertical-align: middle;\n", | |
" width: 1em;\n", | |
" height: 1.5em !important;\n", | |
" stroke-width: 0;\n", | |
" stroke: currentColor;\n", | |
" fill: currentColor;\n", | |
"}\n", | |
"</style><pre class='xr-text-repr-fallback'><xarray.DataArray 'signal' (time: 20, distance_bins: 50)>\n", | |
"dask.array<transpose, shape=(20, 50), dtype=float64, chunksize=(1, 1), chunktype=numpy.ndarray>\n", | |
"Coordinates:\n", | |
" * distance_bins (distance_bins) object (-1.413, 28.256] ... (1384.543, 141...\n", | |
" * time (time) int64 0 1 2 3 4 5 6 7 8 ... 11 12 13 14 15 16 17 18 19</pre><div class='xr-wrap' hidden><div class='xr-header'><div class='xr-obj-type'>xarray.DataArray</div><div class='xr-array-name'>'signal'</div><ul class='xr-dim-list'><li><span class='xr-has-index'>time</span>: 20</li><li><span class='xr-has-index'>distance_bins</span>: 50</li></ul></div><ul class='xr-sections'><li class='xr-section-item'><div class='xr-array-wrap'><input id='section-ea80e050-b2d9-49c1-87e3-b8ab7cee09cd' class='xr-array-in' type='checkbox' checked><label for='section-ea80e050-b2d9-49c1-87e3-b8ab7cee09cd' title='Show/hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-array-preview xr-preview'><span>dask.array<chunksize=(1, 1), meta=np.ndarray></span></div><div class='xr-array-data'><table>\n", | |
"<tr>\n", | |
"<td>\n", | |
"<table>\n", | |
" <thead>\n", | |
" <tr><td> </td><th> Array </th><th> Chunk </th></tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr><th> Bytes </th><td> 8.00 kB </td> <td> 8 B </td></tr>\n", | |
" <tr><th> Shape </th><td> (20, 50) </td> <td> (1, 1) </td></tr>\n", | |
" <tr><th> Count </th><td> 5060 Tasks </td><td> 1000 Chunks </td></tr>\n", | |
" <tr><th> Type </th><td> float64 </td><td> numpy.ndarray </td></tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</td>\n", | |
"<td>\n", | |
"<svg width=\"170\" height=\"98\" style=\"stroke:rgb(0,0,0);stroke-width:1\" >\n", | |
"\n", | |
" <!-- Horizontal lines -->\n", | |
" <line x1=\"0\" y1=\"0\" x2=\"120\" y2=\"0\" style=\"stroke-width:2\" />\n", | |
" <line x1=\"0\" y1=\"2\" x2=\"120\" y2=\"2\" />\n", | |
" <line x1=\"0\" y1=\"4\" x2=\"120\" y2=\"4\" />\n", | |
" <line x1=\"0\" y1=\"7\" x2=\"120\" y2=\"7\" />\n", | |
" <line x1=\"0\" y1=\"9\" x2=\"120\" y2=\"9\" />\n", | |
" <line x1=\"0\" y1=\"12\" x2=\"120\" y2=\"12\" />\n", | |
" <line x1=\"0\" y1=\"14\" x2=\"120\" y2=\"14\" />\n", | |
" <line x1=\"0\" y1=\"16\" x2=\"120\" y2=\"16\" />\n", | |
" <line x1=\"0\" y1=\"19\" x2=\"120\" y2=\"19\" />\n", | |
" <line x1=\"0\" y1=\"21\" x2=\"120\" y2=\"21\" />\n", | |
" <line x1=\"0\" y1=\"24\" x2=\"120\" y2=\"24\" />\n", | |
" <line x1=\"0\" y1=\"26\" x2=\"120\" y2=\"26\" />\n", | |
" <line x1=\"0\" y1=\"28\" x2=\"120\" y2=\"28\" />\n", | |
" <line x1=\"0\" y1=\"31\" x2=\"120\" y2=\"31\" />\n", | |
" <line x1=\"0\" y1=\"33\" x2=\"120\" y2=\"33\" />\n", | |
" <line x1=\"0\" y1=\"36\" x2=\"120\" y2=\"36\" />\n", | |
" <line x1=\"0\" y1=\"38\" x2=\"120\" y2=\"38\" />\n", | |
" <line x1=\"0\" y1=\"40\" x2=\"120\" y2=\"40\" />\n", | |
" <line x1=\"0\" y1=\"43\" x2=\"120\" y2=\"43\" />\n", | |
" <line x1=\"0\" y1=\"45\" x2=\"120\" y2=\"45\" />\n", | |
" <line x1=\"0\" y1=\"48\" x2=\"120\" y2=\"48\" style=\"stroke-width:2\" />\n", | |
"\n", | |
" <!-- Vertical lines -->\n", | |
" <line x1=\"0\" y1=\"0\" x2=\"0\" y2=\"48\" style=\"stroke-width:2\" />\n", | |
" <line x1=\"2\" y1=\"0\" x2=\"2\" y2=\"48\" />\n", | |
" <line x1=\"4\" y1=\"0\" x2=\"4\" y2=\"48\" />\n", | |
" <line x1=\"7\" y1=\"0\" x2=\"7\" y2=\"48\" />\n", | |
" <line x1=\"9\" y1=\"0\" x2=\"9\" y2=\"48\" />\n", | |
" <line x1=\"12\" y1=\"0\" x2=\"12\" y2=\"48\" />\n", | |
" <line x1=\"14\" y1=\"0\" x2=\"14\" y2=\"48\" />\n", | |
" <line x1=\"16\" y1=\"0\" x2=\"16\" y2=\"48\" />\n", | |
" <line x1=\"19\" y1=\"0\" x2=\"19\" y2=\"48\" />\n", | |
" <line x1=\"21\" y1=\"0\" x2=\"21\" y2=\"48\" />\n", | |
" <line x1=\"24\" y1=\"0\" x2=\"24\" y2=\"48\" />\n", | |
" <line x1=\"26\" y1=\"0\" x2=\"26\" y2=\"48\" />\n", | |
" <line x1=\"28\" y1=\"0\" x2=\"28\" y2=\"48\" />\n", | |
" <line x1=\"31\" y1=\"0\" x2=\"31\" y2=\"48\" />\n", | |
" <line x1=\"33\" y1=\"0\" x2=\"33\" y2=\"48\" />\n", | |
" <line x1=\"36\" y1=\"0\" x2=\"36\" y2=\"48\" />\n", | |
" <line x1=\"38\" y1=\"0\" x2=\"38\" y2=\"48\" />\n", | |
" <line x1=\"40\" y1=\"0\" x2=\"40\" y2=\"48\" />\n", | |
" <line x1=\"43\" y1=\"0\" x2=\"43\" y2=\"48\" />\n", | |
" <line x1=\"45\" y1=\"0\" x2=\"45\" y2=\"48\" />\n", | |
" <line x1=\"48\" y1=\"0\" x2=\"48\" y2=\"48\" />\n", | |
" <line x1=\"50\" y1=\"0\" x2=\"50\" y2=\"48\" />\n", | |
" <line x1=\"52\" y1=\"0\" x2=\"52\" y2=\"48\" />\n", | |
" <line x1=\"55\" y1=\"0\" x2=\"55\" y2=\"48\" />\n", | |
" <line x1=\"57\" y1=\"0\" x2=\"57\" y2=\"48\" />\n", | |
" <line x1=\"60\" y1=\"0\" x2=\"60\" y2=\"48\" />\n", | |
" <line x1=\"62\" y1=\"0\" x2=\"62\" y2=\"48\" />\n", | |
" <line x1=\"64\" y1=\"0\" x2=\"64\" y2=\"48\" />\n", | |
" <line x1=\"67\" y1=\"0\" x2=\"67\" y2=\"48\" />\n", | |
" <line x1=\"69\" y1=\"0\" x2=\"69\" y2=\"48\" />\n", | |
" <line x1=\"72\" y1=\"0\" x2=\"72\" y2=\"48\" />\n", | |
" <line x1=\"74\" y1=\"0\" x2=\"74\" y2=\"48\" />\n", | |
" <line x1=\"76\" y1=\"0\" x2=\"76\" y2=\"48\" />\n", | |
" <line x1=\"79\" y1=\"0\" x2=\"79\" y2=\"48\" />\n", | |
" <line x1=\"81\" y1=\"0\" x2=\"81\" y2=\"48\" />\n", | |
" <line x1=\"84\" y1=\"0\" x2=\"84\" y2=\"48\" />\n", | |
" <line x1=\"86\" y1=\"0\" x2=\"86\" y2=\"48\" />\n", | |
" <line x1=\"88\" y1=\"0\" x2=\"88\" y2=\"48\" />\n", | |
" <line x1=\"91\" y1=\"0\" x2=\"91\" y2=\"48\" />\n", | |
" <line x1=\"93\" y1=\"0\" x2=\"93\" y2=\"48\" />\n", | |
" <line x1=\"96\" y1=\"0\" x2=\"96\" y2=\"48\" />\n", | |
" <line x1=\"98\" y1=\"0\" x2=\"98\" y2=\"48\" />\n", | |
" <line x1=\"100\" y1=\"0\" x2=\"100\" y2=\"48\" />\n", | |
" <line x1=\"103\" y1=\"0\" x2=\"103\" y2=\"48\" />\n", | |
" <line x1=\"105\" y1=\"0\" x2=\"105\" y2=\"48\" />\n", | |
" <line x1=\"108\" y1=\"0\" x2=\"108\" y2=\"48\" />\n", | |
" <line x1=\"110\" y1=\"0\" x2=\"110\" y2=\"48\" />\n", | |
" <line x1=\"112\" y1=\"0\" x2=\"112\" y2=\"48\" />\n", | |
" <line x1=\"115\" y1=\"0\" x2=\"115\" y2=\"48\" />\n", | |
" <line x1=\"117\" y1=\"0\" x2=\"117\" y2=\"48\" />\n", | |
" <line x1=\"120\" y1=\"0\" x2=\"120\" y2=\"48\" style=\"stroke-width:2\" />\n", | |
"\n", | |
" <!-- Colored Rectangle -->\n", | |
" <polygon points=\"0.000000,0.000000 120.000000,0.000000 120.000000,48.000000 0.000000,48.000000\" style=\"fill:#ECB172A0;stroke-width:0\"/>\n", | |
"\n", | |
" <!-- Text -->\n", | |
" <text x=\"60.000000\" y=\"68.000000\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" >50</text>\n", | |
" <text x=\"140.000000\" y=\"24.000000\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" transform=\"rotate(0,140.000000,24.000000)\">20</text>\n", | |
"</svg>\n", | |
"</td>\n", | |
"</tr>\n", | |
"</table></div></div></li><li class='xr-section-item'><input id='section-4f194f46-dcbd-417d-8460-d84ca5d56aba' class='xr-section-summary-in' type='checkbox' checked><label for='section-4f194f46-dcbd-417d-8460-d84ca5d56aba' class='xr-section-summary' >Coordinates: <span>(2)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>distance_bins</span></div><div class='xr-var-dims'>(distance_bins)</div><div class='xr-var-dtype'>object</div><div class='xr-var-preview xr-preview'>(-1.413, 28.256] ... (1384.543, ...</div><input id='attrs-89079314-17db-44e9-9fba-3925692586c6' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-89079314-17db-44e9-9fba-3925692586c6' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-5008dc49-0da3-4365-a47c-d641c41b2618' class='xr-var-data-in' type='checkbox'><label for='data-5008dc49-0da3-4365-a47c-d641c41b2618' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([Interval(-1.413, 28.256, closed='right'),\n", | |
" Interval(28.256, 56.512, closed='right'),\n", | |
" Interval(56.512, 84.768, closed='right'),\n", | |
" Interval(84.768, 113.024, closed='right'),\n", | |
" Interval(113.024, 141.28, closed='right'),\n", | |
" Interval(141.28, 169.536, closed='right'),\n", | |
" Interval(169.536, 197.792, closed='right'),\n", | |
" Interval(197.792, 226.048, closed='right'),\n", | |
" Interval(226.048, 254.304, closed='right'),\n", | |
" Interval(254.304, 282.56, closed='right'),\n", | |
" Interval(282.56, 310.816, closed='right'),\n", | |
" Interval(310.816, 339.072, closed='right'),\n", | |
" Interval(339.072, 367.328, closed='right'),\n", | |
" Interval(367.328, 395.584, closed='right'),\n", | |
" Interval(395.584, 423.84, closed='right'),\n", | |
" Interval(423.84, 452.096, closed='right'),\n", | |
" Interval(452.096, 480.352, closed='right'),\n", | |
" Interval(480.352, 508.608, closed='right'),\n", | |
" Interval(508.608, 536.864, closed='right'),\n", | |
" Interval(536.864, 565.12, closed='right'),\n", | |
" Interval(565.12, 593.376, closed='right'),\n", | |
" Interval(593.376, 621.632, closed='right'),\n", | |
" Interval(621.632, 649.888, closed='right'),\n", | |
" Interval(649.888, 678.144, closed='right'),\n", | |
" Interval(678.144, 706.4, closed='right'),\n", | |
" Interval(706.4, 734.656, closed='right'),\n", | |
" Interval(734.656, 762.912, closed='right'),\n", | |
" Interval(762.912, 791.168, closed='right'),\n", | |
" Interval(791.168, 819.424, closed='right'),\n", | |
" Interval(819.424, 847.68, closed='right'),\n", | |
" Interval(847.68, 875.936, closed='right'),\n", | |
" Interval(875.936, 904.192, closed='right'),\n", | |
" Interval(904.192, 932.448, closed='right'),\n", | |
" Interval(932.448, 960.704, closed='right'),\n", | |
" Interval(960.704, 988.96, closed='right'),\n", | |
" Interval(988.96, 1017.216, closed='right'),\n", | |
" Interval(1017.216, 1045.472, closed='right'),\n", | |
" Interval(1045.472, 1073.728, closed='right'),\n", | |
" Interval(1073.728, 1101.983, closed='right'),\n", | |
" Interval(1101.983, 1130.239, closed='right'),\n", | |
" Interval(1130.239, 1158.495, closed='right'),\n", | |
" Interval(1158.495, 1186.751, closed='right'),\n", | |
" Interval(1186.751, 1215.007, closed='right'),\n", | |
" Interval(1215.007, 1243.263, closed='right'),\n", | |
" Interval(1243.263, 1271.519, closed='right'),\n", | |
" Interval(1271.519, 1299.775, closed='right'),\n", | |
" Interval(1299.775, 1328.031, closed='right'),\n", | |
" Interval(1328.031, 1356.287, closed='right'),\n", | |
" Interval(1356.287, 1384.543, closed='right'),\n", | |
" Interval(1384.543, 1412.799, closed='right')], dtype=object)</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>time</span></div><div class='xr-var-dims'>(time)</div><div class='xr-var-dtype'>int64</div><div class='xr-var-preview xr-preview'>0 1 2 3 4 5 6 ... 14 15 16 17 18 19</div><input id='attrs-f5700706-8819-49df-ba82-43cd59e69d36' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-f5700706-8819-49df-ba82-43cd59e69d36' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-e1236edf-43bf-4826-9b43-cedc7132ca97' class='xr-var-data-in' type='checkbox'><label for='data-e1236edf-43bf-4826-9b43-cedc7132ca97' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,\n", | |
" 18, 19])</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-779a570f-a899-4bdc-9db5-fed8c6a3a035' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-779a570f-a899-4bdc-9db5-fed8c6a3a035' class='xr-section-summary' title='Expand/collapse section'>Attributes: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'></dl></div></li></ul></div></div>" | |
], | |
"text/plain": [ | |
"<xarray.DataArray 'signal' (time: 20, distance_bins: 50)>\n", | |
"dask.array<transpose, shape=(20, 50), dtype=float64, chunksize=(1, 1), chunktype=numpy.ndarray>\n", | |
"Coordinates:\n", | |
" * distance_bins (distance_bins) object (-1.413, 28.256] ... (1384.543, 141...\n", | |
" * time (time) int64 0 1 2 3 4 5 6 7 8 ... 11 12 13 14 15 16 17 18 19" | |
] | |
}, | |
"execution_count": 85, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"%time result = dask_signal.groupby_bins(distance, bins).mean()\n", | |
"%time result.compute()\n", | |
"result" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 84, | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "kEOl2RPNJU0v", | |
"outputId": "0118c6ac-5d56-4f2e-b9f7-8dd8db7d1b32" | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"CPU times: user 54.8 ms, sys: 7.46 ms, total: 62.2 ms\n", | |
"Wall time: 61.3 ms\n", | |
"CPU times: user 884 ms, sys: 191 ms, total: 1.08 s\n", | |
"Wall time: 484 ms\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/html": [ | |
"<div><svg style=\"position: absolute; width: 0; height: 0; overflow: hidden\">\n", | |
"<defs>\n", | |
"<symbol id=\"icon-database\" viewBox=\"0 0 32 32\">\n", | |
"<path d=\"M16 0c-8.837 0-16 2.239-16 5v4c0 2.761 7.163 5 16 5s16-2.239 16-5v-4c0-2.761-7.163-5-16-5z\"></path>\n", | |
"<path d=\"M16 17c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n", | |
"<path d=\"M16 26c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n", | |
"</symbol>\n", | |
"<symbol id=\"icon-file-text2\" viewBox=\"0 0 32 32\">\n", | |
"<path d=\"M28.681 7.159c-0.694-0.947-1.662-2.053-2.724-3.116s-2.169-2.030-3.116-2.724c-1.612-1.182-2.393-1.319-2.841-1.319h-15.5c-1.378 0-2.5 1.121-2.5 2.5v27c0 1.378 1.122 2.5 2.5 2.5h23c1.378 0 2.5-1.122 2.5-2.5v-19.5c0-0.448-0.137-1.23-1.319-2.841zM24.543 5.457c0.959 0.959 1.712 1.825 2.268 2.543h-4.811v-4.811c0.718 0.556 1.584 1.309 2.543 2.268zM28 29.5c0 0.271-0.229 0.5-0.5 0.5h-23c-0.271 0-0.5-0.229-0.5-0.5v-27c0-0.271 0.229-0.5 0.5-0.5 0 0 15.499-0 15.5 0v7c0 0.552 0.448 1 1 1h7v19.5z\"></path>\n", | |
"<path d=\"M23 26h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n", | |
"<path d=\"M23 22h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n", | |
"<path d=\"M23 18h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n", | |
"</symbol>\n", | |
"</defs>\n", | |
"</svg>\n", | |
"<style>/* CSS stylesheet for displaying xarray objects in jupyterlab.\n", | |
" *\n", | |
" */\n", | |
"\n", | |
":root {\n", | |
" --xr-font-color0: var(--jp-content-font-color0, rgba(0, 0, 0, 1));\n", | |
" --xr-font-color2: var(--jp-content-font-color2, rgba(0, 0, 0, 0.54));\n", | |
" --xr-font-color3: var(--jp-content-font-color3, rgba(0, 0, 0, 0.38));\n", | |
" --xr-border-color: var(--jp-border-color2, #e0e0e0);\n", | |
" --xr-disabled-color: var(--jp-layout-color3, #bdbdbd);\n", | |
" --xr-background-color: var(--jp-layout-color0, white);\n", | |
" --xr-background-color-row-even: var(--jp-layout-color1, white);\n", | |
" --xr-background-color-row-odd: var(--jp-layout-color2, #eeeeee);\n", | |
"}\n", | |
"\n", | |
"html[theme=dark],\n", | |
"body.vscode-dark {\n", | |
" --xr-font-color0: rgba(255, 255, 255, 1);\n", | |
" --xr-font-color2: rgba(255, 255, 255, 0.54);\n", | |
" --xr-font-color3: rgba(255, 255, 255, 0.38);\n", | |
" --xr-border-color: #1F1F1F;\n", | |
" --xr-disabled-color: #515151;\n", | |
" --xr-background-color: #111111;\n", | |
" --xr-background-color-row-even: #111111;\n", | |
" --xr-background-color-row-odd: #313131;\n", | |
"}\n", | |
"\n", | |
".xr-wrap {\n", | |
" display: block;\n", | |
" min-width: 300px;\n", | |
" max-width: 700px;\n", | |
"}\n", | |
"\n", | |
".xr-text-repr-fallback {\n", | |
" /* fallback to plain text repr when CSS is not injected (untrusted notebook) */\n", | |
" display: none;\n", | |
"}\n", | |
"\n", | |
".xr-header {\n", | |
" padding-top: 6px;\n", | |
" padding-bottom: 6px;\n", | |
" margin-bottom: 4px;\n", | |
" border-bottom: solid 1px var(--xr-border-color);\n", | |
"}\n", | |
"\n", | |
".xr-header > div,\n", | |
".xr-header > ul {\n", | |
" display: inline;\n", | |
" margin-top: 0;\n", | |
" margin-bottom: 0;\n", | |
"}\n", | |
"\n", | |
".xr-obj-type,\n", | |
".xr-array-name {\n", | |
" margin-left: 2px;\n", | |
" margin-right: 10px;\n", | |
"}\n", | |
"\n", | |
".xr-obj-type {\n", | |
" color: var(--xr-font-color2);\n", | |
"}\n", | |
"\n", | |
".xr-sections {\n", | |
" padding-left: 0 !important;\n", | |
" display: grid;\n", | |
" grid-template-columns: 150px auto auto 1fr 20px 20px;\n", | |
"}\n", | |
"\n", | |
".xr-section-item {\n", | |
" display: contents;\n", | |
"}\n", | |
"\n", | |
".xr-section-item input {\n", | |
" display: none;\n", | |
"}\n", | |
"\n", | |
".xr-section-item input + label {\n", | |
" color: var(--xr-disabled-color);\n", | |
"}\n", | |
"\n", | |
".xr-section-item input:enabled + label {\n", | |
" cursor: pointer;\n", | |
" color: var(--xr-font-color2);\n", | |
"}\n", | |
"\n", | |
".xr-section-item input:enabled + label:hover {\n", | |
" color: var(--xr-font-color0);\n", | |
"}\n", | |
"\n", | |
".xr-section-summary {\n", | |
" grid-column: 1;\n", | |
" color: var(--xr-font-color2);\n", | |
" font-weight: 500;\n", | |
"}\n", | |
"\n", | |
".xr-section-summary > span {\n", | |
" display: inline-block;\n", | |
" padding-left: 0.5em;\n", | |
"}\n", | |
"\n", | |
".xr-section-summary-in:disabled + label {\n", | |
" color: var(--xr-font-color2);\n", | |
"}\n", | |
"\n", | |
".xr-section-summary-in + label:before {\n", | |
" display: inline-block;\n", | |
" content: '►';\n", | |
" font-size: 11px;\n", | |
" width: 15px;\n", | |
" text-align: center;\n", | |
"}\n", | |
"\n", | |
".xr-section-summary-in:disabled + label:before {\n", | |
" color: var(--xr-disabled-color);\n", | |
"}\n", | |
"\n", | |
".xr-section-summary-in:checked + label:before {\n", | |
" content: '▼';\n", | |
"}\n", | |
"\n", | |
".xr-section-summary-in:checked + label > span {\n", | |
" display: none;\n", | |
"}\n", | |
"\n", | |
".xr-section-summary,\n", | |
".xr-section-inline-details {\n", | |
" padding-top: 4px;\n", | |
" padding-bottom: 4px;\n", | |
"}\n", | |
"\n", | |
".xr-section-inline-details {\n", | |
" grid-column: 2 / -1;\n", | |
"}\n", | |
"\n", | |
".xr-section-details {\n", | |
" display: none;\n", | |
" grid-column: 1 / -1;\n", | |
" margin-bottom: 5px;\n", | |
"}\n", | |
"\n", | |
".xr-section-summary-in:checked ~ .xr-section-details {\n", | |
" display: contents;\n", | |
"}\n", | |
"\n", | |
".xr-array-wrap {\n", | |
" grid-column: 1 / -1;\n", | |
" display: grid;\n", | |
" grid-template-columns: 20px auto;\n", | |
"}\n", | |
"\n", | |
".xr-array-wrap > label {\n", | |
" grid-column: 1;\n", | |
" vertical-align: top;\n", | |
"}\n", | |
"\n", | |
".xr-preview {\n", | |
" color: var(--xr-font-color3);\n", | |
"}\n", | |
"\n", | |
".xr-array-preview,\n", | |
".xr-array-data {\n", | |
" padding: 0 5px !important;\n", | |
" grid-column: 2;\n", | |
"}\n", | |
"\n", | |
".xr-array-data,\n", | |
".xr-array-in:checked ~ .xr-array-preview {\n", | |
" display: none;\n", | |
"}\n", | |
"\n", | |
".xr-array-in:checked ~ .xr-array-data,\n", | |
".xr-array-preview {\n", | |
" display: inline-block;\n", | |
"}\n", | |
"\n", | |
".xr-dim-list {\n", | |
" display: inline-block !important;\n", | |
" list-style: none;\n", | |
" padding: 0 !important;\n", | |
" margin: 0;\n", | |
"}\n", | |
"\n", | |
".xr-dim-list li {\n", | |
" display: inline-block;\n", | |
" padding: 0;\n", | |
" margin: 0;\n", | |
"}\n", | |
"\n", | |
".xr-dim-list:before {\n", | |
" content: '(';\n", | |
"}\n", | |
"\n", | |
".xr-dim-list:after {\n", | |
" content: ')';\n", | |
"}\n", | |
"\n", | |
".xr-dim-list li:not(:last-child):after {\n", | |
" content: ',';\n", | |
" padding-right: 5px;\n", | |
"}\n", | |
"\n", | |
".xr-has-index {\n", | |
" font-weight: bold;\n", | |
"}\n", | |
"\n", | |
".xr-var-list,\n", | |
".xr-var-item {\n", | |
" display: contents;\n", | |
"}\n", | |
"\n", | |
".xr-var-item > div,\n", | |
".xr-var-item label,\n", | |
".xr-var-item > .xr-var-name span {\n", | |
" background-color: var(--xr-background-color-row-even);\n", | |
" margin-bottom: 0;\n", | |
"}\n", | |
"\n", | |
".xr-var-item > .xr-var-name:hover span {\n", | |
" padding-right: 5px;\n", | |
"}\n", | |
"\n", | |
".xr-var-list > li:nth-child(odd) > div,\n", | |
".xr-var-list > li:nth-child(odd) > label,\n", | |
".xr-var-list > li:nth-child(odd) > .xr-var-name span {\n", | |
" background-color: var(--xr-background-color-row-odd);\n", | |
"}\n", | |
"\n", | |
".xr-var-name {\n", | |
" grid-column: 1;\n", | |
"}\n", | |
"\n", | |
".xr-var-dims {\n", | |
" grid-column: 2;\n", | |
"}\n", | |
"\n", | |
".xr-var-dtype {\n", | |
" grid-column: 3;\n", | |
" text-align: right;\n", | |
" color: var(--xr-font-color2);\n", | |
"}\n", | |
"\n", | |
".xr-var-preview {\n", | |
" grid-column: 4;\n", | |
"}\n", | |
"\n", | |
".xr-var-name,\n", | |
".xr-var-dims,\n", | |
".xr-var-dtype,\n", | |
".xr-preview,\n", | |
".xr-attrs dt {\n", | |
" white-space: nowrap;\n", | |
" overflow: hidden;\n", | |
" text-overflow: ellipsis;\n", | |
" padding-right: 10px;\n", | |
"}\n", | |
"\n", | |
".xr-var-name:hover,\n", | |
".xr-var-dims:hover,\n", | |
".xr-var-dtype:hover,\n", | |
".xr-attrs dt:hover {\n", | |
" overflow: visible;\n", | |
" width: auto;\n", | |
" z-index: 1;\n", | |
"}\n", | |
"\n", | |
".xr-var-attrs,\n", | |
".xr-var-data {\n", | |
" display: none;\n", | |
" background-color: var(--xr-background-color) !important;\n", | |
" padding-bottom: 5px !important;\n", | |
"}\n", | |
"\n", | |
".xr-var-attrs-in:checked ~ .xr-var-attrs,\n", | |
".xr-var-data-in:checked ~ .xr-var-data {\n", | |
" display: block;\n", | |
"}\n", | |
"\n", | |
".xr-var-data > table {\n", | |
" float: right;\n", | |
"}\n", | |
"\n", | |
".xr-var-name span,\n", | |
".xr-var-data,\n", | |
".xr-attrs {\n", | |
" padding-left: 25px !important;\n", | |
"}\n", | |
"\n", | |
".xr-attrs,\n", | |
".xr-var-attrs,\n", | |
".xr-var-data {\n", | |
" grid-column: 1 / -1;\n", | |
"}\n", | |
"\n", | |
"dl.xr-attrs {\n", | |
" padding: 0;\n", | |
" margin: 0;\n", | |
" display: grid;\n", | |
" grid-template-columns: 125px auto;\n", | |
"}\n", | |
"\n", | |
".xr-attrs dt, dd {\n", | |
" padding: 0;\n", | |
" margin: 0;\n", | |
" float: left;\n", | |
" padding-right: 10px;\n", | |
" width: auto;\n", | |
"}\n", | |
"\n", | |
".xr-attrs dt {\n", | |
" font-weight: normal;\n", | |
" grid-column: 1;\n", | |
"}\n", | |
"\n", | |
".xr-attrs dt:hover span {\n", | |
" display: inline-block;\n", | |
" background: var(--xr-background-color);\n", | |
" padding-right: 10px;\n", | |
"}\n", | |
"\n", | |
".xr-attrs dd {\n", | |
" grid-column: 2;\n", | |
" white-space: pre-wrap;\n", | |
" word-break: break-all;\n", | |
"}\n", | |
"\n", | |
".xr-icon-database,\n", | |
".xr-icon-file-text2 {\n", | |
" display: inline-block;\n", | |
" vertical-align: middle;\n", | |
" width: 1em;\n", | |
" height: 1.5em !important;\n", | |
" stroke-width: 0;\n", | |
" stroke: currentColor;\n", | |
" fill: currentColor;\n", | |
"}\n", | |
"</style><pre class='xr-text-repr-fallback'><xarray.DataArray (time: 20, distance_bins: 50)>\n", | |
"dask.array<transpose, shape=(20, 50), dtype=float64, chunksize=(1, 50), chunktype=numpy.ndarray>\n", | |
"Coordinates:\n", | |
" * time (time) int64 0 1 2 3 4 5 6 7 8 ... 11 12 13 14 15 16 17 18 19\n", | |
" * distance_bins (distance_bins) object (-1.413, 28.256] ... (1384.543, 141...</pre><div class='xr-wrap' hidden><div class='xr-header'><div class='xr-obj-type'>xarray.DataArray</div><div class='xr-array-name'></div><ul class='xr-dim-list'><li><span class='xr-has-index'>time</span>: 20</li><li><span class='xr-has-index'>distance_bins</span>: 50</li></ul></div><ul class='xr-sections'><li class='xr-section-item'><div class='xr-array-wrap'><input id='section-1e790e1d-acbf-46f3-aeac-238622f87f8b' class='xr-array-in' type='checkbox' checked><label for='section-1e790e1d-acbf-46f3-aeac-238622f87f8b' title='Show/hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-array-preview xr-preview'><span>dask.array<chunksize=(1, 50), meta=np.ndarray></span></div><div class='xr-array-data'><table>\n", | |
"<tr>\n", | |
"<td>\n", | |
"<table>\n", | |
" <thead>\n", | |
" <tr><td> </td><th> Array </th><th> Chunk </th></tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr><th> Bytes </th><td> 8.00 kB </td> <td> 400 B </td></tr>\n", | |
" <tr><th> Shape </th><td> (20, 50) </td> <td> (1, 50) </td></tr>\n", | |
" <tr><th> Count </th><td> 101 Tasks </td><td> 20 Chunks </td></tr>\n", | |
" <tr><th> Type </th><td> float64 </td><td> numpy.ndarray </td></tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</td>\n", | |
"<td>\n", | |
"<svg width=\"170\" height=\"98\" style=\"stroke:rgb(0,0,0);stroke-width:1\" >\n", | |
"\n", | |
" <!-- Horizontal lines -->\n", | |
" <line x1=\"0\" y1=\"0\" x2=\"120\" y2=\"0\" style=\"stroke-width:2\" />\n", | |
" <line x1=\"0\" y1=\"2\" x2=\"120\" y2=\"2\" />\n", | |
" <line x1=\"0\" y1=\"4\" x2=\"120\" y2=\"4\" />\n", | |
" <line x1=\"0\" y1=\"7\" x2=\"120\" y2=\"7\" />\n", | |
" <line x1=\"0\" y1=\"9\" x2=\"120\" y2=\"9\" />\n", | |
" <line x1=\"0\" y1=\"12\" x2=\"120\" y2=\"12\" />\n", | |
" <line x1=\"0\" y1=\"14\" x2=\"120\" y2=\"14\" />\n", | |
" <line x1=\"0\" y1=\"16\" x2=\"120\" y2=\"16\" />\n", | |
" <line x1=\"0\" y1=\"19\" x2=\"120\" y2=\"19\" />\n", | |
" <line x1=\"0\" y1=\"21\" x2=\"120\" y2=\"21\" />\n", | |
" <line x1=\"0\" y1=\"24\" x2=\"120\" y2=\"24\" />\n", | |
" <line x1=\"0\" y1=\"26\" x2=\"120\" y2=\"26\" />\n", | |
" <line x1=\"0\" y1=\"28\" x2=\"120\" y2=\"28\" />\n", | |
" <line x1=\"0\" y1=\"31\" x2=\"120\" y2=\"31\" />\n", | |
" <line x1=\"0\" y1=\"33\" x2=\"120\" y2=\"33\" />\n", | |
" <line x1=\"0\" y1=\"36\" x2=\"120\" y2=\"36\" />\n", | |
" <line x1=\"0\" y1=\"38\" x2=\"120\" y2=\"38\" />\n", | |
" <line x1=\"0\" y1=\"40\" x2=\"120\" y2=\"40\" />\n", | |
" <line x1=\"0\" y1=\"43\" x2=\"120\" y2=\"43\" />\n", | |
" <line x1=\"0\" y1=\"45\" x2=\"120\" y2=\"45\" />\n", | |
" <line x1=\"0\" y1=\"48\" x2=\"120\" y2=\"48\" style=\"stroke-width:2\" />\n", | |
"\n", | |
" <!-- Vertical lines -->\n", | |
" <line x1=\"0\" y1=\"0\" x2=\"0\" y2=\"48\" style=\"stroke-width:2\" />\n", | |
" <line x1=\"120\" y1=\"0\" x2=\"120\" y2=\"48\" style=\"stroke-width:2\" />\n", | |
"\n", | |
" <!-- Colored Rectangle -->\n", | |
" <polygon points=\"0.000000,0.000000 120.000000,0.000000 120.000000,48.000000 0.000000,48.000000\" style=\"fill:#ECB172A0;stroke-width:0\"/>\n", | |
"\n", | |
" <!-- Text -->\n", | |
" <text x=\"60.000000\" y=\"68.000000\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" >50</text>\n", | |
" <text x=\"140.000000\" y=\"24.000000\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" transform=\"rotate(0,140.000000,24.000000)\">20</text>\n", | |
"</svg>\n", | |
"</td>\n", | |
"</tr>\n", | |
"</table></div></div></li><li class='xr-section-item'><input id='section-d321cc8c-1320-4d2f-b234-dce2d86a5521' class='xr-section-summary-in' type='checkbox' checked><label for='section-d321cc8c-1320-4d2f-b234-dce2d86a5521' class='xr-section-summary' >Coordinates: <span>(2)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>time</span></div><div class='xr-var-dims'>(time)</div><div class='xr-var-dtype'>int64</div><div class='xr-var-preview xr-preview'>0 1 2 3 4 5 6 ... 14 15 16 17 18 19</div><input id='attrs-d97d391e-3907-4b1e-af0b-d70a79711805' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-d97d391e-3907-4b1e-af0b-d70a79711805' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-1b6ce3ef-322c-48b4-b8f3-5c6c57a86de3' class='xr-var-data-in' type='checkbox'><label for='data-1b6ce3ef-322c-48b4-b8f3-5c6c57a86de3' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,\n", | |
" 18, 19])</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>distance_bins</span></div><div class='xr-var-dims'>(distance_bins)</div><div class='xr-var-dtype'>object</div><div class='xr-var-preview xr-preview'>(-1.413, 28.256] ... (1384.543, ...</div><input id='attrs-5d273765-7f72-406a-8a0e-96278680356f' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-5d273765-7f72-406a-8a0e-96278680356f' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-aaa28834-3905-44ac-88e8-49dce15eeb0b' class='xr-var-data-in' type='checkbox'><label for='data-aaa28834-3905-44ac-88e8-49dce15eeb0b' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([Interval(-1.413, 28.256, closed='right'),\n", | |
" Interval(28.256, 56.512, closed='right'),\n", | |
" Interval(56.512, 84.768, closed='right'),\n", | |
" Interval(84.768, 113.024, closed='right'),\n", | |
" Interval(113.024, 141.28, closed='right'),\n", | |
" Interval(141.28, 169.536, closed='right'),\n", | |
" Interval(169.536, 197.792, closed='right'),\n", | |
" Interval(197.792, 226.048, closed='right'),\n", | |
" Interval(226.048, 254.304, closed='right'),\n", | |
" Interval(254.304, 282.56, closed='right'),\n", | |
" Interval(282.56, 310.816, closed='right'),\n", | |
" Interval(310.816, 339.072, closed='right'),\n", | |
" Interval(339.072, 367.328, closed='right'),\n", | |
" Interval(367.328, 395.584, closed='right'),\n", | |
" Interval(395.584, 423.84, closed='right'),\n", | |
" Interval(423.84, 452.096, closed='right'),\n", | |
" Interval(452.096, 480.352, closed='right'),\n", | |
" Interval(480.352, 508.608, closed='right'),\n", | |
" Interval(508.608, 536.864, closed='right'),\n", | |
" Interval(536.864, 565.12, closed='right'),\n", | |
" Interval(565.12, 593.376, closed='right'),\n", | |
" Interval(593.376, 621.632, closed='right'),\n", | |
" Interval(621.632, 649.888, closed='right'),\n", | |
" Interval(649.888, 678.144, closed='right'),\n", | |
" Interval(678.144, 706.4, closed='right'),\n", | |
" Interval(706.4, 734.656, closed='right'),\n", | |
" Interval(734.656, 762.912, closed='right'),\n", | |
" Interval(762.912, 791.168, closed='right'),\n", | |
" Interval(791.168, 819.424, closed='right'),\n", | |
" Interval(819.424, 847.68, closed='right'),\n", | |
" Interval(847.68, 875.936, closed='right'),\n", | |
" Interval(875.936, 904.192, closed='right'),\n", | |
" Interval(904.192, 932.448, closed='right'),\n", | |
" Interval(932.448, 960.704, closed='right'),\n", | |
" Interval(960.704, 988.96, closed='right'),\n", | |
" Interval(988.96, 1017.216, closed='right'),\n", | |
" Interval(1017.216, 1045.472, closed='right'),\n", | |
" Interval(1045.472, 1073.728, closed='right'),\n", | |
" Interval(1073.728, 1101.983, closed='right'),\n", | |
" Interval(1101.983, 1130.239, closed='right'),\n", | |
" Interval(1130.239, 1158.495, closed='right'),\n", | |
" Interval(1158.495, 1186.751, closed='right'),\n", | |
" Interval(1186.751, 1215.007, closed='right'),\n", | |
" Interval(1215.007, 1243.263, closed='right'),\n", | |
" Interval(1243.263, 1271.519, closed='right'),\n", | |
" Interval(1271.519, 1299.775, closed='right'),\n", | |
" Interval(1299.775, 1328.031, closed='right'),\n", | |
" Interval(1328.031, 1356.287, closed='right'),\n", | |
" Interval(1356.287, 1384.543, closed='right'),\n", | |
" Interval(1384.543, 1412.799, closed='right')], dtype=object)</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-0dc53b43-5ad6-4f91-8a43-d2a552de949b' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-0dc53b43-5ad6-4f91-8a43-d2a552de949b' class='xr-section-summary' title='Expand/collapse section'>Attributes: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'></dl></div></li></ul></div></div>" | |
], | |
"text/plain": [ | |
"<xarray.DataArray (time: 20, distance_bins: 50)>\n", | |
"dask.array<transpose, shape=(20, 50), dtype=float64, chunksize=(1, 50), chunktype=numpy.ndarray>\n", | |
"Coordinates:\n", | |
" * time (time) int64 0 1 2 3 4 5 6 7 8 ... 11 12 13 14 15 16 17 18 19\n", | |
" * distance_bins (distance_bins) object (-1.413, 28.256] ... (1384.543, 141..." | |
] | |
}, | |
"execution_count": 84, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"%time result = groupby_bins_agg(dask_signal, distance, bins, func='mean')\n", | |
"%time result.compute()\n", | |
"result" | |
] | |
} | |
], | |
"metadata": { | |
"colab": { | |
"collapsed_sections": [], | |
"name": "fast groupby agg.ipynb", | |
"provenance": [] | |
}, | |
"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.8.5" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment