3
3
import numpy as np
4
4
import pytest
5
5
6
- from diffpy .labpdfproc .functions import CVE_METHODS , Gridded_circle , apply_corr , compute_cve
7
- from diffpy .utils .scattering_objects .diffraction_objects import Diffraction_object
6
+ from diffpy .labpdfproc .functions import (
7
+ CVE_METHODS ,
8
+ Gridded_circle ,
9
+ apply_corr ,
10
+ compute_cve ,
11
+ interpolate_to_xtype_grid ,
12
+ )
13
+ from diffpy .utils .scattering_objects .diffraction_objects import XQUANTITIES , Diffraction_object
8
14
9
15
params1 = [
10
16
([0.5 , 3 , 1 ], {(0.0 , - 0.5 ), (0.0 , 0.0 ), (0.5 , 0.0 ), (- 0.5 , 0.0 ), (0.0 , 0.5 )}),
@@ -58,19 +64,62 @@ def test_set_muls_at_angle(inputs, expected):
58
64
assert actual_muls_sorted == pytest .approx (expected_muls_sorted , rel = 1e-4 , abs = 1e-6 )
59
65
60
66
61
- def _instantiate_test_do (xarray , yarray , name = "test" , scat_quantity = "x-ray" ):
67
+ def _instantiate_test_do (xarray , yarray , xtype = "tth" , name = "test" , scat_quantity = "x-ray" ):
62
68
test_do = Diffraction_object (wavelength = 1.54 )
63
69
test_do .insert_scattering_quantity (
64
70
xarray ,
65
71
yarray ,
66
- "tth" ,
72
+ xtype ,
67
73
scat_quantity = scat_quantity ,
68
74
name = name ,
69
75
metadata = {"thing1" : 1 , "thing2" : "thing2" },
70
76
)
71
77
return test_do
72
78
73
79
80
+ params4 = [
81
+ ([np .array ([30 , 60 , 90 ]), np .array ([1 , 2 , 3 ]), "tth" ], [np .array ([30 , 60 , 90 ]), np .array ([1 , 2 , 3 ]), "tth" ]),
82
+ (
83
+ [np .array ([30 , 60 , 90 ]), np .array ([1 , 2 , 3 ]), "q" ],
84
+ [np .array ([2.11195 , 4.07999 , 5.76998 ]), np .array ([1 , 1 , 1 ]), "q" ],
85
+ ),
86
+ ]
87
+
88
+
89
+ @pytest .mark .parametrize ("inputs, expected" , params4 )
90
+ def test_interpolate_xtype (inputs , expected , mocker ):
91
+ expected_cve_do = _instantiate_test_do (
92
+ expected [0 ],
93
+ expected [1 ],
94
+ xtype = expected [2 ],
95
+ name = "absorption correction, cve, for test" ,
96
+ scat_quantity = "cve" ,
97
+ )
98
+ input_cve_do = _instantiate_test_do (
99
+ inputs [0 ],
100
+ inputs [1 ],
101
+ xtype = "tth" ,
102
+ name = "absorption correction, cve, for test" ,
103
+ scat_quantity = "cve" ,
104
+ )
105
+ actual_cve_do = interpolate_to_xtype_grid (input_cve_do , xtype = inputs [2 ])
106
+ assert actual_cve_do == expected_cve_do
107
+
108
+
109
+ def test_interpolate_xtype_bad ():
110
+ input_cve_do = _instantiate_test_do (
111
+ np .array ([30 , 60 , 90 ]),
112
+ np .array ([1 , 2 , 3 ]),
113
+ xtype = "tth" ,
114
+ name = "absorption correction, cve, for test" ,
115
+ scat_quantity = "cve" ,
116
+ )
117
+ with pytest .raises (
118
+ ValueError , match = re .escape (f"Unknown xtype: invalid. Allowed xtypes are { * XQUANTITIES , } ." )
119
+ ):
120
+ interpolate_to_xtype_grid (input_cve_do , xtype = "invalid" )
121
+
122
+
74
123
def test_compute_cve (mocker ):
75
124
xarray , yarray = np .array ([90 , 90.1 , 90.2 ]), np .array ([2 , 2 , 2 ])
76
125
expected_cve = np .array ([0.5 , 0.5 , 0.5 ])
@@ -92,7 +141,7 @@ def test_compute_cve(mocker):
92
141
[7 , "polynomial_interpolation" ],
93
142
[
94
143
f"mu*D is out of the acceptable range (0.5 to 6) for polynomial interpolation. "
95
- f"Please rerun with a value within this range or specifying another method from { * CVE_METHODS , } ."
144
+ f"Please rerun with a value within this range or specifying another method from { * CVE_METHODS , } ."
96
145
],
97
146
),
98
147
([1 , "invalid_method" ], [f"Unknown method: invalid_method. Allowed methods are { * CVE_METHODS , } ." ]),
0 commit comments