Skip to content

Commit 6f5776a

Browse files
add function for fast computation
1 parent 9b7d92d commit 6f5776a

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

src/diffpy/labpdfproc/fast_cve.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,56 @@
22
import pandas as pd
33
from scipy.interpolate import interp1d
44

5+
from diffpy.utils.scattering_objects.diffraction_objects import Diffraction_object
6+
57
TTH_GRID = np.arange(1, 180.1, 0.1)
68
MUD_LIST = [0.5, 1, 2, 3, 4, 5, 6]
79
INVERSE_CVE_DATA = np.loadtxt("data/inverse_cve.xy")
810
COEFFICIENT_LIST = pd.read_csv("data/coefficient_list.csv", header=None)
911
INTERPOLATION_FUNCTIONS = [interp1d(MUD_LIST, coefficients, kind="quadratic") for coefficients in COEFFICIENT_LIST]
12+
13+
14+
def fast_compute_cve(diffraction_data, mud, wavelength):
15+
"""
16+
use precomputed datasets to compute the cve for given diffraction data, mud and wavelength
17+
18+
Parameters
19+
----------
20+
diffraction_data Diffraction_object
21+
the diffraction pattern
22+
mud float
23+
the mu*D of the diffraction object, where D is the diameter of the circle
24+
wavelength float
25+
the wavelength of the diffraction object
26+
27+
Returns
28+
-------
29+
the diffraction object with cve curves
30+
"""
31+
32+
coefficient_a, coefficient_b, coefficient_c, coefficient_d, coefficient_e = [
33+
interpolation_function(mud) for interpolation_function in INTERPOLATION_FUNCTIONS
34+
]
35+
inverse_cve = (
36+
coefficient_a * INVERSE_CVE_DATA**4
37+
+ coefficient_b * INVERSE_CVE_DATA**3
38+
+ coefficient_c * INVERSE_CVE_DATA**2
39+
+ coefficient_d * INVERSE_CVE_DATA**1
40+
+ coefficient_e
41+
)
42+
cve = 1 / np.array(inverse_cve)
43+
44+
orig_grid = diffraction_data.on_tth[0]
45+
newcve = np.interp(orig_grid, TTH_GRID, cve)
46+
abdo = Diffraction_object(wavelength=wavelength)
47+
abdo.insert_scattering_quantity(
48+
orig_grid,
49+
newcve,
50+
"tth",
51+
metadata=diffraction_data.metadata,
52+
name=f"absorption correction, cve, for {diffraction_data.name}",
53+
wavelength=diffraction_data.wavelength,
54+
scat_quantity="cve",
55+
)
56+
57+
return abdo

0 commit comments

Comments
 (0)