10
10
RADIUS_MM = 1
11
11
N_POINTS_ON_DIAMETER = 300
12
12
TTH_GRID = np .arange (1 , 180.1 , 0.1 )
13
+ CVE_METHODS = ["brute_force" , "polynomial_interpolation" ]
13
14
14
15
# pre-computed datasets for fast calculation
15
16
MUD_LIST = [0.5 , 1 , 2 , 3 , 4 , 5 , 6 ]
@@ -172,15 +173,10 @@ def get_path_length(self, grid_point, angle):
172
173
return total_distance , primary_distance , secondary_distance
173
174
174
175
175
- def _cve_brute_force (diffraction_data , mud , wavelength ):
176
+ def _cve_brute_force (mud ):
176
177
"""
177
- compute cve using brute-force method
178
-
179
- it is computed as follows:
180
- We first resample data and absorption correction to a more reasonable grid,
181
- then calculate corresponding cve for the given mud in the resample grid
182
- (since the same mu*D yields the same cve, we can assume that D/2=1, so mu=mud/2),
183
- and finally interpolate cve to the original grid in diffraction_data.
178
+ compute cve for the given mud on a global grid using the brute-force method
179
+ assume mu=mud/2, given that the same mu*D yields the same cve and D/2=1
184
180
"""
185
181
186
182
mu_sample_invmm = mud / 2
@@ -197,15 +193,15 @@ def _cve_brute_force(diffraction_data, mud, wavelength):
197
193
return cve
198
194
199
195
200
- def _cve_interp_polynomial ( diffraction_data , mud , wavelength ):
196
+ def _cve_polynomial_interpolation ( mud ):
201
197
"""
202
198
compute cve using polynomial interpolation method, raise an error if mu*D is out of the range (0.5 to 6)
203
199
"""
204
200
205
201
if mud > 6 or mud < 0.5 :
206
202
raise ValueError (
207
- "mu*D is out of the acceptable range (0.5 to 6) for fast calculation . "
208
- "Please rerun with a value within this range or use -b to enable brute-force calculation. "
203
+ f "mu*D is out of the acceptable range (0.5 to 6) for polynomial interpolation . "
204
+ f "Please rerun with a value within this range or specifying another method from { * CVE_METHODS , } . "
209
205
)
210
206
coeff_a , coeff_b , coeff_c , coeff_d , coeff_e = [
211
207
interpolation_function (mud ) for interpolation_function in INTERPOLATION_FUNCTIONS
@@ -215,19 +211,20 @@ def _cve_interp_polynomial(diffraction_data, mud, wavelength):
215
211
return cve
216
212
217
213
218
- def _cve_method ( diffraction_data , mud , wavelength , brute_force = False ):
214
+ def _compute_cve ( method , mud ):
219
215
"""
220
- selects the appropriate CVE calculation method
216
+ compute cve for the given mud on a global grid using the specified method
221
217
"""
222
- if brute_force :
223
- return _cve_brute_force (diffraction_data , mud , wavelength )
224
- else :
225
- return _cve_interp_polynomial (diffraction_data , mud , wavelength )
218
+ methods = {
219
+ "brute_force" : _cve_brute_force ,
220
+ "polynomial_interpolation" : _cve_polynomial_interpolation ,
221
+ }
222
+ return methods [method ](mud )
226
223
227
224
228
- def compute_cve (diffraction_data , mud , wavelength , brute_force = False ):
225
+ def interpolate_cve (diffraction_data , mud , wavelength , method = "polynomial_interpolation" ):
229
226
"""
230
- compute the cve for given diffraction data, mud, and wavelength, using the selected method
227
+ compute and interpolate the cve for the given diffraction data, mud, and wavelength, using the selected method
231
228
232
229
Parameters
233
230
----------
@@ -237,14 +234,16 @@ def compute_cve(diffraction_data, mud, wavelength, brute_force=False):
237
234
the mu*D of the diffraction object, where D is the diameter of the circle
238
235
wavelength float
239
236
the wavelength of the diffraction object
237
+ method str
238
+ the method used to calculate cve
240
239
241
240
Returns
242
241
-------
243
242
the diffraction object with cve curves
244
243
245
244
"""
246
245
247
- cve = _cve_method ( diffraction_data , mud , wavelength , brute_force )
246
+ cve = _compute_cve ( method , mud )
248
247
orig_grid = diffraction_data .on_tth [0 ]
249
248
newcve = np .interp (orig_grid , TTH_GRID , cve )
250
249
abdo = Diffraction_object (wavelength = wavelength )
0 commit comments