Skip to content

Commit fc4d876

Browse files
integrate fast cve module in functions
1 parent a450dda commit fc4d876

File tree

3 files changed

+17
-56
lines changed

3 files changed

+17
-56
lines changed

src/diffpy/labpdfproc/fast_cve.py

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/diffpy/labpdfproc/functions.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
import math
2+
import os
23

34
import numpy as np
5+
import pandas as pd
6+
from scipy.interpolate import interp1d
47

5-
from diffpy.labpdfproc.fast_cve import fast_compute_cve
68
from diffpy.utils.scattering_objects.diffraction_objects import Diffraction_object
79

810
RADIUS_MM = 1
911
N_POINTS_ON_DIAMETER = 300
10-
TTH_GRID = np.arange(1, 141, 1)
12+
TTH_GRID = np.arange(1, 180.1, 0.1)
13+
14+
# pre-computed datasets for fast calculation
15+
MUD_LIST = [0.5, 1, 2, 3, 4, 5, 6]
16+
CWD = os.path.dirname(os.path.abspath(__file__))
17+
MULS = np.loadtxt(CWD + "/data/inverse_cve.xy")
18+
COEFFICIENT_LIST = np.array(pd.read_csv(CWD + "/data/coefficient_list.csv", header=None))
19+
INTERPOLATION_FUNCTIONS = [interp1d(MUD_LIST, coefficients, kind="quadratic") for coefficients in COEFFICIENT_LIST]
1120

1221

1322
class Gridded_circle:
@@ -199,7 +208,6 @@ def compute_cve(diffraction_data, mud, wavelength, brute_force=False):
199208
"""
200209

201210
if brute_force:
202-
tth_grid = TTH_GRID
203211
mu_sample_invmm = mud / 2
204212
abs_correction = Gridded_circle(mu=mu_sample_invmm)
205213
distances, muls = [], []
@@ -217,10 +225,14 @@ def compute_cve(diffraction_data, mud, wavelength, brute_force=False):
217225
"mu*D is out of the acceptable range (0.5 to 6) for fast calculation. "
218226
"Please rerun with a value within this range or use -b to enable brute-force calculation. "
219227
)
220-
tth_grid, cve = fast_compute_cve(mud)
228+
coeff_a, coeff_b, coeff_c, coeff_d, coeff_e = [
229+
interpolation_function(mud) for interpolation_function in INTERPOLATION_FUNCTIONS
230+
]
231+
muls = np.array(coeff_a * MULS**4 + coeff_b * MULS**3 + coeff_c * MULS**2 + coeff_d * MULS + coeff_e)
232+
cve = 1 / muls
221233

222234
orig_grid = diffraction_data.on_tth[0]
223-
newcve = np.interp(orig_grid, tth_grid, cve)
235+
newcve = np.interp(orig_grid, TTH_GRID, cve)
224236
abdo = Diffraction_object(wavelength=wavelength)
225237
abdo.insert_scattering_quantity(
226238
orig_grid,

src/diffpy/labpdfproc/tests/test_fast_cve.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)