Skip to content

Commit bc138c0

Browse files
authored
Merge pull request #38 from sbillinge/wavelength
wavelength
2 parents 0e2ab8c + 6b31a90 commit bc138c0

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

src/diffpy/labpdfproc/labpdfprocapp.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,27 @@
33
from pathlib import Path
44

55
from diffpy.labpdfproc.functions import apply_corr, compute_cve
6-
from diffpy.labpdfproc.tools import set_wavelength
6+
from diffpy.labpdfproc.tools import known_sources, set_wavelength
77
from diffpy.utils.parsers.loaddata import loadData
88
from diffpy.utils.scattering_objects.diffraction_objects import XQUANTITIES, Diffraction_object
99

10-
WAVELENGTHS = {"Mo": 0.71, "Ag": 0.59, "Cu": 1.54}
11-
known_sources = [key for key in WAVELENGTHS.keys()]
12-
1310

1411
def get_args():
1512
p = ArgumentParser()
1613
p.add_argument("mud", help="Value of mu*D for your " "sample. Required.", type=float)
1714
p.add_argument("-i", "--input-file", help="The filename of the " "datafile to load")
1815
p.add_argument(
19-
"-a", "--anode-type", help=f"X-ray source, allowed " f"values: {*[known_sources], }", default="Mo"
16+
"-a",
17+
"--anode-type",
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",
20+
default="Mo",
2021
)
2122
p.add_argument(
2223
"-w",
2324
"--wavelength",
24-
help="X-ray source wavelength. Not needed if the anode-type "
25-
"is specified. This will override the wavelength if anode "
26-
"type is specified",
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",
2727
default=None,
2828
type=float,
2929
)
@@ -55,7 +55,7 @@ def get_args():
5555
"-f",
5656
"--force-overwrite",
5757
action="store_true",
58-
help="outputs will not overwrite existing file unless --force is spacified",
58+
help="outputs will not overwrite existing files unless --force is spacified",
5959
)
6060
args = p.parse_args()
6161
return args

src/diffpy/labpdfproc/tests/test_tools.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pytest
44

5-
from diffpy.labpdfproc.tools import set_wavelength
5+
from diffpy.labpdfproc.tools import known_sources, set_wavelength
66

77
params2 = [
88
([None, None], [0.71]),
@@ -21,14 +21,17 @@ def test_set_wavelength(inputs, expected):
2121

2222

2323
params3 = [
24-
([None, "invalid"]),
25-
([0, None]),
26-
([-1, "Mo"]),
24+
(
25+
[None, "invalid"],
26+
[f"Anode type not recognized. please rerun specifying an anode_type from {*known_sources, }"],
27+
),
28+
([0, None], ["No valid wavelength. Please rerun specifying a known anode_type or a positive wavelength"]),
29+
([-1, "Mo"], ["No valid wavelength. Please rerun specifying a known anode_type or a positive wavelength"]),
2730
]
2831

2932

30-
@pytest.mark.parametrize("inputs", params3)
31-
def test_set_wavelength_bad(inputs):
32-
with pytest.raises(ValueError):
33-
actual_args = argparse.Namespace(wavelength=inputs[0], anode_type=inputs[1])
33+
@pytest.mark.parametrize("inputs, msg", params3)
34+
def test_set_wavelength_bad(inputs, msg):
35+
actual_args = argparse.Namespace(wavelength=inputs[0], anode_type=inputs[1])
36+
with pytest.raises(ValueError, match=msg[0]):
3437
actual_args.wavelength = set_wavelength(actual_args)

0 commit comments

Comments
 (0)