Ejemplo n.º 1
0
    def test_orientations_symmetry(self, point_group, rotation, expected_orientation):
        r = Rotation(rotation)
        cm = CrystalMap(rotations=r, phase_id=np.array([0]))
        cm.phases = PhaseList(Phase("a", point_group=point_group))

        o = cm.orientations

        assert np.allclose(
            o.data, Orientation(r).set_symmetry(point_group).data, atol=1e-3
        )
        assert np.allclose(o.data, expected_orientation, atol=1e-3)
Ejemplo n.º 2
0
    def test_get_orientations_array(self, crystal_map_input, phase_list):
        cm = CrystalMap(**crystal_map_input)

        cm[:2, 0].phase_id = 1
        # Test code assumption
        id1 = 0
        id2 = 1
        assert np.allclose(np.unique(cm.phase_id), np.array([id1, id2]))
        cm.phases = phase_list

        # Get all with string
        o = cm.get_map_data("orientations")

        # Get per phase with string
        cm1 = cm[cm.phase_id == id1]
        cm2 = cm[cm.phase_id == id2]
        o1 = cm1.get_map_data("orientations")
        o2 = cm2.get_map_data("orientations")

        expected_o1 = cm1.orientations.to_euler()
        expected_shape = expected_o1.shape
        assert np.allclose(
            o1[~np.isnan(o1)].reshape(expected_shape), expected_o1, atol=1e-3
        )

        expected_o2 = cm2.orientations.to_euler()
        expected_shape = expected_o2.shape
        assert np.allclose(
            o2[~np.isnan(o2)].reshape(expected_shape), expected_o2, atol=1e-3
        )

        # Do calculations "manually"
        data_shape = (cm.size, 3)
        array = np.zeros(data_shape)

        if cm.rotations_per_point > 1:
            rotations = cm.rotations[:, 0]
        else:
            rotations = cm.rotations

        for i, phase in cm.phases_in_data:
            phase_mask = cm._phase_id == i
            phase_mask_in_data = cm.phase_id == i
            array[phase_mask] = (
                Orientation(rotations[phase_mask_in_data])
                .set_symmetry(phase.point_group)
                .to_euler()
            )

        assert np.allclose(o, array.reshape(o.shape), atol=1e-3)
Ejemplo n.º 3
0
 def orientations(self):
     """Rotations, respecting symmetry, in data."""
     # TODO: Consider whether orientations should be calculated upon
     #  loading since computing orientations are slow (should benefit
     #  from dask!)
     phases = self.phases_in_data
     if phases.size == 1:
         # Extract top matching rotations per point, if more than one
         if self.rotations_per_point > 1:
             rotations = self.rotations[:, 0]
         else:
             rotations = self.rotations
         return Orientation(rotations).set_symmetry(phases[:].point_group)
     else:
         raise ValueError(
             f"Data has the phases {phases.names}, however, you are executing a "
             "command that only permits one phase."
         )
Ejemplo n.º 4
0
def test_sub_orientation_and_other():
    m = Orientation([1, 1, 1, 1])  # any will do
    mis = m - 3
Ejemplo n.º 5
0
def orientation(request):
    return Orientation(request.param)
Ejemplo n.º 6
0
def test_sub():
    m = Orientation([1, 1, 1, 1])  # any will do
    m.set_symmetry(C4)  # only one as it a O
    mis = m - m  # this should give a set of zeroes
    return None
Ejemplo n.º 7
0
def test_coverage_on_faces():
    o = OrientationRegion(Orientation([1, 1, 1, 1]))
    f = o.faces()
    return None
Ejemplo n.º 8
0
def test_sub_orientation_and_other():
    m = Orientation([1, 1, 1, 1])  # any will do
    with pytest.raises(TypeError):
        _ = m - 3
Ejemplo n.º 9
0
def test_sub():
    m = Orientation([1, 1, 1, 1])  # any will do
    m.set_symmetry(C4)  # only one as it a O
    assert np.allclose((m - m).data, [1, 0, 0, 0])