1
1
import math
2
+ import os
2
3
3
4
import numpy as np
5
+ import pandas as pd
6
+ from scipy .interpolate import interp1d
4
7
5
- from diffpy .labpdfproc .fast_cve import fast_compute_cve
6
8
from diffpy .utils .scattering_objects .diffraction_objects import Diffraction_object
7
9
8
10
RADIUS_MM = 1
9
11
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 ]
11
20
12
21
13
22
class Gridded_circle :
@@ -199,7 +208,6 @@ def compute_cve(diffraction_data, mud, wavelength, brute_force=False):
199
208
"""
200
209
201
210
if brute_force :
202
- tth_grid = TTH_GRID
203
211
mu_sample_invmm = mud / 2
204
212
abs_correction = Gridded_circle (mu = mu_sample_invmm )
205
213
distances , muls = [], []
@@ -217,10 +225,14 @@ def compute_cve(diffraction_data, mud, wavelength, brute_force=False):
217
225
"mu*D is out of the acceptable range (0.5 to 6) for fast calculation. "
218
226
"Please rerun with a value within this range or use -b to enable brute-force calculation. "
219
227
)
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
221
233
222
234
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 )
224
236
abdo = Diffraction_object (wavelength = wavelength )
225
237
abdo .insert_scattering_quantity (
226
238
orig_grid ,
0 commit comments