Skip to content

add fast_cve to labpdfprocapp.py and some other fixes #87

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 15 commits into from
Closed
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
change compute cve function to call cve methods and interpolate tth
  • Loading branch information
yucongalicechen committed Aug 28, 2024
commit bb28204a10d2a778e2001a66f713c9317cf18417
13 changes: 8 additions & 5 deletions src/diffpy/labpdfproc/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,18 +211,20 @@ def _cve_polynomial_interpolation(mud):
return cve


def _compute_cve(method, mud):
def _cve_method(method):
"""
compute cve for the given mud on a global grid using the specified method
retrieve the cve computation function for the given method
"""
methods = {
"brute_force": _cve_brute_force,
"polynomial_interpolation": _cve_polynomial_interpolation,
}
return methods[method](mud)
if method not in CVE_METHODS:
raise ValueError(f"Unknown method: {method}. Allowed methods are {*CVE_METHODS, }.")
return methods[method]


def interpolate_cve(diffraction_data, mud, wavelength, method="polynomial_interpolation"):
def compute_cve(diffraction_data, mud, wavelength, method="polynomial_interpolation"):
"""
compute and interpolate the cve for the given diffraction data, mud, and wavelength, using the selected method

Expand All @@ -243,7 +245,8 @@ def interpolate_cve(diffraction_data, mud, wavelength, method="polynomial_interp

"""

cve = _compute_cve(method, mud)
cve_function = _cve_method(method)
cve = cve_function(mud)
orig_grid = diffraction_data.on_tth[0]
newcve = np.interp(orig_grid, TTH_GRID, cve)
abdo = Diffraction_object(wavelength=wavelength)
Expand Down
4 changes: 2 additions & 2 deletions src/diffpy/labpdfproc/labpdfprocapp.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
from argparse import ArgumentParser

from diffpy.labpdfproc.functions import CVE_METHODS, apply_corr, interpolate_cve
from diffpy.labpdfproc.functions import CVE_METHODS, apply_corr, compute_cve
from diffpy.labpdfproc.tools import known_sources, load_metadata, preprocessing_args
from diffpy.utils.parsers.loaddata import loadData
from diffpy.utils.scattering_objects.diffraction_objects import XQUANTITIES, Diffraction_object
Expand Down Expand Up @@ -140,7 +140,7 @@ def main():
metadata=load_metadata(args, filepath),
)

absorption_correction = interpolate_cve(input_pattern, args.mud, args.wavelength, args.method)
absorption_correction = compute_cve(input_pattern, args.mud, args.wavelength, args.method)
corrected_data = apply_corr(input_pattern, absorption_correction)
corrected_data.name = f"Absorption corrected input_data: {input_pattern.name}"
corrected_data.dump(f"{outfile}", xtype="tth")
Expand Down
6 changes: 3 additions & 3 deletions 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, apply_corr, interpolate_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 @@ -69,13 +69,13 @@ def _instantiate_test_do(xarray, yarray, name="test", scat_quantity="x-ray"):
return test_do


def test_interpolate_cve(mocker):
def test_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("diffpy.labpdfproc.functions.TTH_GRID", xarray)
mocker.patch("numpy.interp", return_value=expected_cve)
input_pattern = _instantiate_test_do(xarray, yarray)
actual_abdo = interpolate_cve(input_pattern, mud=1, wavelength=1.54)
actual_abdo = compute_cve(input_pattern, mud=1, wavelength=1.54)
expected_abdo = _instantiate_test_do(
xarray,
expected_cve,
Expand Down