Skip to content

Commit 6f50e0c

Browse files
corrected mu vs muD usage, remove packing fraction option
1 parent d61ee4e commit 6f50e0c

File tree

4 files changed

+78
-118
lines changed

4 files changed

+78
-118
lines changed

news/remove-pf.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* no news added - corrected mu vs muD usage and removed packing fraction option for estimating muD
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: 15 additions & 29 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,46 +156,39 @@ def _add_mud_selection_group(p, use_gui=False):
163156
"""Current Options:
164157
1. Manually enter muD (`--mud`).
165158
2. Estimate from a z-scan file (`-z` or `--z-scan-file`).
166-
3. Estimate theoretically based on sample mass density
167-
(`-d` or `--theoretical-from-density`).
168-
4. Estimate theoretically based on packing fraction
169-
(`-p` or `--theoretical-from-packing`).
159+
3. Estimate theoretically based on relevant chemical information
160+
(`-t` or `--theoretical-estimation`).
170161
"""
171-
g = p.add_argument_group("Options for setting mu*D value (Required)")
162+
g = p.add_argument_group("Options for setting muD value (Required)")
172163
g = g.add_mutually_exclusive_group(required=True)
173164
g.add_argument(
174165
"--mud",
175166
type=float,
176-
help="Enter the mu*D value manually.",
167+
help="Enter the muD value manually.",
177168
**({"widget": "DecimalField"} if use_gui else {}),
178169
)
179170
g.add_argument(
180171
"-z",
181172
"--z-scan-file",
182173
help=(
183-
"Estimate mu*D experimentally from a z-scan file. "
174+
"Estimate muD experimentally from a z-scan file. "
184175
"Specify the path to the file "
185-
"used to compute the mu*D value."
176+
"used to compute the muD value."
186177
),
187178
**({"widget": "FileChooser"} if use_gui else {}),
188179
)
189180
g.add_argument(
190-
"-d",
191-
"--theoretical-from-density",
192-
help=(
193-
"Estimate mu*D theoretically using sample mass density. "
194-
"Specify the chemical formula, incident x-ray energy (in keV), "
195-
"and sample mass density (in g/cm^3), "
196-
+ theoretical_mud_hmsg_suffix
197-
),
198-
)
199-
g.add_argument(
200-
"-p",
201-
"--theoretical-from-packing",
181+
"-t",
182+
"--theoretical-estimation",
202183
help=(
203-
"Estimate mu*D theoretically using packing fraction. "
184+
"Estimate muD theoretically. "
204185
"Specify the chemical formula, incident x-ray energy (in keV), "
205-
"and packing fraction (0 to 1), " + theoretical_mud_hmsg_suffix
186+
"sample mass density (in g/cm^3), "
187+
"and capillary diameter (in mm) "
188+
"in that exact order, "
189+
"separated by commas (e.g., ZrO2,17.45,0.5,1.0). "
190+
"If you add whitespaces, "
191+
"enclose it in quotes (e.g., 'ZrO2, 17.45, 0.5, 1.0'). "
206192
),
207193
)
208194
return p

src/diffpy/labpdfproc/tools.py

Lines changed: 27 additions & 44 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
"subcommand",
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, capillary 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+
capillary_diameter = float(parts[3])
332+
return sample_composition, energy, sample_mass_density, capillary_diameter
334333

335334

