def test_base(self): micro = Microstructure(name='test', autodelete=True) micro.add_grains(self.test_eulers) self.assertTrue(micro.get_sample_name() == 'test') self.assertTrue(os.path.exists(micro.h5_file)) self.assertTrue(os.path.exists(micro.xdmf_file)) h5_file = micro.h5_file xdmf_file = micro.xdmf_file del micro self.assertTrue(not os.path.exists(h5_file)) self.assertTrue(not os.path.exists(xdmf_file))
def plot(orientations, **kwargs): """Plot a pole figure (both direct and inverse) for a list of crystal orientations. :param orientations: the list of crystalline :py:class:`~pymicro.crystal.microstructure.Orientation` to plot. """ micro = Microstructure(autodelete=True) if isinstance(orientations, list): for i in range(len(orientations)): micro.add_grains([o.euler for o in orientations]) elif isinstance(orientations, Orientation): micro.add_grains([orientations.euler]) else: print('Unrecognized argument: %s' % orientations.__repr__) pf = PoleFigure(microstructure=micro, **kwargs) pf.plot_pole_figures(display=True)
A Microstructure object is first created with the 6 grains of interest. The grain ids corerespond to the actual grain number (in an EBSD scan for instance). A PoleFigure object is then created using this microstructure and the pole figures (both direct and inverse) are drawn by calling the plot_pole_figures() method. ''' micro = Microstructure(name='Au_6grains', overwrite_hdf5=True) micro.autodelete = True gid_list = [1158, 1349, 1585, 1805, 1833, 2268] euler_list = [(344.776, 52.2589, 53.9933), (344.899, 125.961, 217.330), (228.039, 57.4791, 143.171), (186.741, 60.333, 43.311), (151.709, 55.0406, 44.1051), (237.262, 125.149, 225.615), ] micro.add_grains(euler_list, grain_ids=gid_list) # create pole figure (both direct and inverse) pf = PoleFigure(hkl='111', axis='Z', proj='stereo', microstructure=micro) pf.mksize = 100 pf.set_map_field('grain_id') pf.pflegend = True # this works well for a few grains pf.plot_pole_figures(plot_sst=True, display=False, save_as='png') del pf del micro image_name = os.path.splitext(__file__)[0] + '.png' print('writing %s' % image_name) from matplotlib import image
#!/usr/bin/env python import os, numpy as np from pymicro.crystal.microstructure import Microstructure from pymicro.crystal.texture import PoleFigure if __name__ == '__main__': """ 111 Pole figure of a copper sample containing 10000 grains with a fibre texture. """ euler_list = np.genfromtxt('../data/Cu_111.dat', usecols=(0, 1, 2), max_rows=1000) micro = Microstructure(name='Cu_111', autodelete=True) micro.add_grains(euler_list) # create pole figure (both direct and inverse) pf = PoleFigure(hkl='111', proj='stereo', microstructure=micro) pf.color_by_grain_id = False pf.mksize = 5 pf.pflegend = False pf.plot_pole_figures(plot_sst=True, display=False, save_as='png') del pf del micro image_name = os.path.splitext(__file__)[0] + '.png' print('writing %s' % image_name) from matplotlib import image image.thumbnail(image_name, 'thumb_' + image_name, 0.2)
def test_add_grains(self): micro = Microstructure(name='test', autodelete=True) self.assertEqual(micro.get_number_of_grains(), 0) micro.add_grains(self.test_eulers) self.assertEqual(micro.get_number_of_grains(), 3) del micro
import numpy as np import os from pymicro.crystal.microstructure import Microstructure, Orientation, Grain from pymicro.crystal.texture import PoleFigure from matplotlib import pyplot as plt # read data from Z-set calculation (50% tension load) data = np.genfromtxt('../data/R_1g.dat') t, R11, R22, R33, R12, R23, R31, R21, R32, R13, _, _, _, _ = data.T step = 1 # plot every step point max_step = data.shape[0] # create a microstructure with the initial grain orientation micro = Microstructure(name='1g', autodelete=True) g = Grain(50, Orientation.from_euler((12.293, 149.266, -167.068))) micro.add_grains([(12.293, 149.266, -167.068)], grain_ids=[50]) ipf = PoleFigure(proj='stereo', microstructure=micro) ipf.mksize = 100 ipf.set_map_field('grain_id') fig = plt.figure(1, figsize=(6, 5)) # for IPF ax1 = fig.add_subplot(111, aspect='equal') print('** plotting the initial orientation (with label for legend) **') ipf.plot_sst(ax=ax1, mk='.', col='k', ann=False) ax1.set_title('grain rotation in tension') axis = np.array([0, 0, 1]) grain = micro.get_grain(50) cgid = Microstructure.rand_cmap().colors[grain.id] # color by grain id g = grain.orientation_matrix()