Skip to content

Commit 6e0e447

Browse files
corrected mu vs muD usage, remove packing fraction option
1 parent 53ee55d commit 6e0e447

File tree

4 files changed

+75
-115
lines changed

4 files changed

+75
-115
lines changed

news/remove-packing-fraction.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* <news item>
4+
5+
**Changed:**
6+
7+
* <news item>
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* <news item>
20+
21+
**Security:**
22+
23+
* <news item>

src/diffpy/labpdfproc/labpdfprocapp.py

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@
1212
from diffpy.utils.diffraction_objects import XQUANTITIES, DiffractionObject
1313
from diffpy.utils.parsers.loaddata import loadData
1414

15-
theoretical_mud_hmsg_suffix = (
16-
"in that exact order, "
17-
"separated by commas (e.g., ZrO2,17.45,0.5). "
18-
"If you add whitespaces, "
19-
"enclose it in quotes (e.g., 'ZrO2, 17.45, 0.5'). "
20-
)
21-
2215

2316
def _define_arguments():
2417
args = [
@@ -163,45 +156,38 @@ def _add_mud_selection_group(p, is_gui=False):
163156
1. Manually enter muD (`--mud`).
164157
2. Estimate from a z-scan file (`-z` or `--z-scan-file`).
165158
3. Estimate theoretically based on sample mass density
166-
(`-d` or `--theoretical-from-density`).
167-
4. Estimate theoretically based on packing fraction
168-
(`-p` or `--theoretical-from-packing`).
159+
(`-t` or `--theoretical-estimation`).
169160
"""
170-
g = p.add_argument_group("Options for setting mu*D value (Required)")
161+
g = p.add_argument_group("Options for setting muD value (Required)")
171162
g = g.add_mutually_exclusive_group(required=True)
172163
g.add_argument(
173164
"--mud",
174165
type=float,
175-
help="Enter the mu*D value manually.",
166+
help="Enter the muD value manually.",
176167
**({"widget": "DecimalField"} if is_gui else {}),
177168
)
178169
g.add_argument(
179170
"-z",
180171
"--z-scan-file",
181172
help=(
182-
"Estimate mu*D experimentally from a z-scan file. "
173+
"Estimate muD experimentally from a z-scan file. "
183174
"Specify the path to the file "
184175
"used to compute the mu*D value."
185176
),
186177
**({"widget": "FileChooser"} if is_gui else {}),
187178
)
188179
g.add_argument(
189-
"-d",
190-
"--theoretical-from-density",
191-
help=(
192-
"Estimate mu*D theoretically using sample mass density. "
193-
"Specify the chemical formula, incident x-ray energy (in keV), "
194-
"and sample mass density (in g/cm^3), "
195-
+ theoretical_mud_hmsg_suffix
196-
),
197-
)
198-
g.add_argument(
199-
"-p",
200-
"--theoretical-from-packing",
180+
"-t",
181+
"--theoretical-estimation",
201182
help=(
202-
"Estimate mu*D theoretically using packing fraction. "
183+
"Estimate muD theoretically. "
203184
"Specify the chemical formula, incident x-ray energy (in keV), "
204-
"and packing fraction (0 to 1), " + theoretical_mud_hmsg_suffix
185+
"sample mass density (in g/cm^3), "
186+
"and capillary diameter (in mm) "
187+
"in that exact order, "
188+
"separated by commas (e.g., ZrO2,17.45,0.5,1.0). "
189+
"If you add whitespaces, "
190+
"enclose it in quotes (e.g., 'ZrO2, 17.45, 0.5, 1.0'). "
205191
),
206192
)
207193
return p

src/diffpy/labpdfproc/tools.py

Lines changed: 26 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,15 @@
3434

3535
# Exclude wavelength to avoid duplication,
3636
# as it's written explicitly by diffpy.utils dump function.
37-
# Exclude "theoretical_from_density" and "theoretical_from_packing"
38-
# as they are only used for theoretical mu*D estimation
39-
# and will be written into separate arguments for clarity.
37+
# Exclude "theoretical_estimation"
38+
# as it will be written into separate arguments for clarity.
4039
METADATA_KEYS_TO_EXCLUDE = [
4140
"output_correction",
4241
"force_overwrite",
4342
"input",
4443
"input_paths",
4544
"wavelength",
46-
"theoretical_from_density",
47-
"theoretical_from_packing",
45+
"theoretical_estimation",
4846
]
4947

5048

@@ -320,49 +318,37 @@ def _set_mud_from_zscan(args):
320318
def _parse_theoretical_input(input_str):
321319
"""Helper function to parse and validate the input string."""
322320
parts = [part.strip() for part in input_str.split(",")]
323-
if len(parts) != 3:
321+
if len(parts) != 4:
324322
raise ValueError(
325-
f"Invalid mu*D input '{input_str}'. "
323+
f"Invalid muD input '{input_str}'. "
326324
"Expected format is 'sample composition, energy, "
327-
"sample mass density or packing fraction' "
328-
"(e.g., 'ZrO2,17.45,0.5').",
325+
"sample mass density, diameter' "
326+
"(e.g., 'ZrO2,17.45,0.5,1.0').",
329327
)
330328
sample_composition = parts[0]
331329
energy = float(parts[1])
332-
mass_density_or_packing_fraction = float(parts[2])
333-
return sample_composition, energy, mass_density_or_packing_fraction
330+
sample_mass_density = float(parts[2])
331+
diameter = float(parts[3])
332+
return sample_composition, energy, sample_mass_density, diameter
334333

335334

336-
def _set_theoretical_mud_from_density(args):
335+
def _set_theoretical_mud(args):
337336
"""Theoretical estimation of mu*D from
338-
sample composition, energy, and sample mass density."""
339-
sample_composition, energy, sample_mass_density = _parse_theoretical_input(
340-
args.theoretical_from_density
337+
sample composition, energy, sample mass density, and capillary diameter"""
338+
sample_composition, energy, sample_mass_density, diameter = (
339+
_parse_theoretical_input(args.theoretical_estimation)
341340
)
342341
args.sample_composition = sample_composition
343342
args.energy = energy
344343
args.sample_mass_density = sample_mass_density
345-
args.mud = compute_mu_using_xraydb(
346-
args.sample_composition,
347-
args.energy,
348-
sample_mass_density=args.sample_mass_density,
349-
)
350-
return args
351-
352-
353-
def _set_theoretical_mud_from_packing(args):
354-
"""Theoretical estimation of mu*D from
355-
sample composition, energy, and packing fraction."""
356-
sample_composition, energy, packing_fraction = _parse_theoretical_input(
357-
args.theoretical_from_packing
358-
)
359-
args.sample_composition = sample_composition
360-
args.energy = energy
361-
args.packing_fraction = packing_fraction
362-
args.mud = compute_mu_using_xraydb(
363-
args.sample_composition,
364-
args.energy,
365-
packing_fraction=args.packing_fraction,
344+
args.diameter = diameter
345+
args.mud = (
346+
compute_mu_using_xraydb(
347+
args.sample_composition,
348+
args.energy,
349+
sample_mass_density=args.sample_mass_density,
350+
)
351+
* args.diameter
366352
)
367353
return args
368354

@@ -373,8 +359,7 @@ def set_mud(args):
373359
Options include:
374360
1. Manually entering a value.
375361
2. Estimating from a z-scan file.
376-
3. Estimating theoretically based on sample mass density.
377-
4. Estimating theoretically based on packing fraction.
362+
3. Estimating theoretically based on relevant chemical info.
378363
379364
Parameters
380365
----------
@@ -384,14 +369,12 @@ def set_mud(args):
384369
Returns
385370
-------
386371
args : argparse.Namespace
387-
The updated arguments with mu*D.
372+
The updated arguments with muD.
388373
"""
389374
if args.z_scan_file:
390375
return _set_mud_from_zscan(args)
391-
elif args.theoretical_from_density:
392-
return _set_theoretical_mud_from_density(args)
393-
elif args.theoretical_from_packing:
394-
return _set_theoretical_mud_from_packing(args)
376+
elif args.theoretical_estimation:
377+
return _set_theoretical_mud(args)
395378
return args
396379

397380

tests/test_tools.py

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -461,14 +461,10 @@ 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,
464+
# sample mass density, and diameter
465465
# both with and without whitespaces, expect to estimate theoretically
466-
(["--theoretical-from-density", "ZrO2,17.45,1.2"], 1.49),
467-
(["--theoretical-from-density", "ZrO2, 17.45, 1.2"], 1.49),
468-
# C4: user specifies sample composition, energy, and packing fraction
469-
# both with and without whitespaces, expect to estimate theoretically
470-
# (["--theoretical-from-packing", "ZrO2,17.45,0.3"], 1.49),
471-
# (["--theoretical-from-packing", "ZrO2, 17.45, 0.3"], 1.49),
466+
(["--theoretical-estimation", "ZrO2,17.45,1.2,1.0"], 1.49),
467+
(["--theoretical-estimation", "ZrO2, 17.45, 1.2, 1.0"], 1.49),
472468
],
473469
)
474470
def test_set_mud(user_filesystem, inputs, expected_mud):
@@ -492,56 +488,28 @@ def test_set_mud(user_filesystem, inputs, expected_mud):
492488
"Cannot find invalid file. Please specify a valid file path.",
493489
],
494490
),
495-
# C2.1: (sample mass density option)
496-
# user provides fewer than three input values
497-
# expect ValueError with a message indicating the correct format
498-
(
499-
["--theoretical-from-density", "ZrO2,0.5"],
500-
[
501-
ValueError,
502-
"Invalid mu*D input 'ZrO2,0.5'. "
503-
"Expected format is 'sample composition, energy, "
504-
"sample mass density or packing fraction' "
505-
"(e.g., 'ZrO2,17.45,0.5').",
506-
],
507-
),
508-
# C2.2: (packing fraction option)
509-
# user provides fewer than three input values
510-
# expect ValueError with a message indicating the correct format
511-
(
512-
["--theoretical-from-packing", "ZrO2,0.5"],
513-
[
514-
ValueError,
515-
"Invalid mu*D input 'ZrO2,0.5'. "
516-
"Expected format is 'sample composition, energy, "
517-
"sample mass density or packing fraction' "
518-
"(e.g., 'ZrO2,17.45,0.5').",
519-
],
520-
),
521-
# C3.1: (sample mass density option)
522-
# user provides more than 3 input values
491+
# C2: user provides fewer than 4 inputs for theoretical estimation,
523492
# expect ValueError with a message indicating the correct format
524493
(
525-
["--theoretical-from-density", "ZrO2,17.45,1.5,0.5"],
494+
["--theoretical-estimation", "ZrO2,0.5"],
526495
[
527496
ValueError,
528-
"Invalid mu*D input 'ZrO2,17.45,1.5,0.5'. "
497+
"Invalid muD input 'ZrO2,0.5'. "
529498
"Expected format is 'sample composition, energy, "
530-
"sample mass density or packing fraction' "
531-
"(e.g., 'ZrO2,17.45,0.5').",
499+
"sample mass density, diameter' "
500+
"(e.g., 'ZrO2,17.45,0.5,1.0').",
532501
],
533502
),
534-
# C3.2: (packing fraction option)
535-
# user provides more than 3 input values
503+
# C3: user provides more than 4 inputs for theoretical estimation,
536504
# expect ValueError with a message indicating the correct format
537505
(
538-
["--theoretical-from-packing", "ZrO2,17.45,1.5,0.5"],
506+
["--theoretical-estimation", "ZrO2,17.45,1.5,0.5,1.0"],
539507
[
540508
ValueError,
541-
"Invalid mu*D input 'ZrO2,17.45,1.5,0.5'. "
509+
"Invalid muD input 'ZrO2,17.45,1.5,0.5,1.0'. "
542510
"Expected format is 'sample composition, energy, "
543-
"sample mass density or packing fraction' "
544-
"(e.g., 'ZrO2,17.45,0.5').",
511+
"sample mass density, diameter' "
512+
"(e.g., 'ZrO2,17.45,0.5,1.0').",
545513
],
546514
),
547515
],

0 commit comments

Comments
 (0)