WIP on Treshold refactoring

This commit is contained in:
Florent Guiotte 2018-05-09 16:58:27 +02:00
parent 7b6ae7c9ca
commit d0971e58a4
4 changed files with 183 additions and 2 deletions

View File

@ -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
}

View File

@ -22,7 +22,7 @@ class Input(Node):
"""Override abstract method""" """Override abstract method"""
data, meta = self._process(data, metadata) data, meta = self._process(data, metadata)
for output in self.outputs: for output in self.outputs:
output.process(data, meta) output.process(data, [x.copy() for x in meta])
def _run(self): def _run(self):
self.process(None, None) self.process(None, None)

View File

@ -8,9 +8,11 @@
# #
# TODO details # TODO details
import logging
class Stack(object): class Stack(object):
def __init__(self, begin=0, size=1, desc=None, symb=None) : def __init__(self, begin=0, size=1, desc=None, symb=None) :
self.logger = logging.getLogger('Stack')
self.begin = begin self.begin = begin
self.end = begin + size self.end = begin + size
self.desc = list() self.desc = list()
@ -22,6 +24,16 @@ class Stack(object):
for i in range(size): for i in range(size):
self.symb.append(symb.copy() if isinstance(symb, list) else [symb]) 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): def __str__(self):
return ("Stack: begin: {}, end: {}, desc: {}, symb: {}".format( return ("Stack: begin: {}, end: {}, desc: {}, symb: {}".format(
self.begin, self.end, self.desc, self.symb)) self.begin, self.end, self.desc, self.symb))

View File

@ -7,7 +7,7 @@ formatters:
handlers: handlers:
console: console:
class: logging.StreamHandler class: logging.StreamHandler
level: INFO level: DEBUG
formatter: simple formatter: simple
stream: ext://sys.stdout stream: ext://sys.stdout