Skip to content

Commit e0d27e6

Browse files
add function for applying correction and its test
1 parent 10b0d5f commit e0d27e6

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/diffpy/labpdfproc/fast_cve.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,24 @@ def fast_compute_cve(diffraction_data, mud, wavelength):
5858
)
5959

6060
return abdo
61+
62+
63+
def apply_fast_corr(diffraction_pattern, absorption_correction):
64+
"""
65+
Apply absorption correction to the given diffraction object modo with the correction diffraction object abdo
66+
67+
Parameters
68+
----------
69+
diffraction_pattern Diffraction_object
70+
the input diffraction object to which the cve will be applied
71+
absorption_correction Diffraction_object
72+
the diffraction object that contains the cve to be applied
73+
74+
Returns
75+
-------
76+
a corrected diffraction object with the correction applied through multiplication
77+
78+
"""
79+
80+
corrected_pattern = diffraction_pattern * absorption_correction
81+
return corrected_pattern

src/diffpy/labpdfproc/tests/test_fast_cve.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import numpy as np
22

3-
from diffpy.labpdfproc.fast_cve import fast_compute_cve
3+
from diffpy.labpdfproc.fast_cve import apply_fast_corr, fast_compute_cve
44
from diffpy.utils.scattering_objects.diffraction_objects import Diffraction_object
55

66

@@ -30,3 +30,19 @@ def test_fast_compute_cve(mocker):
3030
scat_quantity="cve",
3131
)
3232
assert actual_abdo == expected_abdo
33+
34+
35+
def test_apply_fast_corr(mocker):
36+
xarray, yarray = np.array([90, 90.1, 90.2]), np.array([2, 2, 2])
37+
expected_cve = np.array([0.5, 0.5, 0.5])
38+
mocker.patch("numpy.interp", return_value=expected_cve)
39+
input_pattern = _instantiate_test_do(xarray, yarray)
40+
absorption_correction = _instantiate_test_do(
41+
xarray,
42+
expected_cve,
43+
name="absorption correction, cve, for test",
44+
scat_quantity="cve",
45+
)
46+
actual_corr = apply_fast_corr(input_pattern, absorption_correction)
47+
expected_corr = _instantiate_test_do(xarray, np.array([1, 1, 1]))
48+
assert actual_corr == expected_corr

0 commit comments

Comments
 (0)