Skip to content

Commit 421c8de

Browse files
feat: allow whitespace for muD options 3 and 4, slight tweak in help msg
1 parent f4dd476 commit 421c8de

File tree

3 files changed

+33
-27
lines changed

3 files changed

+33
-27
lines changed

src/diffpy/labpdfproc/labpdfprocapp.py

+14-15
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ def _define_arguments():
2121
"The filename(s) or folder(s) of the datafile(s) to load. "
2222
"Required.\n"
2323
"Supply a space-separated list of files or directories. "
24+
"If a filename contains whitespace, enclose it in quotes. "
2425
"Long lists can be supplied, one per line, "
2526
"in a file with name file_list.txt. "
2627
"If one or more directory is provided, all valid "
2728
"data-files in that directory will be processed. "
2829
"Examples of valid inputs are 'file.xy', 'data/file.xy', "
29-
"'file.xy, data/file.xy', "
30+
"'file.xy data/file.xy', "
3031
"'.' (load everything in the current directory), "
3132
"'data' (load everything in the folder ./data), "
3233
"'data/file_list.txt' (load the list of files "
@@ -177,29 +178,27 @@ def _add_mud_selection_group(p, is_gui=False):
177178
**({"widget": "FileChooser"} if is_gui else {}),
178179
)
179180
g.add_argument(
180-
"-td",
181+
"-d",
181182
"--theoretical-from-density",
182183
help=(
183184
"Estimate mu*D theoretically using sample mass density. "
184-
"Specify the sample composition (chemical formula), "
185-
"incident x-ray energy in keV, "
186-
"and sample mass density in g/cm^3 "
187-
"in that exact order "
188-
"and separated by commas with no whitespaces "
189-
"(e.g., 'ZrO2,2,1.2')."
185+
"Specify the chemical formula, incident x-ray energy (in keV), "
186+
"and sample mass density (in g/cm^3), in that exact order, "
187+
"separated by commas (e.g., ZrO2,20,1.5). "
188+
"If you add whitespaces, "
189+
"enclose it in quotes (e.g., 'ZrO2, 20, 1.5'). "
190190
),
191191
)
192192
g.add_argument(
193-
"-tp",
193+
"-p",
194194
"--theoretical-from-packing",
195195
help=(
196196
"Estimate mu*D theoretically using packing fraction. "
197-
"Specify the sample composition (chemical formula), "
198-
"incident x-ray energy in keV, "
199-
"and packing fraction (0 to 1) "
200-
"in that exact order "
201-
"and separated by commas with no whitespaces "
202-
"(e.g., 'ZrO2,2,0.5')."
197+
"Specify the chemical formula, incident x-ray energy (in keV), "
198+
"and packing fraction (0 to 1), in that exact order, "
199+
"separated by commas (e.g., ZrO2,20,0.5). "
200+
"If you add whitespaces, "
201+
"enclose it in quotes (e.g., 'ZrO2, 20, 0.5'). "
203202
),
204203
)
205204
return p

src/diffpy/labpdfproc/tools.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -319,13 +319,13 @@ def _set_mud_from_zscan(args):
319319

320320
def _parse_theoretical_input(input_str):
321321
"""Helper function to parse and validate the input string."""
322-
parts = input_str.split(",")
322+
parts = [part.strip() for part in input_str.split(",")]
323323
if len(parts) != 3:
324324
raise ValueError(
325325
f"Invalid mu*D input '{input_str}'. "
326326
"Expected format is 'sample composition, energy, "
327327
"sample mass density or packing fraction' "
328-
"with no whitespaces (e.g., 'ZrO2,2,0.8').",
328+
"(e.g., 'ZrO2,20,0.8').",
329329
)
330330
sample_composition = parts[0]
331331
energy = float(parts[1])

tests/test_tools.py

