How to use test_5 method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

postProcessing.py

Source:postProcessing.py Github

copy

Full Screen

1import numpy as np2from pathlib import Path3from matplotlib import pyplot as plt4from collections import deque5from matplotlib.animation import FuncAnimation6import mpl_toolkits.mplot3d.art3d as art3d7from matplotlib.patches import Circle8import fym.logging as logging9from fym.utils import rot10def set_size(width_pt=245.7, fraction=1, subplots=(1,1)):11# def set_size(width_pt=155, fraction=1, subplots=(1,1)):12 fig_width_pt = width_pt * fraction13 inches_per_pt = 1 / 72.2714 # golden_ratio = (5**.5 - 1) / 215 golden_ratio = 3 / 416 fig_width_in = fig_width_pt * inches_per_pt17 # fig_height_in = fig_width_in * golden_ratio * (subplots[0] / subplots[1])18 fig_height_in = fig_width_in * golden_ratio19 return (fig_width_in, fig_height_in)20 21tex_fonts = {22 "text.usetex": True,23 "font.family": 'Times New Roman',24 "axes.labelsize": 6,25 "font.size": 6,26 "legend.fontsize": 6,27 "xtick.labelsize": 6,28 "ytick.labelsize": 6,29 "axes.grid": True,30}31plt.rcParams.update(tex_fonts)32def plot_TwoDimTwoPointMass(dir_save, data_path):33 env_data = logging.load(data_path)34 time = env_data['t']35 action = env_data['action']36 pos = env_data['plant']['pos'].squeeze()37 vel = env_data['plant']['vel'].squeeze()38 lyap_dot = env_data['lyap_dot']39 width = 14040 fig, ax = plt.subplots(1, 1, figsize=set_size(width_pt=width))41 ax.plot(pos[:,0], pos[:,1], 'r')42 ax.set_ylabel('Y [m]')43 ax.set_xlabel('X [m]')44 ax.set_title('Trajectory')45 fig.savefig(Path(dir_save, "trajectory.pdf"), bbox_inches='tight')46 plt.close('all')47 fig, ax = plt.subplots(2, 1, figsize=set_size(width_pt=width, subplots=(2,1)))48 ax[0].plot(time, pos[:,0], 'r')49 ax[0].set_ylabel("X [m]")50 ax[0].set_title("Position")51 ax[0].axes.xaxis.set_ticklabels([])52 ax[1].plot(time, pos[:,1], 'r')53 ax[1].set_ylabel("Y [m]")54 ax[1].set_xlabel("time [s]")55 fig.align_ylabels(ax)56 fig.savefig(Path(dir_save, "position.pdf"), bbox_inches='tight')57 plt.close('all')58 fig, ax = plt.subplots(2, 1, figsize=set_size(width_pt=155, subplots=(2,1)))59 ax[0].plot(time, vel[:,0], 'r')60 ax[0].set_ylabel("$V_x$ [m/s]")61 ax[0].set_title("Velocity")62 ax[0].axes.xaxis.set_ticklabels([])63 ax[1].plot(time, vel[:,1], 'r')64 ax[1].set_ylabel("$V_y$ [m/s]")65 ax[1].set_xlabel("time [s]")66 fig.align_ylabels(ax)67 fig.savefig(Path(dir_save, "velocity.pdf"), bbox_inches='tight')68 plt.close('all')69 fig, ax = plt.subplots(2, 1, figsize=set_size(width_pt=width, subplots=(2,1)))70 ax[0].plot(time, action[:,0])71 ax[0].set_ylabel("$a_x [m/s^2]$")72 ax[0].set_title("Acceleration")73 ax[0].axes.xaxis.set_ticklabels([])74 ax[1].plot(time, action[:,1], 'r')75 ax[1].set_ylabel("$a_y [m/s^2]$")76 ax[1].set_xlabel("time [s]")77 fig.align_ylabels(ax)78 fig.savefig(Path(dir_save, "acceleration.pdf"), bbox_inches='tight')79 plt.close('all')80 fig, ax = plt.subplots(1, 1, figsize=set_size(width_pt=width))81 ax.plot(time, lyap_dot, 'r')82 ax.set_ylabel(r'$\frac{dV}{dt}$')83 ax.set_xlabel('time [s]')84 ax.set_title('Time derivative of Lyapunov candidate function')85 fig.savefig(Path(dir_save, "lyap_dot.pdf"), bbox_inches='tight')86 plt.close('all')87def plot_compare():88 dir_save = Path('./ray_results/compare/')89 # Compare btw L1 and L290 pathes = [Path('./ray_results/PPO_2021-10-27_12-10-21/PPO_MyEnv_6bee6_00000_0_2021-10-27_12-10-21/checkpoint_001000/test_5/env_data.h5'),91 Path('./ray_results/PPO_2021-10-27_16-10-08/PPO_MyEnv_eb2e0_00000_0_2021-10-27_16-10-08/checkpoint_001000/test_5/env_data.h5')92 ]93 env_data = [logging.load(path) for path in pathes]94 time = env_data[0]['t']95 action = [data['action'] for data in env_data]96 pos = [data['plant']['pos'].squeeze() for data in env_data]97 vel = [data['plant']['vel'].squeeze() for data in env_data]98 width = 17099 fig, ax = plt.subplots(2, 1, figsize=set_size(width_pt=width, subplots=(2,1)))100 line1, = ax[0].plot(time, pos[0][:,0], 'r')101 line2, = ax[0].plot(time, pos[1][:,0], 'b--')102 ax[0].legend(handles=(line1, line2),103 labels=('L-reward No.1', 'L-reward No.2'))104 ax[0].set_ylabel("X [m]")105 ax[0].set_title("Position")106 ax[0].axes.xaxis.set_ticklabels([])107 ax[1].plot(time, pos[0][:,1], 'r', time, pos[1][:,1], 'b--')108 ax[1].set_ylabel("Y [m]")109 ax[1].set_xlabel("time [s]")110 [ax[i].grid(True) for i in range(2)]111 fig.align_ylabels(ax)112 fig.savefig(Path(dir_save, "L1-2.pdf"), bbox_inches='tight')113 plt.close('all')114 # Compare btw L3 and L4115 pathes = [Path('./ray_results/PPO_2021-10-27_18-06-35/PPO_MyEnv_2fb91_00000_0_2021-10-27_18-06-35/checkpoint_001000/test_5/env_data.h5'),116 Path('./ray_results/PPO_2021-10-27_19-45-57/PPO_MyEnv_112a5_00000_0_2021-10-27_19-45-57/checkpoint_001000/test_5/env_data.h5')117 ]118 env_data = [logging.load(path) for path in pathes]119 time = env_data[0]['t']120 action = [data['action'] for data in env_data]121 pos = [data['plant']['pos'].squeeze() for data in env_data]122 vel = [data['plant']['vel'].squeeze() for data in env_data]123 fig, ax = plt.subplots(2, 1, figsize=set_size(width_pt=width, subplots=(2,1)))124 line1, = ax[0].plot(time, pos[0][:,0], 'r')125 line2, = ax[0].plot(time, pos[1][:,0], 'b--')126 ax[0].legend(handles=(line1, line2),127 labels=('L-reward No.3', 'L-reward No.4'))128 ax[0].set_ylabel("X [m]")129 ax[0].set_title("Position")130 ax[0].axes.xaxis.set_ticklabels([])131 ax[1].plot(time, pos[0][:,1], 'r', time, pos[1][:,1], 'b--')132 ax[1].set_ylabel("Y [m]")133 ax[1].set_xlabel("time [s]")134 [ax[i].grid(True) for i in range(2)]135 fig.align_ylabels(ax)136 fig.savefig(Path(dir_save, "L3-4.pdf"), bbox_inches='tight')137 plt.close('all')138 # Compare btw L1 and EQL1139 pathes = [Path('./ray_results/PPO_2021-10-27_12-10-21/PPO_MyEnv_6bee6_00000_0_2021-10-27_12-10-21/checkpoint_001000/test_5/env_data.h5'),140 Path('./ray_results/PPO_2021-10-22_15-20-16/PPO_MyEnv_1f7a9_00000_0_2021-10-22_15-20-16/checkpoint_001000/test_5/env_data.h5')141 ]142 env_data = [logging.load(path) for path in pathes]143 time = env_data[0]['t']144 action = [data['action'] for data in env_data]145 pos = [data['plant']['pos'].squeeze() for data in env_data]146 vel = [data['plant']['vel'].squeeze() for data in env_data]147 fig, ax = plt.subplots(2, 1, figsize=set_size(width_pt=width, subplots=(2,1)))148 line1, = ax[0].plot(time, pos[0][:,0], 'r')149 line2, = ax[0].plot(time, pos[1][:,0], 'b--')150 ax[0].legend(handles=(line1, line2),151 labels=('L-reward No.1', 'EQL-reward No.1'))152 ax[0].set_ylabel("X [m]")153 ax[0].set_title("Position")154 ax[0].axes.xaxis.set_ticklabels([])155 ax[1].plot(time, pos[0][:,1], 'r', time, pos[1][:,1], 'b--')156 ax[1].set_ylabel("Y [m]")157 ax[1].set_xlabel("time [s]")158 [ax[i].grid(True) for i in range(2)]159 fig.align_ylabels(ax)160 fig.savefig(Path(dir_save, "L1-EQL1.pdf"), bbox_inches='tight')161 plt.close('all')162 # Compare btw L3 and EQL2163 pathes = [Path('./ray_results/PPO_2021-10-27_18-06-35/PPO_MyEnv_2fb91_00000_0_2021-10-27_18-06-35/checkpoint_001000/test_5/env_data.h5'),164 Path('./ray_results/PPO_2021-10-31_01-29-23/PPO_MyEnv_8a59d_00000_0_2021-10-31_01-29-23/checkpoint_001000/test_5/env_data.h5')165 ]166 env_data = [logging.load(path) for path in pathes]167 time = env_data[0]['t']168 action = [data['action'] for data in env_data]169 pos = [data['plant']['pos'].squeeze() for data in env_data]170 vel = [data['plant']['vel'].squeeze() for data in env_data]171 fig, ax = plt.subplots(2, 1, figsize=set_size(width_pt=width, subplots=(2,1)))172 line1, = ax[0].plot(time, pos[0][:,0], 'r')173 line2, = ax[0].plot(time, pos[1][:,0], 'b--')174 ax[0].legend(handles=(line1, line2),175 labels=('L-reward No.3', 'EQL-reward No.2'))176 ax[0].set_ylabel("X [m]")177 ax[0].set_title("Position")178 ax[0].axes.xaxis.set_ticklabels([])179 ax[1].plot(time, pos[0][:,1], 'r', time, pos[1][:,1], 'b--')180 ax[1].set_ylabel("Y [m]")181 ax[1].set_xlabel("time [s]")182 [ax[i].grid(True) for i in range(2)]183 fig.align_ylabels(ax)184 fig.savefig(Path(dir_save, "L3-EQL2.pdf"), bbox_inches='tight')185 plt.close('all')186def plot_compare2():187 dir_save = Path('./ray_results/compare/')188 # Compare btw L2norm189 pathes = [190 Path('./ray_results/PPO_2021-10-30_11-14-17/PPO_MyEnv_15c55_00000_0_2021-10-30_11-14-17/checkpoint_001000/test_5/env_data.h5'),191 Path('./ray_results/PPO_2021-10-30_04-39-15/PPO_MyEnv_e6a27_00000_0_2021-10-30_04-39-16/checkpoint_001000/test_5/env_data.h5'),192 Path('./ray_results/PPO_2021-10-30_17-48-39/PPO_MyEnv_2d837_00000_0_2021-10-30_17-48-39/checkpoint_001000/test_5/env_data.h5')193 ]194 env_data = [logging.load(path) for path in pathes]195 time = env_data[0]['t']196 action = [data['action'] for data in env_data]197 pos = [data['plant']['pos'].squeeze() for data in env_data]198 vel = [data['plant']['vel'].squeeze() for data in env_data]199 width = 170200 fig, ax = plt.subplots(2, 1, figsize=set_size(width_pt=width, subplots=(2,1)))201 line1, = ax[0].plot(time, pos[0][:,0], 'r')202 line2, = ax[0].plot(time, pos[1][:,0], 'b--')203 line3, = ax[0].plot(time, pos[2][:,0], 'g-.')204 ax[0].legend(handles=(line1, line2, line3),205 labels=('N-reward No.1', 'N-reward No.2', 'N-reward No.3'))206 ax[0].set_ylabel("X [m]")207 ax[0].set_title("Position using N-reward")208 ax[0].set_ylim([-1, 10])209 ax[0].axes.xaxis.set_ticklabels([])210 ax[1].plot(time, pos[0][:,1], 'r', time, pos[1][:,1], 'b--', time, pos[2][:,1], 'g-.')211 ax[1].set_ylabel("Y [m]")212 ax[1].set_xlabel("time [s]")213 ax[1].set_ylim([-0.5, 5.5])214 [ax[i].grid(True) for i in range(2)]215 fig.align_ylabels(ax)216 fig.savefig(Path(dir_save, "N1-3.pdf"), bbox_inches='tight')217 plt.close('all')218 # Compare btw Q219 pathes = [220 Path('./ray_results/PPO_2021-10-29_00-16-02/PPO_MyEnv_f65c8_00000_0_2021-10-29_00-16-02/checkpoint_001000/test_5/env_data.h5'),221 Path('./ray_results/PPO_2021-10-30_19-14-30/PPO_MyEnv_2b983_00000_0_2021-10-30_19-14-30/checkpoint_001000/test_5/env_data.h5'),222 Path('./ray_results/PPO_2021-10-30_20-59-25/PPO_MyEnv_d4182_00000_0_2021-10-30_20-59-26/checkpoint_001000/test_5/env_data.h5')223 ]224 env_data = [logging.load(path) for path in pathes]225 time = env_data[0]['t']226 action = [data['action'] for data in env_data]227 pos = [data['plant']['pos'].squeeze() for data in env_data]228 vel = [data['plant']['vel'].squeeze() for data in env_data]229 fig, ax = plt.subplots(2, 1, figsize=set_size(width_pt=width, subplots=(2,1)))230 line1, = ax[0].plot(time, pos[0][:,0], 'r')231 line2, = ax[0].plot(time, pos[1][:,0], 'b--')232 line3, = ax[0].plot(time, pos[2][:,0], 'g-.')233 ax[0].legend(handles=(line1, line2, line3),234 labels=('Q-reward No.1', 'Q-reward No.2', 'Q-reward No.3'))235 ax[0].set_ylabel("X [m]")236 ax[0].set_title("Position using Q-reward")237 ax[0].set_ylim([-10, 70])238 ax[0].axes.xaxis.set_ticklabels([])239 ax[1].plot(time, pos[0][:,1], 'r', time, pos[1][:,1], 'b--', time, pos[2][:,1], 'g-.')240 ax[1].set_ylabel("Y [m]")241 ax[1].set_xlabel("time [s]")242 ax[1].set_ylim([-20, 50])243 [ax[i].grid(True) for i in range(2)]244 fig.align_ylabels(ax)245 fig.savefig(Path(dir_save, "Q1-3.pdf"), bbox_inches='tight')246 plt.close('all')247 # Compare btw EQ248 pathes = [249 Path('./ray_results/PPO_2021-10-31_03-13-36/PPO_MyEnv_19739_00000_0_2021-10-31_03-13-36/checkpoint_001000/test_5/env_data.h5'),250 Path('./ray_results/PPO_2021-10-30_07-49-32/PPO_MyEnv_7ba2e_00000_0_2021-10-30_07-49-32/checkpoint_001000/test_5/env_data.h5'),251 Path('./ray_results/PPO_2021-10-31_08-35-38/PPO_MyEnv_16544_00000_0_2021-10-31_08-35-38/checkpoint_001000/test_5/env_data.h5')252 ]253 env_data = [logging.load(path) for path in pathes]254 time = env_data[0]['t']255 action = [data['action'] for data in env_data]256 pos = [data['plant']['pos'].squeeze() for data in env_data]257 vel = [data['plant']['vel'].squeeze() for data in env_data]258 fig, ax = plt.subplots(2, 1, figsize=set_size(width_pt=width, subplots=(2,1)))259 line1, = ax[0].plot(time, pos[0][:,0], 'r')260 line2, = ax[0].plot(time, pos[1][:,0], 'b--')261 line3, = ax[0].plot(time, pos[2][:,0], 'g-.')262 ax[0].legend(handles=(line1, line2, line3),263 labels=('EQ-reward No.1', 'EQ-reward No.2', 'EQ-reward No.3'),264 loc='upper center',265 bbox_to_anchor=(0.42, -1.8),266 ncol=3)267 ax[0].set_ylabel("X [m]")268 ax[0].set_title("Position using EQ-reward")269 ax[0].set_ylim([-1, 8])270 ax[0].axes.xaxis.set_ticklabels([])271 ax[1].plot(time, pos[0][:,1], 'r', time, pos[1][:,1], 'b--', time, pos[2][:,1], 'g-.')272 ax[1].set_ylabel("Y [m]")273 ax[1].set_xlabel("time [s]")274 ax[1].set_ylim([-1, 8])275 [ax[i].grid(True) for i in range(2)]276 fig.align_ylabels(ax)277 fig.savefig(Path(dir_save, "EQ1-3.pdf"), bbox_inches='tight')278 plt.close('all')279 # Compare btw N1, EQ2, L4280 pathes = [281 Path('./ray_results/PPO_2021-10-30_11-14-17/PPO_MyEnv_15c55_00000_0_2021-10-30_11-14-17/checkpoint_001000/test_5/env_data.h5'),282 Path('./ray_results/PPO_2021-10-30_07-49-32/PPO_MyEnv_7ba2e_00000_0_2021-10-30_07-49-32/checkpoint_001000/test_5/env_data.h5'),283 Path('./ray_results/PPO_2021-10-27_19-45-57/PPO_MyEnv_112a5_00000_0_2021-10-27_19-45-57/checkpoint_001000/test_5/env_data.h5')284 ]285 env_data = [logging.load(path) for path in pathes]286 time = env_data[0]['t']287 action = [data['action'] for data in env_data]288 pos = [data['plant']['pos'].squeeze() for data in env_data]289 vel = [data['plant']['vel'].squeeze() for data in env_data]290 width=150291 fig, ax = plt.subplots(2, 1, figsize=set_size(width_pt=width, subplots=(2,1)))292 line1, = ax[0].plot(time[1000:], pos[0][1000:,0], 'r')293 line2, = ax[0].plot(time[1000:], pos[1][1000:,0], 'b--')294 line3, = ax[0].plot(time[1000:], pos[2][1000:,0], 'g-.')295 ax[0].legend(handles=(line1, line2, line3),296 labels=('N-reward No.1', 'EQ-reward No.2', 'L-reward No.4'),297 loc='upper center',298 bbox_to_anchor=(0.5, -1.8),299 ncol=3)300 ax[0].set_ylabel("X [m]")301 ax[0].set_title("Position")302 ax[0].set_ylim([-0.1, 0.3])303 ax[0].axes.xaxis.set_ticklabels([])304 ax[1].plot(time[1000:], pos[0][1000:,1], 'r', time[1000:], pos[1][1000:,1], 'b--', time[1000:], pos[2][1000:,1], 'g-.')305 ax[1].set_ylabel("Y [m]")306 ax[1].set_xlabel("time [s]")307 ax[1].set_ylim([-0.5, 0.5])308 [ax[i].grid(True) for i in range(2)]309 fig.align_ylabels(ax)310 fig.savefig(Path(dir_save, "N1-EQ2-L4.pdf"), bbox_inches='tight')311 plt.close('all')312if __name__ == "__main__":313 # plot_compare()...

