Skip to content

Commit 3c6b128

Browse files
updated compute_cve to use DOs consistently
1 parent bb28204 commit 3c6b128

File tree

3 files changed

+35
-13
lines changed

3 files changed

+35
-13
lines changed

src/diffpy/labpdfproc/functions.py

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def get_path_length(self, grid_point, angle):
173173
return total_distance, primary_distance, secondary_distance
174174

175175

176-
def _cve_brute_force(mud):
176+
def _cve_brute_force(diffraction_data, mud):
177177
"""
178178
compute cve for the given mud on a global grid using the brute-force method
179179
assume mu=mud/2, given that the same mu*D yields the same cve and D/2=1
@@ -190,10 +190,21 @@ def _cve_brute_force(mud):
190190
distances = np.array(distances) / abs_correction.total_points_in_grid
191191
muls = np.array(muls) / abs_correction.total_points_in_grid
192192
cve = 1 / muls
193-
return cve
193+
194+
abdo = Diffraction_object(wavelength=diffraction_data.wavelength)
195+
abdo.insert_scattering_quantity(
196+
TTH_GRID,
197+
cve,
198+
"tth",
199+
metadata=diffraction_data.metadata,
200+
name=f"absorption correction, cve, for {diffraction_data.name}",
201+
wavelength=diffraction_data.wavelength,
202+
scat_quantity="cve",
203+
)
204+
return abdo
194205

195206

196-
def _cve_polynomial_interpolation(mud):
207+
def _cve_polynomial_interpolation(diffraction_data, mud):
197208
"""
198209
compute cve using polynomial interpolation method, raise an error if mu*D is out of the range (0.5 to 6)
199210
"""
@@ -208,7 +219,18 @@ def _cve_polynomial_interpolation(mud):
208219
]
209220
muls = np.array(coeff_a * MULS**4 + coeff_b * MULS**3 + coeff_c * MULS**2 + coeff_d * MULS + coeff_e)
210221
cve = 1 / muls
211-
return cve
222+
223+
abdo = Diffraction_object(wavelength=diffraction_data.wavelength)
224+
abdo.insert_scattering_quantity(
225+
TTH_GRID,
226+
cve,
227+
"tth",
228+
metadata=diffraction_data.metadata,
229+
name=f"absorption correction, cve, for {diffraction_data.name}",
230+
wavelength=diffraction_data.wavelength,
231+
scat_quantity="cve",
232+
)
233+
return abdo
212234

213235

214236
def _cve_method(method):
@@ -224,18 +246,16 @@ def _cve_method(method):
224246
return methods[method]
225247

226248

227-
def compute_cve(diffraction_data, mud, wavelength, method="polynomial_interpolation"):
249+
def compute_cve(diffraction_data, mud, method="polynomial_interpolation"):
228250
"""
229-
compute and interpolate the cve for the given diffraction data, mud, and wavelength, using the selected method
251+
compute and interpolate the cve for the given diffraction data and mud using the selected method
230252
231253
Parameters
232254
----------
233255
diffraction_data Diffraction_object
234256
the diffraction pattern
235257
mud float
236258
the mu*D of the diffraction object, where D is the diameter of the circle
237-
wavelength float
238-
the wavelength of the diffraction object
239259
method str
240260
the method used to calculate cve
241261
@@ -246,10 +266,12 @@ def compute_cve(diffraction_data, mud, wavelength, method="polynomial_interpolat
246266
"""
247267

248268
cve_function = _cve_method(method)
249-
cve = cve_function(mud)
269+
abdo_on_global_tth = cve_function(diffraction_data, mud)
270+
global_tth = abdo_on_global_tth.on_tth[0]
271+
cve_on_global_tth = abdo_on_global_tth.on_tth[1]
250272
orig_grid = diffraction_data.on_tth[0]
251-
newcve = np.interp(orig_grid, TTH_GRID, cve)
252-
abdo = Diffraction_object(wavelength=wavelength)
273+
newcve = np.interp(orig_grid, global_tth, cve_on_global_tth)
274+
abdo = Diffraction_object(wavelength=diffraction_data.wavelength)
253275
abdo.insert_scattering_quantity(
254276
orig_grid,
255277
newcve,

src/diffpy/labpdfproc/labpdfprocapp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def main():
140140
metadata=load_metadata(args, filepath),
141141
)
142142

143-
absorption_correction = compute_cve(input_pattern, args.mud, args.wavelength, args.method)
143+
absorption_correction = compute_cve(input_pattern, args.mud, args.method)
144144
corrected_data = apply_corr(input_pattern, absorption_correction)
145145
corrected_data.name = f"Absorption corrected input_data: {input_pattern.name}"
146146
corrected_data.dump(f"{outfile}", xtype="tth")

src/diffpy/labpdfproc/tests/test_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def test_compute_cve(mocker):
7575
mocker.patch("diffpy.labpdfproc.functions.TTH_GRID", xarray)
7676
mocker.patch("numpy.interp", return_value=expected_cve)
7777
input_pattern = _instantiate_test_do(xarray, yarray)
78-
actual_abdo = compute_cve(input_pattern, mud=1, wavelength=1.54)
78+
actual_abdo = compute_cve(input_pattern, mud=1)
7979
expected_abdo = _instantiate_test_do(
8080
xarray,
8181
expected_cve,

0 commit comments

Comments
 (0)