Skip to content

tests for apply_corr #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion src/diffpy/labpdfproc/tests/test_functions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import pytest

from diffpy.labpdfproc.functions import Gridded_circle, compute_cve
from diffpy.labpdfproc.functions import Gridded_circle, apply_corr, compute_cve
from diffpy.utils.scattering_objects.diffraction_objects import Diffraction_object

params1 = [
Expand Down Expand Up @@ -80,3 +80,39 @@ def test_compute_cve(mocker):
scat_quantity="cve",
)
assert actual_abdo == expected_abdo


def test_apply_corr(mocker):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test is probably correct but hard to follow.

  1. there is a lot of duplicated code instantiating the DO's so maybe make a helper function called something like _instantiate_test_do(yarray) and just call that with only the y-array as input
  2. maybe make the inputs easier to understand, so input y-array is [2., 2., 2.] and correction is [0.5, 0.5, 0.5] and so expected is a do with yarray [1., 1., 1.].

Would these make it easier to read?

If you make that wrapper function, on a separate PR we can maybe clean up some of the other tests as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, I'll do that

mocker.patch("diffpy.labpdfproc.functions.N_POINTS_ON_DIAMETER", 4)
mocker.patch("diffpy.labpdfproc.functions.TTH_GRID", np.array([45, 60, 90]))
input_pattern = Diffraction_object(wavelength=1.54)
input_pattern.insert_scattering_quantity(
np.array([45, 60, 90]),
np.array([2.2, 3, 4]),
"tth",
scat_quantity="x-ray",
name="test",
metadata={"thing1": 1, "thing2": "thing2"},
)
absorption_correction = Diffraction_object()
absorption_correction.insert_scattering_quantity(
np.array([45, 60, 90]),
np.array([2.54253, 2.52852, 2.49717]),
"tth",
metadata={"thing1": 1, "thing2": "thing2"},
name="absorption correction, cve, for test",
wavelength=1.54,
scat_quantity="cve",
)
actual_corr = apply_corr(input_pattern, absorption_correction)
expected_corr = Diffraction_object()
expected_corr.insert_scattering_quantity(
np.array([45, 60, 90]),
np.array([5.59357, 7.58556, 9.98868]),
"tth",
metadata={"thing1": 1, "thing2": "thing2"},
name="test",
wavelength=1.54,
scat_quantity="x-ray",
)
assert actual_corr == expected_corr
Loading