{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import sys\n", "from pathlib import Path\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "\n", "triskele_path = Path('../triskele/python/')\n", "sys.path.append(str(triskele_path.resolve()))\n", "import triskele\n", "\n", "def DFC_filter(raster):\n", " raster[raster > 1e4] = raster[raster < 1e4].max()\n", "\n", " \n", "def show(im, im_size=1, save=None):\n", " plt.figure(figsize=(16*im_size,3*im_size))\n", " plt.imshow(im)\n", " plt.colorbar()\n", " \n", " if save is not None:\n", " plt.savefig(save, bbox_inches='tight', pad_inches=1)\n", " \n", " plt.show()\n", "\n", "def mshow(Xs, titles=None, im_size=1, save=None):\n", " s = len(Xs)\n", "\n", " plt.figure(figsize=(16*im_size,3*im_size*s))\n", "\n", " for i in range(s):\n", " plt.subplot(s,1,i+1)\n", " plt.imshow(Xs[i])\n", " \n", " if titles is not None:\n", " plt.title(titles[i])\n", " \n", " plt.colorbar()\n", " \n", " if save is not None:\n", " plt.savefig(save, bbox_inches='tight', pad_inches=1)\n", " \n", " plt.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "layers_files = [\n", " '../Data/phase1_rasters/DEM+B_C123/UH17_GEM051_TR.tif',\n", " '../Data/phase1_rasters/DEM_C123_3msr/UH17_GEG051_TR.tif']" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "layers = list()\n", "\n", "for file in layers_files:\n", " print('Loading {}'.format(file))\n", " layer = triskele.read(file)\n", " DFC_filter(layer)\n", " layers.append(layer)\n", "\n", "layers_stack = np.stack(layers, axis=2)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "t = triskele.Triskele(layers_stack, verbose=False)\n", "\n", "attributes = t.filter(tree='min-tree',\n", " area=[1e3,1e5], \n", " standard_deviation=[.3,.9],\n", " moment_of_inertia=[.1,.4]\n", " )" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "attributes.shape" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3" } }, "nbformat": 4, "nbformat_minor": 2 }