def get_DisplacementGradientMap(strained_vectors, unstrained_vectors): """ Calculates the displacement gradient by comparing vectors with linear algebra Parameters ---------- strained_vectors : Signal2D unstrained_vectors : numpy.array with shape (2,2) For two vectors: V and U measured in x and y the components should fill the array as >>> array([[Vx, Vy], [Ux, Uy]]) Returns ------- D : DisplacementGradientMap The 3x3 displacement gradient tensor (measured in reciprocal space) at every navigation position See Also -------- get_single_DisplacementGradientTensor() Notes ----- This function does not currently support keyword arguments to the underlying map function. """ D = strained_vectors.map(get_single_DisplacementGradientTensor, Vu=unstrained_vectors, inplace=False) return DisplacementGradientMap(D)
def get_DisplacementGradientMap(strained_vectors, unstrained_vectors, weights=None): r"""Calculates the displacement gradient tensor at each navigation position in a map. Compares vectors to determine the 2 x 2 matrix, :math:`\\mathbf(L)`, that maps unstrained vectors, Vu, to strained vectors, Vs, using the np.lingalg.inv() function to find L that satisfies :math:`Vs = \\mathbf(L) Vu`. The transformation is returned as a 3 x 3 displacement gradient tensor. Parameters ---------- strained_vectors : hyperspy.Signal2D Signal2D with a 2 x n array at each navigation position containing the Cartesian components of two strained basis vectors, V and U, defined as row vectors. unstrained_vectors : numpy.array A 2 x n array containing the Cartesian components of two unstrained basis vectors, V and U, defined as row vectors. weights : list of weights to be passed to the least squares optimiser, not used for n=2 Returns ------- D : DisplacementGradientMap The 3 x 3 displacement gradient tensor (measured in reciprocal space) at every navigation position. Notes ----- n=2 now behaves the same as the n>2 case; see Release Notes for 0.10.0 for details. See Also -------- get_single_DisplacementGradientTensor() """ # Calculate displacement gradient tensor across map. D = strained_vectors.map( get_single_DisplacementGradientTensor, Vu=unstrained_vectors, weights=weights, inplace=False, output_signal_size=(3, 3), output_dtype=np.float64, ) return DisplacementGradientMap(D)
def get_DisplacementGradientMap(strained_vectors, unstrained_vectors): """Calculates the displacement gradient tensor at each navigation position in a map by comparing vectors to determine the 2 x 2 matrix, :math:`\\mathbf(L)`, that maps unstrained vectors, Vu, to strained vectors, Vs, using the np.lingalg.inv() function to find L that satisfies :math:`Vs = \\mathbf(L) Vu`. The transformation is returned as a 3 x 3 displacement gradient tensor. Parameters ---------- strained_vectors : hyperspy.Signal2D Signal2D with a 2 x 2 array at each navigation position containing the Cartesian components of two strained basis vectors, V and U, defined as row vectors. unstrained_vectors : numpy.array A 2 x 2 array containing the Cartesian components of two unstrained basis vectors, V and U, defined as row vectors. Returns ------- D : DisplacementGradientMap The 3 x 3 displacement gradient tensor (measured in reciprocal space) at every navigation position. See Also -------- get_single_DisplacementGradientTensor() """ # Calculate displacement gradient tensor across map. D = strained_vectors.map(get_single_DisplacementGradientTensor, Vu=unstrained_vectors, inplace=False) return DisplacementGradientMap(D)
def construct_displacement_gradient(self): """Construct a map of the displacement gradient tensor at each navigation position as determined by fitting an affine transformed reference pattern. Returns ------- D : DisplacementGradientMap Signal containing the displacement gradient tensor at each navigation postion. """ D = DisplacementGradientMap( np.ones(np.append(self.d11.map.shape, (3, 3)))) D.data[:, :, 0, 0] = self.d11.map["values"] D.data[:, :, 1, 0] = self.d12.map["values"] D.data[:, :, 2, 0] = 0.0 D.data[:, :, 0, 1] = self.d21.map["values"] D.data[:, :, 1, 1] = self.d22.map["values"] D.data[:, :, 2, 1] = 0.0 D.data[:, :, 0, 2] = 0.0 D.data[:, :, 1, 2] = 0.0 D.data[:, :, 2, 2] = 1.0 return D
[0.25881905, 0.96592583, 0.], [0., 0., 1.]]), -0.2617993877991494), ]) def test_get_rotation_angle(R, theta): tc = _get_rotation_angle(R) np.testing.assert_almost_equal(tc, theta) @pytest.mark.parametrize('dgm, rotation_map, distortion_map', [ (DisplacementGradientMap(np.array([[[[0.98860899, -0.2661997, 0.], [0.2514384, 0.94324267, 0.], [0., 0., 1.]], [[0.98860899, -0.2661997, 0.], [0.2514384, 0.94324267, 0.], [0., 0., 1.]]], [[[0.98860899, -0.2661997, 0.], [0.2514384, 0.94324267, 0.], [0., 0., 1.]], [[0.98860899, -0.2661997, 0.], [0.2514384, 0.94324267, 0.], [0., 0., 1.]]]])), np.array([[[[0.96592583, -0.25881905, 0.], [0.25881905, 0.96592583, 0.], [0., 0., 1.]], [[0.96592583, -0.25881905, 0.], [0.25881905, 0.96592583, 0.], [0., 0., 1.]]], [[[0.96592583, -0.25881905, 0.], [0.25881905, 0.96592583, 0.], [0., 0., 1.]], [[0.96592583, -0.25881905, 0.],
[ ( DisplacementGradientMap( np.array([ [ [ [0.98860899, -0.2661997, 0.0], [0.2514384, 0.94324267, 0.0], [0.0, 0.0, 1.0], ], [ [0.98860899, -0.2661997, 0.0], [0.2514384, 0.94324267, 0.0], [0.0, 0.0, 1.0], ], ], [ [ [0.98860899, -0.2661997, 0.0], [0.2514384, 0.94324267, 0.0], [0.0, 0.0, 1.0], ], [ [0.98860899, -0.2661997, 0.0], [0.2514384, 0.94324267, 0.0], [0.0, 0.0, 1.0], ], ], ])), np.array([ [