diff --git a/Notebooks/Node Treshold.ipynb b/Notebooks/Node Treshold.ipynb new file mode 100644 index 0000000..dab7969 --- /dev/null +++ b/Notebooks/Node Treshold.ipynb @@ -0,0 +1,169 @@ +{ + "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": "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 = in_test\n", + "o.input = in_test\n", + "\n", + "\n", + "disp_test.run()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "A = list()\n", + "A.copy()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "print(o.metadata[0])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "[x.copy() for x in o.metadata]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "mdesc = o.metadata[0].desc\n", + "mdesc_copy = o.metadata[0].desc.copy()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "o.metadata[0].desc.app" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "hex(id(mdesc)), hex(id(o.metadata[0].desc)), hex(id(mdesc_copy))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "mdesc_copy.append('BDQ')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "mdesc_copy" + ] + } + ], + "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 +} diff --git a/ld2dap/core/Input.py b/ld2dap/core/Input.py index 5245b70..77dec73 100644 --- a/ld2dap/core/Input.py +++ b/ld2dap/core/Input.py @@ -22,7 +22,7 @@ class Input(Node): """Override abstract method""" data, meta = self._process(data, metadata) for output in self.outputs: - output.process(data, meta) + output.process(data, [x.copy() for x in meta]) def _run(self): self.process(None, None) diff --git a/ld2dap/core/Stack.py b/ld2dap/core/Stack.py index 8033bf7..d9c83ba 100644 --- a/ld2dap/core/Stack.py +++ b/ld2dap/core/Stack.py @@ -8,9 +8,11 @@ # # TODO details +import logging class Stack(object): def __init__(self, begin=0, size=1, desc=None, symb=None) : + self.logger = logging.getLogger('Stack') self.begin = begin self.end = begin + size self.desc = list() @@ -22,6 +24,16 @@ class Stack(object): for i in range(size): self.symb.append(symb.copy() if isinstance(symb, list) else [symb]) + def copy(self): + self.logger.debug('Copy method called') + new_stack = Stack() + new_stack.__dict__ = self.__dict__.copy() + new_stack.desc = self.desc.copy() + new_stack.symb = self.symb.copy() + self.logger.debug('Old Meta: {}, New Meta: {}'.format( + hex(id(self.desc)), hex(id(new_stack.symb)))) + return new_stack + def __str__(self): return ("Stack: begin: {}, end: {}, desc: {}, symb: {}".format( self.begin, self.end, self.desc, self.symb)) diff --git a/logging.yaml b/logging.yaml index b18e6ed..cf50544 100644 --- a/logging.yaml +++ b/logging.yaml @@ -7,7 +7,7 @@ formatters: handlers: console: class: logging.StreamHandler - level: INFO + level: DEBUG formatter: simple stream: ext://sys.stdout