diff options
| -rw-r--r-- | Wrappers/Python/ccpi/data/__init__.py | 66 | ||||
| -rwxr-xr-x | Wrappers/Python/ccpi/framework/TestData.py | 79 | ||||
| -rwxr-xr-x | Wrappers/Python/ccpi/framework/__init__.py | 2 | ||||
| -rw-r--r-- | Wrappers/Python/conda-recipe/meta.yaml | 1 | ||||
| -rw-r--r-- | Wrappers/Python/data/boat.tiff (renamed from Wrappers/Python/ccpi/data/boat.tiff) | bin | 262278 -> 262278 bytes | |||
| -rw-r--r-- | Wrappers/Python/data/camera.png (renamed from Wrappers/Python/ccpi/data/camera.png) | bin | 114228 -> 114228 bytes | |||
| -rw-r--r-- | Wrappers/Python/data/peppers.tiff (renamed from Wrappers/Python/ccpi/data/peppers.tiff) | bin | 786572 -> 786572 bytes | |||
| -rw-r--r-- | Wrappers/Python/data/test_show_data.py (renamed from Wrappers/Python/ccpi/data/test_show_data.py) | 0 | ||||
| -rw-r--r-- | Wrappers/Python/setup.py | 9 | ||||
| -rw-r--r-- | Wrappers/Python/test/test_functions.py | 2 | 
10 files changed, 89 insertions, 70 deletions
| 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/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/ccpi/data/boat.tiff b/Wrappers/Python/data/boat.tiffBinary files differ index fc1205a..fc1205a 100644 --- a/Wrappers/Python/ccpi/data/boat.tiff +++ b/Wrappers/Python/data/boat.tiff diff --git a/Wrappers/Python/ccpi/data/camera.png b/Wrappers/Python/data/camera.pngBinary files differ index 49be869..49be869 100644 --- a/Wrappers/Python/ccpi/data/camera.png +++ b/Wrappers/Python/data/camera.png diff --git a/Wrappers/Python/ccpi/data/peppers.tiff b/Wrappers/Python/data/peppers.tiffBinary files differ index 8c956f8..8c956f8 100644 --- a/Wrappers/Python/ccpi/data/peppers.tiff +++ b/Wrappers/Python/data/peppers.tiff diff --git a/Wrappers/Python/ccpi/data/test_show_data.py b/Wrappers/Python/data/test_show_data.py index 7325c27..7325c27 100644 --- a/Wrappers/Python/ccpi/data/test_show_data.py +++ b/Wrappers/Python/data/test_show_data.py 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) | 
