forked from diffpy/diffpy.morph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_morphrdftopdf.py
More file actions
39 lines (29 loc) · 1.19 KB
/
test_morphrdftopdf.py
File metadata and controls
39 lines (29 loc) · 1.19 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
#!/usr/bin/env python
import os
import numpy
import pytest
from diffpy.morph.morph_helpers.transformrdftopdf import TransformXtalRDFtoPDF
# 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 TestTransformXtalRDFtoPDF:
@pytest.fixture
def setup(self):
self.x_morph = numpy.arange(0.01, 5, 0.01)
self.y_morph = numpy.exp(-0.5 * (self.x_morph - 1.0) ** 2)
self.x_target = numpy.arange(0.01, 5, 0.01)
self.y_target = numpy.exp(-0.5 * (self.x_morph - 2.0) ** 2)
return
def test_transform(self, setup):
"""Check TransformXtalRDFtoPDF.morph()"""
config = {"baselineslope": -1.0}
transform = TransformXtalRDFtoPDF(config)
x_morph, y_morph, x_target, y_target = transform(
self.x_morph, self.y_morph, self.x_target, self.y_target
)
rdf1 = numpy.exp(-0.5 * (x_morph - 1.0) ** 2) / x_morph - x_morph
rdf2 = numpy.exp(-0.5 * (x_target - 2.0) ** 2) / x_target - x_target
assert numpy.allclose(rdf1, y_morph)
assert numpy.allclose(rdf2, y_target)
return