Skip to content

Commit 76d8975

Browse files
change value error to warning msg
1 parent 03eaa87 commit 76d8975

File tree

2 files changed

+9
-49
lines changed

2 files changed

+9
-49
lines changed

src/diffpy/utils/transforms.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
"The supplied q-array and wavelength will result in an impossible two-theta. "
1717
"Please check these values and re-instantiate the DiffractionObject with correct values."
1818
)
19-
invalid_input_emsg = (
20-
"Input values have resulted in an infinite output. Please ensure there are no zeros in the input."
21-
)
19+
inf_output_msg = "WARNING: The largest output is infinite and cannot be plotted."
2220

2321

2422
def _validate_inputs(q, wavelength):
@@ -61,7 +59,6 @@ def q_to_tth(q, wavelength):
6159
-------
6260
tth : 1D array
6361
The array of :math:`2\theta` values in degrees numpy.array([tths]).
64-
This is the correct format for loading into diffpy.utils.DiffractionObject.on_tth.
6562
"""
6663
_validate_inputs(q, wavelength)
6764
q.astype(float)
@@ -107,7 +104,6 @@ def tth_to_q(tth, wavelength):
107104
q : 1D array
108105
The array of :math:`q` values np.array([qs]).
109106
The units for the q-values are the inverse of the units of the provided wavelength.
110-
This is the correct format for loading into diffpy.utils.DiffractionObject.on_q.
111107
"""
112108
tth.astype(float)
113109
if np.any(np.deg2rad(tth) > np.pi):
@@ -138,8 +134,8 @@ def q_to_d(q):
138134
The array of :math:`d` values np.array([ds]).
139135
"""
140136
if 0 in q:
141-
raise ValueError(invalid_input_emsg)
142-
return 2.0 * np.pi / copy(q)[::-1]
137+
warnings.warn(inf_output_msg)
138+
return 2.0 * np.pi / copy(q)
143139

144140

145141
def tth_to_d(ttharray, wavelength):
@@ -163,8 +159,8 @@ def d_to_q(d):
163159
The units of q must be reciprocal of the units of wavelength.
164160
"""
165161
if 0 in d:
166-
raise ValueError(invalid_input_emsg)
167-
return 2.0 * np.pi / copy(d)[::-1]
162+
warnings.warn(inf_output_msg)
163+
return 2.0 * np.pi / copy(d)
168164

169165

170166
def d_to_tth(darray, wavelength):

tests/test_transforms.py

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ def test_tth_to_q_bad(inputs, expected):
103103
([np.array([])], np.array([])),
104104
# UC2: User specified valid q values
105105
(
106-
[np.array([np.pi / 6, 1 * np.pi, 2 * np.pi, 3 * np.pi, 4 * np.pi, 5 * np.pi])],
107-
np.array([0.4, 0.5, 0.66667, 1, 2, 12]),
106+
[np.array([5 * np.pi, 4 * np.pi, 3 * np.pi, 2 * np.pi, np.pi, 0])],
107+
np.array([0.4, 0.5, 0.66667, 1, 2, np.inf]),
108108
),
109109
]
110110

@@ -115,31 +115,13 @@ def test_q_to_d(inputs, expected):
115115
assert np.allclose(actual, expected)
116116

117117

118-
params_q_to_d_bad = [
119-
# UC1: user specified an invalid q value that results in an infinite d value
120-
(
121-
[np.array([0, 1, 2, 3, 4])],
122-
[
123-
ValueError,
124-
"Input values have resulted in an infinite output. Please ensure there are no zeros in the input.",
125-
],
126-
),
127-
]
128-
129-
130-
@pytest.mark.parametrize("inputs, expected", params_q_to_d_bad)
131-
def test_q_to_d_bad(inputs, expected):
132-
with pytest.raises(expected[0], match=expected[1]):
133-
q_to_d(inputs[0])
134-
135-
136118
params_d_to_q = [
137119
# UC1: User specified empty d values
138120
([np.array([])], np.array([])),
139121
# UC2: User specified valid d values
140122
(
141-
[np.array([np.pi / 6, 1 * np.pi, 2 * np.pi, 3 * np.pi, 4 * np.pi, 5 * np.pi])],
142-
np.array([0.4, 0.5, 0.66667, 1, 2, 12]),
123+
[np.array([0, 1 * np.pi, 2 * np.pi, 3 * np.pi, 4 * np.pi, 5 * np.pi])],
124+
np.array([np.inf, 2, 1, 0.66667, 0.5, 0.4]),
143125
),
144126
]
145127

@@ -148,21 +130,3 @@ def test_q_to_d_bad(inputs, expected):
148130
def test_d_to_q(inputs, expected):
149131
actual = d_to_q(inputs[0])
150132
assert np.allclose(actual, expected)
151-
152-
153-
params_d_to_q_bad = [
154-
# UC1: user specified an invalid d value that results in an infinite q value
155-
(
156-
[np.array([0, 1, 2, 3, 4])],
157-
[
158-
ValueError,
159-
"Input values have resulted in an infinite output. Please ensure there are no zeros in the input.",
160-
],
161-
),
162-
]
163-
164-
165-
@pytest.mark.parametrize("inputs, expected", params_d_to_q_bad)
166-
def test_d_to_q_bad(inputs, expected):
167-
with pytest.raises(expected[0], match=expected[1]):
168-
d_to_q(inputs[0])

0 commit comments

Comments
 (0)