From daaf8112e67d4c09a3d10ebd1e11d993fb00327a Mon Sep 17 00:00:00 2001 From: Paddy Harrison Date: Mon, 7 Feb 2022 15:48:20 +0100 Subject: [PATCH 1/2] 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 cc70e90bcfc5383b388d60d1404b1808ef85acda Mon Sep 17 00:00:00 2001 From: Paddy Harrison Date: Mon, 7 Feb 2022 15:49:03 +0100 Subject: [PATCH 2/2] 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 c20cf574..8af36d7f 100644 --- a/orix/quaternion/rotation.py +++ b/orix/quaternion/rotation.py @@ -178,10 +178,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, @@ -206,7 +206,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): @@ -328,22 +328,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]) @@ -472,10 +472,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 @@ -581,7 +581,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) @@ -670,4 +670,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 4a27c1a2..89b95224 100644 --- a/orix/tests/quaternion/test_rotation.py +++ b/orix/tests/quaternion/test_rotation.py @@ -442,7 +442,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"], @@ -456,7 +456,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