Checkpoint
This commit is contained in:
parent
8fd8dd3374
commit
2388452d45
179
demo.ipynb
179
demo.ipynb
@ -67,7 +67,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"execution_count": 65,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -76,15 +76,7 @@
|
||||
"\n",
|
||||
"def get_tile(feature, name):\n",
|
||||
" return list(data_dir.glob('**/{}_vox_50cm_tile_{}.tif'.format(feature, name)))[0]\n",
|
||||
"\n",
|
||||
"def load_tile(feature, name):\n",
|
||||
" model['im'] = rio.open(get_tile(feature, name)).read()[0]\n",
|
||||
" model['im_hs'] = ui8_clip(hillshades(model['im']), -1, 1)\n",
|
||||
" model['im_hs_alpha'] = ((model['im_hs'].astype(float) - 127) / 127) ** 2 * .4\n",
|
||||
" kwargs = {}\n",
|
||||
" kwargs['vmin'], kwargs['vmax'] = np.quantile(model['im'], (.01, .99))\n",
|
||||
" model['im_kwargs'] = kwargs\n",
|
||||
" model['im_mesh'] = np.meshgrid(np.arange(model['im'].shape[1]), np.arange(model['im'].shape[0]))"
|
||||
"\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -218,7 +210,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"execution_count": 90,
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
@ -226,7 +218,7 @@
|
||||
{
|
||||
"data": {
|
||||
"application/vnd.jupyter.widget-view+json": {
|
||||
"model_id": "baf2371d25d543739572153d8e331efa",
|
||||
"model_id": "bb4daff9ec66456ab58f00021b778efd",
|
||||
"version_major": 2,
|
||||
"version_minor": 0
|
||||
},
|
||||
@ -243,7 +235,7 @@
|
||||
"<function __main__.spectrum_widget(tree=<class 'sap.trees.MaxTree'>, x='area', y='compactness', x_log=True, y_log=False, hillshade_overlay=True, highlight=False)>"
|
||||
]
|
||||
},
|
||||
"execution_count": 8,
|
||||
"execution_count": 90,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@ -320,6 +312,8 @@
|
||||
" x1, x2 = model['x1'], model['x2']\n",
|
||||
" y1, y2 = model['y1'], model['y2']\n",
|
||||
" \n",
|
||||
" model['ax_dtm'].clear()\n",
|
||||
"\n",
|
||||
" # No filter\n",
|
||||
" if x1 == x2 == y1 == y2 == 0:\n",
|
||||
" if not model['overlay']:\n",
|
||||
@ -337,7 +331,6 @@
|
||||
"\n",
|
||||
" img = model['tree_cache'].reconstruct((X < x1) | (X > x2) | (Y < y1) | (Y > y2), filtering='subtractive')\n",
|
||||
" \n",
|
||||
" model['ax_dtm'].clear()\n",
|
||||
" if not model['overlay']:\n",
|
||||
" model['ax_dtm'].imshow(img)\n",
|
||||
" else:\n",
|
||||
@ -408,6 +401,164 @@
|
||||
" y=sap.available_attributes().keys())"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 58,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[('AlphaTree', sap.trees.AlphaTree),\n",
|
||||
" ('MaxTree', sap.trees.MaxTree),\n",
|
||||
" ('MinTree', sap.trees.MinTree),\n",
|
||||
" ('OmegaTree', sap.trees.OmegaTree),\n",
|
||||
" ('TosTree', sap.trees.TosTree)]"
|
||||
]
|
||||
},
|
||||
"execution_count": 58,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"inspect.getmembers(sap.trees, lambda t: inspect.isclass(t) and issubclass(t, sap.Tree) and t != sap.Tree)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 87,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def load_tile():\n",
|
||||
" model['im'] = rio.open(get_tile(model['lidar_feature'].value, model['tile_name'].value)).read()[0]\n",
|
||||
" model['im_hs'] = ui8_clip(hillshades(model['im']), -1, 1)\n",
|
||||
" model['im_hs_alpha'] = ((model['im_hs'].astype(float) - 127) / 127) ** 2 * .4\n",
|
||||
" kwargs = {}\n",
|
||||
" kwargs['vmin'], kwargs['vmax'] = np.quantile(model['im'], (.01, .99))\n",
|
||||
" model['im_kwargs'] = kwargs\n",
|
||||
" model['im_mesh'] = np.meshgrid(np.arange(model['im'].shape[1]), np.arange(model['im'].shape[0]))\n",
|
||||
"\n",
|
||||
"def load_tree():\n",
|
||||
" model['tree_cache'] = model['tree_type'].value(model['im'])\n",
|
||||
"\n",
|
||||
"def reset_selections():\n",
|
||||
" model.update({\n",
|
||||
" 'x1': 0,\n",
|
||||
" 'x2': 0,\n",
|
||||
" 'y1': 0,\n",
|
||||
" 'y2': 0,\n",
|
||||
" 'dtm_x1': 0,\n",
|
||||
" 'dtm_x2': 0,\n",
|
||||
" 'dtm_y1': 0,\n",
|
||||
" 'dtm_y2': 0,\n",
|
||||
" 'overlay': True,\n",
|
||||
" 'highlight': False\n",
|
||||
"})"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 89,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"application/vnd.jupyter.widget-view+json": {
|
||||
"model_id": "db0b0312a8e44889a7bfd821b6578afe",
|
||||
"version_major": 2,
|
||||
"version_minor": 0
|
||||
},
|
||||
"text/plain": [
|
||||
"HBox(children=(Dropdown(description='Tile ID', options=('-11_7', '-12_-1', '-13_-3', '-10_-1', '-4_4', '-9_1',…"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"model['lidar_feature'] = ipw.Dropdown(description='LiDAR feature', options=lidar_features)\n",
|
||||
"model['tile_name'] = ipw.Dropdown(description='Tile ID', options=tile_names)\n",
|
||||
"model['tree_type'] = ipw.Dropdown(description='Hierarchy', value=sap.trees.MaxTree, options=inspect.getmembers(sap.trees, lambda t: inspect.isclass(t) and issubclass(t, sap.Tree) and t != sap.Tree))\n",
|
||||
"load_button = ipw.Button(description='Analyse', icon='rocket')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def load_change(change):\n",
|
||||
" print('Loading tile...')\n",
|
||||
" load_tile()\n",
|
||||
" print('Loading tree...')\n",
|
||||
" load_tree()\n",
|
||||
" print('Loading complete')\n",
|
||||
" reset_selections()\n",
|
||||
" show_spectrum()\n",
|
||||
" filter_dtm()\n",
|
||||
" plt.show()\n",
|
||||
"\n",
|
||||
"lidar_feature.observe(feature_change, names='value')\n",
|
||||
"tile_name.observe(name_change, names='value')\n",
|
||||
"tree_type.observe(tree_change, names='value')\n",
|
||||
"load_button.on_click(load_change)\n",
|
||||
"\n",
|
||||
"ipw.HBox([model['tile_name'], model['lidar_feature'], model['tree_type'] , load_button])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 82,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"tree_type.value = sap.trees.MinTree"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 26,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"'ndsm'"
|
||||
]
|
||||
},
|
||||
"execution_count": 26,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"lidar_feature.value"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 24,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def feature_change(change):\n",
|
||||
" print(feature)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 18,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"<ipython-input-18-012395bc2283>:1: DeprecationWarning: on_trait_change is deprecated in traitlets 4.1: use observe instead\n",
|
||||
" lidar_feature.on_trait_change(ld)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
|
Loading…
Reference in New Issue
Block a user