From 329a895fb82185a27fff7b842ed891700fa4e705 Mon Sep 17 00:00:00 2001 From: yucongalicechen Date: Thu, 25 Jul 2024 12:07:17 -0400 Subject: [PATCH 01/15] add back labpdfproc command --- pyproject.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 90c9dca..68eef87 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,6 +42,9 @@ template = "{tag}" dev_template = "{tag}" dirty_template = "{tag}" +[project.scripts] +labpdfproc = "diffpy.labpdfproc.labpdfprocapp:main" + [tool.setuptools.packages.find] where = ["src"] # list of folders that contain the packages (["."] by default) include = ["*"] # package names should match these glob patterns (["*"] by default) From 6954a2996010f30ea9444257c3bb438c5c5ac1de Mon Sep 17 00:00:00 2001 From: yucongalicechen Date: Thu, 25 Jul 2024 12:31:35 -0400 Subject: [PATCH 02/15] change default to fast cve, add brute-force option, handle muD out-of-range error --- src/diffpy/labpdfproc/labpdfprocapp.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/diffpy/labpdfproc/labpdfprocapp.py b/src/diffpy/labpdfproc/labpdfprocapp.py index aedbd0a..9ebbbd7 100644 --- a/src/diffpy/labpdfproc/labpdfprocapp.py +++ b/src/diffpy/labpdfproc/labpdfprocapp.py @@ -1,6 +1,7 @@ import sys from argparse import ArgumentParser +from diffpy.labpdfproc.fast_cve import apply_fast_corr, fast_compute_cve from diffpy.labpdfproc.functions import apply_corr, compute_cve from diffpy.labpdfproc.tools import known_sources, load_metadata, preprocessing_args from diffpy.utils.parsers.loaddata import loadData @@ -72,6 +73,13 @@ def get_args(override_cli_inputs=None): action="store_true", help="Outputs will not overwrite existing file unless --force is specified.", ) + p.add_argument( + "-b", + "--brute-force", + action="store_true", + help="The absorption correction will be computed using brute-force calculation " + "if this flag is set. Default is using fast calculation. ", + ) p.add_argument( "-u", "--user-metadata", @@ -134,11 +142,20 @@ def main(): metadata=load_metadata(args, filepath), ) - absorption_correction = compute_cve(input_pattern, args.mud, args.wavelength) - corrected_data = apply_corr(input_pattern, absorption_correction) + if args.brute_force: + absorption_correction = compute_cve(input_pattern, args.mud, args.wavelength) + corrected_data = apply_corr(input_pattern, absorption_correction) + else: + if args.mud > 6 or args.mud < 0.5: + sys.exit( + "mu*D is out of the acceptable range (0.5 to 6) for fast calculation. " + "Please rerun with a value within this range or use -b enable brute-force calculation. " + ) + absorption_correction = fast_compute_cve(input_pattern, args.mud, args.wavelength) + corrected_data = apply_fast_corr(input_pattern, absorption_correction) + corrected_data.name = f"Absorption corrected input_data: {input_pattern.name}" corrected_data.dump(f"{outfile}", xtype="tth") - if args.output_correction: absorption_correction.dump(f"{corrfile}", xtype="tth") From 97bcc00f4b82e8da024a9d014851a9a9c58f3aff Mon Sep 17 00:00:00 2001 From: yucongalicechen Date: Thu, 25 Jul 2024 12:35:20 -0400 Subject: [PATCH 03/15] minor correction on output correction command --- src/diffpy/labpdfproc/labpdfprocapp.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/diffpy/labpdfproc/labpdfprocapp.py b/src/diffpy/labpdfproc/labpdfprocapp.py index 9ebbbd7..c2fe16f 100644 --- a/src/diffpy/labpdfproc/labpdfprocapp.py +++ b/src/diffpy/labpdfproc/labpdfprocapp.py @@ -65,7 +65,6 @@ def get_args(override_cli_inputs=None): action="store_true", help="The absorption correction will be output to a file if this " "flag is set. Default is that it is not output.", - default="tth", ) p.add_argument( "-f", From 2487ae63f385a99b4c1d2daf6b8b36909e6020a0 Mon Sep 17 00:00:00 2001 From: yucongalicechen Date: Thu, 25 Jul 2024 12:47:40 -0400 Subject: [PATCH 04/15] add brute force argument to metadata test --- src/diffpy/labpdfproc/tests/test_tools.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/diffpy/labpdfproc/tests/test_tools.py b/src/diffpy/labpdfproc/tests/test_tools.py index 3b4847f..fda91fb 100644 --- a/src/diffpy/labpdfproc/tests/test_tools.py +++ b/src/diffpy/labpdfproc/tests/test_tools.py @@ -312,6 +312,7 @@ def test_load_metadata(mocker, user_filesystem): "wavelength": 0.71, "output_directory": str(Path.cwd().resolve()), "xtype": "tth", + "brute_force": False, "key": "value", "username": "cli_username", "email": "cli@email.com", From 7d0d57440221fc19c901a3131f59e20ea86ec695 Mon Sep 17 00:00:00 2001 From: yucongalicechen Date: Fri, 26 Jul 2024 13:13:07 -0400 Subject: [PATCH 05/15] remove duplicated functions in fast cve --- src/diffpy/labpdfproc/fast_cve.py | 51 ++------------------ src/diffpy/labpdfproc/functions.py | 51 ++++++++++++-------- src/diffpy/labpdfproc/labpdfprocapp.py | 16 ++---- src/diffpy/labpdfproc/tests/test_fast_cve.py | 48 ------------------ 4 files changed, 39 insertions(+), 127 deletions(-) delete mode 100644 src/diffpy/labpdfproc/tests/test_fast_cve.py diff --git a/src/diffpy/labpdfproc/fast_cve.py b/src/diffpy/labpdfproc/fast_cve.py index dedc48c..2c1bc09 100644 --- a/src/diffpy/labpdfproc/fast_cve.py +++ b/src/diffpy/labpdfproc/fast_cve.py @@ -4,9 +4,7 @@ import pandas as pd from scipy.interpolate import interp1d -from diffpy.utils.scattering_objects.diffraction_objects import Diffraction_object - -TTH_GRID = np.arange(1, 180.1, 0.1) +FAST_TTH_GRID = np.arange(1, 180.1, 0.1) MUD_LIST = [0.5, 1, 2, 3, 4, 5, 6] CWD = os.path.dirname(os.path.abspath(__file__)) INVERSE_CVE_DATA = np.loadtxt(CWD + "/data/inverse_cve.xy") @@ -14,22 +12,18 @@ INTERPOLATION_FUNCTIONS = [interp1d(MUD_LIST, coefficients, kind="quadratic") for coefficients in COEFFICIENT_LIST] -def fast_compute_cve(diffraction_data, mud, wavelength): +def fast_compute_cve(mud): """ - use precomputed datasets to compute the cve for given diffraction data, mud and wavelength + use precomputed datasets to compute the cve for given mud Parameters ---------- - diffraction_data Diffraction_object - the diffraction pattern mud float the mu*D of the diffraction object, where D is the diameter of the circle - wavelength float - the wavelength of the diffraction object Returns ------- - the diffraction object with cve curves + the array of tth grid and the corresponding cve """ coefficient_a, coefficient_b, coefficient_c, coefficient_d, coefficient_e = [ @@ -43,39 +37,4 @@ def fast_compute_cve(diffraction_data, mud, wavelength): + coefficient_e ) cve = 1 / np.array(inverse_cve) - - orig_grid = diffraction_data.on_tth[0] - newcve = np.interp(orig_grid, TTH_GRID, cve) - abdo = Diffraction_object(wavelength=wavelength) - abdo.insert_scattering_quantity( - orig_grid, - newcve, - "tth", - metadata=diffraction_data.metadata, - name=f"absorption correction, cve, for {diffraction_data.name}", - wavelength=diffraction_data.wavelength, - scat_quantity="cve", - ) - - return abdo - - -def apply_fast_corr(diffraction_pattern, absorption_correction): - """ - Apply absorption correction to the given diffraction object modo with the correction diffraction object abdo - - Parameters - ---------- - diffraction_pattern Diffraction_object - the input diffraction object to which the cve will be applied - absorption_correction Diffraction_object - the diffraction object that contains the cve to be applied - - Returns - ------- - a corrected diffraction object with the correction applied through multiplication - - """ - - corrected_pattern = diffraction_pattern * absorption_correction - return corrected_pattern + return FAST_TTH_GRID, cve diff --git a/src/diffpy/labpdfproc/functions.py b/src/diffpy/labpdfproc/functions.py index 494be9b..a46bf2c 100644 --- a/src/diffpy/labpdfproc/functions.py +++ b/src/diffpy/labpdfproc/functions.py @@ -2,6 +2,7 @@ import numpy as np +from diffpy.labpdfproc.fast_cve import fast_compute_cve from diffpy.utils.scattering_objects.diffraction_objects import Diffraction_object RADIUS_MM = 1 @@ -27,7 +28,7 @@ def _get_grid_points(self): self.grid = {(x, y) for x in xs for y in ys if x**2 + y**2 <= self.radius**2} self.total_points_in_grid = len(self.grid) - # def get_coordinate_index(self, coordinate): # I think we probably dont need this function? + # def get_coordinate_index(self, coordinate): # count = 0 # for i, target in enumerate(self.grid): # if coordinate == target: @@ -172,9 +173,9 @@ def get_path_length(self, grid_point, angle): return total_distance, primary_distance, secondary_distance -def compute_cve(diffraction_data, mud, wavelength): +def compute_cve(diffraction_data, mud, wavelength, brute_force=False): """ - compute the cve for given diffraction data, mud and wavelength + compute the cve for given diffraction data, mud and wavelength, and a boolean to determine the way to compute Parameters ---------- @@ -185,31 +186,41 @@ def compute_cve(diffraction_data, mud, wavelength): wavelength float the wavelength of the diffraction object - Returns - ------- - the diffraction object with cve curves - - it is computed as follows: + the brute-force method is computed as follows: We first resample data and absorption correction to a more reasonable grid, then calculate corresponding cve for the given mud in the resample grid (since the same mu*D yields the same cve, we can assume that D/2=1, so mu=mud/2), and finally interpolate cve to the original grid in diffraction_data. + + Returns + ------- + the diffraction object with cve curves + """ - mu_sample_invmm = mud / 2 - abs_correction = Gridded_circle(mu=mu_sample_invmm) - distances, muls = [], [] - for angle in TTH_GRID: - abs_correction.set_distances_at_angle(angle) - abs_correction.set_muls_at_angle(angle) - distances.append(sum(abs_correction.distances)) - muls.append(sum(abs_correction.muls)) - distances = np.array(distances) / abs_correction.total_points_in_grid - muls = np.array(muls) / abs_correction.total_points_in_grid - cve = 1 / muls + if brute_force: + tth_grid = TTH_GRID + mu_sample_invmm = mud / 2 + abs_correction = Gridded_circle(mu=mu_sample_invmm) + distances, muls = [], [] + for angle in TTH_GRID: + abs_correction.set_distances_at_angle(angle) + abs_correction.set_muls_at_angle(angle) + distances.append(sum(abs_correction.distances)) + muls.append(sum(abs_correction.muls)) + distances = np.array(distances) / abs_correction.total_points_in_grid + muls = np.array(muls) / abs_correction.total_points_in_grid + cve = 1 / muls + else: + if mud > 6 or mud < 0.5: + raise ValueError( + "mu*D is out of the acceptable range (0.5 to 6) for fast calculation. " + "Please rerun with a value within this range or use -b to enable brute-force calculation. " + ) + tth_grid, cve = fast_compute_cve(mud) orig_grid = diffraction_data.on_tth[0] - newcve = np.interp(orig_grid, TTH_GRID, cve) + newcve = np.interp(orig_grid, tth_grid, cve) abdo = Diffraction_object(wavelength=wavelength) abdo.insert_scattering_quantity( orig_grid, diff --git a/src/diffpy/labpdfproc/labpdfprocapp.py b/src/diffpy/labpdfproc/labpdfprocapp.py index c2fe16f..24d5b0a 100644 --- a/src/diffpy/labpdfproc/labpdfprocapp.py +++ b/src/diffpy/labpdfproc/labpdfprocapp.py @@ -1,7 +1,6 @@ import sys from argparse import ArgumentParser -from diffpy.labpdfproc.fast_cve import apply_fast_corr, fast_compute_cve from diffpy.labpdfproc.functions import apply_corr, compute_cve from diffpy.labpdfproc.tools import known_sources, load_metadata, preprocessing_args from diffpy.utils.parsers.loaddata import loadData @@ -141,20 +140,11 @@ def main(): metadata=load_metadata(args, filepath), ) - if args.brute_force: - absorption_correction = compute_cve(input_pattern, args.mud, args.wavelength) - corrected_data = apply_corr(input_pattern, absorption_correction) - else: - if args.mud > 6 or args.mud < 0.5: - sys.exit( - "mu*D is out of the acceptable range (0.5 to 6) for fast calculation. " - "Please rerun with a value within this range or use -b enable brute-force calculation. " - ) - absorption_correction = fast_compute_cve(input_pattern, args.mud, args.wavelength) - corrected_data = apply_fast_corr(input_pattern, absorption_correction) - + absorption_correction = compute_cve(input_pattern, args.mud, args.wavelength, args.brute_force) + 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") + if args.output_correction: absorption_correction.dump(f"{corrfile}", xtype="tth") diff --git a/src/diffpy/labpdfproc/tests/test_fast_cve.py b/src/diffpy/labpdfproc/tests/test_fast_cve.py deleted file mode 100644 index 374abe4..0000000 --- a/src/diffpy/labpdfproc/tests/test_fast_cve.py +++ /dev/null @@ -1,48 +0,0 @@ -import numpy as np - -from diffpy.labpdfproc.fast_cve import apply_fast_corr, 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 - - -def test_apply_fast_corr(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) - absorption_correction = _instantiate_test_do( - xarray, - expected_cve, - name="absorption correction, cve, for test", - scat_quantity="cve", - ) - actual_corr = apply_fast_corr(input_pattern, absorption_correction) - expected_corr = _instantiate_test_do(xarray, np.array([1, 1, 1])) - assert actual_corr == expected_corr From b7e037e9a68ac65b573795b86f24d3f9f1104ed7 Mon Sep 17 00:00:00 2001 From: yucongalicechen Date: Fri, 26 Jul 2024 13:21:10 -0400 Subject: [PATCH 06/15] test function for fast_compute_cve --- src/diffpy/labpdfproc/tests/test_fast_cve.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/diffpy/labpdfproc/tests/test_fast_cve.py diff --git a/src/diffpy/labpdfproc/tests/test_fast_cve.py b/src/diffpy/labpdfproc/tests/test_fast_cve.py new file mode 100644 index 0000000..9c88335 --- /dev/null +++ b/src/diffpy/labpdfproc/tests/test_fast_cve.py @@ -0,0 +1,11 @@ +import numpy as np + +from diffpy.labpdfproc.fast_cve import FAST_TTH_GRID, INVERSE_CVE_DATA, fast_compute_cve + + +def test_fast_compute_cve(): + expected_tth_grid = FAST_TTH_GRID + expected_cve = 1 / np.array(INVERSE_CVE_DATA) + actual_tth_grid, actual_cve = fast_compute_cve(mud=1) + assert np.allclose(actual_tth_grid, expected_tth_grid) + assert np.allclose(actual_cve, expected_cve, rtol=1e-5) From a450dda45b602cf24c67437436767a6ccbb92e70 Mon Sep 17 00:00:00 2001 From: yucongalicechen Date: Fri, 26 Jul 2024 13:26:36 -0400 Subject: [PATCH 07/15] fix misplaced docstring --- src/diffpy/labpdfproc/tools.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/diffpy/labpdfproc/tools.py b/src/diffpy/labpdfproc/tools.py index 5ada419..c56aa30 100644 --- a/src/diffpy/labpdfproc/tools.py +++ b/src/diffpy/labpdfproc/tools.py @@ -17,15 +17,15 @@ def set_output_directory(args): args argparse.Namespace the arguments from the parser - Returns - ------- - pathlib.PosixPath that contains the full path of the output directory - it is determined as follows: If user provides an output directory, use it. Otherwise, we set it to the current directory if nothing is provided. We then create the directory if it does not exist. + Returns + ------- + pathlib.PosixPath that contains the full path of the output directory + """ output_dir = Path(args.output_directory).resolve() if args.output_directory else Path.cwd().resolve() output_dir.mkdir(parents=True, exist_ok=True) @@ -110,13 +110,13 @@ def set_wavelength(args): args argparse.Namespace the arguments from the parser + we raise an ValueError if the input wavelength is non-positive + or if the input anode_type is not one of the known sources + Returns ------- args argparse.Namespace - we raise an ValueError if the input wavelength is non-positive - or if the input anode_type is not one of the known sources - """ if args.wavelength is not None and args.wavelength <= 0: raise ValueError( From fc4d87649a325aa6dddd31fbb2f0e62843b49255 Mon Sep 17 00:00:00 2001 From: yucongalicechen Date: Mon, 29 Jul 2024 13:06:04 -0400 Subject: [PATCH 08/15] integrate fast cve module in functions --- src/diffpy/labpdfproc/fast_cve.py | 40 -------------------- src/diffpy/labpdfproc/functions.py | 22 ++++++++--- src/diffpy/labpdfproc/tests/test_fast_cve.py | 11 ------ 3 files changed, 17 insertions(+), 56 deletions(-) delete mode 100644 src/diffpy/labpdfproc/fast_cve.py delete mode 100644 src/diffpy/labpdfproc/tests/test_fast_cve.py diff --git a/src/diffpy/labpdfproc/fast_cve.py b/src/diffpy/labpdfproc/fast_cve.py deleted file mode 100644 index 2c1bc09..0000000 --- a/src/diffpy/labpdfproc/fast_cve.py +++ /dev/null @@ -1,40 +0,0 @@ -import os - -import numpy as np -import pandas as pd -from scipy.interpolate import interp1d - -FAST_TTH_GRID = np.arange(1, 180.1, 0.1) -MUD_LIST = [0.5, 1, 2, 3, 4, 5, 6] -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] - - -def fast_compute_cve(mud): - """ - use precomputed datasets to compute the cve for given mud - - Parameters - ---------- - mud float - the mu*D of the diffraction object, where D is the diameter of the circle - - Returns - ------- - the array of tth grid and the corresponding cve - """ - - coefficient_a, coefficient_b, coefficient_c, coefficient_d, coefficient_e = [ - interpolation_function(mud) for interpolation_function in INTERPOLATION_FUNCTIONS - ] - inverse_cve = ( - coefficient_a * INVERSE_CVE_DATA**4 - + coefficient_b * INVERSE_CVE_DATA**3 - + coefficient_c * INVERSE_CVE_DATA**2 - + coefficient_d * INVERSE_CVE_DATA**1 - + coefficient_e - ) - cve = 1 / np.array(inverse_cve) - return FAST_TTH_GRID, cve diff --git a/src/diffpy/labpdfproc/functions.py b/src/diffpy/labpdfproc/functions.py index a46bf2c..254a1fe 100644 --- a/src/diffpy/labpdfproc/functions.py +++ b/src/diffpy/labpdfproc/functions.py @@ -1,13 +1,22 @@ import math +import os import numpy as np +import pandas as pd +from scipy.interpolate import interp1d -from diffpy.labpdfproc.fast_cve import fast_compute_cve from diffpy.utils.scattering_objects.diffraction_objects import Diffraction_object RADIUS_MM = 1 N_POINTS_ON_DIAMETER = 300 -TTH_GRID = np.arange(1, 141, 1) +TTH_GRID = np.arange(1, 180.1, 0.1) + +# pre-computed datasets for fast calculation +MUD_LIST = [0.5, 1, 2, 3, 4, 5, 6] +CWD = os.path.dirname(os.path.abspath(__file__)) +MULS = 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] class Gridded_circle: @@ -199,7 +208,6 @@ def compute_cve(diffraction_data, mud, wavelength, brute_force=False): """ if brute_force: - tth_grid = TTH_GRID mu_sample_invmm = mud / 2 abs_correction = Gridded_circle(mu=mu_sample_invmm) distances, muls = [], [] @@ -217,10 +225,14 @@ def compute_cve(diffraction_data, mud, wavelength, brute_force=False): "mu*D is out of the acceptable range (0.5 to 6) for fast calculation. " "Please rerun with a value within this range or use -b to enable brute-force calculation. " ) - tth_grid, cve = fast_compute_cve(mud) + coeff_a, coeff_b, coeff_c, coeff_d, coeff_e = [ + interpolation_function(mud) for interpolation_function in INTERPOLATION_FUNCTIONS + ] + muls = np.array(coeff_a * MULS**4 + coeff_b * MULS**3 + coeff_c * MULS**2 + coeff_d * MULS + coeff_e) + cve = 1 / muls orig_grid = diffraction_data.on_tth[0] - newcve = np.interp(orig_grid, tth_grid, cve) + newcve = np.interp(orig_grid, TTH_GRID, cve) abdo = Diffraction_object(wavelength=wavelength) abdo.insert_scattering_quantity( orig_grid, diff --git a/src/diffpy/labpdfproc/tests/test_fast_cve.py b/src/diffpy/labpdfproc/tests/test_fast_cve.py deleted file mode 100644 index 9c88335..0000000 --- a/src/diffpy/labpdfproc/tests/test_fast_cve.py +++ /dev/null @@ -1,11 +0,0 @@ -import numpy as np - -from diffpy.labpdfproc.fast_cve import FAST_TTH_GRID, INVERSE_CVE_DATA, fast_compute_cve - - -def test_fast_compute_cve(): - expected_tth_grid = FAST_TTH_GRID - expected_cve = 1 / np.array(INVERSE_CVE_DATA) - actual_tth_grid, actual_cve = fast_compute_cve(mud=1) - assert np.allclose(actual_tth_grid, expected_tth_grid) - assert np.allclose(actual_cve, expected_cve, rtol=1e-5) From 956408d606351252c8b52b2056d0b2cadff8b30f Mon Sep 17 00:00:00 2001 From: yucongalicechen Date: Thu, 22 Aug 2024 19:30:55 -0400 Subject: [PATCH 09/15] add private function _cve_method in compute_cve to select cve computers _cve_brute_force or _cve_interp_polynomial --- src/diffpy/labpdfproc/functions.py | 97 +++++++++++++++++------------- 1 file changed, 55 insertions(+), 42 deletions(-) diff --git a/src/diffpy/labpdfproc/functions.py b/src/diffpy/labpdfproc/functions.py index 254a1fe..55547b8 100644 --- a/src/diffpy/labpdfproc/functions.py +++ b/src/diffpy/labpdfproc/functions.py @@ -37,16 +37,6 @@ def _get_grid_points(self): self.grid = {(x, y) for x in xs for y in ys if x**2 + y**2 <= self.radius**2} self.total_points_in_grid = len(self.grid) - # def get_coordinate_index(self, coordinate): - # count = 0 - # for i, target in enumerate(self.grid): - # if coordinate == target: - # return i - # else: - # count += 1 - # if count >= len(self.grid): - # raise IndexError(f"WARNING: no coordinate {coordinate} found in coordinates list") - def set_distances_at_angle(self, angle): """ given an angle, set the distances from the grid points to the entry and exit coordinates @@ -182,9 +172,62 @@ def get_path_length(self, grid_point, angle): return total_distance, primary_distance, secondary_distance +def _cve_brute_force(diffraction_data, mud, wavelength): + """ + compute cve using brute-force method + + it is computed as follows: + We first resample data and absorption correction to a more reasonable grid, + then calculate corresponding cve for the given mud in the resample grid + (since the same mu*D yields the same cve, we can assume that D/2=1, so mu=mud/2), + and finally interpolate cve to the original grid in diffraction_data. + """ + + mu_sample_invmm = mud / 2 + abs_correction = Gridded_circle(mu=mu_sample_invmm) + distances, muls = [], [] + for angle in TTH_GRID: + abs_correction.set_distances_at_angle(angle) + abs_correction.set_muls_at_angle(angle) + distances.append(sum(abs_correction.distances)) + muls.append(sum(abs_correction.muls)) + distances = np.array(distances) / abs_correction.total_points_in_grid + muls = np.array(muls) / abs_correction.total_points_in_grid + cve = 1 / muls + return cve + + +def _cve_interp_polynomial(diffraction_data, mud, wavelength): + """ + compute cve using polynomial interpolation method, raise an error if mu*D is out of the range (0.5 to 6) + """ + + if mud > 6 or mud < 0.5: + raise ValueError( + "mu*D is out of the acceptable range (0.5 to 6) for fast calculation. " + "Please rerun with a value within this range or use -b to enable brute-force calculation. " + ) + coeff_a, coeff_b, coeff_c, coeff_d, coeff_e = [ + interpolation_function(mud) for interpolation_function in INTERPOLATION_FUNCTIONS + ] + muls = np.array(coeff_a * MULS**4 + coeff_b * MULS**3 + coeff_c * MULS**2 + coeff_d * MULS + coeff_e) + cve = 1 / muls + return cve + + +def _cve_method(diffraction_data, mud, wavelength, brute_force=False): + """ + selects the appropriate CVE calculation method + """ + if brute_force: + return _cve_brute_force(diffraction_data, mud, wavelength) + else: + return _cve_interp_polynomial(diffraction_data, mud, wavelength) + + def compute_cve(diffraction_data, mud, wavelength, brute_force=False): """ - compute the cve for given diffraction data, mud and wavelength, and a boolean to determine the way to compute + compute the cve for given diffraction data, mud, and wavelength, using the selected method Parameters ---------- @@ -195,42 +238,13 @@ def compute_cve(diffraction_data, mud, wavelength, brute_force=False): wavelength float the wavelength of the diffraction object - the brute-force method is computed as follows: - We first resample data and absorption correction to a more reasonable grid, - then calculate corresponding cve for the given mud in the resample grid - (since the same mu*D yields the same cve, we can assume that D/2=1, so mu=mud/2), - and finally interpolate cve to the original grid in diffraction_data. - Returns ------- the diffraction object with cve curves """ - if brute_force: - mu_sample_invmm = mud / 2 - abs_correction = Gridded_circle(mu=mu_sample_invmm) - distances, muls = [], [] - for angle in TTH_GRID: - abs_correction.set_distances_at_angle(angle) - abs_correction.set_muls_at_angle(angle) - distances.append(sum(abs_correction.distances)) - muls.append(sum(abs_correction.muls)) - distances = np.array(distances) / abs_correction.total_points_in_grid - muls = np.array(muls) / abs_correction.total_points_in_grid - cve = 1 / muls - else: - if mud > 6 or mud < 0.5: - raise ValueError( - "mu*D is out of the acceptable range (0.5 to 6) for fast calculation. " - "Please rerun with a value within this range or use -b to enable brute-force calculation. " - ) - coeff_a, coeff_b, coeff_c, coeff_d, coeff_e = [ - interpolation_function(mud) for interpolation_function in INTERPOLATION_FUNCTIONS - ] - muls = np.array(coeff_a * MULS**4 + coeff_b * MULS**3 + coeff_c * MULS**2 + coeff_d * MULS + coeff_e) - cve = 1 / muls - + cve = _cve_method(diffraction_data, mud, wavelength, brute_force) orig_grid = diffraction_data.on_tth[0] newcve = np.interp(orig_grid, TTH_GRID, cve) abdo = Diffraction_object(wavelength=wavelength) @@ -243,7 +257,6 @@ def compute_cve(diffraction_data, mud, wavelength, brute_force=False): wavelength=diffraction_data.wavelength, scat_quantity="cve", ) - return abdo From 4bbe4a2b88fc8782bf19bfd8c00f4cce13e563b9 Mon Sep 17 00:00:00 2001 From: yucongalicechen Date: Mon, 26 Aug 2024 15:38:22 -0400 Subject: [PATCH 10/15] add method to argparser and correct functions and docstrings --- src/diffpy/labpdfproc/functions.py | 39 +++++++++---------- src/diffpy/labpdfproc/labpdfprocapp.py | 16 ++++---- src/diffpy/labpdfproc/tests/test_functions.py | 6 +-- 3 files changed, 30 insertions(+), 31 deletions(-) diff --git a/src/diffpy/labpdfproc/functions.py b/src/diffpy/labpdfproc/functions.py index 55547b8..a355f87 100644 --- a/src/diffpy/labpdfproc/functions.py +++ b/src/diffpy/labpdfproc/functions.py @@ -10,6 +10,7 @@ RADIUS_MM = 1 N_POINTS_ON_DIAMETER = 300 TTH_GRID = np.arange(1, 180.1, 0.1) +CVE_METHODS = ["brute_force", "polynomial_interpolation"] # pre-computed datasets for fast calculation MUD_LIST = [0.5, 1, 2, 3, 4, 5, 6] @@ -172,15 +173,10 @@ def get_path_length(self, grid_point, angle): return total_distance, primary_distance, secondary_distance -def _cve_brute_force(diffraction_data, mud, wavelength): +def _cve_brute_force(mud): """ - compute cve using brute-force method - - it is computed as follows: - We first resample data and absorption correction to a more reasonable grid, - then calculate corresponding cve for the given mud in the resample grid - (since the same mu*D yields the same cve, we can assume that D/2=1, so mu=mud/2), - and finally interpolate cve to the original grid in diffraction_data. + compute cve for the given mud on a global grid using the brute-force method + assume mu=mud/2, given that the same mu*D yields the same cve and D/2=1 """ mu_sample_invmm = mud / 2 @@ -197,15 +193,15 @@ def _cve_brute_force(diffraction_data, mud, wavelength): return cve -def _cve_interp_polynomial(diffraction_data, mud, wavelength): +def _cve_polynomial_interpolation(mud): """ compute cve using polynomial interpolation method, raise an error if mu*D is out of the range (0.5 to 6) """ if mud > 6 or mud < 0.5: raise ValueError( - "mu*D is out of the acceptable range (0.5 to 6) for fast calculation. " - "Please rerun with a value within this range or use -b to enable brute-force calculation. " + f"mu*D is out of the acceptable range (0.5 to 6) for polynomial interpolation. " + f"Please rerun with a value within this range or specifying another method from {* CVE_METHODS, }." ) coeff_a, coeff_b, coeff_c, coeff_d, coeff_e = [ interpolation_function(mud) for interpolation_function in INTERPOLATION_FUNCTIONS @@ -215,19 +211,20 @@ def _cve_interp_polynomial(diffraction_data, mud, wavelength): return cve -def _cve_method(diffraction_data, mud, wavelength, brute_force=False): +def _compute_cve(method, mud): """ - selects the appropriate CVE calculation method + compute cve for the given mud on a global grid using the specified method """ - if brute_force: - return _cve_brute_force(diffraction_data, mud, wavelength) - else: - return _cve_interp_polynomial(diffraction_data, mud, wavelength) + methods = { + "brute_force": _cve_brute_force, + "polynomial_interpolation": _cve_polynomial_interpolation, + } + return methods[method](mud) -def compute_cve(diffraction_data, mud, wavelength, brute_force=False): +def interpolate_cve(diffraction_data, mud, wavelength, method="polynomial_interpolation"): """ - compute the cve for given diffraction data, mud, and wavelength, using the selected method + compute and interpolate the cve for the given diffraction data, mud, and wavelength, using the selected method Parameters ---------- @@ -237,6 +234,8 @@ def compute_cve(diffraction_data, mud, wavelength, brute_force=False): the mu*D of the diffraction object, where D is the diameter of the circle wavelength float the wavelength of the diffraction object + method str + the method used to calculate cve Returns ------- @@ -244,7 +243,7 @@ def compute_cve(diffraction_data, mud, wavelength, brute_force=False): """ - cve = _cve_method(diffraction_data, mud, wavelength, brute_force) + cve = _compute_cve(method, mud) orig_grid = diffraction_data.on_tth[0] newcve = np.interp(orig_grid, TTH_GRID, cve) abdo = Diffraction_object(wavelength=wavelength) diff --git a/src/diffpy/labpdfproc/labpdfprocapp.py b/src/diffpy/labpdfproc/labpdfprocapp.py index 24d5b0a..0d25c54 100644 --- a/src/diffpy/labpdfproc/labpdfprocapp.py +++ b/src/diffpy/labpdfproc/labpdfprocapp.py @@ -1,7 +1,7 @@ import sys from argparse import ArgumentParser -from diffpy.labpdfproc.functions import apply_corr, compute_cve +from diffpy.labpdfproc.functions import CVE_METHODS, apply_corr, interpolate_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 @@ -45,7 +45,7 @@ def get_args(override_cli_inputs=None): "-o", "--output-directory", help="The name of the output directory. If not specified " - "then corrected files will be written to the current directory." + "then corrected files will be written to the current directory. " "If the specified directory doesn't exist it will be created.", default=None, ) @@ -72,11 +72,11 @@ def get_args(override_cli_inputs=None): help="Outputs will not overwrite existing file unless --force is specified.", ) p.add_argument( - "-b", - "--brute-force", - action="store_true", - help="The absorption correction will be computed using brute-force calculation " - "if this flag is set. Default is using fast calculation. ", + "-m", + "--method", + help=f"The method for computing absorption correction. Allowed methods: {*CVE_METHODS, }. " + f"Default method is polynomial interpolation if not specified. ", + default="polynomial_interpolation", ) p.add_argument( "-u", @@ -140,7 +140,7 @@ def main(): metadata=load_metadata(args, filepath), ) - absorption_correction = compute_cve(input_pattern, args.mud, args.wavelength, args.brute_force) + absorption_correction = interpolate_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") diff --git a/src/diffpy/labpdfproc/tests/test_functions.py b/src/diffpy/labpdfproc/tests/test_functions.py index 75ef019..19acd64 100644 --- a/src/diffpy/labpdfproc/tests/test_functions.py +++ b/src/diffpy/labpdfproc/tests/test_functions.py @@ -1,7 +1,7 @@ import numpy as np import pytest -from diffpy.labpdfproc.functions import Gridded_circle, apply_corr, compute_cve +from diffpy.labpdfproc.functions import Gridded_circle, apply_corr, interpolate_cve from diffpy.utils.scattering_objects.diffraction_objects import Diffraction_object params1 = [ @@ -69,13 +69,13 @@ def _instantiate_test_do(xarray, yarray, name="test", scat_quantity="x-ray"): return test_do -def test_compute_cve(mocker): +def test_interpolate_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 = compute_cve(input_pattern, mud=1, wavelength=1.54) + actual_abdo = interpolate_cve(input_pattern, mud=1, wavelength=1.54) expected_abdo = _instantiate_test_do( xarray, expected_cve, From b91b6ecc8163f79e445f29d0820688a4563deba6 Mon Sep 17 00:00:00 2001 From: yucongalicechen Date: Mon, 26 Aug 2024 15:41:10 -0400 Subject: [PATCH 11/15] change cwd path from os to pathlib --- src/diffpy/labpdfproc/functions.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/diffpy/labpdfproc/functions.py b/src/diffpy/labpdfproc/functions.py index a355f87..c10a92e 100644 --- a/src/diffpy/labpdfproc/functions.py +++ b/src/diffpy/labpdfproc/functions.py @@ -1,5 +1,5 @@ import math -import os +from pathlib import Path import numpy as np import pandas as pd @@ -12,11 +12,11 @@ TTH_GRID = np.arange(1, 180.1, 0.1) CVE_METHODS = ["brute_force", "polynomial_interpolation"] -# pre-computed datasets for fast calculation +# pre-computed datasets for polynomial interpolation (fast calculation) MUD_LIST = [0.5, 1, 2, 3, 4, 5, 6] -CWD = os.path.dirname(os.path.abspath(__file__)) -MULS = np.loadtxt(CWD + "/data/inverse_cve.xy") -COEFFICIENT_LIST = np.array(pd.read_csv(CWD + "/data/coefficient_list.csv", header=None)) +CWD = Path(__file__).parent.resolve() +MULS = 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] From e7d3d0591b28f0b128899f9e90bb64f0561f55d9 Mon Sep 17 00:00:00 2001 From: yucongalicechen Date: Mon, 26 Aug 2024 15:45:15 -0400 Subject: [PATCH 12/15] add method argument to metadata test --- src/diffpy/labpdfproc/tests/test_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diffpy/labpdfproc/tests/test_tools.py b/src/diffpy/labpdfproc/tests/test_tools.py index fda91fb..e17ed42 100644 --- a/src/diffpy/labpdfproc/tests/test_tools.py +++ b/src/diffpy/labpdfproc/tests/test_tools.py @@ -312,7 +312,7 @@ def test_load_metadata(mocker, user_filesystem): "wavelength": 0.71, "output_directory": str(Path.cwd().resolve()), "xtype": "tth", - "brute_force": False, + "method": "polynomial_interpolation", "key": "value", "username": "cli_username", "email": "cli@email.com", From bb28204a10d2a778e2001a66f713c9317cf18417 Mon Sep 17 00:00:00 2001 From: yucongalicechen Date: Wed, 28 Aug 2024 11:04:21 -0400 Subject: [PATCH 13/15] change compute cve function to call cve methods and interpolate tth --- src/diffpy/labpdfproc/functions.py | 13 ++++++++----- src/diffpy/labpdfproc/labpdfprocapp.py | 4 ++-- src/diffpy/labpdfproc/tests/test_functions.py | 6 +++--- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/diffpy/labpdfproc/functions.py b/src/diffpy/labpdfproc/functions.py index c10a92e..d136926 100644 --- a/src/diffpy/labpdfproc/functions.py +++ b/src/diffpy/labpdfproc/functions.py @@ -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 @@ -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) diff --git a/src/diffpy/labpdfproc/labpdfprocapp.py b/src/diffpy/labpdfproc/labpdfprocapp.py index 0d25c54..2c21605 100644 --- a/src/diffpy/labpdfproc/labpdfprocapp.py +++ b/src/diffpy/labpdfproc/labpdfprocapp.py @@ -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 @@ -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") diff --git a/src/diffpy/labpdfproc/tests/test_functions.py b/src/diffpy/labpdfproc/tests/test_functions.py index 19acd64..75ef019 100644 --- a/src/diffpy/labpdfproc/tests/test_functions.py +++ b/src/diffpy/labpdfproc/tests/test_functions.py @@ -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 = [ @@ -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, From 3c6b1281fa55c72de119940459fc0679de30620b Mon Sep 17 00:00:00 2001 From: yucongalicechen Date: Wed, 28 Aug 2024 14:36:56 -0400 Subject: [PATCH 14/15] updated compute_cve to use DOs consistently --- src/diffpy/labpdfproc/functions.py | 44 ++++++++++++++----- src/diffpy/labpdfproc/labpdfprocapp.py | 2 +- src/diffpy/labpdfproc/tests/test_functions.py | 2 +- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/diffpy/labpdfproc/functions.py b/src/diffpy/labpdfproc/functions.py index d136926..6d80a4d 100644 --- a/src/diffpy/labpdfproc/functions.py +++ b/src/diffpy/labpdfproc/functions.py @@ -173,7 +173,7 @@ def get_path_length(self, grid_point, angle): return total_distance, primary_distance, secondary_distance -def _cve_brute_force(mud): +def _cve_brute_force(diffraction_data, mud): """ compute cve for the given mud on a global grid using the brute-force method assume mu=mud/2, given that the same mu*D yields the same cve and D/2=1 @@ -190,10 +190,21 @@ def _cve_brute_force(mud): distances = np.array(distances) / abs_correction.total_points_in_grid muls = np.array(muls) / abs_correction.total_points_in_grid cve = 1 / muls - return cve + + abdo = Diffraction_object(wavelength=diffraction_data.wavelength) + abdo.insert_scattering_quantity( + TTH_GRID, + cve, + "tth", + metadata=diffraction_data.metadata, + name=f"absorption correction, cve, for {diffraction_data.name}", + wavelength=diffraction_data.wavelength, + scat_quantity="cve", + ) + return abdo -def _cve_polynomial_interpolation(mud): +def _cve_polynomial_interpolation(diffraction_data, mud): """ compute cve using polynomial interpolation method, raise an error if mu*D is out of the range (0.5 to 6) """ @@ -208,7 +219,18 @@ def _cve_polynomial_interpolation(mud): ] muls = np.array(coeff_a * MULS**4 + coeff_b * MULS**3 + coeff_c * MULS**2 + coeff_d * MULS + coeff_e) cve = 1 / muls - return cve + + abdo = Diffraction_object(wavelength=diffraction_data.wavelength) + abdo.insert_scattering_quantity( + TTH_GRID, + cve, + "tth", + metadata=diffraction_data.metadata, + name=f"absorption correction, cve, for {diffraction_data.name}", + wavelength=diffraction_data.wavelength, + scat_quantity="cve", + ) + return abdo def _cve_method(method): @@ -224,9 +246,9 @@ def _cve_method(method): return methods[method] -def compute_cve(diffraction_data, mud, wavelength, method="polynomial_interpolation"): +def compute_cve(diffraction_data, mud, method="polynomial_interpolation"): """ - compute and interpolate the cve for the given diffraction data, mud, and wavelength, using the selected method + compute and interpolate the cve for the given diffraction data and mud using the selected method Parameters ---------- @@ -234,8 +256,6 @@ def compute_cve(diffraction_data, mud, wavelength, method="polynomial_interpolat the diffraction pattern mud float the mu*D of the diffraction object, where D is the diameter of the circle - wavelength float - the wavelength of the diffraction object method str the method used to calculate cve @@ -246,10 +266,12 @@ def compute_cve(diffraction_data, mud, wavelength, method="polynomial_interpolat """ cve_function = _cve_method(method) - cve = cve_function(mud) + abdo_on_global_tth = cve_function(diffraction_data, mud) + global_tth = abdo_on_global_tth.on_tth[0] + cve_on_global_tth = abdo_on_global_tth.on_tth[1] orig_grid = diffraction_data.on_tth[0] - newcve = np.interp(orig_grid, TTH_GRID, cve) - abdo = Diffraction_object(wavelength=wavelength) + newcve = np.interp(orig_grid, global_tth, cve_on_global_tth) + abdo = Diffraction_object(wavelength=diffraction_data.wavelength) abdo.insert_scattering_quantity( orig_grid, newcve, diff --git a/src/diffpy/labpdfproc/labpdfprocapp.py b/src/diffpy/labpdfproc/labpdfprocapp.py index 2c21605..9510e90 100644 --- a/src/diffpy/labpdfproc/labpdfprocapp.py +++ b/src/diffpy/labpdfproc/labpdfprocapp.py @@ -140,7 +140,7 @@ def main(): metadata=load_metadata(args, filepath), ) - absorption_correction = compute_cve(input_pattern, args.mud, args.wavelength, args.method) + absorption_correction = compute_cve(input_pattern, args.mud, 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") diff --git a/src/diffpy/labpdfproc/tests/test_functions.py b/src/diffpy/labpdfproc/tests/test_functions.py index 75ef019..417a34f 100644 --- a/src/diffpy/labpdfproc/tests/test_functions.py +++ b/src/diffpy/labpdfproc/tests/test_functions.py @@ -75,7 +75,7 @@ def test_compute_cve(mocker): 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 = compute_cve(input_pattern, mud=1, wavelength=1.54) + actual_abdo = compute_cve(input_pattern, mud=1) expected_abdo = _instantiate_test_do( xarray, expected_cve, From 377607a4334935e65f0888a7aee62af2bb9234b2 Mon Sep 17 00:00:00 2001 From: yucongalicechen Date: Wed, 28 Aug 2024 14:39:44 -0400 Subject: [PATCH 15/15] change output file format from .chi to .xy --- src/diffpy/labpdfproc/labpdfprocapp.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/diffpy/labpdfproc/labpdfprocapp.py b/src/diffpy/labpdfproc/labpdfprocapp.py index 9510e90..9325f20 100644 --- a/src/diffpy/labpdfproc/labpdfprocapp.py +++ b/src/diffpy/labpdfproc/labpdfprocapp.py @@ -115,8 +115,8 @@ def main(): for filepath in args.input_paths: outfilestem = filepath.stem + "_corrected" corrfilestem = filepath.stem + "_cve" - outfile = args.output_directory / (outfilestem + ".chi") - corrfile = args.output_directory / (corrfilestem + ".chi") + outfile = args.output_directory / (outfilestem + ".xy") + corrfile = args.output_directory / (corrfilestem + ".xy") if outfile.exists() and not args.force_overwrite: sys.exit(