Skip to content

Commit 01470c1

Browse files
clean up docstring and test descriptions
1 parent 0534fa8 commit 01470c1

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

src/diffpy/utils/scattering_objects/diffraction_objects.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,7 @@ def tth_to_q(self):
366366

367367
def q_to_d(self):
368368
r"""
369-
Helper function to convert q to d using :math:`d = \frac{2 \pi}{q}`
370-
371-
adds a small value (epsilon = 1e-10) to `q` where `q` is close to zero to avoid division by zero
369+
Helper function to convert q to d using :math:`d = \frac{2 \pi}{q}`, set dmax to DMAX=100
372370
373371
Parameters
374372
----------
@@ -387,9 +385,7 @@ def q_to_d(self):
387385

388386
def d_to_q(self):
389387
r"""
390-
Helper function to convert d to q using :math:`q = \frac{2 \pi}{d}`
391-
392-
adds a small value (epsilon = 1e-10) to `d` where `d` is close to zero to avoid division by zero
388+
Helper function to convert d to q using :math:`q = \frac{2 \pi}{d}`, set qmax to QMAX=40
393389
394390
Parameters
395391
----------
@@ -410,8 +406,7 @@ def tth_to_d(self):
410406
r"""
411407
Helper function to convert two-theta to d
412408
413-
uses the formula .. math:: d = \frac{\lambda}{2 \sin\left(\frac{2\theta}{2}\right)},
414-
and adds a small value (epsilon = 1e-10) to sin where sin is close to zero to avoid division by zero
409+
uses the formula .. math:: d = \frac{\lambda}{2 \sin\left(\frac{2\theta}{2}\right)}, set dmax to DMAX=100
415410
416411
Parameters
417412
----------
@@ -438,8 +433,7 @@ def d_to_tth(self):
438433
r"""
439434
Helper function to convert d to two-theta
440435
441-
uses the formula .. math:: 2\theta = 2 \arcsin\left(\frac{\lambda}{2d}\right),
442-
and adds a small value (epsilon = 1e-10) to `d` where `d` is close to zero to avoid division by zero
436+
uses the formula .. math:: 2\theta = 2 \arcsin\left(\frac{\lambda}{2d}\right), set tth to 180 when d=0
443437
444438
Parameters
445439
----------
@@ -465,17 +459,17 @@ def set_all_arrays(self):
465459
self.on_tth[0] = self.q_to_tth()
466460
self.on_tth[1] = master_array[1]
467461
self.on_d[0] = self.q_to_d()
468-
self.on_d[1] = master_array[1]
462+
self.on_d[1] = master_array[1][::-1]
469463
if xtype == "tth":
470464
self.on_q[0] = self.tth_to_q()
471465
self.on_q[1] = master_array[1]
472466
self.on_d[0] = self.tth_to_d()
473-
self.on_d[1] = master_array[1]
467+
self.on_d[1] = master_array[1][::-1]
474468
if xtype == "d":
475469
self.on_tth[0] = self.d_to_tth()
476-
self.on_tth[1] = master_array[1]
470+
self.on_tth[1] = master_array[1][::-1]
477471
self.on_q[0] = self.d_to_q()
478-
self.on_q[1] = master_array[1]
472+
self.on_q[1] = master_array[1][::-1]
479473
self.tthmin = self.on_tth[0][0]
480474
self.tthmax = self.on_tth[0][-1]
481475
self.qmin = self.on_q[0][0]

tests/test_diffraction_objects.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,19 +250,19 @@ def test_tth_to_q():
250250

251251

252252
def test_q_to_d():
253-
actual = Diffraction_object(wavelength=0.71)
253+
actual = Diffraction_object()
254254
setattr(actual, "on_q", [[0, np.pi, 2 * np.pi, 3 * np.pi, 4 * np.pi, 5 * np.pi], [1, 2, 3, 4, 5, 6]])
255255
actual_d = actual.q_to_d()
256-
# expected d values are DMAX=100, 2/1, 2/2, 2/3, 2/4, 2/5, and in reverse order
256+
# expected d values are DMAX=100, 2/1, 2/2, 2/3, 2/4, 2/5, in reverse order
257257
expected_d = [0.4, 0.5, 0.66667, 1, 2, 100]
258258
assert np.allclose(actual_d, expected_d)
259259

260260

261261
def test_d_to_q():
262-
actual = Diffraction_object(wavelength=1)
262+
actual = Diffraction_object()
263263
setattr(actual, "on_d", [[0, np.pi, 2 * np.pi, 3 * np.pi, 4 * np.pi, 5 * np.pi], [1, 2, 3, 4, 5, 6]])
264264
actual_q = actual.d_to_q()
265-
# expected q values are QMAX=40, 2/1, 2/2, 2/3, 2/4, 2/5, and in reverse order
265+
# expected q values are QMAX=40, 2/1, 2/2, 2/3, 2/4, 2/5, in reverse order
266266
expected_q = [0.4, 0.5, 0.66667, 1, 2, 40]
267267
assert np.allclose(actual_q, expected_q)
268268

@@ -281,7 +281,7 @@ def test_d_to_tth():
281281
setattr(actual, "on_d", [[0, 2, 4, 6, 8, 100], [1, 2, 3, 4, 5, 6]])
282282
actual_tth = actual.d_to_tth()
283283
# expected tth values are 2*arcsin(1/d), in reverse order
284-
# when d is really small we have tth to be 180
284+
# when d is 0, we set tth to 180
285285
expected_tth = [1.14593, 14.36151, 19.18814, 28.95502, 60, 180]
286286
assert np.allclose(actual_tth, expected_tth)
287287

0 commit comments

Comments
 (0)