336-
def _set_theoretical_mud_from_density(args):
337-
"""Theoretical estimation of mu*D from sample composition, energy, and
338-
sample mass density."""
339-
sample_composition, energy, sample_mass_density = _parse_theoretical_input(
340-
args.theoretical_from_density
335+
def _set_theoretical_mud(args):
336+
"""Theoretical estimation of muD from sample composition, energy, sample
337+
mass density, and capillary diameter."""
338+
sample_composition, energy, sample_mass_density, capillary_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 sample composition, energy, and
355-
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.capillary_diameter = capillary_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.capillary_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
@@ -462,14 +462,10 @@ def test_set_xtype_bad():
462462
# C2: user provides a z-scan file, expect to estimate through the file
463463
(["--z-scan-file", "test_dir/testfile.xy"], 3),
464464
# C3: user specifies sample composition, energy,
465-
# and sample mass density,
465+
# sample mass density, and capillary diameter,
466466
# both with and without whitespaces, expect to estimate theoretically
467-
(["--theoretical-from-density", "ZrO2,17.45,1.2"], 1.49),
468-
(["--theoretical-from-density", "ZrO2, 17.45, 1.2"], 1.49),
469-
# C4: user specifies sample composition, energy, and packing fraction
470-
# both with and without whitespaces, expect to estimate theoretically
471-
# (["--theoretical-from-packing", "ZrO2,17.45,0.3"], 1.49),
472-
# (["--theoretical-from-packing", "ZrO2, 17.45, 0.3"], 1.49),
467+
(["--theoretical-estimation", "ZrO2,17.45,1.2,1.0"], 1.49),
468+
(["--theoretical-estimation", "ZrO2, 17.45, 1.2,1.0"], 1.49),
473469
],
474470
)
475471
def test_set_mud(user_filesystem, inputs, expected_mud):
@@ -493,56 +489,28 @@ def test_set_mud(user_filesystem, inputs, expected_mud):
493489
"Cannot find invalid file. Please specify a valid file path.",
494490
],
495491
),
496-
# C2.1: (sample mass density option)
497-
# user provides fewer than three input values
498-
# expect ValueError with a message indicating the correct format
499-
(
500-
["--theoretical-from-density", "ZrO2,0.5"],
501-
[
502-
ValueError,
503-
"Invalid mu*D input 'ZrO2,0.5'. "
504-
"Expected format is 'sample composition, energy, "
505-
"sample mass density or packing fraction' "
506-
"(e.g., 'ZrO2,17.45,0.5').",
507-
],
508-
),
509-
# C2.2: (packing fraction option)
510-
# user provides fewer than three input values
511-
# expect ValueError with a message indicating the correct format
512-
(
513-
["--theoretical-from-packing", "ZrO2,0.5"],
514-
[
515-
ValueError,
516-
"Invalid mu*D input 'ZrO2,0.5'. "
517-
"Expected format is 'sample composition, energy, "
518-
"sample mass density or packing fraction' "
519-
"(e.g., 'ZrO2,17.45,0.5').",
520-
],
521-
),
522-
# C3.1: (sample mass density option)
523-
# user provides more than 3 input values
492+
# C2: user provides fewer than 4 inputs for theoretical estimation,
524493
# expect ValueError with a message indicating the correct format
525494
(
526-
["--theoretical-from-density", "ZrO2,17.45,1.5,0.5"],
495+
["--theoretical-estimation", "ZrO2,0.5"],
527496
[
528497
ValueError,
529-
"Invalid mu*D input 'ZrO2,17.45,1.5,0.5'. "
498+
"Invalid muD input 'ZrO2,0.5'. "
530499
"Expected format is 'sample composition, energy, "
531-
"sample mass density or packing fraction' "
532-
"(e.g., 'ZrO2,17.45,0.5').",
500+
"sample mass density, capillary diameter' "
501+
"(e.g., 'ZrO2,17.45,0.5,1.0').",
533502
],
534503
),
535-
# C3.2: (packing fraction option)
536-
# user provides more than 3 input values
504+
# C3: user provides more than 4 inputs for theoretical estimation
537505
# expect ValueError with a message indicating the correct format
538506
(
539-
["--theoretical-from-packing", "ZrO2,17.45,1.5,0.5"],
507+
["--theoretical-estimation", "ZrO2,17.45,1.5,0.5,1.0"],
540508
[
541509
ValueError,
542-
"Invalid mu*D input 'ZrO2,17.45,1.5,0.5'. "
510+
"Invalid muD input 'ZrO2,17.45,1.5,0.5,1.0'. "
543511
"Expected format is 'sample composition, energy, "
544-
"sample mass density or packing fraction' "
545-
"(e.g., 'ZrO2,17.45,0.5').",
512+
"sample mass density, capillary diameter' "
513+
"(e.g., 'ZrO2,17.45,0.5,1.0').",
546514
],
547515
),
548516
],

0 commit comments

Comments
 (0)