Skip to content

implement fast_cve module #86

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

Merged
merged 6 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add tests for compute_cve, change datasets paths to absolute paths
  • Loading branch information
yucongalicechen committed Jul 24, 2024
commit 10b0d5f2a8487b916f9f27f3a15c376072c10dae
7 changes: 5 additions & 2 deletions src/diffpy/labpdfproc/fast_cve.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

import numpy as np
import pandas as pd
from scipy.interpolate import interp1d
Expand All @@ -6,8 +8,9 @@

TTH_GRID = np.arange(1, 180.1, 0.1)
MUD_LIST = [0.5, 1, 2, 3, 4, 5, 6]
INVERSE_CVE_DATA = np.loadtxt("data/inverse_cve.xy")
COEFFICIENT_LIST = pd.read_csv("data/coefficient_list.csv", header=None)
CWD = os.path.dirname(os.path.abspath(__file__))
INVERSE_CVE_DATA = np.loadtxt(CWD + "/data/inverse_cve.xy")
COEFFICIENT_LIST = np.array(pd.read_csv(CWD + "/data/coefficient_list.csv", header=None))
INTERPOLATION_FUNCTIONS = [interp1d(MUD_LIST, coefficients, kind="quadratic") for coefficients in COEFFICIENT_LIST]


Expand Down
32 changes: 32 additions & 0 deletions src/diffpy/labpdfproc/tests/test_fast_cve.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import numpy as np

from diffpy.labpdfproc.fast_cve import fast_compute_cve
from diffpy.utils.scattering_objects.diffraction_objects import Diffraction_object


def _instantiate_test_do(xarray, yarray, name="test", scat_quantity="x-ray"):
test_do = Diffraction_object(wavelength=1.54)
test_do.insert_scattering_quantity(
xarray,
yarray,
"tth",
scat_quantity=scat_quantity,
name=name,
metadata={"thing1": 1, "thing2": "thing2"},
)
return test_do


def test_fast_compute_cve(mocker):
xarray, yarray = np.array([90, 90.1, 90.2]), np.array([2, 2, 2])
expected_cve = np.array([0.5, 0.5, 0.5])
mocker.patch("numpy.interp", return_value=expected_cve)
input_pattern = _instantiate_test_do(xarray, yarray)
actual_abdo = fast_compute_cve(input_pattern, mud=1, wavelength=1.54)
expected_abdo = _instantiate_test_do(
xarray,
expected_cve,
name="absorption correction, cve, for test",
scat_quantity="cve",
)
assert actual_abdo == expected_abdo