def roberts_filter(arr): padded = padding(arr) for x in range(arr.shape[0]): for y in range(arr.shape[1]): padded[x, y, 0] = bound( np.absolute( np.sum(np.multiply(padded[x:x + 2, y:y + 2, 0], roberts1))) + np.absolute( np.sum(np.multiply(padded[x:x + 2, y:y + 2, 0], roberts2)))) padded[x, y, 1] = bound( np.absolute( np.sum(np.multiply(padded[x:x + 2, y:y + 2, 1], roberts1))) + np.absolute( np.sum(np.multiply(padded[x:x + 2, y:y + 2, 1], roberts2)))) padded[x, y, 2] = bound( np.absolute( np.sum(np.multiply(padded[x:x + 2, y:y + 2, 2], roberts1))) + np.absolute( np.sum(np.multiply(padded[x:x + 2, y:y + 2, 2], roberts2)))) return padded
def main(args): img = im_to_arr(args[0]) r_lut = bound(np.array(range(0, 256)) + 50) g_lut = bound(np.array(range(0, 256)) + 40) b_lut = bound(np.array(range(0, 256)) - 100) img[:, :, 0] = lut_mainp(img[:, :, 2], r_lut) img[:, :, 1] = lut_mainp(img[:, :, 2], g_lut) img[:, :, 2] = lut_mainp(img[:, :, 2], b_lut) img = Image.fromarray(img.astype(np.uint8)) img.show()
def applyFilter(arr, filter): padded = padding(arr) for x in range(arr.shape[0]): for y in range(arr.shape[1]): padded[x + 1, y + 1, 0] = bound( np.sum(np.multiply(padded[x:x + 3, y:y + 3, 0], filter))) padded[x + 1, y + 1, 1] = bound( np.sum(np.multiply(padded[x:x + 3, y:y + 3, 1], filter))) padded[x + 1, y + 1, 2] = bound( np.sum(np.multiply(padded[x:x + 3, y:y + 3, 2], filter))) return padded
def process(self): twist_body = addict.Dict() twist_body.linear = self.state.to_body(self.state.twist.linear) twist_body.angular = self.state.to_body(self.state.twist.angular) load_factor = utils.bound(self.state.load_factor, self.load_factor_limit) acceleration_command = np.array([0.0, 0.0, 0.0]) acceleration_command[0] = self.pid.linear.x.update( self.input_.twist.linear.x, self.state.twist.linear[0], self.state.acceleration[0], self.dt ) acceleration_command[1] = self.pid.linear.y.update( self.input_.twist.linear.y, self.state.twist.linear[1], self.state.acceleration[1], self.dt ) acceleration_command[2] = ( self.pid.linear.z.update( self.input_.twist.linear.z, self.state.twist.linear[2], self.state.acceleration[2], self.dt ) + self.state.gravity ) acceleration_command_body = self.state.to_body(acceleration_command) if self.verbose: utils.pv( "twist_body", "self.state.load_factor", "load_factor", "acceleration_command", "acceleration_command_body", ) self.output.wrench.torque.x = self.state.inertia[0] * self.pid.angular.x.update( -acceleration_command_body[1] / self.state.gravity, 0.0, twist_body.angular[0], self.dt ) self.output.wrench.torque.y = self.state.inertia[1] * self.pid.angular.y.update( acceleration_command_body[0] / self.state.gravity, 0.0, twist_body.angular[1], self.dt ) self.output.wrench.torque.z = self.state.inertia[2] * self.pid.angular.z.update( self.input_.twist.angular.z, self.state.twist.angular[2], 0.0, self.dt ) self.output.wrench.force.x = 0.0 self.output.wrench.force.y = 0.0 self.output.wrench.force.z = self.state.mass * ( (acceleration_command[2] - self.state.gravity) * load_factor + self.state.gravity ) self.output.wrench.force.z = utils.bound(self.output.wrench.force.z, self.force_z_limit) self.output.wrench.force.z = max(self.output.wrench.force.z, 0.0) self.output.wrench.torque.x = utils.bound(self.output.wrench.torque.x, self.torque_xy_limit) self.output.wrench.torque.y = utils.bound(self.output.wrench.torque.y, self.torque_xy_limit) self.output.wrench.torque.z = utils.bound(self.output.wrench.torque.z, self.torque_z_limit)
def process(self): twist_body = addict.Dict() twist_body.linear = self.state.to_body(self.state.twist.linear) twist_body.angular = self.state.to_body(self.state.twist.angular) load_factor = utils.bound(self.state.load_factor, self.load_factor_limit) acceleration_command = np.array([0.0, 0.0, 0.0]) acceleration_command[0] = self.pid.linear.x.update( self.input_.twist.linear.x, self.state.twist.linear[0], self.state.acceleration[0], self.dt) acceleration_command[1] = self.pid.linear.y.update( self.input_.twist.linear.y, self.state.twist.linear[1], self.state.acceleration[1], self.dt) acceleration_command[2] = self.pid.linear.z.update( self.input_.twist.linear.z, self.state.twist.linear[2], self.state.acceleration[2], self.dt) + self.state.gravity acceleration_command_body = self.state.to_body(acceleration_command) if self.verbose: utils.pv('twist_body', 'self.state.load_factor', 'load_factor', 'acceleration_command', 'acceleration_command_body') self.output.wrench.torque.x = self.state.inertia[ 0] * self.pid.angular.x.update( -acceleration_command_body[1] / self.state.gravity, 0.0, twist_body.angular[0], self.dt) self.output.wrench.torque.y = self.state.inertia[ 1] * self.pid.angular.y.update( acceleration_command_body[0] / self.state.gravity, 0.0, twist_body.angular[1], self.dt) self.output.wrench.torque.z = self.state.inertia[ 2] * self.pid.angular.z.update(self.input_.twist.angular.z, self.state.twist.angular[2], 0.0, self.dt) self.output.wrench.force.x = 0.0 self.output.wrench.force.y = 0.0 self.output.wrench.force.z = self.state.mass * \ ((acceleration_command[2] - self.state.gravity) * load_factor + self.state.gravity) self.output.wrench.force.z = utils.bound(self.output.wrench.force.z, self.force_z_limit) self.output.wrench.force.z = max(self.output.wrench.force.z, 0.0) self.output.wrench.torque.x = utils.bound(self.output.wrench.torque.x, self.torque_xy_limit) self.output.wrench.torque.y = utils.bound(self.output.wrench.torque.y, self.torque_xy_limit) self.output.wrench.torque.z = utils.bound(self.output.wrench.torque.z, self.torque_z_limit)
def pid(self, error, dx, dt): if self.verbose: print "error: {}, dx: {}, dt: {}".format(error, dx, dt) if math.isnan(error): return 0.0 # integral error self.state.i += error * dt self.state.i = utils.bound(self.state.i, self.params.limit_i) # differential error if dt > 0.0 and not math.isnan(self.state.p) and not math.isnan( self.state.dx): self.state.d = (error - self.state.p) / dt + self.state.dx - dx else: self.state.d = -dx self.state.dx = dx # proportional error self.state.p = error # calculate output... output = self.params.k_p * self.state.p +\ self.params.k_i * self.state.i + \ self.params.k_d * self.state.d if self.verbose: print "output: {}, k_p: {}, p: {}, k_i: {}, i: {}, k_d: {}, d: {}".format( output, self.params.k_p, self.state.p, self.params.k_i, self.state.i, self.params.k_d, self.state.d) antiwindup = 0 if self.params.limit_output > 0.0: if output > self.params.limit_output: antiwindup = 1 elif output < -self.params.limit_output: antiwindup = -1 output = utils.bound(output, self.params.limit_output) if antiwindup != 0 and error * dt * antiwindup > 0.0: self.state.i -= error * dt if math.isnan(output): output = 0.0 return output
def start_deviation(self, a_step: int): self.settings[self.MEASURE_SECTION][self.START_DEVIATION_KEY] = str( a_step) self.save() self.__start_deviation = a_step self.__start_deviation = utils.bound(self.__start_deviation, 0, 100)
def mouse_inversion(self, a_enable: int): self.settings[self.MEASURE_SECTION][self.MOUSE_INVERSION_KEY] = str( a_enable) self.save() self.__mouse_inversion = a_enable self.__mouse_inversion = utils.bound(self.__mouse_inversion, 0, 1)
def frequency_changed(self): actual_frequency = utils.bound(self.__clb_dll.get_frequency(), clb.MIN_FREQUENCY, clb.MAX_FREQUENCY) if self.__frequency != actual_frequency: self.__frequency = actual_frequency return True else: return False
def main(args): m = 100 img = im_to_arr(args[0]) m = max(0, min(m, 255)) inv = bound(img + m) inv = Image.fromarray(inv.astype(np.uint8)) inv.show()
def pid(self, error, dx, dt): if self.verbose: print "error: {}, dx: {}, dt: {}".format(error, dx, dt) if math.isnan(error): return 0.0 # integral error self.state.i += error * dt self.state.i = utils.bound(self.state.i, self.params.limit_i) # differential error if dt > 0.0 and not math.isnan(self.state.p) and not math.isnan(self.state.dx): self.state.d = (error - self.state.p) / dt + self.state.dx - dx else: self.state.d = -dx self.state.dx = dx # proportional error self.state.p = error # calculate output... output = self.params.k_p * self.state.p +\ self.params.k_i * self.state.i + \ self.params.k_d * self.state.d if self.verbose: print "output: {}, k_p: {}, p: {}, k_i: {}, i: {}, k_d: {}, d: {}".format( output, self.params.k_p, self.state.p, self.params.k_i, self.state.i, self.params.k_d, self.state.d) antiwindup = 0 if self.params.limit_output > 0.0: if output > self.params.limit_output: antiwindup = 1 elif output < -self.params.limit_output: antiwindup = -1 output = utils.bound(output, self.params.limit_output) if antiwindup != 0 and error * dt * antiwindup > 0.0: self.state.i -= error * dt if math.isnan(output): output = 0.0 return output
def disable_scroll_on_table(self, a_enable: int): self.settings[self.MEASURE_SECTION][ self.DISABLE_SCROLL_ON_TABLE_KEY] = str(a_enable) self.save() self.__disable_scroll_on_table = a_enable self.__disable_scroll_on_table = utils.bound( self.__disable_scroll_on_table, 0, 1)
def fixed_step_idx(self, a_idx: int): self.settings[self.MEASURE_SECTION][self.FIXED_STEP_IDX_KEY] = str( a_idx) self.save() self.__fixed_step_idx = a_idx self.__fixed_step_idx = utils.bound(self.__fixed_step_idx, 0, len(self.__fixed_step_list) - 1)
def limit_amplitude(self, a_amplitude, a_lower, a_upper): """ Обрезает значение амплитуды с учетом типа сигнала и параметров пользователя :param a_amplitude: Заданная амплитуда :param a_lower: Нижняя граница :param a_upper: Верхняя граница """ return utils.bound(clb.bound_amplitude(a_amplitude, self.__signal_type), a_lower, a_upper)
def set_amplitude(self, a_amplitude: float): self.calibrator.amplitude = utils.bound(a_amplitude, self.lowest_amplitude, self.highest_amplitude) self.ui.amplitude_edit.setText( self.value_to_user(self.calibrator.amplitude)) self.amplitude_edit_text_changed() self.update_current_point(self.calibrator.amplitude)
def bound_amplitude(a_amplitude: float, a_signal_type: SignalType): min_value = MIN_VOLTAGE max_value = MAX_VOLTAGE if not is_voltage_signal[a_signal_type]: min_value = MIN_CURRENT max_value = MAX_CURRENT if is_ac_signal[a_signal_type]: min_value = MIN_ALTERNATIVE return round(bound(a_amplitude, min_value, max_value), 9)
def main(args): try: img = Image.open(args[0]) except FileNotFoundError: print('usege: python color_inversion.py <name of a file to convert>') else: img = np.array(img.convert('RGB')) inv = bound(255 - img) inv = Image.fromarray(inv).convert("RGB") inv.show()
def get_action(self, i, obs): if i <= self.pause_time: input_to_net = np.array(obs[0] + obs[1] + obs[2] + obs[3] + list(obs[4]) + [i / self.pause_time]) with torch.no_grad(): input_to_net = torch.Tensor(input_to_net) action = self.action_network(input_to_net).numpy() # hypothesis: control in speed instead of position action = self.last_action[:7] + self.gain * action utils.bound(action, self.action_bounds) if i < self.grip_time: action = np.append(action, 1) # gripper is open else: action = np.append(action, -1) # gripper is closed self.last_action = action else: # feed last action action = self.last_action return action
def voltage_to_dac_code(a_voltage: float, r1: float, r2: float, r3: float, v0: float): v_max = 3.3 u1 = v0 + r1 * (v0 / r2 - (a_voltage - v0) / r3) float_code = 1 - u1 / v_max float_code = utils.bound(float_code, 0, 1) float_code_discrete = floor(float_code * 255) / 255 voltage_discrete = (v0 / r2 - (v_max * (1 - float_code_discrete) - v0) / r1) * r3 + v0 return float_code, voltage_discrete
def status(self): response = bound( self._response, self.min_time, self.max_time) diff = (response - self.min_time) / self._step pixel = bytearray(3) pixel[0] = byte_bound(diff) pixel[1] = byte_bound(254 - diff) pixel[2] = 0 return (colors.STATIC, pixel)
def write_variable(self, a_variable_number: int, a_variable_value: float): variable_info = self.__variables_info[a_variable_number] if variable_info.c_type == 'o': value = int(utils.bound(a_variable_value, 0, 1)) self.__calibrator.write_bit(variable_info.index, variable_info.bit_index, value) else: if variable_info.c_type != 'd' and variable_info.c_type != 'f': a_variable_value = int(a_variable_value) _bytes = struct.pack(variable_info.c_type, a_variable_value) self.__calibrator.write_raw_bytes(variable_info.index, variable_info.size, _bytes)
def gen_sample_pair(self, files_list, mode='train'): image_size = self.hmap[random.choice(files_list)].shape[0] while True: coord_range = (window_size*1.25//2 + 1, image_size - window_size*1.25//2 - 1) normal_queue = self.sample_with_error(target=0, image_files=files_list, coord_range=coord_range, initial_sample_num=self.normal_sampling[0], final_sample_num=int(self.normal_sampling[0]*self.normal_sampling[1])) mitosis_queue = self.sample_with_error(target=1, image_files=files_list, coord_range=coord_range, initial_sample_num=self.mitosis_sampling[0], final_sample_num=int(self.mitosis_sampling[0]*self.mitosis_sampling[1])) queue = np.append(normal_queue, mitosis_queue, axis=0) target = np.append(np.zeros(len(normal_queue)), np.ones(len(mitosis_queue))) queue, target = shuffle(queue, target) for (image_file, x, y), target_val in zip(queue, target): #x, y = x + random.randint(-8, 8), y + random.randint(-8, 8) x, y = int(x), int(y) window_size_exp = window_size if random.randint(0, 1) == 0: window_size_exp = int(window_size * random.choice([0.75, 0.8, 1.0, 1.2, 1.25])) xs, ys = x - window_size_exp//2, y - window_size_exp//2 xs, ys = bound((xs, ys), low=1, high=image_size - window_size_exp -1) pred = np.array([[[1 - target_val, target_val]]]) img = self.img[image_file][xs:(xs + window_size_exp), ys:(ys + window_size_exp)] img = scipy.misc.imresize(img, (window_size, window_size, 3))/255.0 if random.randint(0, 1) == 0: img = np.rot90(img) if random.randint(0, 1) == 0: img = np.fliplr(img) if random.randint(0, 1) == 0: img = np.flipud(img) if random.randint(0, 3) == 0: angle = random.randint(-25, 25) img = rotate(img, angle, reshape=False) yield img, pred
def fixed_step_list(self, a_list: List[float]): # Удаляет дубликаты final_list = list(dict.fromkeys(a_list)) final_list.sort() saved_string = ','.join(str(val) for val in final_list) saved_string = saved_string.strip(',') self.settings[self.MEASURE_SECTION][self.FIXED_STEP_KEY] = saved_string self.save() self.__fixed_step_list = [val for val in final_list] self.__fixed_step_idx = utils.bound(self.__fixed_step_idx, 0, len(self.__fixed_step_list) - 1) self.fixed_step_changed.emit()
def go_to_point(self): rows = self.measure_manager.view().get_selected_rows() if rows: row_idx = rows[0].row() target_amplitude = utils.parse_input( self.measure_manager.view().get_point_by_row(row_idx)) target_frequency = float( self.measure_manager.view().get_frequency_by_row( row_idx).replace(',', '.')) if target_amplitude != self.calibrator.amplitude: measured_up = self.measure_manager.view( ).is_point_measured_by_row(row_idx, PointData.ApproachSide.UP) measured_down = self.measure_manager.view( ).is_point_measured_by_row(row_idx, PointData.ApproachSide.DOWN) if measured_down == measured_up: # Точка измерена полностью либо совсем не измерена, подходим с ближайшей стороны if self.calibrator.amplitude > target_amplitude: change_value_foo = utils.increase_by_percent else: change_value_foo = utils.decrease_by_percent else: if measured_up: change_value_foo = utils.decrease_by_percent else: change_value_foo = utils.increase_by_percent target_amplitude = change_value_foo( target_amplitude, self.settings.start_deviation, a_normalize_value=self.current_case.limit) target_amplitude = utils.bound(target_amplitude, self.lowest_amplitude, self.highest_amplitude) target_frequency = clb.bound_frequency( target_frequency, self.current_case.signal_type) self.start_approach_to_point(target_amplitude, target_frequency)
def gen_sample_pair(self, files_list, mode='train'): while True: image_file = random.choice(files_list) hmap = self.hmap[image_file] if hmap.sum()*1.0/(window_size*window_size) <= 0.1: continue target = np.random.choice([0, 1], p=[0.5, 0.5]) window_size_exp = window_size if random.randint(0, 1) == 0: window_size_exp = int(window_size * random.choice([0.75, 0.8, 1.0, 1.2, 1.25])) while True: x = random.randint(window_size_exp//2 + 10, hmap.shape[0] - window_size_exp//2 - 10) y = random.randint(window_size_exp//2 + 10, hmap.shape[0] - window_size_exp//2 - 10) if target == hmap[x, y]: break #x, y = x + random.randint(-8, 8), y + random.randint(-8, 8) xs, ys = x - window_size_exp//2, y - window_size_exp//2 xs, ys = bound((xs, ys), low=1, high=hmap.shape[0] - window_size -1) pred = np.array([[[1 - target, target]]]) img = self.img[image_file][xs:(xs + window_size_exp), ys:(ys + window_size_exp)] img = scipy.misc.imresize(img, (window_size, window_size, 3))/255.0 if random.randint(0, 1) == 0: img = np.rot90(img) if random.randint(0, 1) == 0: img = np.fliplr(img) if random.randint(0, 1) == 0: img = np.flipud(img) if random.randint(0, 2) == 0: angle = random.randint(-25, 25) img = rotate(img, angle, reshape=False) yield img, pred
def gen_sample_pair(self, files_list, mode='train'): while True: image_file = random.choice(files_list) hmap = self.hmap[image_file] target = np.random.choice([0, 1], p=[0.5, 0.5]) window_size_exp = window_size if random.randint(0, 1) == 0: window_size_exp = int(window_size * random.choice([0.75, 0.8, 1.0, 1.2, 1.25])) while True: x = random.randint(window_size_exp//2 + 10, hmap.shape[0] - window_size_exp//2 - 10) y = random.randint(window_size_exp//2 + 10, hmap.shape[1] - window_size_exp//2 - 10) if target == int(round(hmap[x, y])): break #x, y = x + random.randint(-8, 8), y + random.randint(-8, 8) xs, ys = x - window_size_exp//2, y - window_size_exp//2 xs, ys = bound((xs, ys), low=1, high=hmap.shape[0] - window_size -1) pred = np.array([[[1 - hmap[x, y], hmap[x, y]]]]) img = self.img[image_file][xs:(xs + window_size_exp), ys:(ys + window_size_exp)] img = scipy.ndimage.zoom(img, zoom=(window_size*1.0/window_size_exp, window_size*1.0/window_size_exp, 1)) assert img.shape == (window_size, window_size, 20) if random.randint(0, 1) == 0: img = np.rot90(img) if random.randint(0, 1) == 0: img = np.fliplr(img) if random.randint(0, 1) == 0: img = np.flipud(img) if random.randint(0, 2) == 0: angle = random.randint(-25, 25) img = rotate(img, angle, reshape=False, mode='reflect') yield img, pred
def forward(self, c, h_bottom, h, h_top, z, z_bottom): # h_bottom.size = bottom_size * batch_size s_recur = torch.mm(self.W_01, h_bottom) if not self.last_layer: s_topdown_ = torch.mm(self.U_21, h_top) s_topdown = z.expand_as(s_topdown_) * s_topdown_ else: s_topdown = Variable(torch.zeros(s_recur.size()).cuda(), requires_grad=False).cuda() s_bottomup_ = torch.mm(self.U_11, h) s_bottomup = z_bottom.expand_as(s_bottomup_) * s_bottomup_ f_s = s_recur + s_topdown + s_bottomup + self.bias.unsqueeze(1).expand_as(s_recur) # f_s.size = (4 * hidden_size + 1) * batch_size f = Func.sigmoid(f_s[0:self.hidden_size, :]) # hidden_size * batch_size i = Func.sigmoid(f_s[self.hidden_size:self.hidden_size*2, :]) o = Func.sigmoid(f_s[self.hidden_size*2:self.hidden_size*3, :]) g = Func.tanh(f_s[self.hidden_size*3:self.hidden_size*4, :]) z_hat = hard_sigm(self.a, f_s[self.hidden_size*4:self.hidden_size*4+1, :]) one = Variable(torch.ones(f.size()).cuda(), requires_grad=False) z = z.expand_as(f) z_bottom = z_bottom.expand_as(f) c_new = z * (i * g) + (one - z) * (one - z_bottom) * c + (one - z) * z_bottom * (f * c + i * g) h_new = z * o * Func.tanh(c_new) + (one - z) * (one - z_bottom) * h + (one - z) * z_bottom * o * Func.tanh(c_new) # if z == 1: (FLUSH) # c_new = i * g # h_new = o * Func.tanh(c_new) # elif z_bottom == 0: (COPY) # c_new = c # h_new = h # else: (UPDATE) # c_new = f * c + i * g # h_new = o * Func.tanh(c_new) z_new = bound()(z_hat) return h_new, c_new, z_new
def sobel_filter(arr): padded = padding(arr) for x in range(arr.shape[0]): for y in range(arr.shape[1]): r, g, b = 0, 0, 0 r += np.abs( np.sum(np.multiply(padded[x:x + 3, y:y + 3, 0], sobel0))) g += np.abs( np.sum(np.multiply(padded[x:x + 3, y:y + 3, 1], sobel0))) b += np.abs( np.sum(np.multiply(padded[x:x + 3, y:y + 3, 2], sobel0))) r += np.abs( np.sum(np.multiply(padded[x:x + 3, y:y + 3, 0], sobel45))) g += np.abs( np.sum(np.multiply(padded[x:x + 3, y:y + 3, 1], sobel45))) b += np.abs( np.sum(np.multiply(padded[x:x + 3, y:y + 3, 2], sobel45))) r += np.abs( np.sum(np.multiply(padded[x:x + 3, y:y + 3, 0], sobel90))) g += np.abs( np.sum(np.multiply(padded[x:x + 3, y:y + 3, 1], sobel90))) b += np.abs( np.sum(np.multiply(padded[x:x + 3, y:y + 3, 2], sobel90))) r += np.abs( np.sum(np.multiply(padded[x:x + 3, y:y + 3, 0], sobel135))) g += np.abs( np.sum(np.multiply(padded[x:x + 3, y:y + 3, 1], sobel135))) b += np.abs( np.sum(np.multiply(padded[x:x + 3, y:y + 3, 2], sobel135))) padded[x, y] = bound([int(r), int(g), int(b)]) return padded
def set(self, a_value): try: assert self.__mode == BufferedVariable.Mode.RW, \ f"Режим переменной должен быть RW !! " \ f"(Индекс: {self.__variable_info.index}.{self.__variable_info.bit_index})" if self.__is_bit: a_value = int(utils.bound(a_value, 0, 1)) self.__calibrator.write_bit(self.__variable_info.index, self.__variable_info.bit_index, a_value) else: if self.__variable_info.c_type != 'd' and self.__variable_info.c_type != 'f': a_value = int(a_value) _bytes = struct.pack(self.__variable_info.c_type, a_value) self.__calibrator.write_raw_bytes(self.__variable_info.index, self.__variable_info.size, _bytes) self.__buffer = a_value self.__delay_timer.start() except AssertionError as err: logging.debug(utils.exception_handler(err))
def rough_step(self, a_step: float): self.settings[self.MEASURE_SECTION][self.STEP_ROUGH_KEY] = str(a_step) self.save() self.__rough_step = a_step self.__rough_step = utils.bound(self.__rough_step, 0., 100.)
def frequency(self, a_frequency: float): self.__frequency = utils.bound(a_frequency, clb.MIN_FREQUENCY, clb.MAX_FREQUENCY) self.__clb_dll.set_frequency(self.__frequency)
def bound_frequency(a_frequency: float, a_signal_type: SignalType): min_frequency = MIN_FREQUENCY if is_ac_signal[a_signal_type] else 0 max_frequency = MAX_FREQUENCY if is_ac_signal[a_signal_type] else 0 return round(bound(a_frequency, min_frequency, max_frequency), 9)
def bound_input(self, a_value): return utils.bound(a_value, self.min_value, self.max_value)
def restore_settings(self): if not os.path.exists(self.CONFIG_PATH): self.settings[self.MEASURE_SECTION] = { self.FIXED_STEP_KEY: self.FIXED_STEP_DEFAULT, self.FIXED_STEP_IDX_KEY: self.FIXED_STEP_IDX_DEFAULT, self.STEP_ROUGH_KEY: self.STEP_ROUGH_DEFAULT, self.STEP_COMMON_KEY: self.STEP_COMMON_DEFAULT, self.STEP_EXACT_KEY: self.STEP_EXACT_DEFAULT, self.START_DEVIATION_KEY: self.START_DEVIATION_DEFAULT, self.MOUSE_INVERSION_KEY: self.MOUSE_INVERSION_DEFAULT, self.DISABLE_SCROLL_ON_TABLE_KEY: self.DISABLE_SCROLL_ON_TABLE_DEFAULT } self.settings[self.PROTOCOL_SECTION] = { self.TEMPLATE_FILEPATH_KEY: "", self.SAVE_FOLDER_KEY: "" } utils.save_settings(self.CONFIG_PATH, self.settings) else: self.settings.read(self.CONFIG_PATH) self.add_ini_section(self.MEASURE_SECTION) self.add_ini_section(self.PROTOCOL_SECTION) self.__fixed_step_list = self.check_ini_value( self.MEASURE_SECTION, self.FIXED_STEP_KEY, self.FIXED_STEP_DEFAULT, self.ValueType.LIST_FLOAT) self.__fixed_step_idx = self.check_ini_value( self.MEASURE_SECTION, self.FIXED_STEP_IDX_KEY, self.FIXED_STEP_IDX_DEFAULT, self.ValueType.INT) self.__fixed_step_idx = utils.bound(self.__fixed_step_idx, 0, len(self.__fixed_step_list) - 1) self.__rough_step = self.check_ini_value(self.MEASURE_SECTION, self.STEP_ROUGH_KEY, self.STEP_ROUGH_DEFAULT, self.ValueType.FLOAT) self.__rough_step = utils.bound(self.__rough_step, 0., 100.) self.__common_step = self.check_ini_value(self.MEASURE_SECTION, self.STEP_COMMON_KEY, self.STEP_COMMON_DEFAULT, self.ValueType.FLOAT) self.__common_step = utils.bound(self.__common_step, 0., 100.) self.__exact_step = self.check_ini_value(self.MEASURE_SECTION, self.STEP_EXACT_KEY, self.STEP_EXACT_DEFAULT, self.ValueType.FLOAT) self.__exact_step = utils.bound(self.__exact_step, 0., 100.) self.__start_deviation = self.check_ini_value( self.MEASURE_SECTION, self.START_DEVIATION_KEY, self.START_DEVIATION_DEFAULT, self.ValueType.INT) self.__start_deviation = utils.bound(self.__start_deviation, 0, 100) self.__mouse_inversion = self.check_ini_value( self.MEASURE_SECTION, self.MOUSE_INVERSION_KEY, self.MOUSE_INVERSION_DEFAULT, self.ValueType.INT) self.__mouse_inversion = utils.bound(self.__mouse_inversion, 0, 1) self.__disable_scroll_on_table = self.check_ini_value( self.MEASURE_SECTION, self.DISABLE_SCROLL_ON_TABLE_KEY, self.DISABLE_SCROLL_ON_TABLE_DEFAULT, self.ValueType.INT) self.__disable_scroll_on_table = utils.bound( self.__disable_scroll_on_table, 0, 1) self.__template_filepath = self.check_ini_value( self.PROTOCOL_SECTION, self.TEMPLATE_FILEPATH_KEY, "", self.ValueType.STRING) self.__save_folder = self.check_ini_value(self.PROTOCOL_SECTION, self.SAVE_FOLDER_KEY, "", self.ValueType.STRING)
def common_step(self, a_step: float): self.settings[self.MEASURE_SECTION][self.STEP_COMMON_KEY] = str(a_step) self.save() self.__common_step = a_step self.__common_step = utils.bound(self.__common_step, 0., 100.)
def exact_step(self, a_step: float): self.settings[self.MEASURE_SECTION][self.STEP_EXACT_KEY] = str(a_step) self.save() self.__exact_step = a_step self.__exact_step = utils.bound(self.__exact_step, 0., 100.)