From 7ad2cb13b7727bda42956585daf789257f606ae9 Mon Sep 17 00:00:00 2001 From: Edoardo Pasca Date: Thu, 9 May 2019 11:51:15 +0100 Subject: updates --- Wrappers/Python/ccpi/data/__init__.py | 66 ----------------------- Wrappers/Python/ccpi/data/boat.tiff | Bin 262278 -> 0 bytes Wrappers/Python/ccpi/data/camera.png | Bin 114228 -> 0 bytes Wrappers/Python/ccpi/data/peppers.tiff | Bin 786572 -> 0 bytes Wrappers/Python/ccpi/data/test_show_data.py | 30 ----------- Wrappers/Python/ccpi/framework/TestData.py | 79 ++++++++++++++++++++++++++++ Wrappers/Python/ccpi/framework/__init__.py | 2 + Wrappers/Python/conda-recipe/meta.yaml | 1 + Wrappers/Python/data/boat.tiff | Bin 0 -> 262278 bytes Wrappers/Python/data/camera.png | Bin 0 -> 114228 bytes Wrappers/Python/data/peppers.tiff | Bin 0 -> 786572 bytes Wrappers/Python/data/test_show_data.py | 30 +++++++++++ Wrappers/Python/setup.py | 9 ++-- Wrappers/Python/test/test_functions.py | 2 +- 14 files changed, 119 insertions(+), 100 deletions(-) delete mode 100644 Wrappers/Python/ccpi/data/__init__.py delete mode 100644 Wrappers/Python/ccpi/data/boat.tiff delete mode 100644 Wrappers/Python/ccpi/data/camera.png delete mode 100644 Wrappers/Python/ccpi/data/peppers.tiff delete mode 100644 Wrappers/Python/ccpi/data/test_show_data.py create mode 100755 Wrappers/Python/ccpi/framework/TestData.py create mode 100644 Wrappers/Python/data/boat.tiff create mode 100644 Wrappers/Python/data/camera.png create mode 100644 Wrappers/Python/data/peppers.tiff create mode 100644 Wrappers/Python/data/test_show_data.py diff --git a/Wrappers/Python/ccpi/data/__init__.py b/Wrappers/Python/ccpi/data/__init__.py deleted file mode 100644 index 2884108..0000000 --- a/Wrappers/Python/ccpi/data/__init__.py +++ /dev/null @@ -1,66 +0,0 @@ -# -*- coding: utf-8 -*- -# This work is part of the Core Imaging Library developed by -# Visual Analytics and Imaging System Group of the Science Technology -# Facilities Council, STFC - -# Copyright 2018 Edoardo Pasca - -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at - -# http://www.apache.org/licenses/LICENSE-2.0 - -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -from ccpi.framework import ImageData -import numpy -from PIL import Image -import os -import os.path - -data_dir = os.path.abspath(os.path.dirname(__file__)) - -def camera(**kwargs): - - tmp = Image.open(os.path.join(data_dir, 'camera.png')) - - size = kwargs.get('size',(512, 512)) - - data = numpy.array(tmp.resize(size)) - - data = data/data.max() - - return ImageData(data) - - -def boat(**kwargs): - - tmp = Image.open(os.path.join(data_dir, 'boat.tiff')) - - size = kwargs.get('size',(512, 512)) - - data = numpy.array(tmp.resize(size)) - - data = data/data.max() - - return ImageData(data) - - -def peppers(**kwargs): - - tmp = Image.open(os.path.join(data_dir, 'peppers.tiff')) - - size = kwargs.get('size',(512, 512)) - - data = numpy.array(tmp.resize(size)) - - data = data/data.max() - - return ImageData(data) - diff --git a/Wrappers/Python/ccpi/data/boat.tiff b/Wrappers/Python/ccpi/data/boat.tiff deleted file mode 100644 index fc1205a..0000000 Binary files a/Wrappers/Python/ccpi/data/boat.tiff and /dev/null differ diff --git a/Wrappers/Python/ccpi/data/camera.png b/Wrappers/Python/ccpi/data/camera.png deleted file mode 100644 index 49be869..0000000 Binary files a/Wrappers/Python/ccpi/data/camera.png and /dev/null differ diff --git a/Wrappers/Python/ccpi/data/peppers.tiff b/Wrappers/Python/ccpi/data/peppers.tiff deleted file mode 100644 index 8c956f8..0000000 Binary files a/Wrappers/Python/ccpi/data/peppers.tiff and /dev/null differ diff --git a/Wrappers/Python/ccpi/data/test_show_data.py b/Wrappers/Python/ccpi/data/test_show_data.py deleted file mode 100644 index 7325c27..0000000 --- a/Wrappers/Python/ccpi/data/test_show_data.py +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -""" -Created on Tue May 7 20:43:48 2019 - -@author: evangelos -""" - -from ccpi.data import camera, boat, peppers -import matplotlib.pyplot as plt - - -d = camera(size=(256,256)) - -plt.imshow(d.as_array()) -plt.colorbar() -plt.show() - -d1 = boat(size=(256,256)) - -plt.imshow(d1.as_array()) -plt.colorbar() -plt.show() - - -d2 = peppers(size=(256,256)) - -plt.imshow(d2.as_array()) -plt.colorbar() -plt.show() \ No newline at end of file diff --git a/Wrappers/Python/ccpi/framework/TestData.py b/Wrappers/Python/ccpi/framework/TestData.py new file mode 100755 index 0000000..61ed4df --- /dev/null +++ b/Wrappers/Python/ccpi/framework/TestData.py @@ -0,0 +1,79 @@ +# -*- coding: utf-8 -*- +from ccpi.framework import ImageData +import numpy +from PIL import Image +import os +import os.path + +data_dir = os.path.abspath(os.path.join( + os.path.dirname(__file__), + '../data/') +) + +class TestData(object): + BOAT = 'boat.tiff' + CAMERA = 'camera.png' + PEPPERS = 'peppers.tiff' + + def __init__(self, **kwargs): + self.data_dir = kwargs.get('data_dir', data_dir) + + def load(self, which, size=(512,512), scale=(0,1), **kwargs): + if which not in [TestData.BOAT, TestData.CAMERA, TestData.PEPPERS]: + raise ValueError('Unknown TestData {}.'.format(which)) + tmp = Image.open(os.path.join(data_dir, which)) + + data = numpy.array(tmp.resize(size)) + + if scale is not None: + dmax = data.max() + dmin = data.min() + + data = data -dmin / (dmax - dmin) + + if scale != (0,1): + #data = (data-dmin)/(dmax-dmin) * (scale[1]-scale[0]) +scale[0]) + data *= (scale[1]-scale[0]) + data += scale[0] + + return ImageData(data) + + + def camera(**kwargs): + + tmp = Image.open(os.path.join(data_dir, 'camera.png')) + + size = kwargs.get('size',(512, 512)) + + data = numpy.array(tmp.resize(size)) + + data = data/data.max() + + return ImageData(data) + + + def boat(**kwargs): + + tmp = Image.open(os.path.join(data_dir, 'boat.tiff')) + + size = kwargs.get('size',(512, 512)) + + data = numpy.array(tmp.resize(size)) + + data = data/data.max() + + return ImageData(data) + + + def peppers(**kwargs): + + tmp = Image.open(os.path.join(data_dir, 'peppers.tiff')) + + size = kwargs.get('size',(512, 512)) + + data = numpy.array(tmp.resize(size)) + + data = data/data.max() + + return ImageData(data) + diff --git a/Wrappers/Python/ccpi/framework/__init__.py b/Wrappers/Python/ccpi/framework/__init__.py index 229edb5..8926897 100755 --- a/Wrappers/Python/ccpi/framework/__init__.py +++ b/Wrappers/Python/ccpi/framework/__init__.py @@ -24,3 +24,5 @@ from .framework import DataProcessor from .framework import AX, PixelByPixelDataProcessor, CastDataContainer from .BlockDataContainer import BlockDataContainer from .BlockGeometry import BlockGeometry + +from .TestData import TestData diff --git a/Wrappers/Python/conda-recipe/meta.yaml b/Wrappers/Python/conda-recipe/meta.yaml index 6564014..9d03220 100644 --- a/Wrappers/Python/conda-recipe/meta.yaml +++ b/Wrappers/Python/conda-recipe/meta.yaml @@ -35,6 +35,7 @@ requirements: - scipy - matplotlib - h5py + - pillow about: home: http://www.ccpi.ac.uk diff --git a/Wrappers/Python/data/boat.tiff b/Wrappers/Python/data/boat.tiff new file mode 100644 index 0000000..fc1205a Binary files /dev/null and b/Wrappers/Python/data/boat.tiff differ diff --git a/Wrappers/Python/data/camera.png b/Wrappers/Python/data/camera.png new file mode 100644 index 0000000..49be869 Binary files /dev/null and b/Wrappers/Python/data/camera.png differ diff --git a/Wrappers/Python/data/peppers.tiff b/Wrappers/Python/data/peppers.tiff new file mode 100644 index 0000000..8c956f8 Binary files /dev/null and b/Wrappers/Python/data/peppers.tiff differ diff --git a/Wrappers/Python/data/test_show_data.py b/Wrappers/Python/data/test_show_data.py new file mode 100644 index 0000000..7325c27 --- /dev/null +++ b/Wrappers/Python/data/test_show_data.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Tue May 7 20:43:48 2019 + +@author: evangelos +""" + +from ccpi.data import camera, boat, peppers +import matplotlib.pyplot as plt + + +d = camera(size=(256,256)) + +plt.imshow(d.as_array()) +plt.colorbar() +plt.show() + +d1 = boat(size=(256,256)) + +plt.imshow(d1.as_array()) +plt.colorbar() +plt.show() + + +d2 = peppers(size=(256,256)) + +plt.imshow(d2.as_array()) +plt.colorbar() +plt.show() \ No newline at end of file diff --git a/Wrappers/Python/setup.py b/Wrappers/Python/setup.py index bceea46..6c76eff 100644 --- a/Wrappers/Python/setup.py +++ b/Wrappers/Python/setup.py @@ -31,7 +31,7 @@ if cil_version == '': setup( name="ccpi-framework", version=cil_version, - packages=['ccpi' , 'ccpi.io', 'ccpi.data', + packages=['ccpi' , 'ccpi.io', 'ccpi.framework', 'ccpi.optimisation', 'ccpi.optimisation.operators', 'ccpi.optimisation.algorithms', @@ -39,6 +39,8 @@ setup( 'ccpi.processors', 'ccpi.contrib','ccpi.contrib.optimisation', 'ccpi.contrib.optimisation.algorithms'], + data_file = [('share/ccpi', ['data/boat.tiff', 'data/peppers.tiff', + 'data/camera.png'])], # Project uses reStructuredText, so ensure that the docutils get # installed or upgraded on the target machine @@ -53,8 +55,9 @@ setup( # zip_safe = False, # metadata for upload to PyPI - author="Edoardo Pasca", - author_email="edoardo.pasca@stfc.ac.uk", + author="CCPi developers", + maintainer="Edoardo Pasca", + maintainer_email="edoardo.pasca@stfc.ac.uk", description='CCPi Core Imaging Library - Python Framework Module', license="Apache v2.0", keywords="Python Framework", diff --git a/Wrappers/Python/test/test_functions.py b/Wrappers/Python/test/test_functions.py index af419c7..082548b 100644 --- a/Wrappers/Python/test/test_functions.py +++ b/Wrappers/Python/test/test_functions.py @@ -299,7 +299,7 @@ class TestFunction(unittest.TestCase): A = 0.5 * Identity(ig) old_chisq = Norm2sq(A, b, 1.0) - new_chisq = FunctionOperatorComposition(A, L2NormSquared(b=b)) + new_chisq = FunctionOperatorComposition(L2NormSquared(b=b),A) yold = old_chisq(u) ynew = new_chisq(u) -- cgit v1.2.3