Add contour highlight
This commit is contained in:
parent
3810964728
commit
e75aa11cc1
212
demo.ipynb
212
demo.ipynb
@ -75,7 +75,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 3,
|
"execution_count": 5,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
@ -121,6 +121,10 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"dtm_hs = ui8_clip(hillshades(dtm), -1, 1)\n",
|
"dtm_hs = ui8_clip(hillshades(dtm), -1, 1)\n",
|
||||||
"cm_hud = mpl.colors.LinearSegmentedColormap.from_list('GreenHUD', [(0.,0.,0.,0.), (0.,1.,0.,1.)], 256)\n",
|
"cm_hud = mpl.colors.LinearSegmentedColormap.from_list('GreenHUD', [(0.,0.,0.,0.), (0.,1.,0.,1.)], 256)\n",
|
||||||
|
"alpha = ((dtm_hs.astype(float) - 127) / 127) ** 2 * .4\n",
|
||||||
|
"cX, cY = np.meshgrid(np.arange(dtm.shape[1]), np.arange(dtm.shape[0]))\n",
|
||||||
|
"kwargs = {}\n",
|
||||||
|
"kwargs['vmin'], kwargs['vmax'] = np.quantile(dtm, (.01, .99))\n",
|
||||||
"\n",
|
"\n",
|
||||||
"model = {}"
|
"model = {}"
|
||||||
]
|
]
|
||||||
@ -134,13 +138,13 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 4,
|
"execution_count": 13,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"application/vnd.jupyter.widget-view+json": {
|
"application/vnd.jupyter.widget-view+json": {
|
||||||
"model_id": "87b90d0f6d584b83af83965b32f15118",
|
"model_id": "6a5848b7f64b487fae0ecb76d2ff5f72",
|
||||||
"version_major": 2,
|
"version_major": 2,
|
||||||
"version_minor": 0
|
"version_minor": 0
|
||||||
},
|
},
|
||||||
@ -154,10 +158,10 @@
|
|||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"text/plain": [
|
"text/plain": [
|
||||||
"<function __main__.spectrum_widget(tree=<class 'sap.trees.MaxTree'>, x='area', y='compactness', x_log=True, y_log=False, hillshade_overlay=False, highlight=True)>"
|
"<function __main__.spectrum_widget(tree=<class 'sap.trees.MaxTree'>, x='area', y='compactness', x_log=True, y_log=False, hillshade_overlay=True, highlight=True)>"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"execution_count": 4,
|
"execution_count": 13,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"output_type": "execute_result"
|
"output_type": "execute_result"
|
||||||
}
|
}
|
||||||
@ -218,7 +222,6 @@
|
|||||||
" ps_mask = spectrum2d(model['tree_cache'], x, y, 200, 100, x_log, y_log, node_mask=node_mask)\n",
|
" ps_mask = spectrum2d(model['tree_cache'], x, y, 200, 100, x_log, y_log, node_mask=node_mask)\n",
|
||||||
" ps[0][:] = ps_mask[0] / ps[0]\n",
|
" ps[0][:] = ps_mask[0] / ps[0]\n",
|
||||||
"\n",
|
"\n",
|
||||||
" \n",
|
|
||||||
" # Display spectrum\n",
|
" # Display spectrum\n",
|
||||||
" plt.sca(model['ax_spectrum'])\n",
|
" plt.sca(model['ax_spectrum'])\n",
|
||||||
" plt.cla()\n",
|
" plt.cla()\n",
|
||||||
@ -238,9 +241,12 @@
|
|||||||
" # No filter\n",
|
" # No filter\n",
|
||||||
" if x1 == x2 == y1 == y2 == 0:\n",
|
" if x1 == x2 == y1 == y2 == 0:\n",
|
||||||
" if not model['overlay']:\n",
|
" if not model['overlay']:\n",
|
||||||
" model['ax_dtm'].imshow(dtm)\n",
|
" model['ax_dtm'].imshow(dtm, **kwargs)\n",
|
||||||
" else:\n",
|
" else:\n",
|
||||||
" model['ax_dtm'].imshow(dtm_hs, cmap=plt.cm.Greys)\n",
|
" #model['ax_dtm'].imshow(dtm_hs, cmap=plt.cm.Greys)\n",
|
||||||
|
" model['ax_dtm'].imshow(dtm, **kwargs)\n",
|
||||||
|
" model['ax_dtm'].imshow(dtm_hs, cmap=plt.cm.Greys, alpha=alpha)\n",
|
||||||
|
"\n",
|
||||||
" return\n",
|
" return\n",
|
||||||
" \n",
|
" \n",
|
||||||
" # Filter\n",
|
" # Filter\n",
|
||||||
@ -253,14 +259,18 @@
|
|||||||
" if not model['overlay']:\n",
|
" if not model['overlay']:\n",
|
||||||
" model['ax_dtm'].imshow(img)\n",
|
" model['ax_dtm'].imshow(img)\n",
|
||||||
" else:\n",
|
" else:\n",
|
||||||
" over = img != model['tree_cache']._alt[-1]\n",
|
" #over = img != model['tree_cache']._alt[-1]\n",
|
||||||
" model['ax_dtm'].imshow(dtm_hs, cmap=plt.cm.Greys)\n",
|
" #model['ax_dtm'].imshow(dtm_hs, cmap=plt.cm.Greys)\n",
|
||||||
" model['ax_dtm'].imshow(over, cmap=cm_hud, alpha=.4)\n",
|
" #model['ax_dtm'].imshow(over, cmap=cm_hud, alpha=.4)\n",
|
||||||
|
" model['ax_dtm'].clear()\n",
|
||||||
|
" model['ax_dtm'].imshow(dtm, **kwargs)\n",
|
||||||
|
" model['ax_dtm'].imshow(dtm_hs, cmap=plt.cm.Greys, alpha=alpha)\n",
|
||||||
|
" model['ax_dtm'].contour(cX, cY, img, [model['tree_cache']._alt[-1]], colors='lime')\n",
|
||||||
"\n",
|
"\n",
|
||||||
" plt.gcf().canvas.draw()\n",
|
" plt.gcf().canvas.draw()\n",
|
||||||
"\n",
|
"\n",
|
||||||
"def spectrum_widget(tree=sap.MaxTree, x='area', y='compactness', x_log=True, y_log=False,\n",
|
"def spectrum_widget(tree=sap.MaxTree, x='area', y='compactness', x_log=True, y_log=False,\n",
|
||||||
" hillshade_overlay=False, highlight=True):\n",
|
" hillshade_overlay=True, highlight=True):\n",
|
||||||
" # Update only toggle of hillshade_overlay\n",
|
" # Update only toggle of hillshade_overlay\n",
|
||||||
" if hillshade_overlay != model['overlay']:\n",
|
" if hillshade_overlay != model['overlay']:\n",
|
||||||
" model['overlay'] = hillshade_overlay\n",
|
" model['overlay'] = hillshade_overlay\n",
|
||||||
@ -312,8 +322,7 @@
|
|||||||
"plt.connect('key_press_event', selector)\n",
|
"plt.connect('key_press_event', selector)\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"#model['ax_dtm'].imshow(dtm_hs, cmap=plt.cm.Greys)\n",
|
"#filter_dtm()\n",
|
||||||
"filter_dtm()\n",
|
|
||||||
"\n",
|
"\n",
|
||||||
"ipw.interact(spectrum_widget, \n",
|
"ipw.interact(spectrum_widget, \n",
|
||||||
" tree=inspect.getmembers(sap.trees, lambda t: inspect.isclass(t) and issubclass(t, sap.Tree) and t != sap.Tree),\n",
|
" tree=inspect.getmembers(sap.trees, lambda t: inspect.isclass(t) and issubclass(t, sap.Tree) and t != sap.Tree),\n",
|
||||||
@ -321,6 +330,181 @@
|
|||||||
" y=sap.available_attributes().keys())"
|
" y=sap.available_attributes().keys())"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 70,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"(2001, 2001)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 70,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"model['tree_cache'].reconstruct().shape"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 73,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"2001"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 73,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"len(X)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 66,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"16.93000030517578"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 66,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"model['tree_cache']._alt[-1]"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 62,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"ename": "NameError",
|
||||||
|
"evalue": "name 'img' is not defined",
|
||||||
|
"output_type": "error",
|
||||||
|
"traceback": [
|
||||||
|
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||||
|
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
|
||||||
|
"\u001b[0;32m<ipython-input-62-77a7949ba908>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mimg\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
|
||||||
|
"\u001b[0;31mNameError\u001b[0m: name 'img' is not defined"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"img"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 82,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"<matplotlib.contour.QuadContourSet at 0x7fe61585e430>"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 82,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"plt.close()\n",
|
||||||
|
"plt.figure()\n",
|
||||||
|
"ax = plt.gca()\n",
|
||||||
|
"\n",
|
||||||
|
"plt.imshow(dtm, **kwargs)\n",
|
||||||
|
"plt.colorbar()\n",
|
||||||
|
"ax.imshow(dtm_hs, cmap=plt.cm.Greys, alpha=alpha)\n",
|
||||||
|
"ax.contour(X, Y, dtm, [30], colors='lime')"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 21,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"(2001, 2001)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 21,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"dtm_hs.shape"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 22,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"(2001, 2001)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 22,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"dtm.shape"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 37,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 42,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"0.12586920037702484"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 42,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"alpha.mean()"
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user