+17-10
Original file line numberDiff line numberDiff line change
@@ -461,11 +461,14 @@ def test_set_xtype_bad():
461461
# C2: user provides a z-scan file, expect to estimate through the file
462462
(["--z-scan-file", "test_dir/testfile.xy"], 3),
463463
# C3: user specifies sample composition, energy,
464-
# and sample mass density, expect to estimate theoretically
464+
# and sample mass density,
465+
# both with and without whitespaces, expect to estimate theoretically
465466
(["--theoretical-from-density", "ZrO2,17.45,1.2"], 1.49),
467+
(["--theoretical-from-density", "ZrO2, 17.45, 1.2"], 1.49),
466468
# C4: user specifies sample composition, energy, and packing fraction
467-
# expect to estimate theoretically
469+
# both with and without whitespaces, expect to estimate theoretically
468470
# (["--theoretical-from-packing", "ZrO2,17.45,0.3"], 1.49),
471+
# (["--theoretical-from-packing", "ZrO2, 17.45, 0.3"], 1.49),
469472
],
470473
)
471474
def test_set_mud(user_filesystem, inputs, expected_mud):
@@ -489,7 +492,8 @@ def test_set_mud(user_filesystem, inputs, expected_mud):
489492
"Cannot find invalid file. Please specify a valid file path.",
490493
],
491494
),
492-
# C2.1: user provides fewer than three input values
495+
# C2.1: (sample mass density option)
496+
# user provides fewer than three input values
493497
# expect ValueError with a message indicating the correct format
494498
(
495499
["--theoretical-from-density", "ZrO2,0.5"],
@@ -498,10 +502,11 @@ def test_set_mud(user_filesystem, inputs, expected_mud):
498502
"Invalid mu*D input 'ZrO2,0.5'. "
499503
"Expected format is 'sample composition, energy, "
500504
"sample mass density or packing fraction' "
501-
"with no whitespaces (e.g., 'ZrO2,2,0.8').",
505+
"(e.g., 'ZrO2,20,0.8').",
502506
],
503507
),
504-
# C2.1: user provides fewer than three input values
508+
# C2.2: (packing fraction option)
509+
# user provides fewer than three input values
505510
# expect ValueError with a message indicating the correct format
506511
(
507512
["--theoretical-from-packing", "ZrO2,0.5"],
@@ -510,10 +515,11 @@ def test_set_mud(user_filesystem, inputs, expected_mud):
510515
"Invalid mu*D input 'ZrO2,0.5'. "
511516
"Expected format is 'sample composition, energy, "
512517
"sample mass density or packing fraction' "
513-
"with no whitespaces (e.g., 'ZrO2,2,0.8').",
518+
"(e.g., 'ZrO2,20,0.8').",
514519
],
515520
),
516-
# C3.1: user provides more than 3 input values
521+
# C3.1: (sample mass density option)
522+
# user provides more than 3 input values
517523
# expect ValueError with a message indicating the correct format
518524
(
519525
["--theoretical-from-density", "ZrO2,1.5,1.5,0.5"],
@@ -522,10 +528,11 @@ def test_set_mud(user_filesystem, inputs, expected_mud):
522528
"Invalid mu*D input 'ZrO2,1.5,1.5,0.5'. "
523529
"Expected format is 'sample composition, energy, "
524530
"sample mass density or packing fraction' "
525-
"with no whitespaces (e.g., 'ZrO2,2,0.8').",
531+
"(e.g., 'ZrO2,20,0.8').",
526532
],
527533
),
528-
# C3.2: user provides more than 3 input values
534+
# C3.2: (packing fraction option)
535+
# user provides more than 3 input values
529536
# expect ValueError with a message indicating the correct format
530537
(
531538
["--theoretical-from-packing", "ZrO2,1.5,1.5,0.5"],
@@ -534,7 +541,7 @@ def test_set_mud(user_filesystem, inputs, expected_mud):
534541
"Invalid mu*D input 'ZrO2,1.5,1.5,0.5'. "
535542
"Expected format is 'sample composition, energy, "
536543
"sample mass density or packing fraction' "
537-
"with no whitespaces (e.g., 'ZrO2,2,0.8').",
544+
"(e.g., 'ZrO2,20,0.8').",
538545
],
539546
),
540547
],

0 commit comments

Comments
 (0)