Full Screen

Full Screen

test_instrument.py

Source:test_instrument.py Github

copy

Full Screen

1import pytest2from mamba_client.station import NetworkController, Instrument3from mamba_client.mock.mamba_server_mock import MambaServerMock4from mamba_client.station.exceptions import ParameterSetException5class TestClass:6 def test_parameter_init(self):7 MambaServerMock(port=34574)8 network_controller = NetworkController(port=34574)9 inst = Instrument(instrument_id='inst_1',10 network_controller=network_controller)11 assert inst._id == 'inst_1'12 assert inst._network_controller is not None13 assert inst._parameters == {}14 inst.add_parameter(parameter_id='test_1')15 assert list(inst._parameters.keys()) == ['test_1']16 assert inst.test_1._parameter_id == 'test_1'17 assert inst.test_1._get is not None18 assert inst.test_1._get._parameter_id == 'inst_1_test_1'19 assert inst.test_1._set is not None20 assert inst.test_1._set._parameter_id == 'inst_1_test_1'21 inst.add_parameter(parameter_id='test_2',22 get_alias='test_2_get',23 set_alias='test_2_set')24 assert list(inst._parameters.keys()) == ['test_1', 'test_2']25 assert inst.test_2._parameter_id == 'test_2'26 assert inst.test_2._get is not None27 assert inst.test_2._get._parameter_id == 'test_2_get'28 assert inst.test_2._set is not None29 assert inst.test_2._set._parameter_id == 'test_2_set'30 inst.add_parameter(parameter_id='test_3', set_arg_1=1)31 assert list(inst._parameters.keys()) == ['test_1', 'test_2', 'test_3']32 assert inst.test_3._parameter_id == 'test_3'33 assert inst.test_3._get is not None34 assert inst.test_3._get._parameter_id == 'inst_1_test_3'35 assert inst.test_3._set is not None36 assert inst.test_3._set._parameter_id == 'inst_1_test_3'37 assert inst.test_3._set._arg_1 == 138 assert inst.test_3._set._arg_2 is None39 with pytest.raises(KeyError) as excinfo:40 inst.add_parameter(parameter_id='test_3')41 assert str(excinfo.value) == "'Duplicate parameter name test_3'"42 inst.add_get_parameter(parameter_id='test_4')43 assert list(inst._parameters.keys()) == [44 'test_1', 'test_2', 'test_3', 'test_4'45 ]46 assert inst.test_4._parameter_id == 'test_4'47 assert inst.test_4._get is not None48 assert inst.test_4._get._parameter_id == 'inst_1_test_4'49 assert inst.test_4._set is None50 inst.add_get_parameter(parameter_id='test_5', get_alias='test_5_get')51 assert list(inst._parameters.keys()) == [52 'test_1', 'test_2', 'test_3', 'test_4', 'test_5'53 ]54 assert inst.test_5._parameter_id == 'test_5'55 assert inst.test_5._get is not None56 assert inst.test_5._get._parameter_id == 'test_5_get'57 assert inst.test_5._set is None58 inst.add_set_parameter(parameter_id='test_6')59 assert list(inst._parameters.keys()) == [60 'test_1', 'test_2', 'test_3', 'test_4', 'test_5', 'test_6'61 ]62 assert inst.test_6._parameter_id == 'test_6'63 assert inst.test_6._set is not None64 assert inst.test_6._set._parameter_id == 'inst_1_test_6'65 assert inst.test_6._get is None66 inst.add_set_parameter(parameter_id='test_7',67 set_alias='test_7_set',68 set_arg_1=2)69 assert list(inst._parameters.keys()) == [70 'test_1', 'test_2', 'test_3', 'test_4', 'test_5', 'test_6',71 'test_7'72 ]73 assert inst.test_7._parameter_id == 'test_7'74 assert inst.test_7._set is not None75 assert inst.test_7._set._parameter_id == 'test_7_set'76 assert inst.test_7._get is None77 assert inst.test_7._set._arg_1 == 278 assert inst.test_7._set._arg_2 is None79 with pytest.raises(AttributeError) as excinfo:80 inst.test_881 assert str(excinfo.value) == 'inst_1 instrument has no property test_8'82 network_controller.close()83 def test_parameter_call(self):84 mock = MambaServerMock(port=34575)85 network_controller = NetworkController(port=34575)86 inst = Instrument(instrument_id='inst_1',87 network_controller=network_controller)88 inst.add_parameter(parameter_id='test_1')89 assert mock._shared_memory['last_tc'] == 'tc_meta inst_1_test_1'90 assert mock._shared_memory[91 'last_tm'] == '> OK inst_1_test_1;1;test description'92 reply = inst.test_1.get()93 assert mock._shared_memory['last_tc'] == 'tm inst_1_test_1'94 assert '> OK inst_1_test_1;' in mock._shared_memory['last_tm']95 assert ';1;1;0;1' in mock._shared_memory['last_tm']96 assert reply == '1'97 inst.test_1.set(1)98 assert mock._shared_memory['last_tc'] == 'tc inst_1_test_1 "1"'99 assert mock._shared_memory['last_tm'] == '> OK inst_1_test_1'100 with pytest.raises(ParameterSetException) as excinfo:101 inst.test_1.set(1, 2)102 assert str(103 excinfo.value104 ) == 'inst_1_test_1 set - Wrong number of arguments. Expected: 1, Received: 2.'105 inst.add_parameter(parameter_id='test_2', set_arg_1=1)106 reply = inst.test_2.get()107 assert mock._shared_memory['last_tc'] == 'tm inst_1_test_2'108 assert '> OK inst_1_test_2;' in mock._shared_memory['last_tm']109 assert ';1;1;0;1' in mock._shared_memory['last_tm']110 assert reply == '1'111 inst.test_2.set()112 assert mock._shared_memory['last_tc'] == 'tc inst_1_test_2 "1"'113 assert mock._shared_memory['last_tm'] == '> OK inst_1_test_2'114 inst.test_2.set(2)115 assert mock._shared_memory['last_tc'] == 'tc inst_1_test_2 "2"'116 assert mock._shared_memory['last_tm'] == '> OK inst_1_test_2'117 inst.add_parameter(parameter_id='test_3', parameter_get_type='int')118 assert mock._shared_memory['last_tc'] == 'tc_meta inst_1_test_3'119 assert mock._shared_memory[120 'last_tm'] == '> OK inst_1_test_3;1;test description'121 reply = inst.test_3.get()122 assert mock._shared_memory['last_tc'] == 'tm inst_1_test_3'123 assert '> OK inst_1_test_3;' in mock._shared_memory['last_tm']124 assert ';1;1;0;1' in mock._shared_memory['last_tm']125 assert reply == 1...

