1
1
import sys
2
2
from argparse import ArgumentParser
3
- from pathlib import Path
4
3
5
4
from 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
+ )
7
13
from diffpy .utils .parsers .loaddata import loadData
8
14
from diffpy .utils .scattering_objects .diffraction_objects import XQUANTITIES , Diffraction_object
9
15
@@ -21,7 +27,7 @@ def get_args(override_cli_inputs=None):
21
27
"data-files in that directory will be processed. Examples of valid "
22
28
"inputs are 'file.xy', 'data/file.xy', 'file.xy, data/file.xy', "
23
29
"'.' (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"
25
31
" the list of files contained in the text-file called "
26
32
"file_list.txt that can be found in the folder ./data)." ,
27
33
)
@@ -89,45 +95,47 @@ def get_args(override_cli_inputs=None):
89
95
90
96
def main ():
91
97
args = get_args ()
98
+ args = expand_list_file (args )
99
+ args = set_input_lists (args )
92
100
args .output_directory = set_output_directory (args )
93
101
args .wavelength = set_wavelength (args )
94
102
args = load_user_metadata (args )
95
103
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" )
101
109
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
+ )
112
120
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
+ )
123
131
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" )
128
136
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" )
131
139
132
140
133
141
if __name__ == "__main__" :
0 commit comments