Beispiel #1
0
class MicrostructureTests(unittest.TestCase):

    def setUp(self):
        print('testing the Microstructure class')
        self.test_eulers = [(45., 45, 0.), (10., 20, 30.), (191.9, 69.9, 138.9)]
        self.micro = Microstructure()
        self.micro.name = 'test'
        for i in range(len(self.test_eulers)):
            euler = self.test_eulers[i]
            self.micro.grains.append(Grain(i + 1, Orientation.from_euler(euler)))

    def test_to_h5(self):
        self.micro.to_h5()
        # read the file we have just written
        m = Microstructure.from_h5('%s.h5' % self.micro.name, grain_centroid=None)
        self.assertEqual(len(m.grains), len(self.test_eulers))
        os.remove('%s.h5' % self.micro.name)
Beispiel #2
0
class MicrostructureTests(unittest.TestCase):
    def setUp(self):
        print('testing the Microstructure class')
        self.test_eulers = [(45., 45, 0.), (10., 20, 30.),
                            (191.9, 69.9, 138.9)]
        self.micro = Microstructure()
        self.micro.name = 'test'
        for i in range(len(self.test_eulers)):
            euler = self.test_eulers[i]
            self.micro.grains.append(
                Grain(i + 1, Orientation.from_euler(euler)))

    def test_to_h5(self):
        self.micro.to_h5()
        # read the file we have just written
        m = Microstructure.from_h5('%s.h5' % self.micro.name)
        self.assertEqual(len(m.grains), len(self.test_eulers))
        os.remove('%s.h5' % self.micro.name)

    def test_from_dct(self):
        # read a microstructure from a DCT index.mat file
        m = Microstructure.from_dct(data_dir=PYMICRO_EXAMPLES_DATA_DIR,
                                    grain_file='t5_dct_cen_index.mat',
                                    use_dct_path=False)
        self.assertEqual(len(m.grains), 146)
        self.assertEqual(m.voxel_size, 0.0014)

    def test_from_h5(self):
        # read a test microstructure
        m = Microstructure.from_h5(
            os.path.join(PYMICRO_EXAMPLES_DATA_DIR, 't5_dct_slice.h5'))
        self.assertEqual(len(m.grains), 21)
        self.assertEqual(m.voxel_size, 0.0014)
        self.assertEqual(hasattr(m, 'grain_map'), True)
        self.assertEqual(hasattr(m, 'mask'), True)

    def test_find_neighbors(self):
        m = Microstructure.from_h5(
            os.path.join(PYMICRO_EXAMPLES_DATA_DIR, 't5_dct_slice.h5'))
        neighbors = m.find_neighbors(grain_id=5, distance=3)
        self.assertEqual(len(neighbors), 9)
        for gid in [0, 1, 3, 14, 17, 18, 25, 51, 115]:
            self.assertTrue(gid in neighbors)