Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump Black version #274

Merged
merged 2 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
repos:
- repo: https://github.com/psf/black
rev: 21.8b0
rev: 22.1.0
hooks:
- id: black
4 changes: 2 additions & 2 deletions orix/projections/stereographic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions orix/quaternion/_conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions orix/quaternion/orientation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion orix/quaternion/orientation_region.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions orix/quaternion/quaternion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
30 changes: 15 additions & 15 deletions orix/quaternion/rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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):
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
20 changes: 10 additions & 10 deletions orix/quaternion/symmetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)])

Expand Down Expand Up @@ -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)
Expand All @@ -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"

Expand Down
4 changes: 2 additions & 2 deletions orix/scalar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions orix/tests/quaternion/test_orientation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down
14 changes: 7 additions & 7 deletions orix/tests/quaternion/test_orientation_region.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
],
),
(
Expand Down
4 changes: 2 additions & 2 deletions orix/tests/quaternion/test_quaternion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions orix/tests/quaternion/test_rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand All @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions orix/tests/quaternion/test_symmetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
],
),
],
Expand Down
2 changes: 1 addition & 1 deletion orix/tests/test_scalar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion orix/tests/test_vector3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion orix/vector/miller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down