223 lines
6.9 KiB
Plaintext
223 lines
6.9 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"source": [
|
|
"# Interactive pixel to Spectrum x DTM Analysis in Attribute Space\n",
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"/home/florent/.local/share/micromamba/lib/python3.12/site-packages/numpy/core/getlimits.py:549: UserWarning: The value of the smallest subnormal for <class 'numpy.float64'> type is zero.\n",
|
|
" setattr(self, word, getattr(machar, word).flat[0])\n",
|
|
"/home/florent/.local/share/micromamba/lib/python3.12/site-packages/numpy/core/getlimits.py:89: UserWarning: The value of the smallest subnormal for <class 'numpy.float64'> type is zero.\n",
|
|
" return self._float_to_str(self.smallest_subnormal)\n",
|
|
"/home/florent/.local/share/micromamba/lib/python3.12/site-packages/numpy/core/getlimits.py:549: UserWarning: The value of the smallest subnormal for <class 'numpy.float32'> type is zero.\n",
|
|
" setattr(self, word, getattr(machar, word).flat[0])\n",
|
|
"/home/florent/.local/share/micromamba/lib/python3.12/site-packages/numpy/core/getlimits.py:89: UserWarning: The value of the smallest subnormal for <class 'numpy.float32'> type is zero.\n",
|
|
" return self._float_to_str(self.smallest_subnormal)\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"from matplotlib import pyplot as plt\n",
|
|
"import higra as hg\n",
|
|
"from pathlib import Path\n",
|
|
"import ipywidgets as ipw\n",
|
|
"\n",
|
|
"from spectra_app import *\n",
|
|
"\n",
|
|
"plt.style.use('dark_background')\n",
|
|
"plt.set_cmap('plasma')\n",
|
|
"plt.close()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Load dataset"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import rasterio as rio\n",
|
|
"image = np.random.random((100, 100))\n",
|
|
"#image = rio.open('data/dsm_vox_50cm_tile_-12_0.tif').read()[0]\n",
|
|
"#image = rio.open('data/dsm_vox_50cm_tile_-7_1.tif').read()[0]\n",
|
|
"\n",
|
|
"load_image(image)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"source": [
|
|
"## Run"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"2024-02-14 17:46:43,794 - spectra_app - INFO - Initialize spectra app\n",
|
|
"2024-02-14 17:46:43,854 - spectra_app - INFO - init spectrum axis...\n",
|
|
"2024-02-14 17:46:43,855 - spectra_app - INFO - compute spectrum...\n",
|
|
"2024-02-14 17:46:43,859 - spectra_app - INFO - compute spectrum done\n",
|
|
"2024-02-14 17:46:44,053 - spectra_app - INFO - init spectrum axis done\n",
|
|
"2024-02-14 17:46:44,054 - spectra_app - INFO - init lidar view\n"
|
|
]
|
|
},
|
|
{
|
|
"data": {
|
|
"application/vnd.jupyter.widget-view+json": {
|
|
"model_id": "898e72645d384b3da97065dc823ff386",
|
|
"version_major": 2,
|
|
"version_minor": 0
|
|
},
|
|
"text/plain": [
|
|
"VBox(children=(HBox(children=(Dropdown(description='Attribute X', options=('area', 'child_number', 'children_p…"
|
|
]
|
|
},
|
|
"execution_count": 3,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"# \"widget\" or \"qt\", qt provide a snappier GUI\n",
|
|
"#%matplotlib widget\n",
|
|
"%matplotlib qt\n",
|
|
"\n",
|
|
"plt.style.use('dark_background')\n",
|
|
"\n",
|
|
"init()\n",
|
|
"\n",
|
|
"plt.close()\n",
|
|
"fig = plt.figure('Interactive 2D Shape Size Spectrum Analysis', figsize=(17, 5), constrained_layout=False)\n",
|
|
"grid = mpl.gridspec.GridSpec(1, 3, fig, \n",
|
|
" top=0.915,\n",
|
|
" bottom=0.11,\n",
|
|
" left=0.045,\n",
|
|
" right=1.0,\n",
|
|
" hspace=0.17,\n",
|
|
" wspace=0.1)\n",
|
|
"\n",
|
|
"model['ax_spectrum'] = fig.add_subplot(grid[:2])\n",
|
|
"model['ax_dtm'] = fig.add_subplot(grid[-1])\n",
|
|
"model['fig'] = fig\n",
|
|
"\n",
|
|
"def draw_e(e):\n",
|
|
" refresh_lidar_axis()\n",
|
|
" refresh_spectrum_axis()\n",
|
|
" \n",
|
|
"def on_xlim_change(*args):\n",
|
|
" ax = args[0]\n",
|
|
" print('x change triggered')\n",
|
|
" if ax.get_xlim() == model['ax_dtm_xlim']:\n",
|
|
" return\n",
|
|
" model['ax_dtm_xlim'] = ax.get_xlim()\n",
|
|
" #reset_lidar_axis()\n",
|
|
" \n",
|
|
"def on_ylim_change(*args):\n",
|
|
" ax = args[0]\n",
|
|
" print(f'y change triggered: {ax.get_ylim()}')\n",
|
|
" if ax.get_ylim() == model['ax_dtm_ylim']:\n",
|
|
" return\n",
|
|
" model['ax_dtm_ylim'] = ax.get_ylim()\n",
|
|
" \n",
|
|
" reset_lidar_axis()\n",
|
|
" return\n",
|
|
"\n",
|
|
"def redraw_lidar_contours(event):\n",
|
|
" ax = model['ax_dtm']\n",
|
|
" path_patch = model['dtm_contours']\n",
|
|
" ax.draw_artist(path_patch)\n",
|
|
" fig.canvas.blit(path_patch.clipbox)\n",
|
|
" #fig.canvas.flush_events()\n",
|
|
"\n",
|
|
"#fig.canvas.mpl_connect(\"resize_event\", resize_callback)\n",
|
|
"#fig.canvas.mpl_connect('draw_event', draw_e)\n",
|
|
"\n",
|
|
"init_spectrum_axis()\n",
|
|
"init_lidar_axis()\n",
|
|
"\n",
|
|
"plt.show()\n",
|
|
"\n",
|
|
"#refresh_spectrum_axis()\n",
|
|
"#refresh_lidar_axis()\n",
|
|
"\n",
|
|
"init_selector()\n",
|
|
"ax = model['ax_dtm']\n",
|
|
"ax.callbacks.connect('xlim_changed', on_xlim_change)\n",
|
|
"ax.callbacks.connect('ylim_changed', on_ylim_change)\n",
|
|
"fig.canvas.mpl_connect('draw_event', redraw_lidar_contours)\n",
|
|
"\n",
|
|
"\n",
|
|
"#refresh_spectrum_axis()\n",
|
|
"\n",
|
|
"\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",
|
|
"#model['tree_type'].observe(tree_change, names='value')\n",
|
|
"load_button.on_click(load_change)\n",
|
|
"\n",
|
|
"ipw.VBox([\n",
|
|
" #ipw.HBox([model['tile_name'], model['lidar_feature'], model['tree_type'] , load_button]),\n",
|
|
" ipw.HBox([model['x'], model['x_log']]),\n",
|
|
" ipw.HBox([model['y'], model['y_log']]),\n",
|
|
" #load_button,\n",
|
|
" model['highlight'],\n",
|
|
" model['overlay'],\n",
|
|
" load_button\n",
|
|
"])"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3 (ipykernel)",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.12.1"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 4
|
|
}
|