|
32 | 32 |
|
33 | 33 | from murfey.util import sanitise |
34 | 34 | from murfey.util.config import get_security_config |
35 | | -from murfey.util.models import FoilHoleParameters, GridSquareParameters |
| 35 | +from murfey.util.models import ( |
| 36 | + FoilHoleParameters, |
| 37 | + GridSquareParameters, |
| 38 | + SearchMapParameters, |
| 39 | +) |
36 | 40 |
|
37 | 41 | log = logging.getLogger("murfey.server.ispyb") |
38 | 42 | security_config = get_security_config() |
@@ -388,6 +392,90 @@ def do_update_foil_hole( |
388 | 392 | ) |
389 | 393 | return {"success": False, "return_value": None} |
390 | 394 |
|
| 395 | + def do_insert_search_map( |
| 396 | + self, |
| 397 | + atlas_id: int, |
| 398 | + search_map_parameters: SearchMapParameters, |
| 399 | + ): |
| 400 | + if ( |
| 401 | + search_map_parameters.pixel_size |
| 402 | + and search_map_parameters.height |
| 403 | + and search_map_parameters.height_on_atlas |
| 404 | + ): |
| 405 | + search_map_parameters.pixel_size *= ( |
| 406 | + search_map_parameters.height / search_map_parameters.height_on_atlas |
| 407 | + ) |
| 408 | + record = GridSquare( |
| 409 | + atlasId=atlas_id, |
| 410 | + gridSquareImage=search_map_parameters.image, |
| 411 | + pixelLocationX=search_map_parameters.x_location, |
| 412 | + pixelLocationY=search_map_parameters.y_location, |
| 413 | + height=search_map_parameters.height_on_atlas, |
| 414 | + width=search_map_parameters.width_on_atlas, |
| 415 | + stageLocationX=search_map_parameters.x_stage_position, |
| 416 | + stageLocationY=search_map_parameters.y_stage_position, |
| 417 | + pixelSize=search_map_parameters.pixel_size, |
| 418 | + ) |
| 419 | + try: |
| 420 | + with ISPyBSession() as db: |
| 421 | + db.add(record) |
| 422 | + db.commit() |
| 423 | + log.info(f"Created SearchMap (GridSquare) {record.gridSquareId}") |
| 424 | + return {"success": True, "return_value": record.gridSquareId} |
| 425 | + except ispyb.ISPyBException as e: |
| 426 | + log.error( |
| 427 | + "Inserting SearchMap (GridSquare) entry caused exception '%s'.", |
| 428 | + e, |
| 429 | + exc_info=True, |
| 430 | + ) |
| 431 | + return {"success": False, "return_value": None} |
| 432 | + |
| 433 | + def do_update_search_map( |
| 434 | + self, search_map_id, search_map_parameters: SearchMapParameters |
| 435 | + ): |
| 436 | + try: |
| 437 | + with ISPyBSession() as db: |
| 438 | + grid_square = ( |
| 439 | + db.query(GridSquare) |
| 440 | + .filter(GridSquare.gridSquareId == search_map_id) |
| 441 | + .one() |
| 442 | + ) |
| 443 | + if ( |
| 444 | + search_map_parameters.pixel_size |
| 445 | + and search_map_parameters.height |
| 446 | + and search_map_parameters.height_on_atlas |
| 447 | + ): |
| 448 | + search_map_parameters.pixel_size *= ( |
| 449 | + search_map_parameters.height |
| 450 | + / search_map_parameters.height_on_atlas |
| 451 | + ) |
| 452 | + if search_map_parameters.image: |
| 453 | + grid_square.gridSquareImage = search_map_parameters.image |
| 454 | + if search_map_parameters.x_location: |
| 455 | + grid_square.pixelLocationX = search_map_parameters.x_location |
| 456 | + if search_map_parameters.y_location: |
| 457 | + grid_square.pixelLocationY = search_map_parameters.y_location |
| 458 | + if search_map_parameters.height_on_atlas: |
| 459 | + grid_square.height = search_map_parameters.height_on_atlas |
| 460 | + if search_map_parameters.width_on_atlas: |
| 461 | + grid_square.width = search_map_parameters.width_on_atlas |
| 462 | + if search_map_parameters.x_stage_position: |
| 463 | + grid_square.stageLocationX = search_map_parameters.x_stage_position |
| 464 | + if search_map_parameters.y_stage_position: |
| 465 | + grid_square.stageLocationY = search_map_parameters.y_stage_position |
| 466 | + if search_map_parameters.pixel_size: |
| 467 | + grid_square.pixelSize = search_map_parameters.pixel_size |
| 468 | + db.add(grid_square) |
| 469 | + db.commit() |
| 470 | + return {"success": True, "return_value": grid_square.gridSquareId} |
| 471 | + except ispyb.ISPyBException as e: |
| 472 | + log.error( |
| 473 | + "Updating SearchMap (GridSquare) entry caused exception '%s'.", |
| 474 | + e, |
| 475 | + exc_info=True, |
| 476 | + ) |
| 477 | + return {"success": False, "return_value": None} |
| 478 | + |
391 | 479 | def send(self, queue: str, message: dict, new_connection: bool = False): |
392 | 480 | if self.transport: |
393 | 481 | if not self.transport.is_connected(): |
|
0 commit comments