From b62ccc041f7332d6304cb7c3ff7d166808cff418 Mon Sep 17 00:00:00 2001 From: Paddy Harrison Date: Mon, 7 Feb 2022 12:17:37 +0100 Subject: [PATCH 01/10] remove index sorting to maintain inverse ordering --- orix/quaternion/rotation.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/orix/quaternion/rotation.py b/orix/quaternion/rotation.py index c20cf574..1cb85853 100644 --- a/orix/quaternion/rotation.py +++ b/orix/quaternion/rotation.py @@ -158,13 +158,12 @@ def unique(self, return_index=False, return_inverse=False, antipodal=True): axis=-1, ).round(6) _, idx, inv = np.unique(abcd, axis=0, return_index=True, return_inverse=True) - idx_sort = np.sort(idx) - dat = rotation[idx_sort] - dat.improper = rotation.improper[idx_sort] + dat = rotation[idx] + dat.improper = rotation.improper[idx] if return_index and return_inverse: - return dat, idx_sort, inv + return dat, idx, inv elif return_index and not return_inverse: - return dat, idx_sort + return dat, idx elif return_inverse and not return_index: return dat, inv else: From c110c04c0630c54249b9770d1497a5cfb0770586 Mon Sep 17 00:00:00 2001 From: Paddy Harrison Date: Mon, 7 Feb 2022 12:18:10 +0100 Subject: [PATCH 02/10] add test to check that inverse reconstructed data is the same as original --- orix/tests/quaternion/test_rotation.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/orix/tests/quaternion/test_rotation.py b/orix/tests/quaternion/test_rotation.py index 4a27c1a2..e94d7a72 100644 --- a/orix/tests/quaternion/test_rotation.py +++ b/orix/tests/quaternion/test_rotation.py @@ -299,6 +299,13 @@ def test_kwargs_unique(rotation): rotation.unique(return_index=False, return_inverse=True) +def test_unique_inverse(): + r = Rotation.random((20,)) + u, inverse = r.unique(return_inverse=True) + m = u[inverse] * ~r + assert np.allclose(m.angle.data, 0) + + @pytest.mark.parametrize( "rotation, improper, expected, improper_expected", [ From a72976c65d90172174e664127b843df441b6851e Mon Sep 17 00:00:00 2001 From: Paddy Harrison Date: Mon, 7 Feb 2022 13:04:49 +0100 Subject: [PATCH 03/10] keep index sorting and fix inverse map --- orix/quaternion/rotation.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/orix/quaternion/rotation.py b/orix/quaternion/rotation.py index 1cb85853..fc35292c 100644 --- a/orix/quaternion/rotation.py +++ b/orix/quaternion/rotation.py @@ -158,12 +158,18 @@ def unique(self, return_index=False, return_inverse=False, antipodal=True): axis=-1, ).round(6) _, idx, inv = np.unique(abcd, axis=0, return_index=True, return_inverse=True) - dat = rotation[idx] - dat.improper = rotation.improper[idx] + idx_argsort = np.argsort(idx) + idx_sort = idx[idx_argsort] + # build inverse index map + inv_map = np.empty_like(idx_argsort) + inv_map[idx_argsort] = np.arange(idx_argsort.size) + inv = inv_map[inv] + dat = rotation[idx_sort] + dat.improper = rotation.improper[idx_sort] if return_index and return_inverse: - return dat, idx, inv + return dat, idx_sort, inv elif return_index and not return_inverse: - return dat, idx + return dat, idx_sort elif return_inverse and not return_index: return dat, inv else: From ede19c26f747317b7178814bcb9b33571f222199 Mon Sep 17 00:00:00 2001 From: Paddy Harrison Date: Mon, 7 Feb 2022 14:01:26 +0100 Subject: [PATCH 04/10] update black rev to stable --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0353f36d..29bca3fb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,5 @@ repos: - repo: https://github.com/psf/black - rev: 21.8b0 + rev: stable hooks: - id: black From 539081da2dea05eeee5322f1b550641832e5c0f5 Mon Sep 17 00:00:00 2001 From: Paddy Harrison Date: Mon, 7 Feb 2022 14:04:55 +0100 Subject: [PATCH 05/10] Revert "update black rev to stable" This reverts commit ede19c26f747317b7178814bcb9b33571f222199. --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 29bca3fb..0353f36d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,5 @@ repos: - repo: https://github.com/psf/black - rev: stable + rev: 21.8b0 hooks: - id: black From 35c268b5119070d0d436272a6005c468a3cfd390 Mon Sep 17 00:00:00 2001 From: Paddy Harrison Date: Mon, 7 Feb 2022 14:05:21 +0100 Subject: [PATCH 06/10] update black version --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0353f36d..cf81be99 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,5 @@ repos: - repo: https://github.com/psf/black - rev: 21.8b0 + rev: 22.1.0 hooks: - id: black From 90a4351924f6816a409d63d8105fd71abd7c6438 Mon Sep 17 00:00:00 2001 From: Paddy Harrison Date: Mon, 7 Feb 2022 14:06:48 +0100 Subject: [PATCH 07/10] black formatting --- orix/projections/stereographic.py | 4 +-- orix/quaternion/_conversions.py | 6 ++-- orix/quaternion/orientation.py | 6 ++-- orix/quaternion/orientation_region.py | 2 +- orix/quaternion/quaternion.py | 14 ++++----- orix/quaternion/rotation.py | 30 +++++++++---------- orix/quaternion/symmetry.py | 20 ++++++------- orix/scalar/__init__.py | 4 +-- orix/tests/quaternion/test_orientation.py | 6 ++-- .../quaternion/test_orientation_region.py | 14 ++++----- orix/tests/quaternion/test_quaternion.py | 4 +-- orix/tests/quaternion/test_rotation.py | 4 +-- orix/tests/quaternion/test_symmetry.py | 8 ++--- orix/tests/test_scalar.py | 2 +- orix/tests/test_vector3d.py | 2 +- orix/vector/miller.py | 2 +- 16 files changed, 64 insertions(+), 64 deletions(-) diff --git a/orix/projections/stereographic.py b/orix/projections/stereographic.py index 77e152ae..419e6903 100644 --- a/orix/projections/stereographic.py +++ b/orix/projections/stereographic.py @@ -278,10 +278,10 @@ def xy2vector(self, x, y): where :math:`p` is either 1 (north pole as projection point) or -1 (south pole as projection point). """ - denom = 1 + x ** 2 + y ** 2 + denom = 1 + x**2 + y**2 vx = 2 * x / denom vy = 2 * y / denom - vz = -self.pole * (1 - x ** 2 - y ** 2) / denom + vz = -self.pole * (1 - x**2 - y**2) / denom return Vector3d(np.column_stack([vx, vy, vz])) def xy2spherical(self, x, y): diff --git a/orix/quaternion/_conversions.py b/orix/quaternion/_conversions.py index b2d60e87..ad47bf72 100644 --- a/orix/quaternion/_conversions.py +++ b/orix/quaternion/_conversions.py @@ -131,8 +131,8 @@ def cu2ho_single(cu): q = prefactor * y / np.sqrt(sqrt2 - cosq) t1 = sqrt2 * sinq * q t2 = (sqrt2 * cosq - 1) * q - c = t1 ** 2 + t2 ** 2 - s = np.pi * c / (24 * z ** 2) + c = t1**2 + t2**2 + s = np.pi * c / (24 * z**2) c = np.sqrt(np.pi) * c / np.sqrt(24) / z q = np.sqrt(1 - s) @@ -204,7 +204,7 @@ def ho2ax_single(ho): -2.401996891720091e-7, 4.386887017466388e-8, -3.5917775353564864e-9 ]) # fmt: on - ho_magnitude = np.sum(ho ** 2) + ho_magnitude = np.sum(ho**2) if (ho_magnitude > -1e-8) and (ho_magnitude < 1e-8): ax = np.array([0, 0, 1, 0], dtype=np.float64) else: diff --git a/orix/quaternion/orientation.py b/orix/quaternion/orientation.py index 9ea617e0..c05fa044 100644 --- a/orix/quaternion/orientation.py +++ b/orix/quaternion/orientation.py @@ -549,7 +549,7 @@ def angle_with(self, other): Scalar """ dot_products = self.unit.dot(other.unit).data - angles = np.nan_to_num(np.arccos(2 * dot_products ** 2 - 1)) + angles = np.nan_to_num(np.arccos(2 * dot_products**2 - 1)) return Scalar(angles) def dot(self, other): @@ -635,7 +635,7 @@ def get_distance_matrix(self, lazy=False, chunk_size=20, progressbar=True): n_decimals = np.finfo(dot_products.dtype).precision dot_products = da.round(dot_products, n_decimals) - angles_dask = da.arccos(2 * dot_products ** 2 - 1) + angles_dask = da.arccos(2 * dot_products**2 - 1) angles_dask = da.nan_to_num(angles_dask) # Create array in memory and overwrite, chunk by chunk @@ -647,7 +647,7 @@ def get_distance_matrix(self, lazy=False, chunk_size=20, progressbar=True): da.store(sources=angles_dask, targets=angles) else: dot_products = ori.dot_outer(ori).data - angles = np.arccos(2 * dot_products ** 2 - 1) + angles = np.arccos(2 * dot_products**2 - 1) angles = np.nan_to_num(angles) return Scalar(angles) diff --git a/orix/quaternion/orientation_region.py b/orix/quaternion/orientation_region.py index 29ec2c12..35fa458f 100644 --- a/orix/quaternion/orientation_region.py +++ b/orix/quaternion/orientation_region.py @@ -199,7 +199,7 @@ def get_plot_data(self): d = (-self.axis).dot_outer(g.unit).data x = n * d with np.errstate(divide="ignore"): - omega = 2 * np.arctan(np.where(x != 0, x ** -1, np.pi)) + omega = 2 * np.arctan(np.where(x != 0, x**-1, np.pi)) # Keep the smallest allowed angle omega[omega < 0] = np.pi diff --git a/orix/quaternion/quaternion.py b/orix/quaternion/quaternion.py index e0a33aaa..aab06c5b 100644 --- a/orix/quaternion/quaternion.py +++ b/orix/quaternion/quaternion.py @@ -95,7 +95,7 @@ def conj(self): return Quaternion(q) def __invert__(self): - return self.__class__(self.conj.data / (self.norm.data ** 2)[..., np.newaxis]) + return self.__class__(self.conj.data / (self.norm.data**2)[..., np.newaxis]) def __mul__(self, other): if isinstance(other, Quaternion): @@ -112,13 +112,13 @@ def __mul__(self, other): elif isinstance(other, Vector3d): a, b, c, d = self.a.data, self.b.data, self.c.data, self.d.data x, y, z = other.x.data, other.y.data, other.z.data - x_new = (a ** 2 + b ** 2 - c ** 2 - d ** 2) * x + 2 * ( + x_new = (a**2 + b**2 - c**2 - d**2) * x + 2 * ( (a * c + b * d) * z + (b * c - a * d) * y ) - y_new = (a ** 2 - b ** 2 + c ** 2 - d ** 2) * y + 2 * ( + y_new = (a**2 - b**2 + c**2 - d**2) * y + 2 * ( (a * d + b * c) * x + (c * d - a * b) * z ) - z_new = (a ** 2 - b ** 2 - c ** 2 + d ** 2) * z + 2 * ( + z_new = (a**2 - b**2 - c**2 + d**2) * z + 2 * ( (a * b + c * d) * y + (b * d - a * c) * x ) v = np.stack((x_new, y_new, z_new), axis=-1) @@ -241,13 +241,13 @@ def e(x, y): elif isinstance(other, Vector3d): a, b, c, d = self.a.data, self.b.data, self.c.data, self.d.data x, y, z = other.x.data, other.y.data, other.z.data - x_new = e(a ** 2 + b ** 2 - c ** 2 - d ** 2, x) + 2 * ( + x_new = e(a**2 + b**2 - c**2 - d**2, x) + 2 * ( e(a * c + b * d, z) + e(b * c - a * d, y) ) - y_new = e(a ** 2 - b ** 2 + c ** 2 - d ** 2, y) + 2 * ( + y_new = e(a**2 - b**2 + c**2 - d**2, y) + 2 * ( e(a * d + b * c, x) + e(c * d - a * b, z) ) - z_new = e(a ** 2 - b ** 2 - c ** 2 + d ** 2, z) + 2 * ( + z_new = e(a**2 - b**2 - c**2 + d**2, z) + 2 * ( e(a * b + c * d, y) + e(b * d - a * c, x) ) v = np.stack((x_new, y_new, z_new), axis=-1) diff --git a/orix/quaternion/rotation.py b/orix/quaternion/rotation.py index fc35292c..42c07f34 100644 --- a/orix/quaternion/rotation.py +++ b/orix/quaternion/rotation.py @@ -183,10 +183,10 @@ def _differentiators(self): i = self.improper abcd = np.stack( ( - a ** 2, - b ** 2, - c ** 2, - d ** 2, + a**2, + b**2, + c**2, + d**2, a * b, a * c, a * d, @@ -211,7 +211,7 @@ def angle_with(self, other): dp = self.unit.dot(other.unit).data # Round because some dot products are slightly above 1 dp = np.round(dp, np.finfo(dp.dtype).precision) - angles = Scalar(np.nan_to_num(np.arccos(2 * dp ** 2 - 1))) + angles = Scalar(np.nan_to_num(np.arccos(2 * dp**2 - 1))) return angles def outer(self, other): @@ -333,22 +333,22 @@ def to_euler(self, convention="bunge"): a, b, c, d = self.a.data, self.b.data, self.c.data, self.d.data - q03 = a ** 2 + d ** 2 - q12 = b ** 2 + c ** 2 + q03 = a**2 + d**2 + q12 = b**2 + c**2 chi = np.sqrt(q03 * q12) # P = 1 q12_is_zero = q12 == 0 if np.sum(q12_is_zero) > 0: - alpha = np.arctan2(-2 * a * d, a ** 2 - d ** 2) + alpha = np.arctan2(-2 * a * d, a**2 - d**2) e[..., 0] = np.where(q12_is_zero, alpha, e[..., 0]) e[..., 1] = np.where(q12_is_zero, 0, e[..., 1]) e[..., 2] = np.where(q12_is_zero, 0, e[..., 2]) q03_is_zero = q03 == 0 if np.sum(q03_is_zero) > 0: - alpha = np.arctan2(2 * b * c, b ** 2 - c ** 2) + alpha = np.arctan2(2 * b * c, b**2 - c**2) e[..., 0] = np.where(q03_is_zero, alpha, e[..., 0]) e[..., 1] = np.where(q03_is_zero, np.pi, e[..., 1]) e[..., 2] = np.where(q03_is_zero, 0, e[..., 2]) @@ -477,10 +477,10 @@ def to_matrix(self): a, b, c, d = self.a.data, self.b.data, self.c.data, self.d.data om = np.zeros(self.shape + (3, 3)) - bb = b ** 2 - cc = c ** 2 - dd = d ** 2 - qq = a ** 2 - (bb + cc + dd) + bb = b**2 + cc = c**2 + dd = d**2 + qq = a**2 - (bb + cc + dd) bc = b * c ad = a * d bd = b * d @@ -586,7 +586,7 @@ def random(cls, shape=(1,)): while len(rotations) < n: r = np.random.uniform(-1, 1, (3 * n, cls.dim)) r2 = np.sum(np.square(r), axis=1) - r = r[np.logical_and(1e-9 ** 2 < r2, r2 <= 1)] + r = r[np.logical_and(1e-9**2 < r2, r2 <= 1)] rotations += list(r) return cls(np.array(rotations[:n])).reshape(*shape) @@ -675,4 +675,4 @@ def von_mises(x, alpha, reference=Rotation((1, 0, 0, 0))): numpy.ndarray """ angle = Rotation(x).angle_with(reference) - return np.exp(2 * alpha * np.cos(angle.data)) / hyp0f1(1.5, alpha ** 2) + return np.exp(2 * alpha * np.cos(angle.data)) / hyp0f1(1.5, alpha**2) diff --git a/orix/quaternion/symmetry.py b/orix/quaternion/symmetry.py index 584967c5..57eaa125 100644 --- a/orix/quaternion/symmetry.py +++ b/orix/quaternion/symmetry.py @@ -457,7 +457,7 @@ def fundamental_zone(self): Ci.name = "-1" # Special generators -_mirror_xy = Symmetry([(1, 0, 0, 0), (0, 0.75 ** 0.5, -(0.75 ** 0.5), 0)]) +_mirror_xy = Symmetry([(1, 0, 0, 0), (0, 0.75**0.5, -(0.75**0.5), 0)]) _mirror_xy.improper = [0, 1] _cubic = Symmetry([(1, 0, 0, 0), (0.5, 0.5, 0.5, 0.5)]) @@ -500,25 +500,25 @@ def fundamental_zone(self): C4x = Symmetry( [ (1, 0, 0, 0), - (0.5 ** 0.5, 0.5 ** 0.5, 0, 0), + (0.5**0.5, 0.5**0.5, 0, 0), (0, 1, 0, 0), - (-(0.5 ** 0.5), 0.5 ** 0.5, 0, 0), + (-(0.5**0.5), 0.5**0.5, 0, 0), ] ) C4y = Symmetry( [ (1, 0, 0, 0), - (0.5 ** 0.5, 0, 0.5 ** 0.5, 0), + (0.5**0.5, 0, 0.5**0.5, 0), (0, 0, 1, 0), - (-(0.5 ** 0.5), 0, 0.5 ** 0.5, 0), + (-(0.5**0.5), 0, 0.5**0.5, 0), ] ) C4z = Symmetry( [ (1, 0, 0, 0), - (0.5 ** 0.5, 0, 0, 0.5 ** 0.5), + (0.5**0.5, 0, 0, 0.5**0.5), (0, 0, 0, 1), - (-(0.5 ** 0.5), 0, 0, 0.5 ** 0.5), + (-(0.5**0.5), 0, 0, 0.5**0.5), ] ) C4 = Symmetry(C4z) @@ -539,9 +539,9 @@ def fundamental_zone(self): D4h.name = "4/mmm" # 3-fold rotations -C3x = Symmetry([(1, 0, 0, 0), (0.5, 0.75 ** 0.5, 0, 0), (-0.5, 0.75 ** 0.5, 0, 0)]) -C3y = Symmetry([(1, 0, 0, 0), (0.5, 0, 0.75 ** 0.5, 0), (-0.5, 0, 0.75 ** 0.5, 0)]) -C3z = Symmetry([(1, 0, 0, 0), (0.5, 0, 0, 0.75 ** 0.5), (-0.5, 0, 0, 0.75 ** 0.5)]) +C3x = Symmetry([(1, 0, 0, 0), (0.5, 0.75**0.5, 0, 0), (-0.5, 0.75**0.5, 0, 0)]) +C3y = Symmetry([(1, 0, 0, 0), (0.5, 0, 0.75**0.5, 0), (-0.5, 0, 0.75**0.5, 0)]) +C3z = Symmetry([(1, 0, 0, 0), (0.5, 0, 0, 0.75**0.5), (-0.5, 0, 0, 0.75**0.5)]) C3 = Symmetry(C3z) C3.name = "3" diff --git a/orix/scalar/__init__.py b/orix/scalar/__init__.py index 7606818b..5546ab67 100644 --- a/orix/scalar/__init__.py +++ b/orix/scalar/__init__.py @@ -178,11 +178,11 @@ def __le__(self, other): def __pow__(self, power, modulo=None): if isinstance(power, (int, float)): - return self.__class__(self.data ** power) + return self.__class__(self.data**power) elif isinstance(power, (list, tuple)): power = np.array(power) if isinstance(power, np.ndarray): - return self.__class__(self.data ** power) + return self.__class__(self.data**power) return NotImplemented @classmethod diff --git a/orix/tests/quaternion/test_orientation.py b/orix/tests/quaternion/test_orientation.py index 728d92a0..3e54825d 100644 --- a/orix/tests/quaternion/test_orientation.py +++ b/orix/tests/quaternion/test_orientation.py @@ -44,7 +44,7 @@ def vector(request): return Vector3d(request.param) -@pytest.fixture(params=[(0.5, 0.5, 0.5, 0.5), (0.5 ** 0.5, 0, 0, 0.5 ** 0.5)]) +@pytest.fixture(params=[(0.5, 0.5, 0.5, 0.5), (0.5**0.5, 0, 0, 0.5**0.5)]) def orientation(request): return Orientation(request.param) @@ -368,7 +368,7 @@ def test_from_axes_angles(self, rotations): class TestOrientation: @pytest.mark.parametrize("symmetry", [C1, C2, C3, C4, D2, D3, D6, T, O, Oh]) def test_get_distance_matrix(self, symmetry): - q = [(0.5, 0.5, 0.5, 0.5), (0.5 ** 0.5, 0, 0, 0.5 ** 0.5)] + q = [(0.5, 0.5, 0.5, 0.5), (0.5**0.5, 0, 0, 0.5**0.5)] o = Orientation(q, symmetry=symmetry) o = o.map_into_symmetry_reduced_zone() angles_numpy = o.get_distance_matrix() @@ -394,7 +394,7 @@ def test_get_distance_matrix_lazy_parameters(self): @pytest.mark.parametrize("symmetry", [C1, C2, C3, C4, D2, D3, D6, T, O, Oh]) def test_angle_with(self, symmetry): - q = [(0.5, 0.5, 0.5, 0.5), (0.5 ** 0.5, 0, 0, 0.5 ** 0.5)] + q = [(0.5, 0.5, 0.5, 0.5), (0.5**0.5, 0, 0, 0.5**0.5)] r = Rotation(q) o = Orientation(q, symmetry=symmetry) o = o.map_into_symmetry_reduced_zone() diff --git a/orix/tests/quaternion/test_orientation_region.py b/orix/tests/quaternion/test_orientation_region.py index a5b42ea8..991a4ca4 100644 --- a/orix/tests/quaternion/test_orientation_region.py +++ b/orix/tests/quaternion/test_orientation_region.py @@ -68,19 +68,19 @@ def test_get_distinguished_points(s1, s2, expected): @pytest.mark.parametrize( "s1, s2, expected", [ - (C2, C1, [[0.5 ** 0.5, 0, 0, -(0.5 ** 0.5)], [0.5 ** 0.5, 0, 0, 0.5 ** 0.5]]), + (C2, C1, [[0.5**0.5, 0, 0, -(0.5**0.5)], [0.5**0.5, 0, 0, 0.5**0.5]]), (C6, C1, [[0.258819, 0, 0, -0.965926], [0.258819, 0, 0, 0.965926]]), (C3, C3, [[0.5, 0, 0, -0.866], [0.5, 0, 0, 0.866]]), ( D2, C1, [ - [0.5 ** 0.5, -(0.5 ** 0.5), 0, 0], - [0.5 ** 0.5, 0, -(0.5 ** 0.5), 0], - [0.5 ** 0.5, 0, 0, -(0.5 ** 0.5)], - [0.5 ** 0.5, 0, 0, 0.5 ** 0.5], - [0.5 ** 0.5, 0, 0.5 ** 0.5, 0], - [0.5 ** 0.5, 0.5 ** 0.5, 0, 0], + [0.5**0.5, -(0.5**0.5), 0, 0], + [0.5**0.5, 0, -(0.5**0.5), 0], + [0.5**0.5, 0, 0, -(0.5**0.5)], + [0.5**0.5, 0, 0, 0.5**0.5], + [0.5**0.5, 0, 0.5**0.5, 0], + [0.5**0.5, 0.5**0.5, 0, 0], ], ), ( diff --git a/orix/tests/quaternion/test_quaternion.py b/orix/tests/quaternion/test_quaternion.py index 45fb5c5a..516a0c85 100644 --- a/orix/tests/quaternion/test_quaternion.py +++ b/orix/tests/quaternion/test_quaternion.py @@ -84,7 +84,7 @@ def test_neg(self, quaternion): def test_norm(self, quaternion): q = quaternion - assert np.allclose(q.norm.data, (q.data ** 2).sum(axis=-1) ** 0.5) + assert np.allclose(q.norm.data, (q.data**2).sum(axis=-1) ** 0.5) def test_unit(self, quaternion): assert np.allclose(quaternion.unit.norm.data, 1) @@ -123,7 +123,7 @@ def test_inverse(self, quaternion): def test_dot(self, quaternion, something): q = quaternion - assert np.allclose(q.dot(q).data, np.sum(q.data ** 2, axis=-1)) + assert np.allclose(q.dot(q).data, np.sum(q.data**2, axis=-1)) assert np.allclose(q.dot(something).data, something.dot(q).data) def test_dot_outer(self, quaternion, something): diff --git a/orix/tests/quaternion/test_rotation.py b/orix/tests/quaternion/test_rotation.py index e94d7a72..df329c9a 100644 --- a/orix/tests/quaternion/test_rotation.py +++ b/orix/tests/quaternion/test_rotation.py @@ -449,7 +449,7 @@ def test_dot_outer_quat(rotation, improper, quaternion, expected): [ ([1, 0, 0, 0], [0, 0, 1]), ([-1, 0, 0, 0], [0, 0, -1]), - ([0, 0.5 ** 0.5, 0.5 ** 0.5, 0], [0.5 ** 0.5, 0.5 ** 0.5, 0]), + ([0, 0.5**0.5, 0.5**0.5, 0], [0.5**0.5, 0.5**0.5, 0]), ([[1, 0, 0, 0], [-1, 0, 0, 0]], [[0, 0, 1], [0, 0, -1]]), ], indirect=["rotation"], @@ -463,7 +463,7 @@ def test_axis(rotation, expected): "rotation, improper", [ ([(1, 0, 0, 0), (1, 0, 0, 0)], [0, 1]), - ([(0.5 ** 0.5, 0, 0, 0.5 ** 0.5)], [1]), + ([(0.5**0.5, 0, 0, 0.5**0.5)], [1]), ], ) def test_antipodal(rotation, improper): diff --git a/orix/tests/quaternion/test_symmetry.py b/orix/tests/quaternion/test_symmetry.py index de68a430..8e4725c7 100644 --- a/orix/tests/quaternion/test_symmetry.py +++ b/orix/tests/quaternion/test_symmetry.py @@ -361,10 +361,10 @@ def test_eq(symmetry, other, expected): ( T, [ - [0.5 ** 0.5, -(0.5 ** 0.5), 0], - [0, -(0.5 ** 0.5), 0.5 ** 0.5], - [0, 0.5 ** 0.5, 0.5 ** 0.5], - [0.5 ** 0.5, 0.5 ** 0.5, 0], + [0.5**0.5, -(0.5**0.5), 0], + [0, -(0.5**0.5), 0.5**0.5], + [0, 0.5**0.5, 0.5**0.5], + [0.5**0.5, 0.5**0.5, 0], ], ), ], diff --git a/orix/tests/test_scalar.py b/orix/tests/test_scalar.py index d31c21ff..fafdcfd0 100644 --- a/orix/tests/test_scalar.py +++ b/orix/tests/test_scalar.py @@ -192,7 +192,7 @@ def test_le(scalar, other, expected): indirect=["scalar"], ) def test_pow(scalar, other, expected): - pow = scalar ** other + pow = scalar**other assert np.allclose(pow.data, expected) diff --git a/orix/tests/test_vector3d.py b/orix/tests/test_vector3d.py index 257f2b3c..d9ce6750 100644 --- a/orix/tests/test_vector3d.py +++ b/orix/tests/test_vector3d.py @@ -181,7 +181,7 @@ def test_rdiv(): def test_dot(vector, something): - assert np.allclose(vector.dot(vector).data, (vector.data ** 2).sum(axis=-1)) + assert np.allclose(vector.dot(vector).data, (vector.data**2).sum(axis=-1)) assert np.allclose(vector.dot(something).data, something.dot(vector).data) diff --git a/orix/vector/miller.py b/orix/vector/miller.py index eb0415ce..d82255c6 100644 --- a/orix/vector/miller.py +++ b/orix/vector/miller.py @@ -907,7 +907,7 @@ def _round_indices(indices, max_index=12): error = 1e-7 * np.round( 1e7 * np.sum((idx_scaled - np.round(idx_scaled)) ** 2, axis=-1) - / np.sum(idx_scaled ** 2, axis=-1) + / np.sum(idx_scaled**2, axis=-1) ) idx_min_error = np.argmin(error, axis=0) multiplier = (idx_min_error + 1) / max_per_set From c4f8653ef173dc589457c6c95c501c00ccbfa81a Mon Sep 17 00:00:00 2001 From: Paddy Harrison Date: Mon, 7 Feb 2022 14:07:55 +0100 Subject: [PATCH 08/10] Revert "black formatting" This reverts commit 90a4351924f6816a409d63d8105fd71abd7c6438. --- orix/projections/stereographic.py | 4 +-- orix/quaternion/_conversions.py | 6 ++-- orix/quaternion/orientation.py | 6 ++-- orix/quaternion/orientation_region.py | 2 +- orix/quaternion/quaternion.py | 14 ++++----- orix/quaternion/rotation.py | 30 +++++++++---------- orix/quaternion/symmetry.py | 20 ++++++------- orix/scalar/__init__.py | 4 +-- orix/tests/quaternion/test_orientation.py | 6 ++-- .../quaternion/test_orientation_region.py | 14 ++++----- orix/tests/quaternion/test_quaternion.py | 4 +-- orix/tests/quaternion/test_rotation.py | 4 +-- orix/tests/quaternion/test_symmetry.py | 8 ++--- orix/tests/test_scalar.py | 2 +- orix/tests/test_vector3d.py | 2 +- orix/vector/miller.py | 2 +- 16 files changed, 64 insertions(+), 64 deletions(-) diff --git a/orix/projections/stereographic.py b/orix/projections/stereographic.py index 419e6903..77e152ae 100644 --- a/orix/projections/stereographic.py +++ b/orix/projections/stereographic.py @@ -278,10 +278,10 @@ def xy2vector(self, x, y): where :math:`p` is either 1 (north pole as projection point) or -1 (south pole as projection point). """ - denom = 1 + x**2 + y**2 + denom = 1 + x ** 2 + y ** 2 vx = 2 * x / denom vy = 2 * y / denom - vz = -self.pole * (1 - x**2 - y**2) / denom + vz = -self.pole * (1 - x ** 2 - y ** 2) / denom return Vector3d(np.column_stack([vx, vy, vz])) def xy2spherical(self, x, y): diff --git a/orix/quaternion/_conversions.py b/orix/quaternion/_conversions.py index ad47bf72..b2d60e87 100644 --- a/orix/quaternion/_conversions.py +++ b/orix/quaternion/_conversions.py @@ -131,8 +131,8 @@ def cu2ho_single(cu): q = prefactor * y / np.sqrt(sqrt2 - cosq) t1 = sqrt2 * sinq * q t2 = (sqrt2 * cosq - 1) * q - c = t1**2 + t2**2 - s = np.pi * c / (24 * z**2) + c = t1 ** 2 + t2 ** 2 + s = np.pi * c / (24 * z ** 2) c = np.sqrt(np.pi) * c / np.sqrt(24) / z q = np.sqrt(1 - s) @@ -204,7 +204,7 @@ def ho2ax_single(ho): -2.401996891720091e-7, 4.386887017466388e-8, -3.5917775353564864e-9 ]) # fmt: on - ho_magnitude = np.sum(ho**2) + ho_magnitude = np.sum(ho ** 2) if (ho_magnitude > -1e-8) and (ho_magnitude < 1e-8): ax = np.array([0, 0, 1, 0], dtype=np.float64) else: diff --git a/orix/quaternion/orientation.py b/orix/quaternion/orientation.py index c05fa044..9ea617e0 100644 --- a/orix/quaternion/orientation.py +++ b/orix/quaternion/orientation.py @@ -549,7 +549,7 @@ def angle_with(self, other): Scalar """ dot_products = self.unit.dot(other.unit).data - angles = np.nan_to_num(np.arccos(2 * dot_products**2 - 1)) + angles = np.nan_to_num(np.arccos(2 * dot_products ** 2 - 1)) return Scalar(angles) def dot(self, other): @@ -635,7 +635,7 @@ def get_distance_matrix(self, lazy=False, chunk_size=20, progressbar=True): n_decimals = np.finfo(dot_products.dtype).precision dot_products = da.round(dot_products, n_decimals) - angles_dask = da.arccos(2 * dot_products**2 - 1) + angles_dask = da.arccos(2 * dot_products ** 2 - 1) angles_dask = da.nan_to_num(angles_dask) # Create array in memory and overwrite, chunk by chunk @@ -647,7 +647,7 @@ def get_distance_matrix(self, lazy=False, chunk_size=20, progressbar=True): da.store(sources=angles_dask, targets=angles) else: dot_products = ori.dot_outer(ori).data - angles = np.arccos(2 * dot_products**2 - 1) + angles = np.arccos(2 * dot_products ** 2 - 1) angles = np.nan_to_num(angles) return Scalar(angles) diff --git a/orix/quaternion/orientation_region.py b/orix/quaternion/orientation_region.py index 35fa458f..29ec2c12 100644 --- a/orix/quaternion/orientation_region.py +++ b/orix/quaternion/orientation_region.py @@ -199,7 +199,7 @@ def get_plot_data(self): d = (-self.axis).dot_outer(g.unit).data x = n * d with np.errstate(divide="ignore"): - omega = 2 * np.arctan(np.where(x != 0, x**-1, np.pi)) + omega = 2 * np.arctan(np.where(x != 0, x ** -1, np.pi)) # Keep the smallest allowed angle omega[omega < 0] = np.pi diff --git a/orix/quaternion/quaternion.py b/orix/quaternion/quaternion.py index aab06c5b..e0a33aaa 100644 --- a/orix/quaternion/quaternion.py +++ b/orix/quaternion/quaternion.py @@ -95,7 +95,7 @@ def conj(self): return Quaternion(q) def __invert__(self): - return self.__class__(self.conj.data / (self.norm.data**2)[..., np.newaxis]) + return self.__class__(self.conj.data / (self.norm.data ** 2)[..., np.newaxis]) def __mul__(self, other): if isinstance(other, Quaternion): @@ -112,13 +112,13 @@ def __mul__(self, other): elif isinstance(other, Vector3d): a, b, c, d = self.a.data, self.b.data, self.c.data, self.d.data x, y, z = other.x.data, other.y.data, other.z.data - x_new = (a**2 + b**2 - c**2 - d**2) * x + 2 * ( + x_new = (a ** 2 + b ** 2 - c ** 2 - d ** 2) * x + 2 * ( (a * c + b * d) * z + (b * c - a * d) * y ) - y_new = (a**2 - b**2 + c**2 - d**2) * y + 2 * ( + y_new = (a ** 2 - b ** 2 + c ** 2 - d ** 2) * y + 2 * ( (a * d + b * c) * x + (c * d - a * b) * z ) - z_new = (a**2 - b**2 - c**2 + d**2) * z + 2 * ( + z_new = (a ** 2 - b ** 2 - c ** 2 + d ** 2) * z + 2 * ( (a * b + c * d) * y + (b * d - a * c) * x ) v = np.stack((x_new, y_new, z_new), axis=-1) @@ -241,13 +241,13 @@ def e(x, y): elif isinstance(other, Vector3d): a, b, c, d = self.a.data, self.b.data, self.c.data, self.d.data x, y, z = other.x.data, other.y.data, other.z.data - x_new = e(a**2 + b**2 - c**2 - d**2, x) + 2 * ( + x_new = e(a ** 2 + b ** 2 - c ** 2 - d ** 2, x) + 2 * ( e(a * c + b * d, z) + e(b * c - a * d, y) ) - y_new = e(a**2 - b**2 + c**2 - d**2, y) + 2 * ( + y_new = e(a ** 2 - b ** 2 + c ** 2 - d ** 2, y) + 2 * ( e(a * d + b * c, x) + e(c * d - a * b, z) ) - z_new = e(a**2 - b**2 - c**2 + d**2, z) + 2 * ( + z_new = e(a ** 2 - b ** 2 - c ** 2 + d ** 2, z) + 2 * ( e(a * b + c * d, y) + e(b * d - a * c, x) ) v = np.stack((x_new, y_new, z_new), axis=-1) diff --git a/orix/quaternion/rotation.py b/orix/quaternion/rotation.py index 42c07f34..fc35292c 100644 --- a/orix/quaternion/rotation.py +++ b/orix/quaternion/rotation.py @@ -183,10 +183,10 @@ def _differentiators(self): i = self.improper abcd = np.stack( ( - a**2, - b**2, - c**2, - d**2, + a ** 2, + b ** 2, + c ** 2, + d ** 2, a * b, a * c, a * d, @@ -211,7 +211,7 @@ def angle_with(self, other): dp = self.unit.dot(other.unit).data # Round because some dot products are slightly above 1 dp = np.round(dp, np.finfo(dp.dtype).precision) - angles = Scalar(np.nan_to_num(np.arccos(2 * dp**2 - 1))) + angles = Scalar(np.nan_to_num(np.arccos(2 * dp ** 2 - 1))) return angles def outer(self, other): @@ -333,22 +333,22 @@ def to_euler(self, convention="bunge"): a, b, c, d = self.a.data, self.b.data, self.c.data, self.d.data - q03 = a**2 + d**2 - q12 = b**2 + c**2 + q03 = a ** 2 + d ** 2 + q12 = b ** 2 + c ** 2 chi = np.sqrt(q03 * q12) # P = 1 q12_is_zero = q12 == 0 if np.sum(q12_is_zero) > 0: - alpha = np.arctan2(-2 * a * d, a**2 - d**2) + alpha = np.arctan2(-2 * a * d, a ** 2 - d ** 2) e[..., 0] = np.where(q12_is_zero, alpha, e[..., 0]) e[..., 1] = np.where(q12_is_zero, 0, e[..., 1]) e[..., 2] = np.where(q12_is_zero, 0, e[..., 2]) q03_is_zero = q03 == 0 if np.sum(q03_is_zero) > 0: - alpha = np.arctan2(2 * b * c, b**2 - c**2) + alpha = np.arctan2(2 * b * c, b ** 2 - c ** 2) e[..., 0] = np.where(q03_is_zero, alpha, e[..., 0]) e[..., 1] = np.where(q03_is_zero, np.pi, e[..., 1]) e[..., 2] = np.where(q03_is_zero, 0, e[..., 2]) @@ -477,10 +477,10 @@ def to_matrix(self): a, b, c, d = self.a.data, self.b.data, self.c.data, self.d.data om = np.zeros(self.shape + (3, 3)) - bb = b**2 - cc = c**2 - dd = d**2 - qq = a**2 - (bb + cc + dd) + bb = b ** 2 + cc = c ** 2 + dd = d ** 2 + qq = a ** 2 - (bb + cc + dd) bc = b * c ad = a * d bd = b * d @@ -586,7 +586,7 @@ def random(cls, shape=(1,)): while len(rotations) < n: r = np.random.uniform(-1, 1, (3 * n, cls.dim)) r2 = np.sum(np.square(r), axis=1) - r = r[np.logical_and(1e-9**2 < r2, r2 <= 1)] + r = r[np.logical_and(1e-9 ** 2 < r2, r2 <= 1)] rotations += list(r) return cls(np.array(rotations[:n])).reshape(*shape) @@ -675,4 +675,4 @@ def von_mises(x, alpha, reference=Rotation((1, 0, 0, 0))): numpy.ndarray """ angle = Rotation(x).angle_with(reference) - return np.exp(2 * alpha * np.cos(angle.data)) / hyp0f1(1.5, alpha**2) + return np.exp(2 * alpha * np.cos(angle.data)) / hyp0f1(1.5, alpha ** 2) diff --git a/orix/quaternion/symmetry.py b/orix/quaternion/symmetry.py index 57eaa125..584967c5 100644 --- a/orix/quaternion/symmetry.py +++ b/orix/quaternion/symmetry.py @@ -457,7 +457,7 @@ def fundamental_zone(self): Ci.name = "-1" # Special generators -_mirror_xy = Symmetry([(1, 0, 0, 0), (0, 0.75**0.5, -(0.75**0.5), 0)]) +_mirror_xy = Symmetry([(1, 0, 0, 0), (0, 0.75 ** 0.5, -(0.75 ** 0.5), 0)]) _mirror_xy.improper = [0, 1] _cubic = Symmetry([(1, 0, 0, 0), (0.5, 0.5, 0.5, 0.5)]) @@ -500,25 +500,25 @@ def fundamental_zone(self): C4x = Symmetry( [ (1, 0, 0, 0), - (0.5**0.5, 0.5**0.5, 0, 0), + (0.5 ** 0.5, 0.5 ** 0.5, 0, 0), (0, 1, 0, 0), - (-(0.5**0.5), 0.5**0.5, 0, 0), + (-(0.5 ** 0.5), 0.5 ** 0.5, 0, 0), ] ) C4y = Symmetry( [ (1, 0, 0, 0), - (0.5**0.5, 0, 0.5**0.5, 0), + (0.5 ** 0.5, 0, 0.5 ** 0.5, 0), (0, 0, 1, 0), - (-(0.5**0.5), 0, 0.5**0.5, 0), + (-(0.5 ** 0.5), 0, 0.5 ** 0.5, 0), ] ) C4z = Symmetry( [ (1, 0, 0, 0), - (0.5**0.5, 0, 0, 0.5**0.5), + (0.5 ** 0.5, 0, 0, 0.5 ** 0.5), (0, 0, 0, 1), - (-(0.5**0.5), 0, 0, 0.5**0.5), + (-(0.5 ** 0.5), 0, 0, 0.5 ** 0.5), ] ) C4 = Symmetry(C4z) @@ -539,9 +539,9 @@ def fundamental_zone(self): D4h.name = "4/mmm" # 3-fold rotations -C3x = Symmetry([(1, 0, 0, 0), (0.5, 0.75**0.5, 0, 0), (-0.5, 0.75**0.5, 0, 0)]) -C3y = Symmetry([(1, 0, 0, 0), (0.5, 0, 0.75**0.5, 0), (-0.5, 0, 0.75**0.5, 0)]) -C3z = Symmetry([(1, 0, 0, 0), (0.5, 0, 0, 0.75**0.5), (-0.5, 0, 0, 0.75**0.5)]) +C3x = Symmetry([(1, 0, 0, 0), (0.5, 0.75 ** 0.5, 0, 0), (-0.5, 0.75 ** 0.5, 0, 0)]) +C3y = Symmetry([(1, 0, 0, 0), (0.5, 0, 0.75 ** 0.5, 0), (-0.5, 0, 0.75 ** 0.5, 0)]) +C3z = Symmetry([(1, 0, 0, 0), (0.5, 0, 0, 0.75 ** 0.5), (-0.5, 0, 0, 0.75 ** 0.5)]) C3 = Symmetry(C3z) C3.name = "3" diff --git a/orix/scalar/__init__.py b/orix/scalar/__init__.py index 5546ab67..7606818b 100644 --- a/orix/scalar/__init__.py +++ b/orix/scalar/__init__.py @@ -178,11 +178,11 @@ def __le__(self, other): def __pow__(self, power, modulo=None): if isinstance(power, (int, float)): - return self.__class__(self.data**power) + return self.__class__(self.data ** power) elif isinstance(power, (list, tuple)): power = np.array(power) if isinstance(power, np.ndarray): - return self.__class__(self.data**power) + return self.__class__(self.data ** power) return NotImplemented @classmethod diff --git a/orix/tests/quaternion/test_orientation.py b/orix/tests/quaternion/test_orientation.py index 3e54825d..728d92a0 100644 --- a/orix/tests/quaternion/test_orientation.py +++ b/orix/tests/quaternion/test_orientation.py @@ -44,7 +44,7 @@ def vector(request): return Vector3d(request.param) -@pytest.fixture(params=[(0.5, 0.5, 0.5, 0.5), (0.5**0.5, 0, 0, 0.5**0.5)]) +@pytest.fixture(params=[(0.5, 0.5, 0.5, 0.5), (0.5 ** 0.5, 0, 0, 0.5 ** 0.5)]) def orientation(request): return Orientation(request.param) @@ -368,7 +368,7 @@ def test_from_axes_angles(self, rotations): class TestOrientation: @pytest.mark.parametrize("symmetry", [C1, C2, C3, C4, D2, D3, D6, T, O, Oh]) def test_get_distance_matrix(self, symmetry): - q = [(0.5, 0.5, 0.5, 0.5), (0.5**0.5, 0, 0, 0.5**0.5)] + q = [(0.5, 0.5, 0.5, 0.5), (0.5 ** 0.5, 0, 0, 0.5 ** 0.5)] o = Orientation(q, symmetry=symmetry) o = o.map_into_symmetry_reduced_zone() angles_numpy = o.get_distance_matrix() @@ -394,7 +394,7 @@ def test_get_distance_matrix_lazy_parameters(self): @pytest.mark.parametrize("symmetry", [C1, C2, C3, C4, D2, D3, D6, T, O, Oh]) def test_angle_with(self, symmetry): - q = [(0.5, 0.5, 0.5, 0.5), (0.5**0.5, 0, 0, 0.5**0.5)] + q = [(0.5, 0.5, 0.5, 0.5), (0.5 ** 0.5, 0, 0, 0.5 ** 0.5)] r = Rotation(q) o = Orientation(q, symmetry=symmetry) o = o.map_into_symmetry_reduced_zone() diff --git a/orix/tests/quaternion/test_orientation_region.py b/orix/tests/quaternion/test_orientation_region.py index 991a4ca4..a5b42ea8 100644 --- a/orix/tests/quaternion/test_orientation_region.py +++ b/orix/tests/quaternion/test_orientation_region.py @@ -68,19 +68,19 @@ def test_get_distinguished_points(s1, s2, expected): @pytest.mark.parametrize( "s1, s2, expected", [ - (C2, C1, [[0.5**0.5, 0, 0, -(0.5**0.5)], [0.5**0.5, 0, 0, 0.5**0.5]]), + (C2, C1, [[0.5 ** 0.5, 0, 0, -(0.5 ** 0.5)], [0.5 ** 0.5, 0, 0, 0.5 ** 0.5]]), (C6, C1, [[0.258819, 0, 0, -0.965926], [0.258819, 0, 0, 0.965926]]), (C3, C3, [[0.5, 0, 0, -0.866], [0.5, 0, 0, 0.866]]), ( D2, C1, [ - [0.5**0.5, -(0.5**0.5), 0, 0], - [0.5**0.5, 0, -(0.5**0.5), 0], - [0.5**0.5, 0, 0, -(0.5**0.5)], - [0.5**0.5, 0, 0, 0.5**0.5], - [0.5**0.5, 0, 0.5**0.5, 0], - [0.5**0.5, 0.5**0.5, 0, 0], + [0.5 ** 0.5, -(0.5 ** 0.5), 0, 0], + [0.5 ** 0.5, 0, -(0.5 ** 0.5), 0], + [0.5 ** 0.5, 0, 0, -(0.5 ** 0.5)], + [0.5 ** 0.5, 0, 0, 0.5 ** 0.5], + [0.5 ** 0.5, 0, 0.5 ** 0.5, 0], + [0.5 ** 0.5, 0.5 ** 0.5, 0, 0], ], ), ( diff --git a/orix/tests/quaternion/test_quaternion.py b/orix/tests/quaternion/test_quaternion.py index 516a0c85..45fb5c5a 100644 --- a/orix/tests/quaternion/test_quaternion.py +++ b/orix/tests/quaternion/test_quaternion.py @@ -84,7 +84,7 @@ def test_neg(self, quaternion): def test_norm(self, quaternion): q = quaternion - assert np.allclose(q.norm.data, (q.data**2).sum(axis=-1) ** 0.5) + assert np.allclose(q.norm.data, (q.data ** 2).sum(axis=-1) ** 0.5) def test_unit(self, quaternion): assert np.allclose(quaternion.unit.norm.data, 1) @@ -123,7 +123,7 @@ def test_inverse(self, quaternion): def test_dot(self, quaternion, something): q = quaternion - assert np.allclose(q.dot(q).data, np.sum(q.data**2, axis=-1)) + assert np.allclose(q.dot(q).data, np.sum(q.data ** 2, axis=-1)) assert np.allclose(q.dot(something).data, something.dot(q).data) def test_dot_outer(self, quaternion, something): diff --git a/orix/tests/quaternion/test_rotation.py b/orix/tests/quaternion/test_rotation.py index df329c9a..e94d7a72 100644 --- a/orix/tests/quaternion/test_rotation.py +++ b/orix/tests/quaternion/test_rotation.py @@ -449,7 +449,7 @@ def test_dot_outer_quat(rotation, improper, quaternion, expected): [ ([1, 0, 0, 0], [0, 0, 1]), ([-1, 0, 0, 0], [0, 0, -1]), - ([0, 0.5**0.5, 0.5**0.5, 0], [0.5**0.5, 0.5**0.5, 0]), + ([0, 0.5 ** 0.5, 0.5 ** 0.5, 0], [0.5 ** 0.5, 0.5 ** 0.5, 0]), ([[1, 0, 0, 0], [-1, 0, 0, 0]], [[0, 0, 1], [0, 0, -1]]), ], indirect=["rotation"], @@ -463,7 +463,7 @@ def test_axis(rotation, expected): "rotation, improper", [ ([(1, 0, 0, 0), (1, 0, 0, 0)], [0, 1]), - ([(0.5**0.5, 0, 0, 0.5**0.5)], [1]), + ([(0.5 ** 0.5, 0, 0, 0.5 ** 0.5)], [1]), ], ) def test_antipodal(rotation, improper): diff --git a/orix/tests/quaternion/test_symmetry.py b/orix/tests/quaternion/test_symmetry.py index 8e4725c7..de68a430 100644 --- a/orix/tests/quaternion/test_symmetry.py +++ b/orix/tests/quaternion/test_symmetry.py @@ -361,10 +361,10 @@ def test_eq(symmetry, other, expected): ( T, [ - [0.5**0.5, -(0.5**0.5), 0], - [0, -(0.5**0.5), 0.5**0.5], - [0, 0.5**0.5, 0.5**0.5], - [0.5**0.5, 0.5**0.5, 0], + [0.5 ** 0.5, -(0.5 ** 0.5), 0], + [0, -(0.5 ** 0.5), 0.5 ** 0.5], + [0, 0.5 ** 0.5, 0.5 ** 0.5], + [0.5 ** 0.5, 0.5 ** 0.5, 0], ], ), ], diff --git a/orix/tests/test_scalar.py b/orix/tests/test_scalar.py index fafdcfd0..d31c21ff 100644 --- a/orix/tests/test_scalar.py +++ b/orix/tests/test_scalar.py @@ -192,7 +192,7 @@ def test_le(scalar, other, expected): indirect=["scalar"], ) def test_pow(scalar, other, expected): - pow = scalar**other + pow = scalar ** other assert np.allclose(pow.data, expected) diff --git a/orix/tests/test_vector3d.py b/orix/tests/test_vector3d.py index d9ce6750..257f2b3c 100644 --- a/orix/tests/test_vector3d.py +++ b/orix/tests/test_vector3d.py @@ -181,7 +181,7 @@ def test_rdiv(): def test_dot(vector, something): - assert np.allclose(vector.dot(vector).data, (vector.data**2).sum(axis=-1)) + assert np.allclose(vector.dot(vector).data, (vector.data ** 2).sum(axis=-1)) assert np.allclose(vector.dot(something).data, something.dot(vector).data) diff --git a/orix/vector/miller.py b/orix/vector/miller.py index d82255c6..eb0415ce 100644 --- a/orix/vector/miller.py +++ b/orix/vector/miller.py @@ -907,7 +907,7 @@ def _round_indices(indices, max_index=12): error = 1e-7 * np.round( 1e7 * np.sum((idx_scaled - np.round(idx_scaled)) ** 2, axis=-1) - / np.sum(idx_scaled**2, axis=-1) + / np.sum(idx_scaled ** 2, axis=-1) ) idx_min_error = np.argmin(error, axis=0) multiplier = (idx_min_error + 1) / max_per_set From 3a6ff7b6c21b924a060e52e402c183f07d3dc38c Mon Sep 17 00:00:00 2001 From: Paddy Harrison Date: Mon, 7 Feb 2022 14:08:25 +0100 Subject: [PATCH 09/10] Revert "update black version" This reverts commit 35c268b5119070d0d436272a6005c468a3cfd390. --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cf81be99..0353f36d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,5 @@ repos: - repo: https://github.com/psf/black - rev: 22.1.0 + rev: 21.8b0 hooks: - id: black From 524277bd8bc1921a8f67da2953370e9669dac909 Mon Sep 17 00:00:00 2001 From: Paddy Harrison Date: Tue, 8 Feb 2022 10:23:38 +0100 Subject: [PATCH 10/10] add fix to changelog --- CHANGELOG.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 95ea60d3..49aac90d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -14,6 +14,11 @@ Added ----- - Python 3.10 support. +Fixed +----- +- The inverse indices returned from `Rotation.unique()` now correctly recreate the + original `Rotation` instance. + 2021-12-21 - version 0.8.0 ==========================