Skip to content

Commit 2de70ed

Browse files
update q_to_tth, d_to_tth
1 parent 01470c1 commit 2de70ed

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/diffpy/utils/scattering_objects/diffraction_objects.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,9 @@ def q_to_tth(self):
323323
q = np.asarray(q)
324324
wavelength = float(self.wavelength)
325325
pre_factor = wavelength / (4 * np.pi)
326-
return np.rad2deg(2.0 * np.arcsin(q * pre_factor))
326+
# limit q * pre_factor to 1 to avoid invalid input to arcsin
327+
arcsin_value = np.where(q * pre_factor <= 1, q * pre_factor, 1)
328+
return np.rad2deg(2.0 * np.arcsin(arcsin_value))
327329

328330
def tth_to_q(self):
329331
r"""
@@ -450,26 +452,26 @@ def d_to_tth(self):
450452
"""
451453
d = np.asarray(self.on_d[0])
452454
wavelength = float(self.wavelength)
453-
tth = np.where(d != 0, np.rad2deg(2.0 * np.arcsin(wavelength / (2 * d))), 180)
454-
return tth[::-1]
455+
pre_factor = np.where(d != 0, wavelength / (2 * d), 1)
456+
return np.rad2deg(2.0 * np.arcsin(pre_factor))[::-1]
455457

456458
def set_all_arrays(self):
457459
master_array, xtype = self._get_original_array()
458460
if xtype == "q":
459461
self.on_tth[0] = self.q_to_tth()
460462
self.on_tth[1] = master_array[1]
461463
self.on_d[0] = self.q_to_d()
462-
self.on_d[1] = master_array[1][::-1]
464+
self.on_d[1] = master_array[1]
463465
if xtype == "tth":
464466
self.on_q[0] = self.tth_to_q()
465467
self.on_q[1] = master_array[1]
466468
self.on_d[0] = self.tth_to_d()
467-
self.on_d[1] = master_array[1][::-1]
469+
self.on_d[1] = master_array[1]
468470
if xtype == "d":
469471
self.on_tth[0] = self.d_to_tth()
470-
self.on_tth[1] = master_array[1][::-1]
472+
self.on_tth[1] = master_array[1]
471473
self.on_q[0] = self.d_to_q()
472-
self.on_q[1] = master_array[1][::-1]
474+
self.on_q[1] = master_array[1]
473475
self.tthmin = self.on_tth[0][0]
474476
self.tthmax = self.on_tth[0][-1]
475477
self.qmin = self.on_q[0][0]

0 commit comments

Comments
 (0)