diff --git a/orix/__init__.py b/orix/__init__.py index de6240a1..1d7478c7 100644 --- a/orix/__init__.py +++ b/orix/__init__.py @@ -1,5 +1,5 @@ __name__ = "orix" -__version__ = "0.2.0dev" +__version__ = "0.2.0rc1" __author__ = "Ben Martineau & Phillip Crout" __author_email__ = "pyxem.team@gmail.com" __description__ = "Orientation, rotation, quaternion, and crystal symmetry handling in Python." diff --git a/orix/objects.py b/orix/objects.py index 9273507f..6971f26a 100644 --- a/orix/objects.py +++ b/orix/objects.py @@ -16,5 +16,5 @@ # You should have received a copy of the GNU General Public License # along with orix. If not, see . -from orix.quaternion.orientation import Orientation, Misorientation #pragma: no cover -from orix.vector.neo_euler import NeoEuler, Homochoric, Rodrigues, AxAngle #pragma: no cover +from orix.quaternion.orientation import Orientation, Misorientation # pragma: no cover +from orix.vector.neo_euler import NeoEuler, Homochoric, Rodrigues, AxAngle # pragma: no cover diff --git a/orix/plot/rotation_plot.py b/orix/plot/rotation_plot.py index 28d76c39..ba9ec089 100644 --- a/orix/plot/rotation_plot.py +++ b/orix/plot/rotation_plot.py @@ -48,7 +48,6 @@ def plot_wireframe(self, xs, **kwargs): return super().plot_wireframe(x, y, z, **kwargs) - class RodriguesPlot(RotationPlot): """Plot rotations in a Rodrigues-Frank projection.""" name = 'rodrigues' diff --git a/orix/quaternion/__init__.py b/orix/quaternion/__init__.py index f1d9b824..673cee3d 100644 --- a/orix/quaternion/__init__.py +++ b/orix/quaternion/__init__.py @@ -163,7 +163,8 @@ def e(x, y): return np.multiply.outer(x, y) 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) return other.__class__(v) - raise NotImplementedError("This operation is currently not avaliable in orix, please use outer with other of type: Quaternion or Vector3d") + raise NotImplementedError( + "This operation is currently not avaliable in orix, please use outer with other of type: Quaternion or Vector3d") def dot(self, other): """Scalar : the dot product of this quaternion and the other.""" diff --git a/orix/quaternion/orientation.py b/orix/quaternion/orientation.py index 7a5399a1..f11242e6 100644 --- a/orix/quaternion/orientation.py +++ b/orix/quaternion/orientation.py @@ -221,7 +221,7 @@ def _distance_1(misorientation, verbose): def _distance_2(misorientation, verbose): - if misorientation.size > 1e4: #pragma no cover + if misorientation.size > 1e4: # pragma no cover confirm = input('Large datasets may crash your RAM.\nAre you sure? (y/n) ') if confirm != 'y': raise InterruptedError('Aborted') diff --git a/orix/quaternion/rotation.py b/orix/quaternion/rotation.py index d0bb47d0..6ec537d7 100644 --- a/orix/quaternion/rotation.py +++ b/orix/quaternion/rotation.py @@ -89,7 +89,7 @@ def __mul__(self, other): improper = (self.improper * np.ones(other.shape)).astype(bool) v[improper] = -v[improper] return v - if isinstance(other,int) or isinstance(other,list): #has to plus/minus 1 + if isinstance(other, int) or isinstance(other, list): # has to plus/minus 1 other = np.atleast_1d(other).astype(int) if isinstance(other, np.ndarray): assert np.all(abs(other) == 1), "Rotations can only be multiplied by 1 or -1" diff --git a/orix/scalar/__init__.py b/orix/scalar/__init__.py index ff3a34b9..5c3ce6a9 100644 --- a/orix/scalar/__init__.py +++ b/orix/scalar/__init__.py @@ -53,7 +53,7 @@ def __init__(self, data): @property def data(self): return self._data - + def __neg__(self): return self.__class__(-self.data) diff --git a/orix/symmetry.py b/orix/symmetry.py index 76c55eb6..3d2450e9 100644 --- a/orix/symmetry.py +++ b/orix/symmetry.py @@ -16,5 +16,5 @@ # You should have received a copy of the GNU General Public License # along with orix. If not, see . -from orix.quaternion.symmetry import * #pragma: no cover -from orix.quaternion.orientation_region import OrientationRegion #pragma: no cover +from orix.quaternion.symmetry import * # pragma: no cover +from orix.quaternion.orientation_region import OrientationRegion # pragma: no cover diff --git a/orix/tests/test_io.py b/orix/tests/test_io.py index 669d01b7..4aeb9e60 100644 --- a/orix/tests/test_io.py +++ b/orix/tests/test_io.py @@ -60,9 +60,10 @@ def test_load_ang(angfile, expected_data): loaded_data = io.loadang(angfile) assert np.allclose(loaded_data.data, expected_data) + def test_load_ctf(): """ Crude test of the ctf loader """ - z = np.random.rand(100,8) - np.savetxt('temp.ctf',z) + z = np.random.rand(100, 8) + np.savetxt('temp.ctf', z) z_loaded = io.loadctf('temp.ctf') os.remove('temp.ctf') diff --git a/orix/tests/test_neoeuler.py b/orix/tests/test_neoeuler.py index 96820a9f..cf199326 100644 --- a/orix/tests/test_neoeuler.py +++ b/orix/tests/test_neoeuler.py @@ -1,11 +1,13 @@ import pytest import numpy as np -from orix.vector.neo_euler import Rodrigues,Homochoric +from orix.vector.neo_euler import Rodrigues, Homochoric from orix.quaternion.rotation import Rotation """ Rodrigues """ + + @pytest.mark.parametrize('rotation, expected', [ (Rotation([1, 0, 0, 0]), [0, 0, 0]), (Rotation([0.9239, 0.2209, 0.2209, 0.2209]), [0.2391, 0.2391, 0.2391]), @@ -22,7 +24,10 @@ def test_angle(rodrigues, expected): angle = rodrigues.angle assert np.allclose(angle.data, expected, atol=1e-3) + """ Homochoric""" + + @pytest.mark.parametrize('rotation', [ Rotation([1, 0, 0, 0]), Rotation([0.9239, 0.2209, 0.2209, 0.2209])]) @@ -30,10 +35,11 @@ def test_Homochoric_from_rotation(rotation): h = Homochoric.from_rotation(rotation) return None + @pytest.mark.parametrize('rotation', [ Rotation([1, 0, 0, 0]), Rotation([0.9239, 0.2209, 0.2209, 0.2209])]) -@pytest.mark.xfail(strict=True,reason=AttributeError) +@pytest.mark.xfail(strict=True, reason=AttributeError) def test_Homochoric_angle(rotation): h = Homochoric.from_rotation(rotation) h.angle diff --git a/orix/tests/test_object3d.py b/orix/tests/test_object3d.py index d24bb57a..d207745b 100644 --- a/orix/tests/test_object3d.py +++ b/orix/tests/test_object3d.py @@ -3,9 +3,11 @@ from orix.base import DimensionError, Object3d, check -@pytest.mark.xfail(strict=True,reason=ValueError) + +@pytest.mark.xfail(strict=True, reason=ValueError) def test_check_failing(): - check(np.asarray([1,1,1,1]),Object3d) + check(np.asarray([1, 1, 1, 1]), Object3d) + @pytest.fixture( params=[ diff --git a/orix/tests/test_orientation.py b/orix/tests/test_orientation.py index 7651f804..766d6c9f 100644 --- a/orix/tests/test_orientation.py +++ b/orix/tests/test_orientation.py @@ -1,7 +1,7 @@ import pytest import numpy as np -from orix.quaternion.orientation import Orientation,Misorientation +from orix.quaternion.orientation import Orientation, Misorientation from orix.quaternion.symmetry import * @@ -75,7 +75,7 @@ def test_orientation_persistence(symmetry, vector): ], indirect=['orientation']) def test_distance_1(orientation, symmetry, expected): o = orientation.set_symmetry(symmetry) - distance = o.distance(speed=1,verbose=True) + distance = o.distance(speed=1, verbose=True) assert np.allclose(distance, expected, atol=1e-3) @@ -100,7 +100,7 @@ def test_distance_1(orientation, symmetry, expected): ], indirect=['orientation']) def test_distance_2(orientation, symmetry, expected): o = orientation.set_symmetry(symmetry) - distance = o.distance(speed=2,verbose=True) + distance = o.distance(speed=2, verbose=True) assert np.allclose(distance, expected, atol=1e-3) @@ -111,7 +111,8 @@ def test_getitem(orientation, symmetry): o = orientation.set_symmetry(symmetry) assert o[0].symmetry._tuples == symmetry._tuples -@pytest.mark.parametrize('Gl',[C4,C2]) + +@pytest.mark.parametrize('Gl', [C4, C2]) def test_equivalent(Gl): """ Tests that the property Misorientation.equivalent runs without error @@ -120,23 +121,26 @@ def test_equivalent(Gl): Gl == C4 ~ "grain exchange" Gl == C2 ~ "no grain exchange" """ - m = Misorientation([1,1,1,1]) # any will do - m_new = m.set_symmetry(Gl,C4,verbose=True) + m = Misorientation([1, 1, 1, 1]) # any will do + m_new = m.set_symmetry(Gl, C4, verbose=True) m_new.symmetry _m = m_new.equivalent + def test_repr(): - m = Misorientation([1,1,1,1]) # any will do - print(m) #hits __repr__ + m = Misorientation([1, 1, 1, 1]) # any will do + print(m) # hits __repr__ return None + 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 + 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 -@pytest.mark.xfail(strict=True,reason=TypeError) + +@pytest.mark.xfail(strict=True, reason=TypeError) def test_sub_orientation_and_other(): - m = Orientation([1,1,1,1]) # any will do + m = Orientation([1, 1, 1, 1]) # any will do mis = m - 3 diff --git a/orix/tests/test_orientation_region.py b/orix/tests/test_orientation_region.py index 7315e005..bdfe70c6 100644 --- a/orix/tests/test_orientation_region.py +++ b/orix/tests/test_orientation_region.py @@ -3,7 +3,7 @@ from orix.quaternion.symmetry import * from orix.quaternion.orientation import Orientation -from orix.quaternion.orientation_region import _get_large_cell_normals,get_proper_groups,OrientationRegion +from orix.quaternion.orientation_region import _get_large_cell_normals, get_proper_groups, OrientationRegion from orix.quaternion.symmetry import get_distinguished_points @@ -82,21 +82,23 @@ def test_get_large_cell_normals(s1, s2, expected): print(n) assert np.allclose(n.data, expected, atol=1e-3) + def test_coverage_on_faces(): - o = OrientationRegion(Orientation([1,1,1,1])) + o = OrientationRegion(Orientation([1, 1, 1, 1])) f = o.faces() return None -@pytest.mark.parametrize('Gl,Gr',[(C1,Ci),(Ci,C1), - (C1,Csz),(Csz,C1), - (Ci,Csz),(Csz,Ci), - (C1,C1),(Ci,Ci)]) -def test_get_proper_point_groups(Gl,Gr): - get_proper_groups(Gl,Gr) +@pytest.mark.parametrize('Gl,Gr', [(C1, Ci), (Ci, C1), + (C1, Csz), (Csz, C1), + (Ci, Csz), (Csz, Ci), + (C1, C1), (Ci, Ci)]) +def test_get_proper_point_groups(Gl, Gr): + get_proper_groups(Gl, Gr) return None -@pytest.mark.xfail(raises=NotImplementedError,strict=True) + +@pytest.mark.xfail(raises=NotImplementedError, strict=True) def test_get_proper_point_group_not_implemented(): """ Double inversion case not yet implemented """ - get_proper_groups(Csz,Csz) + get_proper_groups(Csz, Csz) diff --git a/orix/tests/test_quaternion.py b/orix/tests/test_quaternion.py index 29a610f8..ea70cec2 100644 --- a/orix/tests/test_quaternion.py +++ b/orix/tests/test_quaternion.py @@ -130,31 +130,37 @@ def test_multiply_vector(quaternion, vector, expected): v_new = q * v assert np.allclose(v_new.data, expected) + def test_check_quat(): """ check is an oddly named function""" - quat = Quaternion([2,2,2,2]) - assert np.allclose(quat.data,check_quaternion(quat).data) + quat = Quaternion([2, 2, 2, 2]) + assert np.allclose(quat.data, check_quaternion(quat).data) + def test_abcd(): - quat = Quaternion([2,2,2,2]) + quat = Quaternion([2, 2, 2, 2]) quat.a = 1 quat.b = 1 quat.c = 1 quat.d = 1 - assert np.allclose(quat.data,1) + assert np.allclose(quat.data, 1) + def test_mean(quaternion): _ = quaternion.mean() return None + def test_antipodal(quaternion): _ = quaternion.antipodal return None -@pytest.mark.xfail(strict=True,reason="NotImplemented") + +@pytest.mark.xfail(strict=True, reason="NotImplemented") def test_edgecase_outer(quaternion): - threetwoq = quaternion.outer([3,2]) - -@pytest.mark.xfail(strict=True,reason="NotImplemented") + threetwoq = quaternion.outer([3, 2]) + + +@pytest.mark.xfail(strict=True, reason="NotImplemented") def test_failing_mul(quaternion): quaternion * 'cant-mult-by-this' diff --git a/orix/tests/test_rotation.py b/orix/tests/test_rotation.py index 07ea6493..723ca963 100644 --- a/orix/tests/test_rotation.py +++ b/orix/tests/test_rotation.py @@ -142,10 +142,12 @@ def test_mul_number(rotation, i, number, expected_i): assert np.allclose(rotation.data, r.data) assert np.allclose(r.improper, expected_i) -@pytest.mark.xfail(strict=True,reason=TypeError) + +@pytest.mark.xfail(strict=True, reason=TypeError) def test_mul_failing(rotation): _ = rotation * 'cant-mult-by-this' + @pytest.mark.parametrize('rotation, i, expected_i', [ ([0.5, 0.5, 0.5, 0.5], 0, 1), ([0.5, 0.5, 0.5, 0.5], 1, 0), @@ -232,12 +234,12 @@ def test_unique(rotation, improper, expected, improper_expected): assert np.allclose(u.data, expected, atol=1e-6) assert np.allclose(u.improper, improper_expected) + def test_kwargs_unique(rotation): """ return_index and return_inverse edge cases""" - rotation.unique(return_index=True,return_inverse=True) - rotation.unique(return_index=True,return_inverse=False) - rotation.unique(return_index=False,return_inverse=True) - + rotation.unique(return_index=True, return_inverse=True) + rotation.unique(return_index=True, return_inverse=False) + rotation.unique(return_index=False, return_inverse=True) @pytest.mark.parametrize('rotation, improper, expected, improper_expected', [ diff --git a/orix/tests/test_rotation_plot.py b/orix/tests/test_rotation_plot.py index 19b61a6d..8374498d 100644 --- a/orix/tests/test_rotation_plot.py +++ b/orix/tests/test_rotation_plot.py @@ -19,25 +19,28 @@ from matplotlib import pyplot as plt import numpy as np -from orix.plot.rotation_plot import RotationPlot,RodriguesPlot,AxAnglePlot +from orix.plot.rotation_plot import RotationPlot, RodriguesPlot, AxAnglePlot from orix.quaternion.orientation import Misorientation -from orix.quaternion.symmetry import D6,C1 +from orix.quaternion.symmetry import D6, C1 from orix.quaternion.orientation_region import OrientationRegion + def test_init_RodriguesPlot(): fig = plt.figure(figsize=(3, 3)) _ = RodriguesPlot(fig) return None + def test_init_AxAnglePlot(): fig = plt.figure(figsize=(3, 3)) _ = AxAnglePlot(fig) return None + def test_RotationPlot_methods(): """ This code is lifted from demo-3-v0.1 """ - misori = Misorientation([1,1,1,1]) # any will do - fig = plt.figure(figsize=(6,3)) + misori = Misorientation([1, 1, 1, 1]) # any will do + fig = plt.figure(figsize=(6, 3)) gridspec = plt.GridSpec(1, 1, left=0, right=1, bottom=0, top=1, hspace=0.05) ax_misori = fig.add_subplot(gridspec[0], projection='axangle', proj_type='ortho', aspect='equal') ax_misori.scatter(misori) @@ -45,10 +48,11 @@ def test_RotationPlot_methods(): ax_misori.plot_wireframe(OrientationRegion.from_symmetry(D6, D6)) plt.close('all') - #clear the edge case - ax_misori.transform(np.asarray([1,1,1])) + # clear the edge case + ax_misori.transform(np.asarray([1, 1, 1])) return None + def test_full_region_plot(): - empty = OrientationRegion.from_symmetry(C1,C1) + empty = OrientationRegion.from_symmetry(C1, C1) plot_data = empty.get_plot_data() diff --git a/orix/tests/test_scalar.py b/orix/tests/test_scalar.py index 8ec740d8..aa152ebb 100644 --- a/orix/tests/test_scalar.py +++ b/orix/tests/test_scalar.py @@ -9,6 +9,7 @@ def scalar(request): return Scalar(request.param) + @pytest.mark.parametrize('data, expected', [ ((5, 3), (5, 3)), ([[1], [2]], [[1], [2]]), @@ -176,22 +177,23 @@ def test_stack(data, expected): assert stack.shape[-1] == len(data) assert np.allclose(stack.data, expected) + def test_flatten(scalar): scalar.flatten() return None -@pytest.mark.xfail(strict=True,reason=TypeError) +@pytest.mark.xfail(strict=True, reason=TypeError) class TestSpareNotImplemented(): - def test_radd_notimplemented(self,scalar): + def test_radd_notimplemented(self, scalar): 'cantadd' + scalar - def test_rsub_notimplemented(self,scalar): + def test_rsub_notimplemented(self, scalar): 'cantsub' - scalar - def test_rmul_notimplemented(self,scalar): + def test_rmul_notimplemented(self, scalar): 'cantmul' * scalar - def test_lt_notimplemented(self,scalar): + def test_lt_notimplemented(self, scalar): scalar < 'cantlt' diff --git a/orix/tests/test_symmetry.py b/orix/tests/test_symmetry.py index 466d0e41..2384a687 100644 --- a/orix/tests/test_symmetry.py +++ b/orix/tests/test_symmetry.py @@ -287,6 +287,7 @@ def test_fundamental_sector(symmetry, expected): fs = symmetry.fundamental_sector() assert np.allclose(fs.data, expected) + def test_no_symm_fundemental_sector(): - nosym = Symmetry.from_generators(Rotation([1,0,0,0])) + nosym = Symmetry.from_generators(Rotation([1, 0, 0, 0])) nosym.fundamental_sector() diff --git a/orix/tests/test_vector3d.py b/orix/tests/test_vector3d.py index 3e8c6a87..8deddd8a 100644 --- a/orix/tests/test_vector3d.py +++ b/orix/tests/test_vector3d.py @@ -39,6 +39,7 @@ def vector(request): return Vector3d(request.param) + @pytest.fixture(params=singles) def something(request): return Vector3d(request.param) @@ -50,8 +51,9 @@ def number(request): def test_check_vector(): - vector3 = Vector3d([2,2,2]) - assert np.allclose(vector3.data,check_vector(vector3).data) + vector3 = Vector3d([2, 2, 2]) + assert np.allclose(vector3.data, check_vector(vector3).data) + def test_neg(vector): assert np.all((-vector).data == -(vector.data)) @@ -140,7 +142,7 @@ def test_cross_error(vector, number): ]) def test_polar(theta, phi, r, expected): assert np.allclose(Vector3d.from_polar(theta, phi, r).data, - expected.data, atol=1e-5) + expected.data, atol=1e-5) @pytest.mark.parametrize('shape', [ @@ -231,26 +233,29 @@ def test_assign_z(vector, data, expected): def test_perpendicular(vector: Vector3d): assert np.allclose(vector.dot(vector.perpendicular).data, 0) + def test_mean_xyz(): x = Vector3d.xvector() y = Vector3d.yvector() z = Vector3d.zvector() - t = Vector3d([3*x.data,3*y.data,3*z.data]) - np.allclose(t.mean().data,1) + t = Vector3d([3 * x.data, 3 * y.data, 3 * z.data]) + np.allclose(t.mean().data, 1) -@pytest.mark.xfail(strict=True,reason=ValueError) + +@pytest.mark.xfail(strict=True, reason=ValueError) def test_zero_perpendicular(): - t = Vector3d(np.asarray([0,0,0])) + t = Vector3d(np.asarray([0, 0, 0])) tperp = t.perpendicular() -@pytest.mark.xfail(strict=True,reason=TypeError) + +@pytest.mark.xfail(strict=True, reason=TypeError) class TestSpareNotImplemented(): - def test_radd_notimplemented(self,vector): + def test_radd_notimplemented(self, vector): 'cantadd' + vector - def test_rsub_notimplemented(self,vector): + def test_rsub_notimplemented(self, vector): 'cantsub' - vector - def test_rmul_notimplemented(self,vector): + def test_rmul_notimplemented(self, vector): 'cantmul' * vector diff --git a/orix/vector/neo_euler.py b/orix/vector/neo_euler.py index d3ad76ca..44e36769 100644 --- a/orix/vector/neo_euler.py +++ b/orix/vector/neo_euler.py @@ -41,13 +41,13 @@ class NeoEuler(Vector3d, abc.ABC): @classmethod @abc.abstractmethod - def from_rotation(cls, rotation): #pragma: no cover + def from_rotation(cls, rotation): # pragma: no cover """NeoEuler : Create a new vector from the given rotation.""" pass @property @abc.abstractmethod - def angle(self): #pragma: no cover + def angle(self): # pragma: no cover """Scalar : the angle of rotation.""" pass diff --git a/pepstorm.sh b/pepstorm.sh old mode 100644 new mode 100755 index 48202dd2..4d40a6cb --- a/pepstorm.sh +++ b/pepstorm.sh @@ -1,8 +1,7 @@ #!/bin/bash cd "$(dirname "$0")" -cd orix/tests -cd ../ -for folder in base grid io plot quaternion scalar tests vector +cd orix/ +for folder in base io plot quaternion scalar tests vector do cd $folder autopep8 *.py --aggressive --in-place --max-line-length 130 diff --git a/setup.py b/setup.py index 4cd7d148..0920dcf0 100644 --- a/setup.py +++ b/setup.py @@ -11,11 +11,11 @@ description=__description__, long_description=open('README.rst').read(), classifiers=[ - "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", - "Development Status :: 4 - Beta", - "Intended Audience :: Science/Research", + "Programming Language :: Python :: 3.7", + "Development Status :: 4 - Beta", + "Intended Audience :: Science/Research", "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", "Natural Language :: English", "Operating System :: OS Independent",