Skip to content

closes #24: check if args.input_file is specified #35

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 2 commits 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
76 changes: 45 additions & 31 deletions src/diffpy/labpdfproc/labpdfprocapp.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import glob
import sys
from argparse import ArgumentParser
from pathlib import Path
Expand Down Expand Up @@ -63,41 +64,54 @@ def get_args():
def main():
args = get_args()
wavelength = WAVELENGTHS[args.anode_type]
filepath = Path(args.input_file)
outfilestem = filepath.stem + "_corrected"
corrfilestem = filepath.stem + "_cve"
outfile = Path(outfilestem + ".chi")
corrfile = Path(corrfilestem + ".chi")
input_dir = Path.cwd()
if args.input_file:
filepath = Path(args.input_file)
input_dir = Path.cwd() / filepath.parent

if outfile.exists() and not args.force_overwrite:
sys.exit(
f"output file {str(outfile)} already exists. Please rerun "
f"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 "
f"exists. Please rerun specifying -f if you want to overwrite it"
)
input_files = glob.glob(str(input_dir) + "/*", recursive=True)
filepaths = [Path(file) for file in input_files]

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},
)
for filepath in filepaths:
outfilestem = filepath.stem + "_corrected"
corrfilestem = filepath.stem + "_cve"
outfile = Path(outfilestem + ".chi")
corrfile = Path(corrfilestem + ".chi")

if outfile.exists() and not args.force_overwrite:
sys.exit(
f"output file {str(outfile)} already exists. Please rerun "
f"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 "
f"exists. Please rerun specifying -f if you want to overwrite it"
)

input_pattern = Diffraction_object(wavelength=wavelength)
try:
xarray, yarray = loadData(filepath, unpack=True)
except Exception as e:
Copy link
Contributor

Choose a reason for hiding this comment

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

please specify a specific exception or exceptions, not a general one.

print(f"Non-readable data file {filepath}: {e}")
continue

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")
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 args.output_correction:
absorption_correction.dump(f"{corrfile}", xtype="tth")


if __name__ == "__main__":
Expand Down
Loading