def plot(orientations, **kwargs): '''Plot a pole figure (both direct and inverse) for a list of orientations. :param orientations: the list of crystalline :py:class:`~pymicro.crystal.microstructure.Orientation` to plot. ''' micro = Microstructure() if isinstance(orientations, list): for i in range(len(orientations)): micro.grains.append(Grain(i + 1, orientations[i])) elif isinstance(orientations, Orientation): micro.grains.append(Grain(1, orientations)) else: print('Unrecognized argument: %s' % orientations.__repr__) pf = PoleFigure(microstructure=micro, **kwargs) pf.plot_pole_figures(display=True)
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)))
#!/usr/bin/env python import os, numpy as np from pymicro.crystal.microstructure import Microstructure, Grain, Orientation from pymicro.crystal.texture import PoleFigure from matplotlib import pyplot as plt, colors, cm if __name__ == '__main__': ''' 111 Pole figure of a copper sample containing 10000 grains with a fibre texture. ''' eulers = Orientation.read_euler_txt('../data/Cu_111.dat') micro = Microstructure(name='Cu_111') for index in eulers: micro.grains.append(Grain(index, eulers[index])) # create pole figure (both direct and inverse) pf = PoleFigure(hkl='111', proj='stereo', microstructure=micro, verbose=False) pf.color_by_grain_id = False pf.mksize = 5 pf.pflegend = False pf.plot_pole_figures(plot_sst=True, display=False, save_as='png') image_name = os.path.splitext(__file__)[0] + '.png' print('writting %s' % image_name) from matplotlib import image
def load_grain(self, gid=1): print('loading grain from file 4_grains/phase_01/grain_%04d.mat' % gid) with h5py.File( os.path.join(self.exp.get_sample().data_dir, '4_grains/phase_01/grain_%04d.mat' % gid)) as gmat: g = Grain(gid, Orientation.from_rodrigues(gmat['R_vector'][()])) g.om_exp = gmat['om_exp'][0, :] g.uv_exp = gmat['uv_exp'][:, :] g.center = gmat['center'][:, 0] try: ref_included = gmat['proj/included'][0][0] g.included = gmat[ref_included][0, :] ref_ondet = gmat['proj/ondet'][0][0] g.ondet = gmat[ref_ondet][0, :] # grab the projection stack ref_stack = gmat['proj']['stack'][0][0] g.stack_exp = gmat[ref_stack][()].transpose( 1, 2, 0) # now in [ndx, u, v] form g.hklsp = gmat['allblobs/hklsp'][:, :] except AttributeError: # classic file organization g.included = gmat['proj/included'][0, :] g.ondet = gmat['proj/ondet'][0, :] g.stack_exp = gmat['proj/stack'][()].transpose( 1, 2, 0) # now in [ndx, u, v] form # for the Ti7AL data set, we have to hack around the DCT + TT work in progress #ref_hklsp = gmat['allblobs/hklsp'][()][0][0] #g.hklsp = gmat[ref_hklsp][:, :] g.hklsp = gmat['allblobs/hklsp'][:, :] self.grain = g if self.verbose: print('experimental proj stack shape: {}'.format( g.stack_exp.shape))
its orientation. ''' data_dir = '../data' scan = 'grain1_112x112x121_uint8.raw' im_file = os.path.join(data_dir, scan) # Create the 3D scene base_name = os.path.splitext(__file__)[0] s3d = Scene3D(display=False, ren_size=(800, 800), name=base_name, background=black) # create a python Grain object from the image data orientation = Orientation.from_rodrigues(np.array([0.3889, -0.0885, 0.3268])) grain = Grain(1, orientation) grain_data = HST_read(im_file, header_size=0, autoparse_filename=True, verbose=True) grain.position = ndimage.measurements.center_of_mass(grain_data, grain_data) print('grain position: %s' % str(grain.position)) grain.volume = ndimage.measurements.sum(grain_data) # label is 1.0 here grain.add_vtk_mesh(grain_data, contour=False) print('adding bounding box') grain_bbox = box_3d(size=np.shape(grain_data), line_color=white) print('adding grain with slip planes') z_offsets = np.linspace(-50, 50, 6, endpoint=True) print(z_offsets)
#!/usr/bin/env python import os, numpy as np from pymicro.crystal.microstructure import Microstructure, Grain, Orientation from pymicro.crystal.texture import PoleFigure from matplotlib import pyplot as plt, colors, cm if __name__ == '__main__': ''' Pole figure of a gold sample containing 6 grains with a strong <111> fiber texture. 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') micro.grains.append(Grain(1158, Orientation.from_euler(np.array([344.776, 52.2589, 53.9933])))) micro.grains.append(Grain(1349, Orientation.from_euler(np.array([344.899, 125.961, 217.330])))) micro.grains.append(Grain(1585, Orientation.from_euler(np.array([228.039, 57.4791, 143.171])))) micro.grains.append(Grain(1805, Orientation.from_euler(np.array([186.741, 60.333, 43.311])))) micro.grains.append(Grain(1833, Orientation.from_euler(np.array([151.709, 55.0406, 44.1051])))) micro.grains.append(Grain(2268, Orientation.from_euler(np.array([237.262, 125.149, 225.615])))) # 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') image_name = os.path.splitext(__file__)[0] + '.png' print('writting %s' % image_name)
def load(file_path='experiment.txt'): with open(file_path, 'r') as f: dict_exp = json.load(f) sample = Sample() sample.set_name(dict_exp['Sample']['Name']) sample.set_position(dict_exp['Sample']['Position']) if 'Geometry' in dict_exp['Sample']: sample_geo = ObjectGeometry() sample_geo.set_type(dict_exp['Sample']['Geometry']['Type']) sample.set_geometry(sample_geo) if 'Material' in dict_exp['Sample']: a, b, c = dict_exp['Sample']['Material']['Lengths'] alpha, beta, gamma = dict_exp['Sample']['Material']['Angles'] centering = dict_exp['Sample']['Material']['Centering'] symmetry = Symmetry.from_string( dict_exp['Sample']['Material']['Symmetry']) material = Lattice.from_parameters(a, b, c, alpha, beta, gamma, centering=centering, symmetry=symmetry) sample.set_material(material) if 'Microstructure' in dict_exp['Sample']: micro = Microstructure( dict_exp['Sample']['Microstructure']['Name']) for i in range(len( dict_exp['Sample']['Microstructure']['Grains'])): dict_grain = dict_exp['Sample']['Microstructure']['Grains'][i] grain = Grain( dict_grain['Id'], Orientation.from_euler( dict_grain['Orientation']['Euler Angles (degrees)'])) grain.position = np.array(dict_grain['Position']) grain.volume = dict_grain['Volume'] micro.grains.append(grain) sample.set_microstructure(micro) exp = Experiment() exp.set_sample(sample) source = XraySource() source.set_position(dict_exp['Source']['Position']) if 'Min Energy (keV)' in dict_exp['Source']: source.set_min_energy(dict_exp['Source']['Min Energy (keV)']) if 'Max Energy (keV)' in dict_exp['Source']: source.set_max_energy(dict_exp['Source']['Max Energy (keV)']) exp.set_source(source) for i in range(len(dict_exp['Detectors'])): dict_det = dict_exp['Detectors'][i] if dict_det['Class'] == 'Detector2d': det = Detector2d(size=dict_det['Size (pixels)']) det.ref_pos = dict_det['Reference Position (mm)'] if dict_det['Class'] == 'RegArrayDetector2d': det = RegArrayDetector2d(size=dict_det['Size (pixels)']) det.pixel_size = dict_det['Pixel Size (mm)'] det.ref_pos = dict_det['Reference Position (mm)'] if 'Binning' in dict_det: det.set_binning(dict_det['Binning']) det.u_dir = np.array(dict_det['u_dir']) det.v_dir = np.array(dict_det['v_dir']) det.w_dir = np.array(dict_det['w_dir']) exp.add_detector(det) return exp
import os, numpy as np from pymicro.crystal.texture import PoleFigure from pymicro.crystal.microstructure import Microstructure, Grain, Orientation from matplotlib import pyplot as plt, colors, colorbar, cm ''' An inverse pole figure with symboled colored by the grain size. ''' eulers = Orientation.read_orientations('../data/EBSD_20grains.txt', data_type='euler', usecols=[1, 2, 3]) grain_sizes = np.genfromtxt('../data/EBSD_20grains.txt', usecols=[9]) micro = Microstructure(name='test') for i in range(20): micro.grains.append(Grain(i + 1, eulers[i + 1])) micro.get_grain(i + 1).volume = grain_sizes[i] # build a custom pole figure pf = PoleFigure(microstructure=micro, hkl='001') #, lattice=Ti7Al) #pf.resize_markers = True pf.mksize = 100 pf.set_map_field('strain', grain_sizes, field_min_level=0.0, field_max_level=1000., lut='jet') fig = plt.figure(figsize=(8, 5)) ax1 = fig.add_axes([0.05, 0.05, 0.8, 0.9], aspect='equal') pf.plot_sst(ax=ax1, mk='o') ax1.set_title('%s-axis SST inverse %s projection' % (pf.axis, pf.proj)) # to add the color bar
from pymicro.crystal.texture import PoleFigure from pymicro.view.scene3d import Scene3D from pymicro.view.vtk_utils import pole_figure_3d, axes_actor, setup_camera ''' Create a 3d scene with a cubic crystal lattice at the center. Hkl planes are added to the lattice and their normal displayed. A sphere is added to show how a pole figure can be constructed. ''' base_name = os.path.splitext(__file__)[0] s3d = Scene3D(display=False, ren_size=(800, 800), name=base_name) orientation = Orientation.from_euler(numpy.array([142.8, 32.0, 214.4])) pf = PoleFigure(hkl='111') pf.microstructure.grains.append(Grain(1, orientation)) pole_figure = pole_figure_3d(pf, radius=1.0, show_lattice=True) # add all actors to the 3d scene s3d.add(pole_figure) axes = axes_actor(1.0, fontSize=60) s3d.add(axes) # set up camera cam = setup_camera(size=(1, 1, 1)) cam.SetViewUp(0, 0, 1) cam.SetPosition(0, -4, 0) cam.SetFocalPoint(0, 0, 0) s3d.set_camera(cam) s3d.render()
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()