Skip to content

Commit 6954a29

Browse files
change default to fast cve, add brute-force option, handle muD out-of-range error
1 parent 329a895 commit 6954a29

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/diffpy/labpdfproc/labpdfprocapp.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sys
22
from argparse import ArgumentParser
33

4+
from diffpy.labpdfproc.fast_cve import apply_fast_corr, fast_compute_cve
45
from diffpy.labpdfproc.functions import apply_corr, compute_cve
56
from diffpy.labpdfproc.tools import known_sources, load_metadata, preprocessing_args
67
from diffpy.utils.parsers.loaddata import loadData
@@ -72,6 +73,13 @@ def get_args(override_cli_inputs=None):
7273
action="store_true",
7374
help="Outputs will not overwrite existing file unless --force is specified.",
7475
)
76+
p.add_argument(
77+
"-b",
78+
"--brute-force",
79+
action="store_true",
80+
help="The absorption correction will be computed using brute-force calculation "
81+
"if this flag is set. Default is using fast calculation. ",
82+
)
7583
p.add_argument(
7684
"-u",
7785
"--user-metadata",
@@ -134,11 +142,20 @@ def main():
134142
metadata=load_metadata(args, filepath),
135143
)
136144

137-
absorption_correction = compute_cve(input_pattern, args.mud, args.wavelength)
138-
corrected_data = apply_corr(input_pattern, absorption_correction)
145+
if args.brute_force:
146+
absorption_correction = compute_cve(input_pattern, args.mud, args.wavelength)
147+
corrected_data = apply_corr(input_pattern, absorption_correction)
148+
else:
149+
if args.mud > 6 or args.mud < 0.5:
150+
sys.exit(
151+
"mu*D is out of the acceptable range (0.5 to 6) for fast calculation. "
152+
"Please rerun with a value within this range or use -b enable brute-force calculation. "
153+
)
154+
absorption_correction = fast_compute_cve(input_pattern, args.mud, args.wavelength)
155+
corrected_data = apply_fast_corr(input_pattern, absorption_correction)
156+
139157
corrected_data.name = f"Absorption corrected input_data: {input_pattern.name}"
140158
corrected_data.dump(f"{outfile}", xtype="tth")
141-
142159
if args.output_correction:
143160
absorption_correction.dump(f"{corrfile}", xtype="tth")
144161

0 commit comments

Comments
 (0)