@@ -763,25 +763,29 @@ def q_to_tth(self):
763763
764764 2\theta_n = 2 \arcsin\left(\frac{\lambda q}{4 \pi}\right)
765765
766+ Function adapted from scikit-beam. Thanks to those developers
767+
766768 Parameters
767769 ----------
768770 q : array
769- An array of :math:`q` values
771+ The array of :math:`q` values
770772
771773 wavelength : float
772774 Wavelength of the incoming x-rays
773775
774- Function adapted from scikit-beam. Thanks to those developers
775-
776776 Returns
777777 -------
778778 two_theta : array
779- An array of :math:`2\theta` values in radians
779+ The array of :math:`2\theta` values in radians
780780 """
781781 q = self .on_q [0 ]
782782 q = np .asarray (q )
783783 wavelength = float (self .wavelength )
784784 pre_factor = wavelength / (4 * np .pi )
785+ if np .any (np .abs (q * pre_factor ) > 1 ):
786+ raise ValueError (
787+ "Invalid input for arcsin: some values exceed the range [-1, 1]. Check wavelength or q values."
788+ )
785789 return np .rad2deg (2.0 * np .arcsin (q * pre_factor ))
786790
787791 def tth_to_q (self ):
@@ -800,25 +804,25 @@ def tth_to_q(self):
800804
801805 q = \frac{4 \pi \sin\left(\frac{2\theta}{2}\right)}{\lambda}
802806
803-
807+ Function adapted from scikit-beam. Thanks to those developers.
804808
805809 Parameters
806810 ----------
807811 two_theta : array
808- An array of :math:`2\theta` values in units of degrees
812+ The array of :math:`2\theta` values in units of degrees
809813
810814 wavelength : float
811815 Wavelength of the incoming x-rays
812816
813- Function adapted from scikit-beam. Thanks to those developers.
814-
815817 Returns
816818 -------
817819 q : array
818- An array of :math:`q` values in the inverse of the units
820+ The array of :math:`q` values in the inverse of the units
819821 of ``wavelength``
820822 """
821823 two_theta = np .asarray (np .deg2rad (self .on_tth [0 ]))
824+ if np .any (two_theta > np .pi ):
825+ raise ValueError ("Two theta exceeds 180 degrees." )
822826 wavelength = float (self .wavelength )
823827 pre_factor = (4 * np .pi ) / wavelength
824828 return pre_factor * np .sin (two_theta / 2 )
0 commit comments