11import sys
22from argparse import ArgumentParser
3- from pathlib import Path
43
54from diffpy .labpdfproc .functions import apply_corr , compute_cve
6- from diffpy .labpdfproc .tools import known_sources , load_user_metadata , set_output_directory , set_wavelength
5+ from diffpy .labpdfproc .tools import (
6+ expand_list_file ,
7+ known_sources ,
8+ load_user_metadata ,
9+ set_input_lists ,
10+ set_output_directory ,
11+ set_wavelength ,
12+ )
713from diffpy .utils .parsers .loaddata import loadData
814from diffpy .utils .scattering_objects .diffraction_objects import XQUANTITIES , Diffraction_object
915
@@ -21,7 +27,7 @@ def get_args(override_cli_inputs=None):
2127 "data-files in that directory will be processed. Examples of valid "
2228 "inputs are 'file.xy', 'data/file.xy', 'file.xy, data/file.xy', "
2329 "'.' (load everything in the current directory), 'data' (load"
24- "everything in the folder ./data' , 'data/file_list.txt' (load"
30+ "everything in the folder ./data) , 'data/file_list.txt' (load"
2531 " the list of files contained in the text-file called "
2632 "file_list.txt that can be found in the folder ./data)." ,
2733 )
@@ -89,45 +95,47 @@ def get_args(override_cli_inputs=None):
8995
9096def main ():
9197 args = get_args ()
98+ args = expand_list_file (args )
99+ args = set_input_lists (args )
92100 args .output_directory = set_output_directory (args )
93101 args .wavelength = set_wavelength (args )
94102 args = load_user_metadata (args )
95103
96- filepath = Path ( args .input_file )
97- outfilestem = filepath .stem + "_corrected"
98- corrfilestem = filepath .stem + "_cve"
99- outfile = args .output_directory / (outfilestem + ".chi" )
100- corrfile = args .output_directory / (corrfilestem + ".chi" )
104+ for filepath in args .input_directory :
105+ outfilestem = filepath .stem + "_corrected"
106+ corrfilestem = filepath .stem + "_cve"
107+ outfile = args .output_directory / (outfilestem + ".chi" )
108+ corrfile = args .output_directory / (corrfilestem + ".chi" )
101109
102- if outfile .exists () and not args .force_overwrite :
103- sys .exit (
104- f"Output file { str (outfile )} already exists. Please rerun "
105- f"specifying -f if you want to overwrite it."
106- )
107- if corrfile .exists () and args .output_correction and not args .force_overwrite :
108- sys .exit (
109- f"Corrections file { str (corrfile )} was requested and already "
110- f"exists. Please rerun specifying -f if you want to overwrite it."
111- )
110+ if outfile .exists () and not args .force_overwrite :
111+ sys .exit (
112+ f"Output file { str (outfile )} already exists. Please rerun "
113+ f"specifying -f if you want to overwrite it."
114+ )
115+ if corrfile .exists () and args .output_correction and not args .force_overwrite :
116+ sys .exit (
117+ f"Corrections file { str (corrfile )} was requested and already "
118+ f"exists. Please rerun specifying -f if you want to overwrite it."
119+ )
112120
113- input_pattern = Diffraction_object (wavelength = args .wavelength )
114- xarray , yarray = loadData (args .input_file , unpack = True )
115- input_pattern .insert_scattering_quantity (
116- xarray ,
117- yarray ,
118- "tth" ,
119- scat_quantity = "x-ray" ,
120- name = str (args .input_file ),
121- metadata = {"muD" : args .mud , "anode_type" : args .anode_type },
122- )
121+ input_pattern = Diffraction_object (wavelength = args .wavelength )
122+ xarray , yarray = loadData (args .input_file , unpack = True )
123+ input_pattern .insert_scattering_quantity (
124+ xarray ,
125+ yarray ,
126+ "tth" ,
127+ scat_quantity = "x-ray" ,
128+ name = str (args .input_file ),
129+ metadata = {"muD" : args .mud , "anode_type" : args .anode_type },
130+ )
123131
124- absorption_correction = compute_cve (input_pattern , args .mud , args .wavelength )
125- corrected_data = apply_corr (input_pattern , absorption_correction )
126- corrected_data .name = f"Absorption corrected input_data: { input_pattern .name } "
127- corrected_data .dump (f"{ outfile } " , xtype = "tth" )
132+ absorption_correction = compute_cve (input_pattern , args .mud , args .wavelength )
133+ corrected_data = apply_corr (input_pattern , absorption_correction )
134+ corrected_data .name = f"Absorption corrected input_data: { input_pattern .name } "
135+ corrected_data .dump (f"{ outfile } " , xtype = "tth" )
128136
129- if args .output_correction :
130- absorption_correction .dump (f"{ corrfile } " , xtype = "tth" )
137+ if args .output_correction :
138+ absorption_correction .dump (f"{ corrfile } " , xtype = "tth" )
131139
132140
133141if __name__ == "__main__" :
0 commit comments