|
1 | 1 | import numpy as np
|
2 | 2 | import pytest
|
3 | 3 |
|
4 |
| -from diffpy.labpdfproc.functions import Gridded_circle, compute_cve |
| 4 | +from diffpy.labpdfproc.functions import Gridded_circle, apply_corr, compute_cve |
5 | 5 | from diffpy.utils.scattering_objects.diffraction_objects import Diffraction_object
|
6 | 6 |
|
7 | 7 | params1 = [
|
@@ -56,27 +56,47 @@ def test_set_muls_at_angle(inputs, expected):
|
56 | 56 | assert actual_muls_sorted == pytest.approx(expected_muls_sorted, rel=1e-4, abs=1e-6)
|
57 | 57 |
|
58 | 58 |
|
59 |
| -def test_compute_cve(mocker): |
60 |
| - mocker.patch("diffpy.labpdfproc.functions.N_POINTS_ON_DIAMETER", 4) |
61 |
| - mocker.patch("diffpy.labpdfproc.functions.TTH_GRID", np.array([45, 60, 90])) |
62 |
| - input_pattern = Diffraction_object(wavelength=1.54) |
63 |
| - input_pattern.insert_scattering_quantity( |
64 |
| - np.array([45, 60, 90]), |
65 |
| - np.array([2.2, 3, 4]), |
| 59 | +def _instantiate_test_do(xarray, yarray, name="test", scat_quantity="x-ray"): |
| 60 | + test_do = Diffraction_object(wavelength=1.54) |
| 61 | + test_do.insert_scattering_quantity( |
| 62 | + xarray, |
| 63 | + yarray, |
66 | 64 | "tth",
|
67 |
| - scat_quantity="x-ray", |
68 |
| - name="test", |
| 65 | + scat_quantity=scat_quantity, |
| 66 | + name=name, |
69 | 67 | metadata={"thing1": 1, "thing2": "thing2"},
|
70 | 68 | )
|
| 69 | + return test_do |
| 70 | + |
| 71 | + |
| 72 | +def test_compute_cve(mocker): |
| 73 | + xarray, yarray = np.array([90, 90.1, 90.2]), np.array([2, 2, 2]) |
| 74 | + expected_cve = np.array([0.5, 0.5, 0.5]) |
| 75 | + mocker.patch("diffpy.labpdfproc.functions.TTH_GRID", xarray) |
| 76 | + mocker.patch("numpy.interp", return_value=expected_cve) |
| 77 | + input_pattern = _instantiate_test_do(xarray, yarray) |
71 | 78 | actual_abdo = compute_cve(input_pattern, mud=1, wavelength=1.54)
|
72 |
| - expected_abdo = Diffraction_object() |
73 |
| - expected_abdo.insert_scattering_quantity( |
74 |
| - np.array([45, 60, 90]), |
75 |
| - np.array([2.54253, 2.52852, 2.49717]), |
76 |
| - "tth", |
77 |
| - metadata={"thing1": 1, "thing2": "thing2"}, |
| 79 | + expected_abdo = _instantiate_test_do( |
| 80 | + xarray, |
| 81 | + expected_cve, |
78 | 82 | name="absorption correction, cve, for test",
|
79 |
| - wavelength=1.54, |
80 | 83 | scat_quantity="cve",
|
81 | 84 | )
|
82 | 85 | assert actual_abdo == expected_abdo
|
| 86 | + |
| 87 | + |
| 88 | +def test_apply_corr(mocker): |
| 89 | + xarray, yarray = np.array([90, 90.1, 90.2]), np.array([2, 2, 2]) |
| 90 | + expected_cve = np.array([0.5, 0.5, 0.5]) |
| 91 | + mocker.patch("diffpy.labpdfproc.functions.TTH_GRID", xarray) |
| 92 | + mocker.patch("numpy.interp", return_value=expected_cve) |
| 93 | + input_pattern = _instantiate_test_do(xarray, yarray) |
| 94 | + absorption_correction = _instantiate_test_do( |
| 95 | + xarray, |
| 96 | + expected_cve, |
| 97 | + name="absorption correction, cve, for test", |
| 98 | + scat_quantity="cve", |
| 99 | + ) |
| 100 | + actual_corr = apply_corr(input_pattern, absorption_correction) |
| 101 | + expected_corr = _instantiate_test_do(xarray, np.array([1, 1, 1])) |
| 102 | + assert actual_corr == expected_corr |
0 commit comments