Full Screen

Full Screen

models.py

Source:models.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2# This file is auto-generated, don't edit it. Thanks.3from Tea.model import TeaModel4class Test1(TeaModel):5 """6 TestModel7 """8 def __init__(self, test=None, test_2=None, test_3=None, test_5=None, sts=None, a_sts=None):9 # test desc10 self.test = test # type: str11 # model的test back comment12 # test2 desc13 self.test_2 = test_2 # type: str14 # model的test2 back comment15 # test3 desc16 self.test_3 = test_3 # type: list[list[str]]17 # test desc18 self.test_5 = test_5 # type: str19 # sts desc20 self.sts = sts # type: str21 # asts desc22 self.a_sts = a_sts # type: str23 def validate(self):24 self.validate_required(self.test, 'test')25 self.validate_required(self.test_2, 'test_2')26 self.validate_required(self.test_3, 'test_3')27 self.validate_required(self.test_5, 'test_5')28 self.validate_required(self.sts, 'sts')29 self.validate_required(self.a_sts, 'a_sts')30 def to_map(self):31 _map = super(Test1, self).to_map()32 if _map is not None:33 return _map34 result = dict()35 if self.test is not None:36 result['test'] = self.test37 if self.test_2 is not None:38 result['test2'] = self.test_239 if self.test_3 is not None:40 result['test3'] = self.test_341 if self.test_5 is not None:42 result['test5'] = self.test_543 if self.sts is not None:44 result['sts'] = self.sts45 if self.a_sts is not None:46 result['asts'] = self.a_sts47 return result48 def from_map(self, m=None):49 m = m or dict()50 if m.get('test') is not None:51 self.test = m.get('test')52 if m.get('test2') is not None:53 self.test_2 = m.get('test2')54 if m.get('test3') is not None:55 self.test_3 = m.get('test3')56 if m.get('test5') is not None:57 self.test_5 = m.get('test5')58 if m.get('sts') is not None:59 self.sts = m.get('sts')60 if m.get('asts') is not None:61 self.a_sts = m.get('asts')62 return self63class Test2(TeaModel):64 """65 TestModel266 """67 def __init__(self, test=None, test_2=None):68 # model的test front comment69 # test desc70 self.test = test # type: str71 # model的test front comment72 # test2 desc73 self.test_2 = test_2 # type: str74 def validate(self):75 self.validate_required(self.test, 'test')76 self.validate_required(self.test_2, 'test_2')77 def to_map(self):78 _map = super(Test2, self).to_map()79 if _map is not None:80 return _map81 result = dict()82 if self.test is not None:83 result['test'] = self.test84 if self.test_2 is not None:85 result['test2'] = self.test_286 return result87 def from_map(self, m=None):88 m = m or dict()89 if m.get('test') is not None:90 self.test = m.get('test')91 if m.get('test2') is not None:92 self.test_2 = m.get('test2')93 return self94class Test3(TeaModel):95 """96 TestModel397 """98 def __init__(self, test=None, test_1=None):99 # model的test front comment100 # test desc101 self.test = test # type: str102 # empty comment1103 # empy comment2104 # test desc105 self.test_1 = test_1 # type: str106 # model的test back comment107 def validate(self):108 self.validate_required(self.test, 'test')109 self.validate_required(self.test_1, 'test_1')110 def to_map(self):111 _map = super(Test3, self).to_map()112 if _map is not None:113 return _map114 result = dict()115 if self.test is not None:116 result['test'] = self.test117 if self.test_1 is not None:118 result['test1'] = self.test_1119 return result120 def from_map(self, m=None):121 m = m or dict()122 if m.get('test') is not None:123 self.test = m.get('test')124 if m.get('test1') is not None:125 self.test_1 = m.get('test1')...

