From f633ca0a64622101e39f5593a53e504f9509a0bc Mon Sep 17 00:00:00 2001 From: Karamaz0V1 Date: Thu, 12 Apr 2018 19:15:50 +0200 Subject: [PATCH] Create ld2dap package --- Notebooks/Node Streaming Benchmark.ipynb | 53 +++++++++++++++++++++++- Notebooks/Node Streaming Debug.ipynb | 31 ++++++++++++++ ld2dap/AttributeProfiles.py | 2 +- ld2dap/LoadTIFF.py | 4 +- ld2dap/SaveFig.py | 2 +- ld2dap/ShowFig.py | 5 ++- ld2dap/Treshold.py | 6 ++- ld2dap/__init__.py | 15 +++++++ ld2dap/test.py => test.py | 9 ++-- 9 files changed, 111 insertions(+), 16 deletions(-) create mode 100644 Notebooks/Node Streaming Debug.ipynb create mode 100644 ld2dap/__init__.py rename ld2dap/test.py => test.py (67%) diff --git a/Notebooks/Node Streaming Benchmark.ipynb b/Notebooks/Node Streaming Benchmark.ipynb index f0d975f..ae2a9f9 100644 --- a/Notebooks/Node Streaming Benchmark.ipynb +++ b/Notebooks/Node Streaming Benchmark.ipynb @@ -6,7 +6,16 @@ "metadata": {}, "outputs": [], "source": [ - "from pathlib import Path" + "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" ] }, { @@ -15,7 +24,47 @@ "metadata": {}, "outputs": [], "source": [ - "url = '../Data/test.tiff'" + "load = ld2dap.LoadTIFF('../Data/test.tiff')\n", + "trsh = ld2dap.Treshold(1e3)\n", + "disp = ld2dap.ShowFig(fname=None)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "disp.input = trsh\n", + "trsh.input = load" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "disp.run()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "load.files" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "A = 'est'\n", + "isinstance(A, collections.Iterable)" ] }, { diff --git a/Notebooks/Node Streaming Debug.ipynb b/Notebooks/Node Streaming Debug.ipynb new file mode 100644 index 0000000..0d23948 --- /dev/null +++ b/Notebooks/Node Streaming Debug.ipynb @@ -0,0 +1,31 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "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/AttributeProfiles.py b/ld2dap/AttributeProfiles.py index 8b01389..1334857 100644 --- a/ld2dap/AttributeProfiles.py +++ b/ld2dap/AttributeProfiles.py @@ -8,7 +8,7 @@ # # TODO details -from core import Filter, Stack +from .core import Filter, Stack ## TODO: dep import sys diff --git a/ld2dap/LoadTIFF.py b/ld2dap/LoadTIFF.py index 7f05870..cdc723e 100644 --- a/ld2dap/LoadTIFF.py +++ b/ld2dap/LoadTIFF.py @@ -8,7 +8,7 @@ # # TODO details -from core import Input, Stack +from ld2dap.core import Input, Stack import numpy as np ## TODO: dep @@ -19,7 +19,7 @@ import triskele class LoadTIFF(Input): def __init__(self, tiffFiles): super().__init__(self.__class__.__name__) - self.files = tiffFiles + self.files = tiffFiles if isinstance(tiffFiles, list) else [tiffFiles] def _process(self, data, metadata): layers = list() diff --git a/ld2dap/SaveFig.py b/ld2dap/SaveFig.py index c51c94a..7fff297 100644 --- a/ld2dap/SaveFig.py +++ b/ld2dap/SaveFig.py @@ -8,7 +8,7 @@ # # TODO details -from core import Output +from ld2dap.core import Output import matplotlib.pyplot as plt diff --git a/ld2dap/ShowFig.py b/ld2dap/ShowFig.py index a225753..dac3496 100644 --- a/ld2dap/ShowFig.py +++ b/ld2dap/ShowFig.py @@ -8,7 +8,7 @@ # # TODO details -from core import Output +from ld2dap.core import Output import matplotlib.pyplot as plt @@ -26,6 +26,7 @@ class ShowFig(Output): img = f1.imshow(data[:,:,-1]) plt.colorbar(img) if metadata is not None: - f1.set_title(metadata[-1].desc) + print (metadata[0].desc) + f1.set_title(' > '.join(metadata[0].desc[-1])) plt.show() plt.close(fig) diff --git a/ld2dap/Treshold.py b/ld2dap/Treshold.py index dee20fd..0c6a71b 100644 --- a/ld2dap/Treshold.py +++ b/ld2dap/Treshold.py @@ -8,7 +8,7 @@ # # TODO details -from core import Filter +from ld2dap.core import Filter class Treshold(Filter): def __init__(self, treshold, max_value=None): @@ -21,6 +21,8 @@ class Treshold(Filter): self.max_value = data[data < self.treshold].max() for stack in metadata: - stack.desc.append('treshold {}'.format(self.treshold)) + for d, s in zip(stack.desc, stack.symb): + d.append('treshold {}'.format(self.treshold)) + s.append('T_{{{}}}'.format(self.treshold)) return data * (data < self.treshold) + self.max_value * (data >= self.treshold), metadata diff --git a/ld2dap/__init__.py b/ld2dap/__init__.py new file mode 100644 index 0000000..1ca716d --- /dev/null +++ b/ld2dap/__init__.py @@ -0,0 +1,15 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# \file __init__.py +# \brief TODO +# \author Florent Guiotte +# \version 0.1 +# \date 12 avril 2018 +# +# TODO details + +from .AttributeProfiles import AttributeProfiles +from .Treshold import Treshold +from .LoadTIFF import LoadTIFF +from .SaveFig import SaveFig +from .ShowFig import ShowFig diff --git a/ld2dap/test.py b/test.py similarity index 67% rename from ld2dap/test.py rename to test.py index 00c0725..0e9d325 100644 --- a/ld2dap/test.py +++ b/test.py @@ -9,16 +9,13 @@ # TODO details #from core import Input, Output, Filter -from LoadTIFF import LoadTIFF -from AttributeProfiles import AttributeProfiles as APs -from SaveFig import SaveFig -from Treshold import Treshold -from ShowFig import ShowFig +from ld2dap import LoadTIFF, SaveFig, Treshold, ShowFig +from ld2dap import AttributeProfiles as APs import numpy as np def main(): - i = LoadTIFF(['../Data/test.tiff', '../Data/test.tiff']) + i = LoadTIFF(['Data/test.tiff', 'Data/test2.tiff']) t = Treshold(1e4) ap = APs(np.array([100,1e3,1e4])) o = SaveFig('test.png')