Example #1
0
 def test_from_copy(self):
     # test computing of grain geometrical quantities and copy of an
     # existing Microstructure dataset
     # create new microstructure copy of an already existing file
     filename = os.path.join(PYMICRO_EXAMPLES_DATA_DIR,
                             't5_dct_slice_data.h5')
     new_file = os.path.join(PYMICRO_EXAMPLES_DATA_DIR, 'tmp_slice_dct')
     m = Microstructure.copy_sample(filename, new_file, autodelete=True,
                                    get_object=True)
     h5_file = m.h5_path
     xdmf_file = m.xdmf_path
     self.assertTrue(os.path.exists(h5_file))
     self.assertTrue(os.path.exists(xdmf_file))
     m.recompute_grain_bounding_boxes()
     m.recompute_grain_centers()
     # m.recompute_grain_volumes()
     m_ref = Microstructure(filename=filename)
     for i in range(m_ref.grains.nrows):
         print(' n°1 :',m.grains[i])
         print(' n°2 :',m_ref.grains[i])
         self.assertEqual(m.grains[i], m_ref.grains[i])
     volume = np.sum(m.get_mask(as_numpy=True))
     self.assertEqual(volume, 194025)
     del m
     self.assertTrue(not os.path.exists(h5_file))
     self.assertTrue(not os.path.exists(xdmf_file))
     del m_ref
Example #2
0
 def test_renumber_grains(self):
     # read and copy a microstructure
     m1_path = os.path.join(PYMICRO_EXAMPLES_DATA_DIR, 'm1_data.h5')
     copy_path = os.path.join(PYMICRO_EXAMPLES_DATA_DIR, 'm1_copy_data.h5')
     m1 = Microstructure.copy_sample(m1_path, copy_path, autodelete=True,
                                     get_object=True)
     self.assertTrue(8 not in m1.get_grain_ids())
     m1.renumber_grains()
     self.assertTrue(8 in m1.get_grain_ids())
     m1.renumber_grains(sort_by_size=True)
     self.assertEqual(m1.get_grain_ids()[0], 18)
     del m1