Skip to content

Commit

Permalink
3m releasable version working
Browse files Browse the repository at this point in the history
  • Loading branch information
sbillinge committed Mar 30, 2024
1 parent 55278f8 commit 1abb964
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 21 deletions.
12 changes: 6 additions & 6 deletions diffpy/labpdfproc/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,12 @@ def compute_cve(diffraction_data, mud, wavelength):
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")
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

Expand All @@ -234,8 +239,3 @@ def apply_corr(diffraction_pattern, absorption_correction):
corrected_pattern = diffraction_pattern * absorption_correction
return corrected_pattern


# to be added in diffpy.utils
# def dump(base_name, do):
# data_to_save = np.column_stack((do.on_tth[0], do.on_tth[1]))
# np.savetxt(f'{base_name}_proc.chi', data_to_save)
43 changes: 28 additions & 15 deletions diffpy/labpdfproc/labpdfprocapp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
from argparse import ArgumentParser
from pathlib import Path

import numpy as np
from diffpy.labpdfproc.functions import compute_cve, apply_corr
Expand All @@ -18,30 +19,42 @@ def get_args():
p.add_argument("-w", "--wavelength", help=f"X-ray source wavelength. Not needed if the anode-type is specified. This will override the wavelength if anode type is specified", default=None, type=float)
p.add_argument("-o", "--output-directory", help=f"the name of the output directory. If it doesn't exist it will be created. Not currently implemented", default=None)
p.add_argument("-x", "--xtype", help=f"the quantity on the independnt variable axis. allowed values:{*XQUANTITIES,}. If not specified then two-theta is assumed for the independent variable. Only implemented for tth currently", default="tth")
p.add_argument("-c", "--output-correction", action='store_true', help=f"the quantity on the independnt variable axis. allowed values:{*XQUANTITIES,}. If not specified then two-theta is assumed for the independent variable. Only implemented for tth currently", default="tth")
p.add_argument("-f", "--force-overwrite", action='store_true', help="outputs will not overwrite existing file unless --force is spacified")
args = p.parse_args()
return args


def main():
# we want the user to type the following:
# labpdfproc <input_file> <mu> <diameter> <Ag, ag, Mo, mo, Cu, cu>

# if they give less or more than 4 positional arguments, we return an error message.
if len(sys.argv) < 4:
print("usage: labpdfproc <input_file> <mu> <diameter> <lambda>")

args = get_args()
wavelength = WAVELENGTHS[args.anode_type]
input_pattern = Diffraction_object(wavelength=wavelength)
xarray, yarray = loadData(args.input_file, unpack=True)
input_pattern.insert_scattering_quantity(xarray, yarray, "tth")
filepath = Path(args.input_file)
outfilestem = filepath.stem + "_corrected"
corrfilestem = filepath.stem + "_cve"
outfile = Path(outfilestem + ".chi")
corrfile = Path(corrfilestem + ".chi")

abdo = compute_cve(input_pattern, args.mud, wavelength)
abscormodo = apply_corr(input_pattern, abdo)
if outfile.exists() and not args.force_overwrite:
sys.exit(f"output file {str(outfile)} already exists. Please rerun specifying -f if you want to overwrite it")
if corrfile.exists() and args.output_correction and not args.force_overwrite:
sys.exit(f"corrections file {str(corrfile)} was requested and already exists. Please rerun specifying -f if you want to overwrite it")

base_name = args.input_file.split(".")[0]
data_to_save = np.column_stack((abscormodo.on_tth[0], abscormodo.on_tth[1]))
np.savetxt(f"{base_name}_proc.chi", data_to_save)
input_pattern = Diffraction_object(wavelength=wavelength)
xarray, yarray = loadData(args.input_file, unpack=True)
input_pattern.insert_scattering_quantity(xarray, yarray, "tth",
scat_quantity="x-ray",
name=str(args.input_file),
metadata={"muD": args.mud,
"anode_type": args.anode_type}
)

absorption_correction = compute_cve(input_pattern, args.mud, wavelength)
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")


if __name__ == "__main__":
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ codecov
coverage
flake8
isort
metadata
nbstripout
pre-commit
pre-commit-hooks
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# List required packages in this file, one per line.
numpy
pathlib
diffpy.utils

0 comments on commit 1abb964

Please sign in to comment.