diff options
author | Matthias Vogelgesang <matthias.vogelgesang@kit.edu> | 2013-09-10 12:08:35 +0200 |
---|---|---|
committer | Matthias Vogelgesang <matthias.vogelgesang@kit.edu> | 2013-09-10 12:08:35 +0200 |
commit | 5b0855cf7c1de15694eada6e8d44df12ca879449 (patch) | |
tree | c66f780424a78f47ecb9a3959a5be3f34f68b09d /tests | |
parent | a9b590763f84538adf37ec232021f941c7d68a70 (diff) | |
download | ufo-filters-5b0855cf7c1de15694eada6e8d44df12ca879449.tar.gz ufo-filters-5b0855cf7c1de15694eada6e8d44df12ca879449.tar.bz2 ufo-filters-5b0855cf7c1de15694eada6e8d44df12ca879449.tar.xz ufo-filters-5b0855cf7c1de15694eada6e8d44df12ca879449.zip |
Add unit tests
Diffstat (limited to 'tests')
-rw-r--r-- | tests/data/sinogram-00000.tif | bin | 0 -> 1049734 bytes | |||
-rw-r--r-- | tests/data/sinogram-00001.tif | bin | 0 -> 1049734 bytes | |||
-rw-r--r-- | tests/data/sinogram-00002.tif | bin | 0 -> 1049734 bytes | |||
-rw-r--r-- | tests/data/sinogram-00003.tif | bin | 0 -> 1049734 bytes | |||
-rw-r--r-- | tests/data/sinogram-00004.tif | bin | 0 -> 1049734 bytes | |||
-rw-r--r-- | tests/data/sinogram-00005.tif | bin | 0 -> 1049734 bytes | |||
-rw-r--r-- | tests/data/sinogram-00006.tif | bin | 0 -> 1049734 bytes | |||
-rw-r--r-- | tests/data/sinogram-00007.tif | bin | 0 -> 1049734 bytes | |||
-rw-r--r-- | tests/data/sinogram-00008.tif | bin | 0 -> 1049734 bytes | |||
-rw-r--r-- | tests/data/sinogram-00009.tif | bin | 0 -> 1049734 bytes | |||
-rw-r--r-- | tests/data/sinogram-00010.tif | bin | 0 -> 1049734 bytes | |||
-rw-r--r-- | tests/data/sinogram-00011.tif | bin | 0 -> 1049734 bytes | |||
-rw-r--r-- | tests/data/sinogram-00012.tif | bin | 0 -> 1049734 bytes | |||
-rw-r--r-- | tests/data/sinogram-00013.tif | bin | 0 -> 1049734 bytes | |||
-rw-r--r-- | tests/data/sinogram-00014.tif | bin | 0 -> 1049734 bytes | |||
-rw-r--r-- | tests/data/sinogram-00015.tif | bin | 0 -> 1049734 bytes | |||
-rw-r--r-- | tests/expected/phantom-00000.tif | bin | 0 -> 1049734 bytes | |||
-rw-r--r-- | tests/expected/phantom-00001.tif | bin | 0 -> 1049734 bytes | |||
-rw-r--r-- | tests/expected/phantom-00002.tif | bin | 0 -> 1049734 bytes | |||
-rw-r--r-- | tests/expected/phantom-00003.tif | bin | 0 -> 1049734 bytes | |||
-rw-r--r-- | tests/expected/phantom-00004.tif | bin | 0 -> 1049734 bytes | |||
-rw-r--r-- | tests/expected/phantom-00005.tif | bin | 0 -> 1049734 bytes | |||
-rw-r--r-- | tests/expected/phantom-00006.tif | bin | 0 -> 1049734 bytes | |||
-rw-r--r-- | tests/expected/phantom-00007.tif | bin | 0 -> 1049734 bytes | |||
-rw-r--r-- | tests/expected/phantom-00008.tif | bin | 0 -> 1049734 bytes | |||
-rw-r--r-- | tests/expected/phantom-00009.tif | bin | 0 -> 1049734 bytes | |||
-rw-r--r-- | tests/expected/phantom-00010.tif | bin | 0 -> 1049734 bytes | |||
-rw-r--r-- | tests/expected/phantom-00011.tif | bin | 0 -> 1049734 bytes | |||
-rw-r--r-- | tests/expected/phantom-00012.tif | bin | 0 -> 1049734 bytes | |||
-rw-r--r-- | tests/expected/phantom-00013.tif | bin | 0 -> 1049734 bytes | |||
-rw-r--r-- | tests/expected/phantom-00014.tif | bin | 0 -> 1049734 bytes | |||
-rw-r--r-- | tests/expected/phantom-00015.tif | bin | 0 -> 1049734 bytes | |||
-rw-r--r-- | tests/tests.py | 141 |
33 files changed, 141 insertions, 0 deletions
diff --git a/tests/data/sinogram-00000.tif b/tests/data/sinogram-00000.tif Binary files differnew file mode 100644 index 0000000..b3b43c9 --- /dev/null +++ b/tests/data/sinogram-00000.tif diff --git a/tests/data/sinogram-00001.tif b/tests/data/sinogram-00001.tif Binary files differnew file mode 100644 index 0000000..405f725 --- /dev/null +++ b/tests/data/sinogram-00001.tif diff --git a/tests/data/sinogram-00002.tif b/tests/data/sinogram-00002.tif Binary files differnew file mode 100644 index 0000000..6b9ba8f --- /dev/null +++ b/tests/data/sinogram-00002.tif diff --git a/tests/data/sinogram-00003.tif b/tests/data/sinogram-00003.tif Binary files differnew file mode 100644 index 0000000..8483be2 --- /dev/null +++ b/tests/data/sinogram-00003.tif diff --git a/tests/data/sinogram-00004.tif b/tests/data/sinogram-00004.tif Binary files differnew file mode 100644 index 0000000..ced97f8 --- /dev/null +++ b/tests/data/sinogram-00004.tif diff --git a/tests/data/sinogram-00005.tif b/tests/data/sinogram-00005.tif Binary files differnew file mode 100644 index 0000000..25c7527 --- /dev/null +++ b/tests/data/sinogram-00005.tif diff --git a/tests/data/sinogram-00006.tif b/tests/data/sinogram-00006.tif Binary files differnew file mode 100644 index 0000000..11ea705 --- /dev/null +++ b/tests/data/sinogram-00006.tif diff --git a/tests/data/sinogram-00007.tif b/tests/data/sinogram-00007.tif Binary files differnew file mode 100644 index 0000000..00d994a --- /dev/null +++ b/tests/data/sinogram-00007.tif diff --git a/tests/data/sinogram-00008.tif b/tests/data/sinogram-00008.tif Binary files differnew file mode 100644 index 0000000..03da0f2 --- /dev/null +++ b/tests/data/sinogram-00008.tif diff --git a/tests/data/sinogram-00009.tif b/tests/data/sinogram-00009.tif Binary files differnew file mode 100644 index 0000000..919d819 --- /dev/null +++ b/tests/data/sinogram-00009.tif diff --git a/tests/data/sinogram-00010.tif b/tests/data/sinogram-00010.tif Binary files differnew file mode 100644 index 0000000..f9e95ab --- /dev/null +++ b/tests/data/sinogram-00010.tif diff --git a/tests/data/sinogram-00011.tif b/tests/data/sinogram-00011.tif Binary files differnew file mode 100644 index 0000000..f3288ce --- /dev/null +++ b/tests/data/sinogram-00011.tif diff --git a/tests/data/sinogram-00012.tif b/tests/data/sinogram-00012.tif Binary files differnew file mode 100644 index 0000000..a507b54 --- /dev/null +++ b/tests/data/sinogram-00012.tif diff --git a/tests/data/sinogram-00013.tif b/tests/data/sinogram-00013.tif Binary files differnew file mode 100644 index 0000000..fe3de7d --- /dev/null +++ b/tests/data/sinogram-00013.tif diff --git a/tests/data/sinogram-00014.tif b/tests/data/sinogram-00014.tif Binary files differnew file mode 100644 index 0000000..01facb6 --- /dev/null +++ b/tests/data/sinogram-00014.tif diff --git a/tests/data/sinogram-00015.tif b/tests/data/sinogram-00015.tif Binary files differnew file mode 100644 index 0000000..a628731 --- /dev/null +++ b/tests/data/sinogram-00015.tif diff --git a/tests/expected/phantom-00000.tif b/tests/expected/phantom-00000.tif Binary files differnew file mode 100644 index 0000000..c669db2 --- /dev/null +++ b/tests/expected/phantom-00000.tif diff --git a/tests/expected/phantom-00001.tif b/tests/expected/phantom-00001.tif Binary files differnew file mode 100644 index 0000000..37a4394 --- /dev/null +++ b/tests/expected/phantom-00001.tif diff --git a/tests/expected/phantom-00002.tif b/tests/expected/phantom-00002.tif Binary files differnew file mode 100644 index 0000000..22b2bbc --- /dev/null +++ b/tests/expected/phantom-00002.tif diff --git a/tests/expected/phantom-00003.tif b/tests/expected/phantom-00003.tif Binary files differnew file mode 100644 index 0000000..9b771b9 --- /dev/null +++ b/tests/expected/phantom-00003.tif diff --git a/tests/expected/phantom-00004.tif b/tests/expected/phantom-00004.tif Binary files differnew file mode 100644 index 0000000..5ea52dd --- /dev/null +++ b/tests/expected/phantom-00004.tif diff --git a/tests/expected/phantom-00005.tif b/tests/expected/phantom-00005.tif Binary files differnew file mode 100644 index 0000000..038461f --- /dev/null +++ b/tests/expected/phantom-00005.tif diff --git a/tests/expected/phantom-00006.tif b/tests/expected/phantom-00006.tif Binary files differnew file mode 100644 index 0000000..5a89f04 --- /dev/null +++ b/tests/expected/phantom-00006.tif diff --git a/tests/expected/phantom-00007.tif b/tests/expected/phantom-00007.tif Binary files differnew file mode 100644 index 0000000..2099005 --- /dev/null +++ b/tests/expected/phantom-00007.tif diff --git a/tests/expected/phantom-00008.tif b/tests/expected/phantom-00008.tif Binary files differnew file mode 100644 index 0000000..892bc75 --- /dev/null +++ b/tests/expected/phantom-00008.tif diff --git a/tests/expected/phantom-00009.tif b/tests/expected/phantom-00009.tif Binary files differnew file mode 100644 index 0000000..0fbfe11 --- /dev/null +++ b/tests/expected/phantom-00009.tif diff --git a/tests/expected/phantom-00010.tif b/tests/expected/phantom-00010.tif Binary files differnew file mode 100644 index 0000000..35f7133 --- /dev/null +++ b/tests/expected/phantom-00010.tif diff --git a/tests/expected/phantom-00011.tif b/tests/expected/phantom-00011.tif Binary files differnew file mode 100644 index 0000000..d530658 --- /dev/null +++ b/tests/expected/phantom-00011.tif diff --git a/tests/expected/phantom-00012.tif b/tests/expected/phantom-00012.tif Binary files differnew file mode 100644 index 0000000..c72dff9 --- /dev/null +++ b/tests/expected/phantom-00012.tif diff --git a/tests/expected/phantom-00013.tif b/tests/expected/phantom-00013.tif Binary files differnew file mode 100644 index 0000000..b65b6f1 --- /dev/null +++ b/tests/expected/phantom-00013.tif diff --git a/tests/expected/phantom-00014.tif b/tests/expected/phantom-00014.tif Binary files differnew file mode 100644 index 0000000..32f1353 --- /dev/null +++ b/tests/expected/phantom-00014.tif diff --git a/tests/expected/phantom-00015.tif b/tests/expected/phantom-00015.tif Binary files differnew file mode 100644 index 0000000..77f1c6b --- /dev/null +++ b/tests/expected/phantom-00015.tif diff --git a/tests/tests.py b/tests/tests.py new file mode 100644 index 0000000..a2fce52 --- /dev/null +++ b/tests/tests.py @@ -0,0 +1,141 @@ +import os +import shutil +import tempfile + +try: + import unittest2 as unittest +except ImportError: + import unittest + +import numpy as np +from nose_parameterized import parameterized +from gi.repository import Ufo, GLib +from libtiff import TIFF + + +def data_path(suffix=''): + return os.path.join(os.path.abspath('./data'), suffix) + +def ref_path(suffix=''): + return os.path.join(os.path.abspath('./expected'), suffix) + +def ignore_message(domain, level, message, user): + pass + +GLib.log_set_handler('Ufo', GLib.LogLevelFlags.LEVEL_DEBUG, ignore_message, None) + +class BasicTests(unittest.TestCase): + def setUp(self): + self.pm = Ufo.PluginManager() + self.graph = Ufo.TaskGraph() + self.sched = Ufo.Scheduler() + self.tmpdir = tempfile.mkdtemp() + + def tearDown(self): + shutil.rmtree(self.tmpdir) + + def tmp_path(self, suffix=''): + return os.path.join(self.tmpdir, suffix) + + def get_task(self, name, **kwargs): + plugin = self.pm.get_task(name) + plugin.set_properties(**kwargs) + return plugin + + def test_read_write(self): + reader = self.get_task('reader', path=data_path('sinogram-*.tif'), count=5) + writer = self.get_task('writer', filename=self.tmp_path('b-%05i.tif')) + + self.graph.connect_nodes(reader, writer) + self.sched.run(self.graph) + + expected = ['b-%05i.tif' % i for i in xrange(5)] + found = os.listdir(self.tmpdir) + + for fname in expected: + self.assertIn(fname, found) + + def test_roi(self): + R = {'x': 2, 'y': 13, 'width': 256, 'height': 128} + input_name = data_path('sinogram-00005.tif') + output_name = self.tmp_path('roi-00000.tif') + + reader = self.get_task('reader', path=input_name) + writer = self.get_task('writer', filename=self.tmp_path('roi-%05i.tif')) + roi = self.get_task('region-of-interest', **R) + + self.graph.connect_nodes(reader, roi) + self.graph.connect_nodes(roi, writer) + self.sched.run(self.graph) + + ref_img = TIFF.open(input_name, mode='r').read_image() + res_img = TIFF.open(output_name, mode='r').read_image() + + # Cut it manually + ref_img = ref_img[R['y']:R['y']+R['height'], R['x']:R['x']+R['width']] + + self.assertEqual(res_img.shape, ref_img.shape) + self.assertTrue((res_img == ref_img).all()) + + @parameterized.expand([(1, 0.5), (2, 0.5)]) + def test_fft(self, dimension, expected): + input_name = data_path('sinogram-00005.tif') + output_name = self.tmp_path('r-00000.tif') + + reader = self.get_task('reader', path=input_name) + writer = self.get_task('writer', filename=self.tmp_path('r-%05i.tif')) + fft = self.get_task('fft', dimensions=dimension) + ifft = self.get_task('ifft', dimensions=dimension) + + self.graph.connect_nodes(reader, fft) + self.graph.connect_nodes(fft, ifft) + self.graph.connect_nodes(ifft, writer) + self.sched.run(self.graph) + + ref_img = TIFF.open(input_name, mode='r').read_image() + res_img = TIFF.open(output_name, mode='r').read_image() + diff = np.sum(np.abs(ref_img - res_img)) + self.assertLess(diff, expected) + + def test_flatfield_correction(self): + input_name = data_path('sinogram-*.tif') + output_name = self.tmp_path('r-%i.tif') + flat = self.get_task('reader', path=input_name, count=2) + dark = self.get_task('reader', path=input_name, count=2) + proj = self.get_task('reader', path=input_name, count=10) + writer = self.get_task('writer', filename=output_name) + + flat_avg = self.get_task('averager', num_generate=10) + dark_avg = self.get_task('averager', num_generate=10) + ffc = self.get_task('flat-field-correction') + + self.graph.connect_nodes(dark, dark_avg) + self.graph.connect_nodes(flat, flat_avg) + self.graph.connect_nodes_full(proj, ffc, 0) + self.graph.connect_nodes_full(dark_avg, ffc, 1) + self.graph.connect_nodes_full(flat_avg, ffc, 2) + self.graph.connect_nodes(ffc, writer) + self.sched.run(self.graph) + + # def test_filtered_backprojection(self): + # reader = self.get_task('reader', path=data_path('sinogram*.tif')) + # fft = self.get_task('fft') + # ifft = self.get_task('ifft') + # fltr = self.get_task('filter') + # bp = self.get_task('backproject') + # writer = self.get_task('writer', filename=self.tmp_path('r-%05i.tif')) + + # self.graph.connect_nodes(reader, fft) + # self.graph.connect_nodes(fft, fltr) + # self.graph.connect_nodes(fltr, ifft) + # self.graph.connect_nodes(ifft, bp) + # self.graph.connect_nodes(bp, writer) + # self.sched.run(self.graph) + + # refs = sorted((ref_path(d) for d in os.listdir(ref_path()))) + # results = sorted((os.path.join(self.tmpdir, d) for d in os.listdir(self.tmpdir))) + + # for ref, res in zip(refs, results): + # ref_img = TIFF.open(ref, mode='r').read_image() + # res_img = TIFF.open(res, mode='r').read_image() + # self.assertLess(np.sum(np.abs(res_img - ref_img)), 0.01) |