DAQ: added ml_bounding_box to loop centering, creates grid scan grid using ml. Fixed bug where filename wouldn't iterate for copied grid scans.
This commit is contained in:
@@ -143,6 +143,9 @@ class MainWindow(QMainWindow):
|
||||
self.beamline.samcam.changed.connect(self.daq.samcam_settings)
|
||||
self.beamline.loopctr.background.clicked.connect(self.daq.alc_background)
|
||||
self.beamline.loopctr.find_tip.clicked.connect(self.daq.center_loop)
|
||||
self.beamline.loopctr.bounding_box.clicked.connect(self.daq.ml_bounding_box)
|
||||
self.daq.raster_generated_by_ml.connect(self.raster.update_active_grid_request)
|
||||
|
||||
self.camera_image.smargon.connect(self.daq.move_smargon)
|
||||
self.beamline.smargon_panel.smargon.connect(self.daq.move_smargon)
|
||||
self.camera_image.samcam_updated.connect(self.daq.samcam_settings)
|
||||
|
||||
@@ -8,11 +8,14 @@ class LoopCenteringPanel(QWidget):
|
||||
super().__init__(parent)
|
||||
grid_layout = QGridLayout(self)
|
||||
|
||||
grid_layout.addWidget(TitleLabel("Loop centering", self), 0, 0, 1, 2)
|
||||
grid_layout.addWidget(TitleLabel("Loop centering", self), 0, 0, 1, 3)
|
||||
grid_layout.setColumnStretch(0, 1)
|
||||
grid_layout.setColumnStretch(1, 1)
|
||||
|
||||
self.find_tip = QPushButton("Center", parent=self)
|
||||
grid_layout.addWidget(self.find_tip, 1, 0)
|
||||
self.background = QPushButton("Background", parent=self)
|
||||
self.background = QPushButton("Bkg", parent=self)
|
||||
grid_layout.addWidget(self.background, 1, 1)
|
||||
|
||||
self.bounding_box = QPushButton("Box", parent=self)
|
||||
grid_layout.addWidget(self.bounding_box, 1, 2)
|
||||
|
||||
@@ -123,6 +123,18 @@ class RasterGridManager(QObject):
|
||||
return True
|
||||
return False
|
||||
|
||||
@Slot(RasterGridRequest)
|
||||
def update_active_grid_request(self, grid: RasterGridRequest):
|
||||
self.__active_grid.smargon = grid.smargon
|
||||
self.__active_grid.omega_deg = grid.omega_deg
|
||||
self.__active_grid.grid_size_mm = grid.grid_size_mm
|
||||
self.__active_grid.n_x = grid.n_x
|
||||
self.__active_grid.n_y = grid.n_y
|
||||
self.grid_scan_size_changed.emit(self.__active_grid.n_x,
|
||||
self.__active_grid.n_y,
|
||||
self.__active_grid.grid_size_mm.x,
|
||||
self.__active_grid.grid_size_mm.y)
|
||||
|
||||
@Slot(DAQStatusModel)
|
||||
def update_daq_status(self, s: DAQStatusModel):
|
||||
if s.sample is not None and s.sample.db_id != self.__sample_id:
|
||||
@@ -401,7 +413,13 @@ class RasterGridManager(QObject):
|
||||
@Slot(int)
|
||||
def completed_grid_redo(self, row: int):
|
||||
if 0 <= row < len(self.__completed_grids):
|
||||
self.__active_grid = copy.deepcopy(self.__completed_grids[row].request)
|
||||
copy_of_active_grid = copy.deepcopy(self.__completed_grids[row].request)
|
||||
self.__active_grid.n_x = copy_of_active_grid.n_x
|
||||
self.__active_grid.n_y = copy_of_active_grid.n_y
|
||||
self.__active_grid.grid_size_mm = copy_of_active_grid.grid_size_mm
|
||||
self.__active_grid.smargon = copy_of_active_grid.smargon
|
||||
self.__active_grid.omega_deg = copy_of_active_grid.omega_deg
|
||||
|
||||
self.__active_grid.visible = True
|
||||
self.__completed_grids[row].request.visible = False
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ class DAQWorker(QObject):
|
||||
run_number_incremented = Signal()
|
||||
raster_scan_completed = Signal(CompletedRasterGrid)
|
||||
standard_scan_completed = Signal(CompletedRotationScan)
|
||||
raster_generated_by_ml = Signal(RasterGridRequest)
|
||||
|
||||
def __init__(self, base_url: str | None, token: str, parent=None):
|
||||
super().__init__(parent)
|
||||
@@ -342,3 +343,25 @@ class DAQWorker(QObject):
|
||||
@Slot()
|
||||
def cancel(self):
|
||||
self.generic_post("scan/cancel")
|
||||
|
||||
def handle_ml_box_response(self, reply):
|
||||
try:
|
||||
response_data = self.handle_response(reply)
|
||||
if response_data != "":
|
||||
parsed_response = RasterGridRequest.model_validate_json(response_data)
|
||||
self.raster_generated_by_ml.emit(parsed_response)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
self.http_error.emit(str(e))
|
||||
|
||||
@Slot()
|
||||
def ml_bounding_box(self):
|
||||
if self.__base_url is None:
|
||||
print(f"POST /alc/ml_bounding_box")
|
||||
return
|
||||
|
||||
request = QNetworkRequest(QUrl(f"{self.__base_url}/alc/ml_bounding_box"))
|
||||
request.setRawHeader(b"Authorization", f"Bearer {self.__token}".encode("utf-8"))
|
||||
reply = self.__net_manager.post(request, QByteArray(b""))
|
||||
reply.finished.connect(lambda: self.handle_ml_box_response(reply))
|
||||
|
||||
|
||||
@@ -72,6 +72,7 @@ class SampleCameraImageLabel(QGraphicsView):
|
||||
self.__helical_start = SmargonCoordinate()
|
||||
self.__helical_end = SmargonCoordinate()
|
||||
self.__raster_alpha = 127
|
||||
self.__bounding_box = None
|
||||
|
||||
self.start_point = None # Starting point of the rectangle
|
||||
self.end_point = None # Ending point of the rectangle
|
||||
@@ -106,6 +107,7 @@ class SampleCameraImageLabel(QGraphicsView):
|
||||
self.right_click_hold_threshold = 200
|
||||
|
||||
def drawForeground(self, painter, rect):
|
||||
self.__draw_ml_bounding_box(painter)
|
||||
self.__draw_beam_center(painter)
|
||||
self.__raster_mgr.draw_grid(painter, self.__raster_alpha)
|
||||
self.__draw_helical(painter)
|
||||
@@ -309,6 +311,8 @@ class SampleCameraImageLabel(QGraphicsView):
|
||||
def update_daq_status(self, s: DAQStatusModel):
|
||||
self.__geom = s.geom
|
||||
self.__sam_cam = s.bl.sample_camera
|
||||
self.__bounding_box = s.box
|
||||
|
||||
if s.state == BeamlineStateEnum.BeamLocation:
|
||||
self.__state = SampleCameraImageState.BEAM_MARKING
|
||||
elif self.__state == SampleCameraImageState.BEAM_MARKING:
|
||||
@@ -332,6 +336,22 @@ class SampleCameraImageLabel(QGraphicsView):
|
||||
)
|
||||
self.smargon.emit(smargon_coord)
|
||||
|
||||
def __draw_ml_bounding_box(self, painter: QPainter):
|
||||
if self.__bounding_box is None:
|
||||
return
|
||||
|
||||
painter.setPen(QPen(QColor(50,205, 50), 3, Qt.PenStyle.SolidLine))
|
||||
|
||||
painter.setBrush(Qt.BrushStyle.NoBrush)
|
||||
painter.drawRect(
|
||||
QRect(
|
||||
int(self.__bounding_box.bottom_x),
|
||||
int(self.__bounding_box.bottom_y),
|
||||
int(self.__bounding_box.top_x - self.__bounding_box.bottom_x),
|
||||
int(self.__bounding_box.top_y - self.__bounding_box.bottom_y),
|
||||
)
|
||||
)
|
||||
|
||||
def __draw_beam_center(self, painter: QPainter):
|
||||
beam_size_pxl = self.__geom.beam_size_pxl
|
||||
|
||||
|
||||
Reference in New Issue
Block a user