DAMASK_EICMD/python/tests/conftest.py

109 lines
4.2 KiB
Python
Raw Normal View History

2019-11-23 17:29:41 +05:30
import os
2020-06-30 21:05:52 +05:30
import numpy as np
2019-11-23 17:29:41 +05:30
import pytest
def pytest_addoption(parser):
parser.addoption("--update",
action="store_true",
default=False)
@pytest.fixture
def update(request):
2019-11-27 17:49:58 +05:30
"""Store current results as new reference results."""
2019-11-23 17:29:41 +05:30
return request.config.getoption("--update")
@pytest.fixture
def reference_dir_base():
2019-11-27 17:49:58 +05:30
"""Directory containing reference results."""
return os.path.join(os.path.dirname(__file__),'reference')
2020-06-30 21:05:52 +05:30
@pytest.fixture
2020-06-30 21:42:19 +05:30
def set_of_quaternions():
2020-06-30 21:05:52 +05:30
"""A set of n random rotations."""
2020-06-30 21:42:19 +05:30
def random_quaternions(N):
r = np.random.rand(N,3)
A = np.sqrt(r[:,2])
B = np.sqrt(1.0-r[:,2])
qu = np.column_stack([np.cos(2.0*np.pi*r[:,0])*A,
np.sin(2.0*np.pi*r[:,1])*B,
np.cos(2.0*np.pi*r[:,1])*B,
np.sin(2.0*np.pi*r[:,0])*A])
qu[:,0]*=np.sign(qu[:,0])
return qu
2020-06-30 21:05:52 +05:30
n = 1100
scatter=1.e-2
specials = np.array([
[1.0, 0.0, 0.0, 0.0],
#----------------------
[0.0, 1.0, 0.0, 0.0],
[0.0, 0.0, 1.0, 0.0],
[0.0, 0.0, 0.0, 1.0],
[0.0,-1.0, 0.0, 0.0],
[0.0, 0.0,-1.0, 0.0],
[0.0, 0.0, 0.0,-1.0],
#----------------------
[1.0, 1.0, 0.0, 0.0],
[1.0, 0.0, 1.0, 0.0],
[1.0, 0.0, 0.0, 1.0],
[0.0, 1.0, 1.0, 0.0],
[0.0, 1.0, 0.0, 1.0],
[0.0, 0.0, 1.0, 1.0],
#----------------------
[1.0,-1.0, 0.0, 0.0],
[1.0, 0.0,-1.0, 0.0],
[1.0, 0.0, 0.0,-1.0],
[0.0, 1.0,-1.0, 0.0],
[0.0, 1.0, 0.0,-1.0],
[0.0, 0.0, 1.0,-1.0],
#----------------------
[0.0, 1.0,-1.0, 0.0],
[0.0, 1.0, 0.0,-1.0],
[0.0, 0.0, 1.0,-1.0],
#----------------------
[0.0,-1.0,-1.0, 0.0],
[0.0,-1.0, 0.0,-1.0],
[0.0, 0.0,-1.0,-1.0],
#----------------------
[1.0, 1.0, 1.0, 0.0],
[1.0, 1.0, 0.0, 1.0],
[1.0, 0.0, 1.0, 1.0],
[1.0,-1.0, 1.0, 0.0],
[1.0,-1.0, 0.0, 1.0],
[1.0, 0.0,-1.0, 1.0],
[1.0, 1.0,-1.0, 0.0],
[1.0, 1.0, 0.0,-1.0],
[1.0, 0.0, 1.0,-1.0],
[1.0,-1.0,-1.0, 0.0],
[1.0,-1.0, 0.0,-1.0],
[1.0, 0.0,-1.0,-1.0],
#----------------------
[0.0, 1.0, 1.0, 1.0],
[0.0, 1.0,-1.0, 1.0],
[0.0, 1.0, 1.0,-1.0],
[0.0,-1.0, 1.0, 1.0],
[0.0,-1.0,-1.0, 1.0],
[0.0,-1.0, 1.0,-1.0],
[0.0,-1.0,-1.0,-1.0],
#----------------------
[1.0, 1.0, 1.0, 1.0],
[1.0,-1.0, 1.0, 1.0],
[1.0, 1.0,-1.0, 1.0],
[1.0, 1.0, 1.0,-1.0],
[1.0,-1.0,-1.0, 1.0],
[1.0,-1.0, 1.0,-1.0],
[1.0, 1.0,-1.0,-1.0],
[1.0,-1.0,-1.0,-1.0],
])
specials /= np.linalg.norm(specials,axis=1).reshape(-1,1)
specials_scatter = specials + np.broadcast_to(np.random.rand(4)*scatter,specials.shape)
specials_scatter /= np.linalg.norm(specials_scatter,axis=1).reshape(-1,1)
specials_scatter[specials_scatter[:,0]<0]*=-1
2020-06-30 21:42:19 +05:30
return [s for s in specials] + \
[s for s in specials_scatter] + \
[s for s in random_quaternions(n-2*len(specials))]