Merge branch 'rotation-test-coverage' into 'development'
increase test coverage to 100% See merge request damask/DAMASK!655
This commit is contained in:
commit
5d656d9c76
|
@ -773,12 +773,12 @@ class Rotation:
|
||||||
raise ValueError('P ∉ {-1,1}')
|
raise ValueError('P ∉ {-1,1}')
|
||||||
|
|
||||||
qu[...,1:4] *= -P
|
qu[...,1:4] *= -P
|
||||||
|
|
||||||
if accept_homomorph:
|
if accept_homomorph:
|
||||||
qu[qu[...,0] < 0.0] *= -1
|
qu[qu[...,0] < 0.0] *= -1
|
||||||
else:
|
elif np.any(qu[...,0] < 0.0):
|
||||||
if np.any(qu[...,0] < 0.0):
|
|
||||||
raise ValueError('quaternion with negative first (real) component')
|
raise ValueError('quaternion with negative first (real) component')
|
||||||
if not np.all(np.isclose(np.linalg.norm(qu,axis=-1), 1.0,rtol=0.0)):
|
if not np.all(np.isclose(np.linalg.norm(qu,axis=-1), 1.0,rtol=1e-8)):
|
||||||
raise ValueError('quaternion is not of unit length')
|
raise ValueError('quaternion is not of unit length')
|
||||||
|
|
||||||
return Rotation(qu)
|
return Rotation(qu)
|
||||||
|
|
|
@ -708,6 +708,7 @@ class TestRotation:
|
||||||
@pytest.mark.parametrize('degrees',[True,False])
|
@pytest.mark.parametrize('degrees',[True,False])
|
||||||
def test_axis_angle(self,set_of_rotations,degrees,normalize,P):
|
def test_axis_angle(self,set_of_rotations,degrees,normalize,P):
|
||||||
c = np.array([P*-1,P*-1,P*-1,1.])
|
c = np.array([P*-1,P*-1,P*-1,1.])
|
||||||
|
c[:3] *= 0.9 if normalize else 1.0
|
||||||
for rot in set_of_rotations:
|
for rot in set_of_rotations:
|
||||||
m = rot.as_Euler_angles()
|
m = rot.as_Euler_angles()
|
||||||
o = Rotation.from_axis_angle(rot.as_axis_angle(degrees)*c,degrees,normalize,P).as_Euler_angles()
|
o = Rotation.from_axis_angle(rot.as_axis_angle(degrees)*c,degrees,normalize,P).as_Euler_angles()
|
||||||
|
@ -730,16 +731,30 @@ class TestRotation:
|
||||||
assert ok and np.isclose(np.linalg.norm(o[:3]),1.0) \
|
assert ok and np.isclose(np.linalg.norm(o[:3]),1.0) \
|
||||||
and o[3]<=np.pi+1.e-9, f'{m},{o},{rot.as_quaternion()}'
|
and o[3]<=np.pi+1.e-9, f'{m},{o},{rot.as_quaternion()}'
|
||||||
|
|
||||||
|
def test_parallel(self,set_of_rotations):
|
||||||
|
a = np.array([[1.0,0.0,0.0],
|
||||||
|
[0.0,1.0,0.0]])
|
||||||
|
for rot in set_of_rotations:
|
||||||
|
assert rot.allclose(Rotation.from_parallel(a,rot.broadcast_to((2,))@a))
|
||||||
|
|
||||||
@pytest.mark.parametrize('P',[1,-1])
|
@pytest.mark.parametrize('P',[1,-1])
|
||||||
@pytest.mark.parametrize('normalize',[True,False])
|
@pytest.mark.parametrize('normalize',[True,False])
|
||||||
def test_Rodrigues(self,set_of_rotations,normalize,P):
|
def test_Rodrigues(self,set_of_rotations,normalize,P):
|
||||||
c = np.array([P*-1,P*-1,P*-1,1.])
|
c = np.array([P*-1,P*-1,P*-1,1.])
|
||||||
|
c[:3] *= 0.9 if normalize else 1.0
|
||||||
for rot in set_of_rotations:
|
for rot in set_of_rotations:
|
||||||
m = rot.as_matrix()
|
m = rot.as_matrix()
|
||||||
o = Rotation.from_Rodrigues_vector(rot.as_Rodrigues_vector()*c,normalize,P).as_matrix()
|
o = Rotation.from_Rodrigues_vector(rot.as_Rodrigues_vector()*c,normalize,P).as_matrix()
|
||||||
ok = np.allclose(m,o,atol=atol)
|
ok = np.allclose(m,o,atol=atol)
|
||||||
assert ok and np.isclose(np.linalg.det(o),1.0), f'{m},{o}'
|
assert ok and np.isclose(np.linalg.det(o),1.0), f'{m},{o}'
|
||||||
|
|
||||||
|
def test_Rodrigues_compact(self,set_of_rotations):
|
||||||
|
for rot in set_of_rotations:
|
||||||
|
c = rot.as_Rodrigues_vector(compact=True)
|
||||||
|
r = rot.as_Rodrigues_vector(compact=False)
|
||||||
|
assert np.allclose(r[:3]*r[3], c, equal_nan=True)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('P',[1,-1])
|
@pytest.mark.parametrize('P',[1,-1])
|
||||||
def test_homochoric(self,set_of_rotations,P):
|
def test_homochoric(self,set_of_rotations,P):
|
||||||
cutoff = np.tan(np.pi*.5*(1.-1e-4))
|
cutoff = np.tan(np.pi*.5*(1.-1e-4))
|
||||||
|
@ -760,8 +775,9 @@ class TestRotation:
|
||||||
|
|
||||||
@pytest.mark.parametrize('P',[1,-1])
|
@pytest.mark.parametrize('P',[1,-1])
|
||||||
@pytest.mark.parametrize('accept_homomorph',[True,False])
|
@pytest.mark.parametrize('accept_homomorph',[True,False])
|
||||||
|
# @pytest.mark.parametrize('normalize',[True,False])
|
||||||
def test_quaternion(self,set_of_rotations,P,accept_homomorph):
|
def test_quaternion(self,set_of_rotations,P,accept_homomorph):
|
||||||
c = np.array([1,P*-1,P*-1,P*-1]) * (-1 if accept_homomorph else 1)
|
c = np.array([1,P*-1,P*-1,P*-1]) * (-1 if accept_homomorph else 1) #* (0.9 if normalize else 1.0)
|
||||||
for rot in set_of_rotations:
|
for rot in set_of_rotations:
|
||||||
m = rot.as_cubochoric()
|
m = rot.as_cubochoric()
|
||||||
o = Rotation.from_quaternion(rot.as_quaternion()*c,accept_homomorph,P).as_cubochoric()
|
o = Rotation.from_quaternion(rot.as_quaternion()*c,accept_homomorph,P).as_cubochoric()
|
||||||
|
@ -889,6 +905,15 @@ class TestRotation:
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
fr(eval(f'R.{to}()'),P=-30)
|
fr(eval(f'R.{to}()'),P=-30)
|
||||||
|
|
||||||
|
|
||||||
|
def test_invalid_multiplication(self):
|
||||||
|
rot = Rotation.from_random()
|
||||||
|
with pytest.raises(TypeError):
|
||||||
|
rot@Rotation.from_random()
|
||||||
|
with pytest.raises(TypeError):
|
||||||
|
rot@[1,2,3,4]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('shape',[None,(3,),(4,2)])
|
@pytest.mark.parametrize('shape',[None,(3,),(4,2)])
|
||||||
def test_broadcast(self,shape):
|
def test_broadcast(self,shape):
|
||||||
rot = Rotation.from_random(shape)
|
rot = Rotation.from_random(shape)
|
||||||
|
|
Loading…
Reference in New Issue