def apply_change_infusion_rate(self): self.pump_ui.lineEdit_rate_infuse.setStyleSheet("color: 'red';") new_rate = utils.fit_in_range(value=float(self.pump_ui.lineEdit_rate_infuse.text()), min_max_range=self.pump.get_infusion_rate_limits()) success = self.pump.set_infusion_rate(new_rate) if success: self.pump_ui.lineEdit_rate_infuse.setText("{0:.6g}".format(new_rate)) self.main_ui.pump_lineEdit_rate_infuse.setText("{0:.6g}".format(new_rate)) self.pump_ui.lineEdit_rate_infuse.setStyleSheet("color: 'green';")
def add_new_ov(self): new_ov_number = self.number_ov y_pos = utils.fit_in_range(new_ov_number * 40, 0, 400) self.cs.set_ov_centre_s(new_ov_number, [0, y_pos]) self.set_ov_size_selector(new_ov_number, 2) self.set_ov_rotation(new_ov_number, 0) self.set_ov_magnification(new_ov_number, 360) self.set_ov_dwell_time_selector(new_ov_number, 4) self.set_ov_wd(new_ov_number, 0) self.set_ov_acq_interval(new_ov_number, 1) self.set_ov_acq_interval_offset(new_ov_number, 0) self.update_ov_file_list(new_ov_number, '') self.set_ov_debris_detection_area(new_ov_number, []) self.number_ov += 1 self.cfg['overviews']['number_ov'] = str(self.number_ov)
def update_ov_debris_detection_area(self, ov_number, gm): if self.cfg['debris']['auto_detection_area'] == 'False': # set full detection area: self.set_ov_debris_detection_area(ov_number, [ 0, 0, self.get_ov_width_p(ov_number), self.get_ov_height_p(ov_number) ]) else: (ov_top_left_dx, ov_top_left_dy, ov_bottom_right_dx, ov_bottom_right_dy) = (self.get_ov_bounding_box(ov_number)) ov_pixel_size = self.get_ov_pixel_size(ov_number) top_left_dx_min, top_left_dy_min = None, None bottom_right_dx_max, bottom_right_dy_max = None, None #extra_margin = 20 # Check all grids for active tile overlap with OV for grid_number in range(gm.get_number_grids()): for tile_number in gm.get_active_tiles(grid_number): (top_left_dx, top_left_dy, bottom_right_dx, bottom_right_dy) = (gm.get_tile_bounding_box( grid_number, tile_number)) # Is tile within OV? overlap = not (top_left_dx >= ov_bottom_right_dx or top_left_dy >= ov_bottom_right_dy or bottom_right_dx <= ov_top_left_dx or bottom_right_dy <= ov_top_left_dy) if overlap: # transform coordinates to d coord. rel. to OV image: top_left_dx -= ov_top_left_dx top_left_dy -= ov_top_left_dy bottom_right_dx -= ov_top_left_dx bottom_right_dy -= ov_top_left_dy if (top_left_dx_min is None or top_left_dx < top_left_dx_min): top_left_dx_min = top_left_dx if (top_left_dy_min is None or top_left_dy < top_left_dy_min): top_left_dy_min = top_left_dy if (bottom_right_dx_max is None or bottom_right_dx > bottom_right_dx_max): bottom_right_dx_max = bottom_right_dx if (bottom_right_dy_max is None or bottom_right_dy > bottom_right_dy_max): bottom_right_dy_max = bottom_right_dy if top_left_dx_min is None: top_left_px, top_left_py = 0, 0 bottom_right_px = self.get_ov_width_p(ov_number) bottom_right_py = self.get_ov_height_p(ov_number) else: # Now in pixel coordinates of OV image: top_left_px = int(top_left_dx_min * 1000 / ov_pixel_size) top_left_py = int(top_left_dy_min * 1000 / ov_pixel_size) bottom_right_px = int(bottom_right_dx_max * 1000 / ov_pixel_size) bottom_right_py = int(bottom_right_dy_max * 1000 / ov_pixel_size) # Add/subract margin and must fit in OV image: top_left_px = utils.fit_in_range( top_left_px - self.auto_debris_area_margin, 0, self.get_ov_width_p(ov_number)) top_left_py = utils.fit_in_range( top_left_py - self.auto_debris_area_margin, 0, self.get_ov_height_p(ov_number)) bottom_right_px = utils.fit_in_range( bottom_right_px + self.auto_debris_area_margin, 0, self.get_ov_width_p(ov_number)) bottom_right_py = utils.fit_in_range( bottom_right_py + self.auto_debris_area_margin, 0, self.get_ov_height_p(ov_number)) # set detection area: self.set_ov_debris_detection_area( ov_number, [top_left_px, top_left_py, bottom_right_px, bottom_right_py])
def update_debris_detection_area(self, grid_manager, auto_detection=True, margin=0): """Change the debris detection area to cover all tiles from all grids that fall within the overview specified by ov_number.""" if auto_detection: (ov_top_left_dx, ov_top_left_dy, ov_bottom_right_dx, ov_bottom_right_dy) = self.bounding_box() ov_pixel_size = self.pixel_size # The following corner coordinates define the debris detection area top_left_dx_min, top_left_dy_min = None, None bottom_right_dx_max, bottom_right_dy_max = None, None # Check all grids for active tile overlap with OV for grid_index in range(grid_manager.number_grids): if not grid_manager[grid_index].active: continue for tile_index in grid_manager[grid_index].active_tiles: (min_dx, max_dx, min_dy, max_dy) = ( grid_manager[grid_index].tile_bounding_box(tile_index)) # Is tile within OV? overlap = not (min_dx >= ov_bottom_right_dx or min_dy >= ov_bottom_right_dy or max_dx <= ov_top_left_dx or max_dy <= ov_top_left_dy) if overlap: # transform coordinates to d coord. rel. to OV image: min_dx -= ov_top_left_dx min_dy -= ov_top_left_dy max_dx -= ov_top_left_dx max_dy -= ov_top_left_dy if (top_left_dx_min is None or min_dx < top_left_dx_min): top_left_dx_min = min_dx if (top_left_dy_min is None or min_dy < top_left_dy_min): top_left_dy_min = min_dy if (bottom_right_dx_max is None or max_dx > bottom_right_dx_max): bottom_right_dx_max = max_dx if (bottom_right_dy_max is None or max_dy > bottom_right_dy_max): bottom_right_dy_max = max_dy if top_left_dx_min is None: top_left_px, top_left_py = 0, 0 bottom_right_px = self.width_p() bottom_right_py = self.height_p() else: # Now in pixel coordinates of OV image: top_left_px = int(top_left_dx_min * 1000 / ov_pixel_size) top_left_py = int(top_left_dy_min * 1000 / ov_pixel_size) bottom_right_px = int( bottom_right_dx_max * 1000 / ov_pixel_size) bottom_right_py = int( bottom_right_dy_max * 1000 / ov_pixel_size) # Add/subract margin and must fit in OV image: top_left_px = utils.fit_in_range( top_left_px - margin, 0, self.width_p()) top_left_py = utils.fit_in_range( top_left_py - margin, 0, self.height_p()) bottom_right_px = utils.fit_in_range( bottom_right_px + margin, 0, self.width_p()) bottom_right_py = utils.fit_in_range( bottom_right_py + margin, 0, self.height_p()) # set calculated detection area: self.debris_detection_area = [ top_left_px, top_left_py, bottom_right_px, bottom_right_py] else: # set full detection area: self.debris_detection_area = [0, 0, self.width_p(), self.height_p()]