Best Python code snippet using autotest_python
read_3d_segy.py
Source:read_3d_segy.py
...10 11 def __init___(self):12 read_segy_header.segyheader.__init__(self)13 self.init_binary_header()14# (self.inline_start,self.xline_start,self.X_min,self.Y_min) = self.read_control_file(1)15# (self.inline_end,self.xline_end,self.X_max,self.Y_max) = self.read_last_trace_header()16# self.inline_lens = self.inline_end - self.inline_start + 117# self.xline_lens = self.xline_end - self.xline_start + 118# self.trace_count = self.inline_lens * self.xline_lens19 20 def segy_information(self):21 self.read_binary_header()22 23 (self.inline_start,self.xline_start,self.X_min,self.Y_min) = self.read_control_file(1)24 (self.inline_end,self.xline_end,self.X_max,self.Y_max) = self.read_last_trace_header()25 self.inline_lens = self.inline_end - self.inline_start + 126 self.xline_lens = self.xline_end - self.xline_start + 127 self.trace_count = self.inline_lens * self.xline_lens28 print("=================== Segy Information =======================")29 print("inline:",self.inline_start," to ",self.inline_end)30 print("xline:",self.xline_start," to ",self.xline_end)31 print("coordinate X:",self.X_min," to ",self.X_max)32 print("coordinate Y:",self.Y_min," to ",self.Y_max)33 print("inline lens:",self.inline_lens)34 print("xline lens:",self.xline_lens)35 return self.inline_start, self.inline_end, self.xline_start, self.xline_end36 37 38 39 def read_3dSegy_data(self,inline,xline):40 41 42 if self.data_fmt == 1:43 self.read_ibmfloat_data(inline,xline)44 elif self.data_fmt == 2:45 self.read_int32_data(inline,xline)46 elif self.data_fmt == 3:47 self.read_int16_data(inline,xline)48 elif self.data_fmt == 5:49 self.read_IEEEfloat_data(inline,xline)50 elif self.data_fmt == 8:51 self.read_int8_data(inline,xline)52 else:53 return "This format is no use now."54 55 def read_int32_data(self, inline, xline):56 return 057 def read_int16_data(self, inline, xline):58 return 059 def read_IEEEfloat_data(self, inline, xline):60 return 061 def read_int8_data(self, inline, xline):62 63 self.init_binary_header()64 (self.inline_start,self.xline_start,self.X_min,self.Y_min) = self.read_control_file(1)65 (self.inline_end,self.xline_end,self.X_max,self.Y_max) = self.read_last_trace_header()66 self.inline_lens = self.inline_end - self.inline_start + 167 self.xline_lens = self.xline_end - self.xline_start + 168 self.trace_count = self.inline_lens * self.xline_lens69 70 71 trace_position = (inline-self.inline_start)*self.xline_lens + (xline-self.xline_start)72 start_number = self.text_header_lens+self.bin_header_lens73 data_lens = self.number_of_sample * self.sample_fmt74 trace_lens = data_lens + self.trace_header_lens75 start = start_number+trace_position*trace_lens+self.trace_header_lens76 unpack_fmt = '>' + str(self.number_of_sample) + 'b'77 78 Int8 = np.zeros(self.number_of_sample,dtype=np.int8)79 with open(self.segy_file,'rb') as in_file:80 in_file.seek(start)81 data = in_file.read(data_lens)82 Int8 = np.asarray(struct.unpack(unpack_fmt,data))83 84 return Int885 86 def IBM2float(self, ibm_float):87 p24 = float(pow(2, 24))88 if ibm_float == 0:89 return 0.090 sign = ibm_float >> 31 & 0x0191 exponent = ibm_float >> 24 & 0x7f 92 mantissa = (ibm_float & 0x00ffffff)/p24 93 return (1-2*sign)*(mantissa)*pow(16, exponent-64)94# return pow(-1, sign)*(mantissa)*pow(16, exponent-64)95 96 97 98 def float2IBM(self, float32):99 # This function is for transform pc float to IBM float100 # 符å·101 if float32 < 0:102 sign = 1103 else:104 sign = 0105 #abs float32106 float32 = float32*(1-2*sign)107 exp = 0108 floatc = float32109 110 if floatc > 0: #éé¶å¼æ计ç®111 if int(floatc) > 0:112 exp = exp + 1113 while int(floatc/16) > 0:114 exp = exp + 1115 floatc = floatc/16116 else:117 while int(floatc)*16 == 0:118 exp = exp - 1119 floatc = floatc*16120 exp = exp + 1121 exponent = exp + 64122 123 mant = float32 * pow(16, -exp) #å»æfloat32çæ´æ°ï¼æå®åæå
¨å°æ°124 mantissa = int(mant * pow(2, 24))#å°åæå°æ°çfloat32左移24ä½åæ´125 126 return (sign<<31) | (exponent<<24) | mantissa127 128 129 130 def read_ibmfloat_data(self, inline, xline):131 # The function is to read trace data of 3D seismic segy data. When you input inline and 132 # xlineinformation, you can get the data of the trace. And then the function can transform 133 # the IBM float to pc float 134 self.init_binary_header() # initail the header information135 (self.inline_start, self.xline_start, self.X_min, self.Y_min) = \136 self.read_control_file(1)137 (self.inline_end, self.xline_end, self.X_max, self.Y_max) =\138 self.read_last_trace_header()139 self.inline_lens = self.inline_end - self.inline_start + 1140 self.xline_lens = self.xline_end - self.xline_start + 1141 self.trace_count = self.inline_lens * self.xline_lens142 143 144 trace_position = (inline-self.inline_start)*self.xline_lens + \145 (xline-self.xline_start)146 start_number = self.text_header_lens+self.bin_header_lens147 data_lens = self.number_of_sample * self.sample_fmt148 trace_lens = data_lens + self.trace_header_lens149 start = start_number+trace_position*trace_lens+self.trace_header_lens150 unpack_fmt = '>' + str(self.number_of_sample) + 'i'...
monitor_command.py
Source:monitor_command.py
...14 def simulator_init(self):15 pass16 def real_robot_init(self):17 pass18 def read_control_file(self, path):19 pass20 def run_simulator(self,commands):21 pass22 def back_init_state_simulator(self):23 pass24 def run_real_robot(self, commands):25 pass26 def update_init_state(self):27 pass28 def run(self):29 while not rospy.is_shutdown():30 control_file_path = raw_input("Enter the name of the kinematics file or type 'end' to end the procedure:\n")31 if control_file_path == 'end':32 break33 commands = self.read_control_file(control_file_path)34 self.run_simulator(commands)35 monitor_commands = raw_input("Enter the monitor command, accept/discard:\n")36 while monitor_commands not in self.legal_monitor_command:37 monitor_commands = raw_input("Illgal input" + monitor_commands + "please Enter the monitor command, accept/discard:\n")38 if monitor_commands == "discard":39 self.back_init_state_simulator()40 elif monitor_commands == 'accept':41 self.run_real_robot(commands)42 self.update_init_state()43class CarController(Controller):44 def __init__(self, time_delay=5):45 '''Initialize , ros subscriber'''46 super(CarController, self).__init__()47 def simulator_init(self):48 self._client = Client()49 self._client.connect()50 self.chassis_handle = self._client.get_obj_handle('Chassis')51 # self.shock_fr_handle = self._client.get_obj_handle('ShockFR')52 # self.shock_fl_handle = self._client.get_obj_handle('ShockFL')53 self.update_init_state()54 def real_robot_init(self):55 pass56 def read_control_file(self, path):57 commands = []58 f = open(path, 'r')59 lines = f.readlines()60 for line in lines[1:]:61 data = line.split(' ')62 commands.append([float(d) for d in data[:3]])63 return commands64 def run_simulator(self,commands):65 self.chassis_handle._cmd.cartesian_cmd_type = 066 for c in commands:67 self.chassis_handle.set_joint_effort(5, c[1])68 self.chassis_handle.set_joint_effort(7, c[2])69 time.sleep(c[0])70 # Set some torque for FL Wheel...
grapher.py
Source:grapher.py
1from cProfile import label2import matplotlib.pyplot as plt3import csv4import sys5def read_control_file(filename):6 with open(filename, 'r') as data_file:7 reader = csv.DictReader(data_file, delimiter=',')8 data = {field: [] for field in reader.fieldnames}9 if 'time' not in data:10 print("Data csv file must contain 'time' column")11 exit(1)12 for row in reader:13 for field, val in row.items():14 try:15 val = float(val)16 except ValueError:17 print("Data file contains non-numerical values.")18 exit(1)19 data[field].append(val)20 return data21def graph_data(data):22 time_series = data['time']23 for key in data:24 if key != 'time':25 plt.plot(time_series, data[key], label=key)26 plt.xlabel('Time')27 plt.axhline(0, color='gray', alpha=0.4)28 plt.grid(True, alpha=0.2)29 plt.legend()30 plt.show()31if __name__ == "__main__":32 try:33 data_filename = sys.argv[1]34 except IndexError:35 print("Not enough args provided.\n Usage: python3 grapher.py <data-filename>")36 exit(1)37 data = read_control_file(data_filename)...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!