|
| 1 | +import glob |
1 | 2 | import sys
|
2 | 3 | from argparse import ArgumentParser
|
3 | 4 | from pathlib import Path
|
@@ -67,42 +68,49 @@ def main():
|
67 | 68 | args = set_input_directory(args)
|
68 | 69 | args.output_directory = set_output_directory(args)
|
69 | 70 | args.wavelength = set_wavelength(args)
|
| 71 | + input_files = glob.glob(str(args.input_directory) + "/*", recursive=True) |
70 | 72 |
|
71 |
| - filepath = Path(args.input_file) |
72 |
| - outfilestem = filepath.stem + "_corrected" |
73 |
| - corrfilestem = filepath.stem + "_cve" |
74 |
| - outfile = args.output_directory / (outfilestem + ".chi") |
75 |
| - corrfile = args.output_directory / (corrfilestem + ".chi") |
| 73 | + for input_file in input_files: |
| 74 | + filepath = Path(input_file) |
| 75 | + outfilestem = filepath.stem + "_corrected" |
| 76 | + corrfilestem = filepath.stem + "_cve" |
| 77 | + outfile = args.output_directory / (outfilestem + ".chi") |
| 78 | + corrfile = args.output_directory / (corrfilestem + ".chi") |
76 | 79 |
|
77 |
| - if outfile.exists() and not args.force_overwrite: |
78 |
| - sys.exit( |
79 |
| - f"Output file {str(outfile)} already exists. Please rerun " |
80 |
| - f"specifying -f if you want to overwrite it." |
81 |
| - ) |
82 |
| - if corrfile.exists() and args.output_correction and not args.force_overwrite: |
83 |
| - sys.exit( |
84 |
| - f"Corrections file {str(corrfile)} was requested and already " |
85 |
| - f"exists. Please rerun specifying -f if you want to overwrite it." |
86 |
| - ) |
| 80 | + if outfile.exists() and not args.force_overwrite: |
| 81 | + sys.exit( |
| 82 | + f"Output file {str(outfile)} already exists. Please rerun " |
| 83 | + f"specifying -f if you want to overwrite it." |
| 84 | + ) |
| 85 | + if corrfile.exists() and args.output_correction and not args.force_overwrite: |
| 86 | + sys.exit( |
| 87 | + f"Corrections file {str(corrfile)} was requested and already " |
| 88 | + f"exists. Please rerun specifying -f if you want to overwrite it." |
| 89 | + ) |
87 | 90 |
|
88 |
| - input_pattern = Diffraction_object(wavelength=args.wavelength) |
89 |
| - xarray, yarray = loadData(args.input_file, unpack=True) |
90 |
| - input_pattern.insert_scattering_quantity( |
91 |
| - xarray, |
92 |
| - yarray, |
93 |
| - "tth", |
94 |
| - scat_quantity="x-ray", |
95 |
| - name=str(args.input_file), |
96 |
| - metadata={"muD": args.mud, "anode_type": args.anode_type}, |
97 |
| - ) |
| 91 | + input_pattern = Diffraction_object(wavelength=args.wavelength) |
| 92 | + |
| 93 | + try: |
| 94 | + xarray, yarray = loadData(args.input_file, unpack=True) |
| 95 | + except Exception as e: |
| 96 | + raise ValueError(f"Failed to load data from {filepath}: {e}.") |
| 97 | + |
| 98 | + input_pattern.insert_scattering_quantity( |
| 99 | + xarray, |
| 100 | + yarray, |
| 101 | + "tth", |
| 102 | + scat_quantity="x-ray", |
| 103 | + name=str(args.input_file), |
| 104 | + metadata={"muD": args.mud, "anode_type": args.anode_type}, |
| 105 | + ) |
98 | 106 |
|
99 |
| - absorption_correction = compute_cve(input_pattern, args.mud, args.wavelength) |
100 |
| - corrected_data = apply_corr(input_pattern, absorption_correction) |
101 |
| - corrected_data.name = f"Absorption corrected input_data: {input_pattern.name}" |
102 |
| - corrected_data.dump(f"{outfile}", xtype="tth") |
| 107 | + absorption_correction = compute_cve(input_pattern, args.mud, args.wavelength) |
| 108 | + corrected_data = apply_corr(input_pattern, absorption_correction) |
| 109 | + corrected_data.name = f"Absorption corrected input_data: {input_pattern.name}" |
| 110 | + corrected_data.dump(f"{outfile}", xtype="tth") |
103 | 111 |
|
104 |
| - if args.output_correction: |
105 |
| - absorption_correction.dump(f"{corrfile}", xtype="tth") |
| 112 | + if args.output_correction: |
| 113 | + absorption_correction.dump(f"{corrfile}", xtype="tth") |
106 | 114 |
|
107 | 115 |
|
108 | 116 | if __name__ == "__main__":
|
|
0 commit comments