From 7689382a648a715a303ba7cf8612c0cc44f38684 Mon Sep 17 00:00:00 2001 From: Karamaz0V1 Date: Mon, 9 Apr 2018 20:35:37 +0200 Subject: [PATCH] Matplotlib is garbage --- ld2dap/SaveFig.py | 12 +++++++----- ld2dap/ShowFig.py | 31 +++++++++++++++++++++++++++++++ ld2dap/Treshold.py | 23 +++++++++++++++++++++++ ld2dap/test.py | 10 ++++++++-- 4 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 ld2dap/ShowFig.py create mode 100644 ld2dap/Treshold.py diff --git a/ld2dap/SaveFig.py b/ld2dap/SaveFig.py index 9d72e50..c51c94a 100644 --- a/ld2dap/SaveFig.py +++ b/ld2dap/SaveFig.py @@ -21,9 +21,11 @@ class SaveFig(Output): def _process(self, data, metadata): im_size = 2 - plt.figure(figsize=(16*im_size,3*im_size)) - plt.imshow(data[:,:,-1]) - plt.colorbar() + fig = plt.figure(figsize=(16*im_size,3*im_size)) + f1 = fig.add_subplot(111) + img = f1.imshow(data[:,:,-1]) + plt.colorbar(img) if metadata is not None: - plt.title(metadata[-1]) - plt.savefig(self.fname, bbox_inches=self.bbox_inches, pad_inches=self.pad_inches) + f1.set_title(metadata[-1]) + fig.savefig(self.fname, bbox_inches=self.bbox_inches, pad_inches=self.pad_inches) + plt.close(fig) diff --git a/ld2dap/ShowFig.py b/ld2dap/ShowFig.py new file mode 100644 index 0000000..08494b0 --- /dev/null +++ b/ld2dap/ShowFig.py @@ -0,0 +1,31 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# \file SaveFig.py +# \brief TODO +# \author Florent Guiotte +# \version 0.1 +# \date 09 avril 2018 +# +# TODO details + +from core import Output + +import matplotlib.pyplot as plt + +class ShowFig(Output): + def __init__(self, fname, bbox_inches='tight', pad_inches=1): + super().__init__(self.__class__.__name__) + self.fname = fname + self.bbox_inches = bbox_inches + self.pad_inches = pad_inches + + def _process(self, data, metadata): + im_size = 2 + fig = plt.figure(figsize=(16*im_size,3*im_size)) + f1 = fig.add_subplot(111) + img = f1.imshow(data[:,:,-1]) + plt.colorbar(img) + if metadata is not None: + f1.set_title(metadata[-1]) + plt.show() + plt.close(fig) diff --git a/ld2dap/Treshold.py b/ld2dap/Treshold.py new file mode 100644 index 0000000..37f1540 --- /dev/null +++ b/ld2dap/Treshold.py @@ -0,0 +1,23 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# \file Treshold.py +# \brief TODO +# \author Florent Guiotte +# \version 0.1 +# \date 09 avril 2018 +# +# TODO details + +from core import Filter + +class Treshold(Filter): + def __init__(self, treshold, max_value=None): + super().__init__(self.__class__.__name__) + self.treshold = treshold + self.max_value = max_value #if max_value is not None else treshold + + def _process(self, data, metadata): + if self.max_value is None: + self.max_value = data[data < self.treshold].max() + + return data * (data < self.treshold) + self.max_value * (data >= self.treshold), metadata diff --git a/ld2dap/test.py b/ld2dap/test.py index 6769ceb..00c0725 100644 --- a/ld2dap/test.py +++ b/ld2dap/test.py @@ -12,18 +12,24 @@ from LoadTIFF import LoadTIFF from AttributeProfiles import AttributeProfiles as APs from SaveFig import SaveFig +from Treshold import Treshold +from ShowFig import ShowFig import numpy as np def main(): i = LoadTIFF(['../Data/test.tiff', '../Data/test.tiff']) + t = Treshold(1e4) ap = APs(np.array([100,1e3,1e4])) o = SaveFig('test.png') + s = ShowFig(None) - ap.input = i + t.input = i + ap.input = t o.input = ap + s.input = ap - o.run() + i.run() if __name__ == '__main__': main()