|
3 | 3 | from pathlib import Path
|
4 | 4 |
|
5 | 5 | from diffpy.labpdfproc.functions import apply_corr, compute_cve
|
6 |
| -from diffpy.labpdfproc.tools import known_sources, set_wavelength |
| 6 | +from diffpy.labpdfproc.tools import known_sources, set_output_directory, set_wavelength |
7 | 7 | from diffpy.utils.parsers.loaddata import loadData
|
8 | 8 | from diffpy.utils.scattering_objects.diffraction_objects import XQUANTITIES, Diffraction_object
|
9 | 9 |
|
10 | 10 |
|
11 | 11 | def get_args():
|
12 | 12 | p = ArgumentParser()
|
13 | 13 | p.add_argument("mud", help="Value of mu*D for your " "sample. Required.", type=float)
|
14 |
| - p.add_argument("-i", "--input-file", help="The filename of the " "datafile to load") |
| 14 | + p.add_argument("-i", "--input-file", help="The filename of the " "datafile to load.") |
15 | 15 | p.add_argument(
|
16 | 16 | "-a",
|
17 | 17 | "--anode-type",
|
18 | 18 | help=f"The type of the x-ray source. Allowed values are "
|
19 |
| - f"{*[known_sources], }. Either specify a known x-ray source or specify wavelength", |
| 19 | + f"{*[known_sources], }. Either specify a known x-ray source or specify wavelength.", |
20 | 20 | default="Mo",
|
21 | 21 | )
|
22 | 22 | p.add_argument(
|
23 | 23 | "-w",
|
24 | 24 | "--wavelength",
|
25 | 25 | help="X-ray source wavelength in angstroms. Not needed if the anode-type "
|
26 |
| - "is specified. This wavelength will override the anode wavelength if both are specified", |
| 26 | + "is specified. This wavelength will override the anode wavelength if both are specified.", |
27 | 27 | default=None,
|
28 | 28 | type=float,
|
29 | 29 | )
|
30 | 30 | p.add_argument(
|
31 | 31 | "-o",
|
32 | 32 | "--output-directory",
|
33 |
| - help="the name of the output directory. If it doesn't exist it " |
34 |
| - "will be created. Not currently implemented", |
| 33 | + help="The name of the output directory. If not specified " |
| 34 | + "then corrected files will be written to the current directory." |
| 35 | + "If the specified directory doesn't exist it will be created.", |
35 | 36 | default=None,
|
36 | 37 | )
|
37 | 38 | p.add_argument(
|
38 | 39 | "-x",
|
39 | 40 | "--xtype",
|
40 |
| - help=f"the quantity on the independnt variable axis. allowed " |
| 41 | + help=f"The quantity on the independent variable axis. Allowed " |
41 | 42 | f"values: {*XQUANTITIES, }. If not specified then two-theta "
|
42 | 43 | f"is assumed for the independent variable. Only implemented for "
|
43 |
| - f"tth currently", |
| 44 | + f"tth currently.", |
44 | 45 | default="tth",
|
45 | 46 | )
|
46 | 47 | p.add_argument(
|
47 | 48 | "-c",
|
48 | 49 | "--output-correction",
|
49 | 50 | action="store_true",
|
50 |
| - help="the absorption correction will be output to a file if this " |
51 |
| - "flag is set. Default is that it is not output", |
| 51 | + help="The absorption correction will be output to a file if this " |
| 52 | + "flag is set. Default is that it is not output.", |
52 | 53 | default="tth",
|
53 | 54 | )
|
54 | 55 | p.add_argument(
|
55 | 56 | "-f",
|
56 | 57 | "--force-overwrite",
|
57 | 58 | action="store_true",
|
58 |
| - help="outputs will not overwrite existing files unless --force is spacified", |
| 59 | + help="Outputs will not overwrite existing file unless --force is specified.", |
59 | 60 | )
|
60 | 61 | args = p.parse_args()
|
61 | 62 | return args
|
62 | 63 |
|
63 | 64 |
|
64 | 65 | def main():
|
65 | 66 | args = get_args()
|
| 67 | + args.output_directory = set_output_directory(args) |
66 | 68 | args.wavelength = set_wavelength(args)
|
| 69 | + |
67 | 70 | filepath = Path(args.input_file)
|
68 | 71 | outfilestem = filepath.stem + "_corrected"
|
69 | 72 | corrfilestem = filepath.stem + "_cve"
|
70 |
| - outfile = Path(outfilestem + ".chi") |
71 |
| - corrfile = Path(corrfilestem + ".chi") |
| 73 | + outfile = args.output_directory / (outfilestem + ".chi") |
| 74 | + corrfile = args.output_directory / (corrfilestem + ".chi") |
72 | 75 |
|
73 | 76 | if outfile.exists() and not args.force_overwrite:
|
74 | 77 | sys.exit(
|
75 |
| - f"output file {str(outfile)} already exists. Please rerun " |
76 |
| - f"specifying -f if you want to overwrite it" |
| 78 | + f"Output file {str(outfile)} already exists. Please rerun " |
| 79 | + f"specifying -f if you want to overwrite it." |
77 | 80 | )
|
78 | 81 | if corrfile.exists() and args.output_correction and not args.force_overwrite:
|
79 | 82 | sys.exit(
|
80 |
| - f"corrections file {str(corrfile)} was requested and already " |
81 |
| - f"exists. Please rerun specifying -f if you want to overwrite it" |
| 83 | + f"Corrections file {str(corrfile)} was requested and already " |
| 84 | + f"exists. Please rerun specifying -f if you want to overwrite it." |
82 | 85 | )
|
83 | 86 |
|
84 | 87 | input_pattern = Diffraction_object(wavelength=args.wavelength)
|
|
0 commit comments