2
2
3
3
import numpy as np
4
4
5
+ from diffpy .labpdfproc .fast_cve import fast_compute_cve
5
6
from diffpy .utils .scattering_objects .diffraction_objects import Diffraction_object
6
7
7
8
RADIUS_MM = 1
@@ -27,7 +28,7 @@ def _get_grid_points(self):
27
28
self .grid = {(x , y ) for x in xs for y in ys if x ** 2 + y ** 2 <= self .radius ** 2 }
28
29
self .total_points_in_grid = len (self .grid )
29
30
30
- # def get_coordinate_index(self, coordinate): # I think we probably dont need this function?
31
+ # def get_coordinate_index(self, coordinate):
31
32
# count = 0
32
33
# for i, target in enumerate(self.grid):
33
34
# if coordinate == target:
@@ -172,9 +173,9 @@ def get_path_length(self, grid_point, angle):
172
173
return total_distance , primary_distance , secondary_distance
173
174
174
175
175
- def compute_cve (diffraction_data , mud , wavelength ):
176
+ def compute_cve (diffraction_data , mud , wavelength , brute_force = False ):
176
177
"""
177
- compute the cve for given diffraction data, mud and wavelength
178
+ compute the cve for given diffraction data, mud and wavelength, and a boolean to determine the way to compute
178
179
179
180
Parameters
180
181
----------
@@ -185,31 +186,41 @@ def compute_cve(diffraction_data, mud, wavelength):
185
186
wavelength float
186
187
the wavelength of the diffraction object
187
188
188
- Returns
189
- -------
190
- the diffraction object with cve curves
191
-
192
- it is computed as follows:
189
+ the brute-force method is computed as follows:
193
190
We first resample data and absorption correction to a more reasonable grid,
194
191
then calculate corresponding cve for the given mud in the resample grid
195
192
(since the same mu*D yields the same cve, we can assume that D/2=1, so mu=mud/2),
196
193
and finally interpolate cve to the original grid in diffraction_data.
194
+
195
+ Returns
196
+ -------
197
+ the diffraction object with cve curves
198
+
197
199
"""
198
200
199
- mu_sample_invmm = mud / 2
200
- abs_correction = Gridded_circle (mu = mu_sample_invmm )
201
- distances , muls = [], []
202
- for angle in TTH_GRID :
203
- abs_correction .set_distances_at_angle (angle )
204
- abs_correction .set_muls_at_angle (angle )
205
- distances .append (sum (abs_correction .distances ))
206
- muls .append (sum (abs_correction .muls ))
207
- distances = np .array (distances ) / abs_correction .total_points_in_grid
208
- muls = np .array (muls ) / abs_correction .total_points_in_grid
209
- cve = 1 / muls
201
+ if brute_force :
202
+ tth_grid = TTH_GRID
203
+ mu_sample_invmm = mud / 2
204
+ abs_correction = Gridded_circle (mu = mu_sample_invmm )
205
+ distances , muls = [], []
206
+ for angle in TTH_GRID :
207
+ abs_correction .set_distances_at_angle (angle )
208
+ abs_correction .set_muls_at_angle (angle )
209
+ distances .append (sum (abs_correction .distances ))
210
+ muls .append (sum (abs_correction .muls ))
211
+ distances = np .array (distances ) / abs_correction .total_points_in_grid
212
+ muls = np .array (muls ) / abs_correction .total_points_in_grid
213
+ cve = 1 / muls
214
+ else :
215
+ if mud > 6 or mud < 0.5 :
216
+ raise ValueError (
217
+ "mu*D is out of the acceptable range (0.5 to 6) for fast calculation. "
218
+ "Please rerun with a value within this range or use -b to enable brute-force calculation. "
219
+ )
220
+ tth_grid , cve = fast_compute_cve (mud )
210
221
211
222
orig_grid = diffraction_data .on_tth [0 ]
212
- newcve = np .interp (orig_grid , TTH_GRID , cve )
223
+ newcve = np .interp (orig_grid , tth_grid , cve )
213
224
abdo = Diffraction_object (wavelength = wavelength )
214
225
abdo .insert_scattering_quantity (
215
226
orig_grid ,
0 commit comments