def test_fit_single_ellipse_to_signal_rotation(self): rot_list = [ -np.pi / 16, -np.pi / 8, -np.pi / 4, -np.pi / 2, -0.1, 0.1, np.pi / 16, np.pi / 8, np.pi / 4, np.pi / 2, np.pi + 0.1, np.pi * 2 + 0.1, np.pi * 2.5, np.pi * 3 + 0.1, np.pi * 3.2, ] for rot in rot_list: s = Diffraction2D(np.zeros((200, 200))) s.axes_manager[0].offset, s.axes_manager[1].offset = -100, -100 xx, yy = np.meshgrid(s.axes_manager[0].axis, s.axes_manager[1].axis) s.data += mdtd._get_elliptical_ring(xx, yy, 0, 0, 70, 60, rot, lw_r=1) output = ra.fit_single_ellipse_to_signal(s, (50, 80), angleN=10, show_progressbar=False) output_rot = output[5] % np.pi assert approx(output_rot, abs=0.1) == (rot % np.pi) for rot in rot_list: s = Diffraction2D(np.zeros((200, 200))) s.axes_manager[0].offset, s.axes_manager[1].offset = -100, -100 xx, yy = np.meshgrid(s.axes_manager[0].axis, s.axes_manager[1].axis) s.data += mdtd._get_elliptical_ring(xx, yy, 0, 0, 60, 70, rot, lw_r=1) output = ra.fit_single_ellipse_to_signal(s, (50, 80), angleN=10, show_progressbar=False) output_rot = (output[5] + np.pi / 2) % np.pi assert approx(output_rot, abs=0.1) == (rot % np.pi)
def test_cover_no_signal2(self): s = Signal2D(np.zeros((50, 56))) x, y, semi_len0, semi_len1, rotation = 20, 20, 90, 130, 2.0 xx, yy = np.meshgrid(s.axes_manager[0].axis, s.axes_manager[1].axis) ellipse_image = mdtd._get_elliptical_ring(xx, yy, x, y, semi_len0, semi_len1, rotation) assert not ellipse_image.any()
def test_simple(self): s = Signal2D(np.zeros((110, 200))) x, y, semi_len0, semi_len1, rotation = 60, 70, 12, 9, 0.2 xx, yy = np.meshgrid(s.axes_manager[0].axis, s.axes_manager[1].axis) ellipse_image = mdtd._get_elliptical_ring(xx, yy, x, y, semi_len0, semi_len1, rotation, 3) assert ellipse_image.any()
def setup_method(self): axis1, axis2 = 40, 70 s = Diffraction2D(np.zeros((200, 220))) s.axes_manager[0].offset, s.axes_manager[1].offset = -100, -110 xx, yy = np.meshgrid(s.axes_manager[0].axis, s.axes_manager[1].axis) ellipse_ring = mdtd._get_elliptical_ring( xx, yy, 0, 0, axis1, axis2, 0.8, lw_r=1 ) s.data += ellipse_ring self.s = s self.axis1, self.axis2 = axis1, axis2
def test_fit_ellipses_to_signal(self): s = Diffraction2D(np.zeros((200, 220))) s.axes_manager[0].offset, s.axes_manager[1].offset = -100, -110 xx, yy = np.meshgrid(s.axes_manager[0].axis, s.axes_manager[1].axis) ellipse_ring0 = mdtd._get_elliptical_ring(xx, yy, 2, -1, 60, 60, 0.8) ellipse_ring1 = mdtd._get_elliptical_ring(xx, yy, 1, -2, 80, 80, 0.8) s.data += ellipse_ring0 s.data += ellipse_ring1 output0 = ra.fit_ellipses_to_signal(s, [(50, 70), (70, 95)], angleN=20, show_progressbar=False) output0[0].plot() output1 = ra.fit_ellipses_to_signal(s, [(50, 70), (70, 95)], angleN=[20, 30], show_progressbar=False) output1[0].plot() with pytest.raises(ValueError): ra.fit_ellipses_to_signal( s, [(50, 70), (70, 95), (80, 105)], angleN=[20, 30], show_progressbar=False, )
def test_fit_single_ellipse_to_signal(self): s = Diffraction2D(np.zeros((200, 220))) s.axes_manager[0].offset, s.axes_manager[1].offset = -100, -110 xx, yy = np.meshgrid(s.axes_manager[0].axis, s.axes_manager[1].axis) ellipse_ring = mdtd._get_elliptical_ring(xx, yy, 0, 0, 60, 60, 0.8, lw_r=1) s.data += ellipse_ring output = ra.fit_single_ellipse_to_signal( s, (50, 70), angleN=10, show_progressbar=False ) output[0].plot() assert approx(output[1], abs=0.01) == 0.0 assert approx(output[2], abs=0.01) == 0.0 assert approx(output[3], abs=0.6) == 60 assert approx(output[4], abs=0.6) == 60 assert approx(output[6], abs=0.000001) == 1.0