def get_DIC_image(dic_map, scaling_factor):

    # Construct an array of Euler angles
    grain_quats = np.empty((len(dic_map), 4))

    # Transformation orientations from EBSD orientation reference frame
    # to EBSD spatial reference frame
    frame_transform = Quat.fromAxisAngle(np.array((1, 0, 0)), np.pi)

    if dic_map.ebsdMap.crystalSym == 'hexagonal':
        # Convert hex convention from y // a2 of EBSD map to x // a1 for DAMASK
        hex_transform = Quat.fromAxisAngle(np.array([0, 0, 1]), -np.pi / 6)
        for i, grain in enumerate(dic_map):
            grain_quats[i] = (hex_transform * grain.ebsdGrain.refOri *
                              frame_transform).quatCoef

    else:
        for i, grain in enumerate(dic_map):
            grain_quats[i] = (grain.ebsdGrain.refOri *
                              frame_transform).quatCoef

    # Filter out -1 (grain boundary points) and -2 (too small grains)
    # values in the grain image
    grain_image = dic_map.grains
    remove_boundary_points(grain_image)
    remove_small_grain_points(grain_image)
    remove_boundary_points(grain_image)
    remove_boundary_points(grain_image, force_remove=True)

    # scale down image if needed
    if scaling_factor != 1:
        grain_image = zoom(grain_image,
                           scaling_factor,
                           order=0,
                           prefilter=False,
                           mode='nearest')

    # downstream expects grain numbering to start at 0 not 1
    grain_image -= 1

    DIC_image = {
        'orientations': {
            'type': 'quat',
            'unit_cell_alignment': {
                'x': 'a'
            },
            'quaternions': grain_quats,
            'P': 1,  # DefDAP uses P=+1 (e.g see `defdap.quat.Quat.__mul__`)
            'quat_component_ordering': 'scalar-vector',
        },
        'grains': grain_image,
    }
    try:
        DIC_image['scale'] = dic_map.scale
    except ValueError:
        pass

    return DIC_image
def get_EBSD_image(ebsd_map, scaling_factor):

    # Construct an array of Euler angles
    grain_quats = np.empty((len(ebsd_map), 4))

    # Transformation orientations from EBSD orientation reference frame
    # to EBSD spatial reference frame
    frame_transform = Quat.fromAxisAngle(np.array((1, 0, 0)), np.pi)

    if ebsd_map.crystalSym == 'hexagonal':
        # Convert hex convention from y // a2 of EBSD map to x // a1 for DAMASK
        hex_transform = Quat.fromAxisAngle(np.array([0, 0, 1]), -np.pi / 6)
        for i, grain in enumerate(ebsd_map):
            grain_quats[i] = (hex_transform * grain.refOri *
                              frame_transform).quatCoef

    else:
        for i, grain in enumerate(ebsd_map):
            grain_quats[i] = (grain.refOri * frame_transform).quatCoef

    # Filter out -2 (too small grains) values in the grain image
    grain_image = ebsd_map.grains
    remove_small_grain_points(grain_image)

    # scale down image if needed
    if scaling_factor != 1:
        grain_image = zoom(grain_image,
                           scaling_factor,
                           order=0,
                           prefilter=False,
                           mode='nearest')

    # downstream expects grain numbering to start at 0 not 1
    grain_image -= 1

    EBSD_image = {
        'orientations': {
            'type': 'quat',
            'unit_cell_alignment': {
                'x': 'a'
            },
            'quaternions': grain_quats,
            'P': 1,  # DefDAP uses P=+1 (e.g see `defdap.quat.Quat.__mul__`)
            'quat_component_ordering': 'scalar-vector',
        },
        'grains': grain_image,
        'scale': ebsd_map.scale,
        'phase_labels': [phase.name for phase in ebsd_map.phases],
        'grain_phases': [grain.phaseID for grain in ebsd_map],
    }

    return EBSD_image
Esempio n. 3
0
 def transformData(self):
     """
     Rotate map by 180 degrees and transform quats
     """
     print("\rTransforming EBSD data...", end="")
     self.eulerAngleArray = self.eulerAngleArray[:, ::-1, ::-1]
     self.bandContrastArray = self.bandContrastArray[::-1, ::-1]
     self.phaseArray = self.phaseArray[::-1, ::-1]
     self.buildQuatArray()
     
     transformQuat = Quat.fromAxisAngle(np.array([0, 0, 1]), np.pi)
     for i in range(self.xDim):
         for j in range(self.yDim):
             self.quatArray[j, i] = self.quatArray[j, i] * transformQuat
     print("\rDone                                               ", end="")
Esempio n. 4
0
    def test_ori_tol(beta_oris: List[Quat]):
        ori_tol = 5.
        possible_beta_oris = [
            [beta_oris[0] * Quat.fromAxisAngle(np.array([1, 0, 0]),
                                               1.01 * ori_tol * np.pi / 180)],
            [beta_oris[1]],
            [beta_oris[1]],
            [beta_oris[1], beta_oris[3], beta_oris[4]]
        ]
        variant_count = recon.count_beta_variants(
            beta_oris, possible_beta_oris, ori_tol
        )

        expected_variant_count = [0, 3, 0, 1, 1, 0]

        assert all(np.equal(variant_count, expected_variant_count))