summaryrefslogtreecommitdiffstats
path: root/Wrappers
diff options
context:
space:
mode:
authorEdoardo Pasca <edo.paskino@gmail.com>2020-01-16 11:14:33 +0000
committerGitHub <noreply@github.com>2020-01-16 11:14:33 +0000
commit7756574e2c0a45f55ff974f57eee18c8579dc985 (patch)
tree9c24e6ad3c176e55ad6b7360ec2ac1fbd70d1c1e /Wrappers
parenteffae8056a541b8928caba54f696935c0c5cd014 (diff)
downloadframework-7756574e2c0a45f55ff974f57eee18c8579dc985.tar.gz
framework-7756574e2c0a45f55ff974f57eee18c8579dc985.tar.bz2
framework-7756574e2c0a45f55ff974f57eee18c8579dc985.tar.xz
framework-7756574e2c0a45f55ff974f57eee18c8579dc985.zip
add reduction min and max (#486)
* add reduction min and max closes #441 * add spacing
Diffstat (limited to 'Wrappers')
-rw-r--r--Wrappers/Python/ccpi/framework/framework.py10
-rwxr-xr-xWrappers/Python/test/test_DataContainer.py19
2 files changed, 27 insertions, 2 deletions
diff --git a/Wrappers/Python/ccpi/framework/framework.py b/Wrappers/Python/ccpi/framework/framework.py
index 968c69c..65121d2 100644
--- a/Wrappers/Python/ccpi/framework/framework.py
+++ b/Wrappers/Python/ccpi/framework/framework.py
@@ -939,6 +939,7 @@ class DataContainer(object):
def log(self, *args, **kwargs):
'''Applies log pixel-wise to the DataContainer'''
return self.pixel_wise_unary(numpy.log, *args, **kwargs)
+
#def __abs__(self):
# operation = FM.OPERATION.ABS
# return self.callFieldMath(operation, None, self.mask, self.maskOnValue)
@@ -981,7 +982,14 @@ class DataContainer(object):
return sf
else:
raise ValueError('Shapes are not aligned: {} != {}'.format(self.shape, other.shape))
-
+
+ def min(self, *args, **kwargs):
+ '''Returns the min pixel value in the DataContainer'''
+ return numpy.min(self.as_array(), *args, **kwargs)
+
+ def max(self, *args, **kwargs):
+ '''Returns the max pixel value in the DataContainer'''
+ return numpy.max(self.as_array(), *args, **kwargs)
diff --git a/Wrappers/Python/test/test_DataContainer.py b/Wrappers/Python/test/test_DataContainer.py
index d2d5b05..6e297ee 100755
--- a/Wrappers/Python/test/test_DataContainer.py
+++ b/Wrappers/Python/test/test_DataContainer.py
@@ -744,7 +744,24 @@ class TestDataContainer(unittest.TestCase):
res = numpy.ones_like(d1.as_array()) * 4.
numpy.testing.assert_array_equal(res, out.as_array())
-
+ def test_min(self):
+ print ("test min")
+ ig = ImageGeometry(10,10)
+ a = numpy.asarray(numpy.linspace(-10,10, num=100, endpoint=True), dtype=numpy.float32)
+ a = a.reshape((10,10))
+ d1 = ig.allocate(1)
+ d1.fill(a)
+ self.assertAlmostEqual(d1.min(), -10.)
+
+ def test_max(self):
+ print ("test max")
+ ig = ImageGeometry(10,10)
+ a = numpy.asarray(numpy.linspace(-10,10, num=100, endpoint=True), dtype=numpy.float32)
+ a = a.reshape((10,10))
+ d1 = ig.allocate(1)
+ d1.fill(a)
+ self.assertAlmostEqual(d1.max(), 10.)
+