def test_root_locus_zoom(self): """Check the zooming functionality of the Root locus plot""" system = TransferFunction([1000], [1, 25, 100, 0]) plt.figure() root_locus(system) fig = plt.gcf() ax_rlocus = fig.axes[0] event = type( 'test', (object, ), { 'xdata': 14.7607954359, 'ydata': -35.6171379864, 'inaxes': ax_rlocus.axes })() ax_rlocus.set_xlim((-10.813628105112421, 14.760795435937652)) ax_rlocus.set_ylim((-35.61713798641108, 33.879716621220311)) plt.get_current_fig_manager().toolbar.mode = 'zoom rect' _RLClickDispatcher(event, system, fig, ax_rlocus, '-') zoom_x = ax_rlocus.lines[-2].get_data()[0][0:5] zoom_y = ax_rlocus.lines[-2].get_data()[1][0:5] zoom_y = [abs(y) for y in zoom_y] zoom_x_valid = [ -5., -4.61281263, -4.16689986, -4.04122642, -3.90736502 ] zoom_y_valid = [0., 0., 0., 0., 0.] assert_array_almost_equal(zoom_x, zoom_x_valid) assert_array_almost_equal(zoom_y, zoom_y_valid)
def test_sisotool_tvect_dt(self, sysdt): # test supply tvect tvect = np.linspace(0, 1, 10) sisotool(sysdt, tvect=tvect) fig = plt.gcf() ax_rlocus, ax_step = fig.axes[1], fig.axes[3] # Move the rootlocus to another point and confirm same tvect event = type('test', (object,), {'xdata': 2.31206868287, 'ydata': 15.5983051046, 'inaxes': ax_rlocus.axes})() _RLClickDispatcher(event=event, sys=sysdt, fig=fig, ax_rlocus=ax_rlocus, sisotool=True, plotstr='-', bode_plot_params=dict(), tvect=tvect) assert_array_almost_equal(tvect, ax_step.lines[0].get_data()[0])
def test_sisotool(self): sisotool(self.system,Hz=False) fig = plt.gcf() ax_mag,ax_rlocus,ax_phase,ax_step = fig.axes[0],fig.axes[1],fig.axes[2],fig.axes[3] # Check the initial root locus plot points initial_point_0 = (np.array([-22.53155977]),np.array([0.])) initial_point_1 = (np.array([-1.23422011]), np.array([-6.54667031])) initial_point_2 = (np.array([-1.23422011]), np.array([06.54667031])) assert_array_almost_equal(ax_rlocus.lines[0].get_data(),initial_point_0) assert_array_almost_equal(ax_rlocus.lines[1].get_data(),initial_point_1) assert_array_almost_equal(ax_rlocus.lines[2].get_data(),initial_point_2) # Check the step response before moving the point step_response_original = np.array([ 0., 0.02233651, 0.13118374, 0.33078542, 0.5907113, 0.87041549, 1.13038536, 1.33851053, 1.47374666, 1.52757114]) assert_array_almost_equal(ax_step.lines[0].get_data()[1][:10],step_response_original) bode_plot_params = { 'omega': None, 'dB': False, 'Hz': False, 'deg': True, 'omega_limits': None, 'omega_num': None, 'sisotool': True, 'fig': fig, 'margins': True } # Move the rootlocus to another point event = type('test', (object,), {'xdata': 2.31206868287,'ydata':15.5983051046, 'inaxes':ax_rlocus.axes})() _RLClickDispatcher(event=event, sys=self.system, fig=fig,ax_rlocus=ax_rlocus,sisotool=True, plotstr='-' ,bode_plot_params=bode_plot_params, tvect=None) # Check the moved root locus plot points moved_point_0 = (np.array([-29.91742755]), np.array([0.])) moved_point_1 = (np.array([2.45871378]), np.array([-15.52647768])) moved_point_2 = (np.array([2.45871378]), np.array([15.52647768])) assert_array_almost_equal(ax_rlocus.lines[-3].get_data(),moved_point_0) assert_array_almost_equal(ax_rlocus.lines[-2].get_data(),moved_point_1) assert_array_almost_equal(ax_rlocus.lines[-1].get_data(),moved_point_2) # Check if the bode_mag line has moved bode_mag_moved = np.array([ 111.83321224, 92.29238035, 76.02822315, 62.46884113, 51.14108703, 41.6554004, 33.69409534, 27.00237344, 21.38086717, 16.67791585]) assert_array_almost_equal(ax_mag.lines[0].get_data()[1][10:20],bode_mag_moved) # Check if the step response has changed step_response_moved = np.array([[ 0., 0.02458187, 0.16529784 , 0.46602716 , 0.91012035 , 1.43364313, 1.93996334 , 2.3190105 , 2.47041552 , 2.32724853] ]) assert_array_almost_equal(ax_step.lines[0].get_data()[1][:10],step_response_moved)
def test_root_locus_zoom(self): """Check the zooming functionality of the Root locus plot""" system = TransferFunction([1000], [1, 25, 100, 0]) root_locus(system) fig = plt.gcf() ax_rlocus = fig.axes[0] event = type('test', (object,), {'xdata': 14.7607954359, 'ydata': -35.6171379864, 'inaxes': ax_rlocus.axes})() ax_rlocus.set_xlim((-10.813628105112421, 14.760795435937652)) ax_rlocus.set_ylim((-35.61713798641108, 33.879716621220311)) plt.get_current_fig_manager().toolbar.mode = 'zoom rect' _RLClickDispatcher(event, system, fig, ax_rlocus, '-') zoom_x = ax_rlocus.lines[-2].get_data()[0][0:5] zoom_y = ax_rlocus.lines[-2].get_data()[1][0:5] zoom_y = [abs(y) for y in zoom_y] zoom_x_valid = [-5. ,- 4.61281263, - 4.16689986, - 4.04122642, - 3.90736502] zoom_y_valid = [0. ,0., 0., 0., 0.] assert_array_almost_equal(zoom_x,zoom_x_valid) assert_array_almost_equal(zoom_y,zoom_y_valid)
def test_sisotool(self, sys): sisotool(sys, Hz=False) fig = plt.gcf() ax_mag, ax_rlocus, ax_phase, ax_step = fig.axes[:4] # Check the initial root locus plot points initial_point_0 = (np.array([-22.53155977]), np.array([0.])) initial_point_1 = (np.array([-1.23422011]), np.array([-6.54667031])) initial_point_2 = (np.array([-1.23422011]), np.array([06.54667031])) assert_array_almost_equal(ax_rlocus.lines[0].get_data(), initial_point_0, 4) assert_array_almost_equal(ax_rlocus.lines[1].get_data(), initial_point_1, 4) assert_array_almost_equal(ax_rlocus.lines[2].get_data(), initial_point_2, 4) # Check the step response before moving the point # new array needed because change in compute step response default time step_response_original = np.array([ 0., 0.0069, 0.0448, 0.124, 0.2427, 0.3933, 0.5653, 0.7473, 0.928, 1.0969 ]) #old: np.array([0., 0.0217, 0.1281, 0.3237, 0.5797, 0.8566, 1.116, # 1.3261, 1.4659, 1.526]) assert_array_almost_equal(ax_step.lines[0].get_data()[1][:10], step_response_original, 4) bode_plot_params = { 'omega': None, 'dB': False, 'Hz': False, 'deg': True, 'omega_limits': None, 'omega_num': None, 'sisotool': True, 'fig': fig, 'margins': True } # Move the rootlocus to another point event = type( 'test', (object, ), { 'xdata': 2.31206868287, 'ydata': 15.5983051046, 'inaxes': ax_rlocus.axes })() _RLClickDispatcher(event=event, sys=sys, fig=fig, ax_rlocus=ax_rlocus, sisotool=True, plotstr='-', bode_plot_params=bode_plot_params, tvect=None) # Check the moved root locus plot points moved_point_0 = (np.array([-29.91742755]), np.array([0.])) moved_point_1 = (np.array([2.45871378]), np.array([-15.52647768])) moved_point_2 = (np.array([2.45871378]), np.array([15.52647768])) assert_array_almost_equal(ax_rlocus.lines[-3].get_data(), moved_point_0, 4) assert_array_almost_equal(ax_rlocus.lines[-2].get_data(), moved_point_1, 4) assert_array_almost_equal(ax_rlocus.lines[-1].get_data(), moved_point_2, 4) # Check if the bode_mag line has moved bode_mag_moved = np.array([ 674.0242, 667.8354, 661.7033, 655.6275, 649.6074, 643.6426, 637.7324, 631.8765, 626.0742, 620.3252 ]) assert_array_almost_equal(ax_mag.lines[0].get_data()[1][10:20], bode_mag_moved, 4) # Check if the step response has changed # new array needed because change in compute step response default time step_response_moved = np.array([ 0., 0.0072, 0.0516, 0.1554, 0.3281, 0.5681, 0.8646, 1.1987, 1.5452, 1.875 ]) # old: array([0., 0.0239, 0.161 , 0.4547, 0.8903, 1.407, # 1.9121, 2.2989, 2.4686, 2.353]) assert_array_almost_equal(ax_step.lines[0].get_data()[1][:10], step_response_moved, 4)
def test_sisotool(self, tsys): sisotool(tsys, Hz=False) fig = plt.gcf() ax_mag, ax_rlocus, ax_phase, ax_step = fig.axes[:4] # Check the initial root locus plot points initial_point_0 = (np.array([-22.53155977]), np.array([0.])) initial_point_1 = (np.array([-1.23422011]), np.array([-6.54667031])) initial_point_2 = (np.array([-1.23422011]), np.array([6.54667031])) assert_array_almost_equal(ax_rlocus.lines[0].get_data(), initial_point_0, 4) assert_array_almost_equal(ax_rlocus.lines[1].get_data(), initial_point_1, 4) assert_array_almost_equal(ax_rlocus.lines[2].get_data(), initial_point_2, 4) # Check the step response before moving the point step_response_original = np.array([ 0., 0.0216, 0.1271, 0.3215, 0.5762, 0.8522, 1.1114, 1.3221, 1.4633, 1.5254 ]) assert_array_almost_equal(ax_step.lines[0].get_data()[1][:10], step_response_original, 4) bode_plot_params = { 'omega': None, 'dB': False, 'Hz': False, 'deg': True, 'omega_limits': None, 'omega_num': None, 'sisotool': True, 'fig': fig, 'margins': True } # Move the rootlocus to another point event = type( 'test', (object, ), { 'xdata': 2.31206868287, 'ydata': 15.5983051046, 'inaxes': ax_rlocus.axes })() _RLClickDispatcher(event=event, sys=tsys, fig=fig, ax_rlocus=ax_rlocus, sisotool=True, plotstr='-', bode_plot_params=bode_plot_params, tvect=None) # Check the moved root locus plot points moved_point_0 = (np.array([-29.91742755]), np.array([0.])) moved_point_1 = (np.array([2.45871378]), np.array([-15.52647768])) moved_point_2 = (np.array([2.45871378]), np.array([15.52647768])) assert_array_almost_equal(ax_rlocus.lines[-3].get_data(), moved_point_0, 4) assert_array_almost_equal(ax_rlocus.lines[-2].get_data(), moved_point_1, 4) assert_array_almost_equal(ax_rlocus.lines[-1].get_data(), moved_point_2, 4) # Check if the bode_mag line has moved bode_mag_moved = np.array([ 674.0242, 667.8354, 661.7033, 655.6275, 649.6074, 643.6426, 637.7324, 631.8765, 626.0742, 620.3252 ]) assert_array_almost_equal(ax_mag.lines[0].get_data()[1][10:20], bode_mag_moved, 4) # Check if the step response has changed step_response_moved = np.array([ 0., 0.0237, 0.1596, 0.4511, 0.884, 1.3985, 1.9031, 2.2922, 2.4676, 2.3606 ]) assert_array_almost_equal(ax_step.lines[0].get_data()[1][:10], step_response_moved, 4)
def test_sisotool(self): sisotool(self.system, Hz=False) fig = plt.gcf() ax_mag, ax_rlocus, ax_phase, ax_step = fig.axes[:4] # Check the initial root locus plot points initial_point_0 = (np.array([-22.53155977]), np.array([0.])) initial_point_1 = (np.array([-1.23422011]), np.array([-6.54667031])) initial_point_2 = (np.array([-1.23422011]), np.array([06.54667031])) assert_array_almost_equal(ax_rlocus.lines[0].get_data(), initial_point_0, 4) assert_array_almost_equal(ax_rlocus.lines[1].get_data(), initial_point_1, 4) assert_array_almost_equal(ax_rlocus.lines[2].get_data(), initial_point_2, 4) # Check the step response before moving the point step_response_original = np.array([ 0., 0.0217, 0.1281, 0.3237, 0.5797, 0.8566, 1.116, 1.3261, 1.4659, 1.526 ]) assert_array_almost_equal(ax_step.lines[0].get_data()[1][:10], step_response_original, 4) bode_plot_params = { 'omega': None, 'dB': False, 'Hz': False, 'deg': True, 'omega_limits': None, 'omega_num': None, 'sisotool': True, 'fig': fig, 'margins': True } # Move the rootlocus to another point event = type( 'test', (object, ), { 'xdata': 2.31206868287, 'ydata': 15.5983051046, 'inaxes': ax_rlocus.axes })() _RLClickDispatcher(event=event, sys=self.system, fig=fig, ax_rlocus=ax_rlocus, sisotool=True, plotstr='-', bode_plot_params=bode_plot_params, tvect=None) # Check the moved root locus plot points moved_point_0 = (np.array([-29.91742755]), np.array([0.])) moved_point_1 = (np.array([2.45871378]), np.array([-15.52647768])) moved_point_2 = (np.array([2.45871378]), np.array([15.52647768])) assert_array_almost_equal(ax_rlocus.lines[-3].get_data(), moved_point_0, 4) assert_array_almost_equal(ax_rlocus.lines[-2].get_data(), moved_point_1, 4) assert_array_almost_equal(ax_rlocus.lines[-1].get_data(), moved_point_2, 4) # Check if the bode_mag line has moved bode_mag_moved = np.array([ 111.83321224, 92.29238035, 76.02822315, 62.46884113, 51.14108703, 41.6554004, 33.69409534, 27.00237344, 21.38086717, 16.67791585 ]) assert_array_almost_equal(ax_mag.lines[0].get_data()[1][10:20], bode_mag_moved, 4) # Check if the step response has changed step_response_moved = np.array([ 0., 0.0239, 0.161, 0.4547, 0.8903, 1.407, 1.9121, 2.2989, 2.4686, 2.353 ]) assert_array_almost_equal(ax_step.lines[0].get_data()[1][:10], step_response_moved, 4)
def test_sisotool(self): sisotool(self.system, Hz=False) fig = plt.gcf() ax_mag, ax_rlocus, ax_phase, ax_step = fig.axes[0], fig.axes[ 1], fig.axes[2], fig.axes[3] # Check the initial root locus plot points initial_point_0 = (np.array([-22.53155977]), np.array([0.])) initial_point_1 = (np.array([-1.23422011]), np.array([-6.54667031])) initial_point_2 = (np.array([-1.23422011]), np.array([06.54667031])) assert_array_almost_equal(ax_rlocus.lines[0].get_data(), initial_point_0) assert_array_almost_equal(ax_rlocus.lines[1].get_data(), initial_point_1) assert_array_almost_equal(ax_rlocus.lines[2].get_data(), initial_point_2) # Check the step response before moving the point step_response_original = np.array([ 0., 0.02233651, 0.13118374, 0.33078542, 0.5907113, 0.87041549, 1.13038536, 1.33851053, 1.47374666, 1.52757114 ]) assert_array_almost_equal(ax_step.lines[0].get_data()[1][:10], step_response_original) bode_plot_params = { 'omega': None, 'dB': False, 'Hz': False, 'deg': True, 'omega_limits': None, 'omega_num': None, 'sisotool': True, 'fig': fig, 'margins': True } # Move the rootlocus to another point event = type( 'test', (object, ), { 'xdata': 2.31206868287, 'ydata': 15.5983051046, 'inaxes': ax_rlocus.axes })() _RLClickDispatcher(event=event, sys=self.system, fig=fig, ax_rlocus=ax_rlocus, sisotool=True, plotstr='-', bode_plot_params=bode_plot_params, tvect=None) # Check the moved root locus plot points moved_point_0 = (np.array([-29.91742755]), np.array([0.])) moved_point_1 = (np.array([2.45871378]), np.array([-15.52647768])) moved_point_2 = (np.array([2.45871378]), np.array([15.52647768])) assert_array_almost_equal(ax_rlocus.lines[-3].get_data(), moved_point_0) assert_array_almost_equal(ax_rlocus.lines[-2].get_data(), moved_point_1) assert_array_almost_equal(ax_rlocus.lines[-1].get_data(), moved_point_2) # Check if the bode_mag line has moved bode_mag_moved = np.array([ 111.83321224, 92.29238035, 76.02822315, 62.46884113, 51.14108703, 41.6554004, 33.69409534, 27.00237344, 21.38086717, 16.67791585 ]) assert_array_almost_equal(ax_mag.lines[0].get_data()[1][10:20], bode_mag_moved) # Check if the step response has changed step_response_moved = np.array([[ 0., 0.02458187, 0.16529784, 0.46602716, 0.91012035, 1.43364313, 1.93996334, 2.3190105, 2.47041552, 2.32724853 ]]) assert_array_almost_equal(ax_step.lines[0].get_data()[1][:10], step_response_moved)