Full Screen

Full Screen

knn_ocr.py

Source:knn_ocr.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2"""3Created on Sun May 26 21:44:27 20194@author: dell5"""6# digits 具有5000个手写数字,每个数字有500种,每个数字是一个20x20的小图,所以第一步就是将这个图像分隔为7#5000个不同的数字,我们在拆分后,每一个数字的图像重排成一行含有400个像素点的新图像。这就是我们的特征集。我们使用8#每个数字的前250个作为训练集,后250个作为测试集,让我们先准备一下9import numpy as np10import cv211from matplotlib import pyplot as plt12#img=cv2.imread('digits.png')13#gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)14#15#cells=[np.hsplit(row,100) for row in np.vsplit(gray,50)]16##pic_1=cells[49][1]#第一位【0-49】对应数字0-9 eg 0 ->0 49->917##cv2.imshow('1',pic_1)18#19#x=np.array(cells) #转为数组 (50,100,20,20)20## 准备训练数据和测试数据21#train=x[:,:50].reshape(-1,400).astype(np.float32) #(2500,400) 每250个是一类数字22#test=x[:,50:100].reshape(-1,400).astype(np.float32)23##创建标签24#k=np.arange(10)25#train_labels=np.repeat(k,250)[:,np.newaxis]###################一个不错的用法,将一维数组(长度为a)变成2维[:,np.newaxis]是变成(a,1);26##[np.newaxis,:]是变成(1,a) np.repeat 是重复数字 eg (1,2,3) (1,1,2,2,3,3) 27#test_labels=train_labels.copy() #(2500,1)28#29#knn=cv2.ml.KNearest_create()30#knn.train(train,cv2.ml.ROW_SAMPLE,train_labels) 31#ret,result,neighbours,dist=knn.findNearest(test,k=5) #result=(2500,1)32##确认准确度33#matchs=result==test_labels #match 为bool量34#correct=np.count_nonzero(matchs) #统计不为0的个数35#accuracy=correct*100/result.size36#print(accuracy)37##测试自己的数据38#test_5=cv2.imread('5.png',0)39#test_5=cv2.resize(test_5,(20,20)).reshape(-1,400).astype(np.float32)40##cv2.imshow('5',test_5)41#ret_1,result_1,neighbours_1,dist_1=knn.findNearest(test_5,k=5) 42# =============================================================================43# #保留训练好的分类器44# =============================================================================45#np.savez('knn_data.npz',train=train,train_labels=train_labels)46#now load data47with np.load('knn_data.npz') as data:48 print(data.files)49 train=data['train']50 train_labels=data['train_labels']51test_5=cv2.imread('5.png',0)52test_5=cv2.resize(test_5,(20,20)).reshape(-1,400).astype(np.float32)53#cv2.imshow('5',test_5)54knn=cv2.ml.KNearest_create()55knn.train(train,cv2.ml.ROW_SAMPLE,train_labels) 56#ret,result,neighbours,dist=knn.findNearest(test,k=5) #result=(2500,1)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Lemoncheesecake automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful