Skip to content

Commit 10b0d5f

Browse files
add tests for compute_cve, change datasets paths to absolute paths
1 parent 6f5776a commit 10b0d5f

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

src/diffpy/labpdfproc/fast_cve.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
13
import numpy as np
24
import pandas as pd
35
from scipy.interpolate import interp1d
@@ -6,8 +8,9 @@
68

79
TTH_GRID = np.arange(1, 180.1, 0.1)
810
MUD_LIST = [0.5, 1, 2, 3, 4, 5, 6]
9-
INVERSE_CVE_DATA = np.loadtxt("data/inverse_cve.xy")
10-
COEFFICIENT_LIST = pd.read_csv("data/coefficient_list.csv", header=None)
11+
CWD = os.path.dirname(os.path.abspath(__file__))
12+
INVERSE_CVE_DATA = np.loadtxt(CWD + "/data/inverse_cve.xy")
13+
COEFFICIENT_LIST = np.array(pd.read_csv(CWD + "/data/coefficient_list.csv", header=None))
1114
INTERPOLATION_FUNCTIONS = [interp1d(MUD_LIST, coefficients, kind="quadratic") for coefficients in COEFFICIENT_LIST]
1215

1316

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import numpy as np
2+
3+
from diffpy.labpdfproc.fast_cve import fast_compute_cve
4+
from diffpy.utils.scattering_objects.diffraction_objects import Diffraction_object
5+
6+
7+
def _instantiate_test_do(xarray, yarray, name="test", scat_quantity="x-ray"):
8+
test_do = Diffraction_object(wavelength=1.54)
9+
test_do.insert_scattering_quantity(
10+
xarray,
11+
yarray,
12+
"tth",
13+
scat_quantity=scat_quantity,
14+
name=name,
15+
metadata={"thing1": 1, "thing2": "thing2"},
16+
)
17+
return test_do
18+
19+
20+
def test_fast_compute_cve(mocker):
21+
xarray, yarray = np.array([90, 90.1, 90.2]), np.array([2, 2, 2])
22+
expected_cve = np.array([0.5, 0.5, 0.5])
23+
mocker.patch("numpy.interp", return_value=expected_cve)
24+
input_pattern = _instantiate_test_do(xarray, yarray)
25+
actual_abdo = fast_compute_cve(input_pattern, mud=1, wavelength=1.54)
26+
expected_abdo = _instantiate_test_do(
27+
xarray,
28+
expected_cve,
29+
name="absorption correction, cve, for test",
30+
scat_quantity="cve",
31+
)
32+
assert actual_abdo == expected_abdo

0 commit comments

Comments
 (0)