Skip to content

Commit

Permalink
#32 from pc494/pepstorm-2
Browse files Browse the repository at this point in the history
Pepstorm commit pre releasing 0.2.0
  • Loading branch information
pc494 authored Jan 6, 2020
2 parents d46a9f0 + b6246dd commit f3a6202
Show file tree
Hide file tree
Showing 22 changed files with 119 additions and 85 deletions.
2 changes: 1 addition & 1 deletion orix/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__name__ = "orix"
__version__ = "0.2.0dev"
__version__ = "0.2.0rc1"
__author__ = "Ben Martineau & Phillip Crout"
__author_email__ = "[email protected]"
__description__ = "Orientation, rotation, quaternion, and crystal symmetry handling in Python."
4 changes: 2 additions & 2 deletions orix/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
# You should have received a copy of the GNU General Public License
# along with orix. If not, see <http://www.gnu.org/licenses/>.

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
1 change: 0 additions & 1 deletion orix/plot/rotation_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 2 additions & 1 deletion orix/quaternion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
2 changes: 1 addition & 1 deletion orix/quaternion/orientation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion orix/quaternion/rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion orix/scalar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(self, data):
@property
def data(self):
return self._data

def __neg__(self):
return self.__class__(-self.data)

Expand Down
4 changes: 2 additions & 2 deletions orix/symmetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
# You should have received a copy of the GNU General Public License
# along with orix. If not, see <http://www.gnu.org/licenses/>.

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
5 changes: 3 additions & 2 deletions orix/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
10 changes: 8 additions & 2 deletions orix/tests/test_neoeuler.py
Original file line number Diff line number Diff line change
@@ -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]),
Expand All @@ -22,18 +24,22 @@ 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])])
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
6 changes: 4 additions & 2 deletions orix/tests/test_object3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[
Expand Down
30 changes: 17 additions & 13 deletions orix/tests/test_orientation.py
Original file line number Diff line number Diff line change
@@ -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 *


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


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


Expand All @@ -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
Expand All @@ -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
22 changes: 12 additions & 10 deletions orix/tests/test_orientation_region.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)
22 changes: 14 additions & 8 deletions orix/tests/test_quaternion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
12 changes: 7 additions & 5 deletions orix/tests/test_rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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', [
Expand Down
18 changes: 11 additions & 7 deletions orix/tests/test_rotation_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,40 @@
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)
ax_misori.plot(misori)
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()
Loading

0 comments on commit f3a6202

Please sign in to comment.