Repository navigation
Expand file tree
/
Copy pathtest_morphchain.py
More file actions
55 lines (43 loc) · 1.54 KB
/
Copy pathtest_morphchain.py
File metadata and controls
55 lines (43 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
import os
import numpy
import pytest
from diffpy.morph.morphs.morphchain import MorphChain
from diffpy.morph.morphs.morphrgrid import MorphRGrid
from diffpy.morph.morphs.morphscale import MorphScale
# useful variables
thisfile = locals().get("__file__", "file.py")
tests_dir = os.path.dirname(os.path.abspath(thisfile))
# testdata_dir = os.path.join(tests_dir, 'testdata')
class TestMorphChain:
@pytest.fixture
def setup(self):
self.x_morph = numpy.arange(0.01, 5, 0.01)
self.y_morph = numpy.ones_like(self.x_morph)
self.x_target = numpy.arange(0.01, 5, 0.01)
self.y_target = 3 * numpy.ones_like(self.x_target)
return
def test_morph(self, setup):
"""Check MorphChain.morph()"""
# Define the morphs
config = {
"xmin": 1,
"xmax": 6,
"xstep": 0.1,
"scale": 3.0,
}
mgrid = MorphRGrid()
mscale = MorphScale()
chain = MorphChain(config, mgrid, mscale)
x_morph, y_morph, x_target, y_target = chain(
self.x_morph, self.y_morph, self.x_target, self.y_target
)
assert (x_morph == x_target).all()
pytest.approx(x_morph[0], 1.0)
pytest.approx(x_morph[-1], 4.9)
pytest.approx(x_morph[1] - x_morph[0], 0.1)
pytest.approx(x_morph[0], mgrid.xmin)
pytest.approx(x_morph[-1], mgrid.xmax - mgrid.xstep)
pytest.approx(x_morph[1] - x_morph[0], mgrid.xstep)
assert numpy.allclose(y_morph, y_target)
return