1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
# Author: Suyog Dutt Jain <suyog.jain@aero.iitb.ac.in>
# Copyright (c) 2009, Enthought, Inc.
# License: BSD Style.
# Standard library imports.
import unittest
import numpy
# Local imports.
from mayavi.tests.common import get_example_data
# Enthought library imports
from mayavi.sources.image_reader import ImageReader
from mayavi.tests.data_reader_test_base import DataReaderTestBase
class TestDEMImageReader(DataReaderTestBase):
def setup_reader(self):
""""Setup the reader in here. This is called after the engine
has been created and started. The engine is available as
self.e. This method is called by setUp().
"""
# Read a DEM Image file.
r = ImageReader()
r.initialize(get_example_data('example.dem'))
self.e.add_source(r)
self.bounds =(557945.0, 567725.0, 5107991.5, 5121971.5, 682.0, 682.0)
def check(self, scene, bounds, error = 1.01e-02):
"""Do the actual testing."""
src = scene.children[0]
ot = src.children[0].children[0]
ot.render() # Flush the pipeline.
# Check the outline bounds
self.assertEqual(numpy.allclose(ot.outline_filter.output.bounds,bounds,
atol=error), True)
self.assertEqual(src.reader.spatial_resolution, (30.0, 30.0, 1.0))
self.assertEqual(src.reader.elevation_bounds, (682.0, 2543.0))
def test_dem_image_data_reader(self):
"Test if the test fixture works"
#Now test.
self.check(self.scene, self.bounds)
def test_save_and_restore(self):
"""Test if saving a visualization and restoring it works."""
self.check_saving(self.e, self.scene, self.bounds)
def test_deepcopied(self):
"""Test if the MayaVi2 visualization can be deep-copied."""
############################################################
# Test if the MayaVi2 visualization can be deep-copied.
self.check_deepcopying(self.scene, self.bounds)
class TestMHAImageReader(DataReaderTestBase):
def setup_reader(self):
""""Setup the reader in here. This is called after the engine
has been created and started. The engine is available as
self.e. This method is called by setUp().
"""
# Read a Meta Image file.
r = ImageReader()
r.initialize(get_example_data('foot.mha'))
self.e.add_source(r)
self.bounds =(0.0, 255.0, 0.0, 255.0, 0.0, 0.0)
def check(self, scene, bounds, error = 1.01e-02):
"""Do the actual testing."""
src = scene.children[0]
ot = src.children[0].children[0]
ot.render() # Flush the pipeline.
# Check the outline bounds
self.assertEqual(numpy.allclose(ot.outline_filter.output.bounds,bounds,
atol=error), True)
self.assertEqual(numpy.allclose(src.reader.data_spacing,(1., 1., 1.)),True)
def test_mha_image_data_reader(self):
"Test if the test fixture works"
#Now test.
self.check(self.scene, self.bounds)
def test_save_and_restore(self):
"""Test if saving a visualization and restoring it works."""
self.check_saving(self.e, self.scene, self.bounds)
def test_deepcopied(self):
"""Test if the MayaVi2 visualization can be deep-copied."""
############################################################
# Test if the MayaVi2 visualization can be deep-copied.
self.check_deepcopying(self.scene, self.bounds)
if __name__ == '__main__':
unittest.main()
|