@@ -231,6 +231,42 @@ def test_diffraction_objects_equality(inputs1, inputs2, expected):
231231 assert (diffraction_object1 == diffraction_object2 ) == expected
232232
233233
234+ def test_q_to_tth ():
235+ # valid q values including edge cases when q=0 or 1
236+ # expected tth values are 2*arcsin(q)
237+ actual = DiffractionObject (wavelength = 4 * np .pi )
238+ setattr (actual , "on_q" , [[0 , 0.2 , 0.4 , 0.6 , 0.8 , 1 ], [1 , 2 , 3 , 4 , 5 , 6 ]])
239+ actual_tth = actual .q_to_tth ()
240+ expected_tth = [0 , 23.07392 , 47.15636 , 73.73980 , 106.26020 , 180 ]
241+ assert np .allclose (actual_tth , expected_tth )
242+
243+
244+ def test_q_to_tth_bad ():
245+ # invalid q values when arcsin value is not in the range of [-1, 1]
246+ actual = DiffractionObject (wavelength = 4 * np .pi )
247+ setattr (actual , "on_q" , [[0.6 , 0.8 , 1 , 1.2 ], [1 , 2 , 3 , 4 ]])
248+ with pytest .raises (ValueError ):
249+ actual .q_to_tth ()
250+
251+
252+ def test_tth_to_q ():
253+ # valid tth values including edge cases when tth=0 or 180 degree
254+ # expected q vales are sin15, sin30, sin45, sin60, sin90
255+ actual = DiffractionObject (wavelength = 4 * np .pi )
256+ setattr (actual , "on_tth" , [[0 , 30 , 60 , 90 , 120 , 180 ], [1 , 2 , 3 , 4 , 5 , 6 ]])
257+ actual_q = actual .tth_to_q ()
258+ expected_q = [0 , 0.258819 , 0.5 , 0.707107 , 0.866025 , 1 ]
259+ assert np .allclose (actual_q , expected_q )
260+
261+
262+ def test_tth_to_q_bad ():
263+ # invalid tth value of > 180 degree
264+ actual = DiffractionObject (wavelength = 4 * np .pi )
265+ setattr (actual , "on_tth" , [[0 , 30 , 60 , 90 , 120 , 181 ], [1 , 2 , 3 , 4 , 5 , 6 ]])
266+ with pytest .raises (ValueError ):
267+ actual .tth_to_q ()
268+
269+
234270def test_dump (tmp_path , mocker ):
235271 x , y = np .linspace (0 , 5 , 6 ), np .linspace (0 , 5 , 6 )
236272 directory = Path (tmp_path )
0 commit comments