non-vectorized formulas can be implemented in a user function
This commit is contained in:
parent
a9f53f4822
commit
72ea9a5cec
|
@ -26,7 +26,7 @@ def default():
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def reference_dir(reference_dir_base):
|
def reference_dir(reference_dir_base):
|
||||||
"""Directory containing reference results."""
|
"""Directory containing reference results."""
|
||||||
return os.path.join(reference_dir_base,'Geom')
|
return reference_dir_base/'Geom'
|
||||||
|
|
||||||
|
|
||||||
class TestGeom:
|
class TestGeom:
|
||||||
|
@ -87,7 +87,7 @@ class TestGeom:
|
||||||
modified = copy.deepcopy(default)
|
modified = copy.deepcopy(default)
|
||||||
modified.mirror(directions,reflect)
|
modified.mirror(directions,reflect)
|
||||||
tag = f'directions={"-".join(directions)}_reflect={reflect}'
|
tag = f'directions={"-".join(directions)}_reflect={reflect}'
|
||||||
reference = os.path.join(reference_dir,f'mirror_{tag}.geom')
|
reference = reference_dir/f'mirror_{tag}.geom'
|
||||||
if update: modified.to_file(reference)
|
if update: modified.to_file(reference)
|
||||||
assert geom_equal(modified,Geom.from_file(reference))
|
assert geom_equal(modified,Geom.from_file(reference))
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ class TestGeom:
|
||||||
modified = copy.deepcopy(default)
|
modified = copy.deepcopy(default)
|
||||||
modified.clean(stencil)
|
modified.clean(stencil)
|
||||||
tag = f'stencil={stencil}'
|
tag = f'stencil={stencil}'
|
||||||
reference = os.path.join(reference_dir,f'clean_{tag}.geom')
|
reference = reference_dir/f'clean_{tag}.geom'
|
||||||
if update: modified.to_file(reference)
|
if update: modified.to_file(reference)
|
||||||
assert geom_equal(modified,Geom.from_file(reference))
|
assert geom_equal(modified,Geom.from_file(reference))
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ class TestGeom:
|
||||||
modified = copy.deepcopy(default)
|
modified = copy.deepcopy(default)
|
||||||
modified.scale(grid)
|
modified.scale(grid)
|
||||||
tag = f'grid={util.srepr(grid,"-")}'
|
tag = f'grid={util.srepr(grid,"-")}'
|
||||||
reference = os.path.join(reference_dir,f'scale_{tag}.geom')
|
reference = reference_dir/f'scale_{tag}.geom'
|
||||||
if update: modified.to_file(reference)
|
if update: modified.to_file(reference)
|
||||||
assert geom_equal(modified,Geom.from_file(reference))
|
assert geom_equal(modified,Geom.from_file(reference))
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ class TestGeom:
|
||||||
modified = copy.deepcopy(default)
|
modified = copy.deepcopy(default)
|
||||||
modified.rotate(Rotation.from_Eulers(Eulers,degrees=True))
|
modified.rotate(Rotation.from_Eulers(Eulers,degrees=True))
|
||||||
tag = f'Eulers={util.srepr(Eulers,"-")}'
|
tag = f'Eulers={util.srepr(Eulers,"-")}'
|
||||||
reference = os.path.join(reference_dir,f'rotate_{tag}.geom')
|
reference = reference_dir/f'rotate_{tag}.geom'
|
||||||
if update: modified.to_file(reference)
|
if update: modified.to_file(reference)
|
||||||
assert geom_equal(modified,Geom.from_file(reference))
|
assert geom_equal(modified,Geom.from_file(reference))
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ def inverse_pole(orientation,axis,proper=False,SST=True):
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def reference_dir(reference_dir_base):
|
def reference_dir(reference_dir_base):
|
||||||
"""Directory containing reference results."""
|
"""Directory containing reference results."""
|
||||||
return os.path.join(reference_dir_base,'Rotation')
|
return reference_dir_base/'Rotation'
|
||||||
|
|
||||||
|
|
||||||
class TestOrientation:
|
class TestOrientation:
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import time
|
import time
|
||||||
import shutil
|
import shutil
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -100,14 +101,16 @@ class TestResult:
|
||||||
assert np.allclose(in_memory,in_file)
|
assert np.allclose(in_memory,in_file)
|
||||||
|
|
||||||
@pytest.mark.parametrize('mode',['direct','function'])
|
@pytest.mark.parametrize('mode',['direct','function'])
|
||||||
def test_add_calculation(self,default,mode):
|
def test_add_calculation(self,default,tmp_path,mode):
|
||||||
def my_func(field):
|
|
||||||
return 2.0*np.abs(field)-1.0
|
|
||||||
|
|
||||||
if mode == 'direct':
|
if mode == 'direct':
|
||||||
default.add_calculation('x','2.0*np.abs(#F#)-1.0','-','my notes')
|
default.add_calculation('x','2.0*np.abs(#F#)-1.0','-','my notes')
|
||||||
else:
|
else:
|
||||||
default.enable_user_function(my_func)
|
with open(tmp_path/'f.py','w') as f:
|
||||||
|
f.write("import numpy as np\ndef my_func(field):\n return 2.0*np.abs(field)-1.0\n")
|
||||||
|
sys.path.insert(0,str(tmp_path))
|
||||||
|
import f
|
||||||
|
default.enable_user_function(f.my_func)
|
||||||
default.add_calculation('x','my_func(#F#)','-','my notes')
|
default.add_calculation('x','my_func(#F#)','-','my notes')
|
||||||
|
|
||||||
loc = {'F': default.get_dataset_location('F'),
|
loc = {'F': default.get_dataset_location('F'),
|
||||||
|
|
|
@ -6,7 +6,7 @@ import numpy as np
|
||||||
from damask import Rotation
|
from damask import Rotation
|
||||||
from damask import _rotation
|
from damask import _rotation
|
||||||
|
|
||||||
n = 1100
|
n = 1000
|
||||||
atol=1.e-4
|
atol=1.e-4
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
|
|
@ -15,7 +15,7 @@ def default():
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def reference_dir(reference_dir_base):
|
def reference_dir(reference_dir_base):
|
||||||
"""Directory containing reference results."""
|
"""Directory containing reference results."""
|
||||||
return os.path.join(reference_dir_base,'Table')
|
return reference_dir_base/'Table'
|
||||||
|
|
||||||
class TestTable:
|
class TestTable:
|
||||||
|
|
||||||
|
@ -35,9 +35,13 @@ class TestTable:
|
||||||
d = default.get('5_F')
|
d = default.get('5_F')
|
||||||
assert np.allclose(d,1.0) and d.shape[1:] == (1,)
|
assert np.allclose(d,1.0) and d.shape[1:] == (1,)
|
||||||
|
|
||||||
def test_write_read_str(self,default,tmpdir):
|
@pytest.mark.parametrize('mode',['str','path'])
|
||||||
default.to_ASCII(str(tmpdir.join('default.txt')))
|
def test_write_read(self,default,tmpdir,mode):
|
||||||
new = Table.from_ASCII(str(tmpdir.join('default.txt')))
|
default.to_ASCII(tmpdir/'default.txt')
|
||||||
|
if mode == 'path':
|
||||||
|
new = Table.from_ASCII(tmpdir/'default.txt')
|
||||||
|
elif mode == 'str':
|
||||||
|
new = Table.from_ASCII(str(tmpdir/'default.txt'))
|
||||||
assert all(default.data==new.data) and default.shapes == new.shapes
|
assert all(default.data==new.data) and default.shapes == new.shapes
|
||||||
|
|
||||||
def test_write_read_file(self,default,tmpdir):
|
def test_write_read_file(self,default,tmpdir):
|
||||||
|
@ -54,20 +58,25 @@ class TestTable:
|
||||||
new = Table.from_ASCII(f)
|
new = Table.from_ASCII(f)
|
||||||
assert all(default.data==new.data) and default.shapes == new.shapes
|
assert all(default.data==new.data) and default.shapes == new.shapes
|
||||||
|
|
||||||
def test_read_ang_str(self,reference_dir):
|
|
||||||
new = Table.from_ang(os.path.join(reference_dir,'simple.ang'))
|
@pytest.mark.parametrize('mode',['str','path'])
|
||||||
|
def test_read_ang(self,reference_dir,mode):
|
||||||
|
if mode == 'path':
|
||||||
|
new = Table.from_ang(reference_dir/'simple.ang')
|
||||||
|
elif mode == 'str':
|
||||||
|
new = Table.from_ang(str(reference_dir/'simple.ang'))
|
||||||
assert new.data.shape == (4,10) and \
|
assert new.data.shape == (4,10) and \
|
||||||
new.labels == ['eu', 'pos', 'IQ', 'CI', 'ID', 'intensity', 'fit']
|
new.labels == ['eu', 'pos', 'IQ', 'CI', 'ID', 'intensity', 'fit']
|
||||||
|
|
||||||
def test_read_ang_file(self,reference_dir):
|
def test_read_ang_file(self,reference_dir):
|
||||||
f = open(os.path.join(reference_dir,'simple.ang'))
|
f = open(reference_dir/'simple.ang')
|
||||||
new = Table.from_ang(f)
|
new = Table.from_ang(f)
|
||||||
assert new.data.shape == (4,10) and \
|
assert new.data.shape == (4,10) and \
|
||||||
new.labels == ['eu', 'pos', 'IQ', 'CI', 'ID', 'intensity', 'fit']
|
new.labels == ['eu', 'pos', 'IQ', 'CI', 'ID', 'intensity', 'fit']
|
||||||
|
|
||||||
@pytest.mark.parametrize('fname',['datatype-mix.txt','whitespace-mix.txt'])
|
@pytest.mark.parametrize('fname',['datatype-mix.txt','whitespace-mix.txt'])
|
||||||
def test_read_strange(self,reference_dir,fname):
|
def test_read_strange(self,reference_dir,fname):
|
||||||
with open(os.path.join(reference_dir,fname)) as f:
|
with open(reference_dir/fname) as f:
|
||||||
Table.from_ASCII(f)
|
Table.from_ASCII(f)
|
||||||
|
|
||||||
def test_set(self,default):
|
def test_set(self,default):
|
||||||
|
|
Loading…
Reference in New Issue