{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Node Treshold Design\n", "\n", "We want to apply the treshold filter on the whole stack of rasters, but filter each raster independently." ] }, { "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", "import collections\n", "\n", "ld2dap_path = Path('../')\n", "sys.path.append(str(ld2dap_path.resolve()))\n", "import ld2dap\n", "from ld2dap.core import Filter" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Load and display 2 rasters with different order of magnitude" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "rasters = ['../Data/phase1_rasters/Intensity_C1/UH17_GI1F051_TR.tif',\n", " '../Data/phase1_rasters/DEM_C123_3msr/UH17_GEG051_TR.tif']\n", "\n", "in_test = ld2dap.LoadTIFF(rasters)\n", "disp_test = ld2dap.ShowFig(stack_id='all')\n", "\n", "disp_test.input = in_test\n", "disp_test.run()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Metadata copy bug" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "tresh_test = ld2dap.Treshold(treshold=1e4)\n", "tresh2_test = ld2dap.Treshold(treshold=1e3)\n", "\n", "o = ld2dap.RawOutput()\n", "\n", "in_test = ld2dap.LoadTIFF(rasters)\n", "tresh_test.input = in_test\n", "tresh2_test.input = tresh_test\n", "disp_test.input = tresh_test\n", "o.input = in_test\n", "\n", "\n", "disp_test.run()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### New treshold" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "o.data.shape" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "o.data.max(axis=(0,1)).shape, o.data.max(axis=(0,1))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "t = 1e3\n", "\n", "o.run()\n", "f = o.data > t\n", "o.data[f] = np.nan\n", "m = np.nanmax(o.data, axis=(0,1))\n", "r = f.sum(axis=(0,1))\n", "\n", "display(m, r)\n", "\n", "o.data = np.rollaxis(o.data, 2)\n", "f = np.rollaxis(f, 2)\n", "\n", "o.data[f] = np.repeat(m, r)\n", "o.data = np.rollaxis(o.data, 0, 3)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "o.data.max(axis=(0,1))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "A = np.zeros((10,20,2))\n", "display(A.shape)\n", "\n", "A = np.rollaxis(A, 2)\n", "display(A.shape)\n", "\n", "A = np.rollaxis(A,0,3)\n", "A.shape\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "A.shape" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "A = np.zeros((10,10,2))\n", "A[:,:,1] = 1\n", "\n", "F = np.random.random((10,10,2)) < .2\n", "\n", "r = F.sum(axis=(0,1))\n", "m = np.array([10, 20])\n", "\n", "A = np.rollaxis(A, 2)\n", "F = np.rollaxis(F, 2)\n", "\n", "A[F] = np.repeat(m, r)\n", "\n", "A = np.rollaxis(A, 0, 3)\n", "A\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "want = f.sum(axis=(0,1))\n", "want" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "np.repeat(np.nanmax(o.data, axis=(0,1)), f.sum(axis=(0,1)))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "f.any()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "o.data[f] = 0" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "np.tile(m, (2,1))" ] } ], "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 }