Skip to content

Commit e7411a1

Browse files
committed
Update image path for grid squares in smartem
1 parent 28b4131 commit e7411a1

2 files changed

Lines changed: 26 additions & 10 deletions

File tree

src/murfey/server/api/session_control.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from pathlib import Path
44
from typing import Dict, List, Optional
55

6+
import requests
67
from fastapi import APIRouter, Depends
78
from fastapi.responses import FileResponse
89
from ispyb.sqlalchemy import AutoProcProgram as ISPyBAutoProcProgram
@@ -417,24 +418,31 @@ def register_atlas(
417418

418419
class SquareRegistration(BaseModel):
419420
tag: str
421+
image_path: str | None = None
420422
count: int | None = None
423+
serialem: bool = False
421424

422425

423426
@spa_router.post("/sessions/{session_id}/register_square/{gsid}")
424427
def register_square(
425428
session_id: MurfeySessionID,
426-
gsid: int,
429+
gsid: int | str,
427430
square_registration_data: SquareRegistration,
428431
db=murfey_db,
429432
):
430433
if SMARTEM_ACTIVE:
431-
gs = db.exec(
432-
select(GridSquare)
433-
.where(GridSquare.name == gsid)
434-
.where(GridSquare.tag == square_registration_data.tag)
435-
.where(GridSquare.session_id == session_id)
436-
).one_or_none()
437-
if gs and gs.smartem_uuid:
434+
logger.info(f"smartem active for square {gsid}")
435+
if square_registration_data.serialem:
436+
smartem_uuid: int | str | None = gsid
437+
else:
438+
gs = db.exec(
439+
select(GridSquare)
440+
.where(GridSquare.name == gsid)
441+
.where(GridSquare.tag == square_registration_data.tag)
442+
.where(GridSquare.session_id == session_id)
443+
).one_or_none()
444+
smartem_uuid = gs.smartem_uuid if gs else None
445+
if smartem_uuid is not None:
438446
session = db.exec(select(Session).where(Session.id == session_id)).one()
439447
machine_config = get_machine_config(session.instrument_name)[
440448
session.instrument_name
@@ -444,8 +452,16 @@ def register_square(
444452
base_url=machine_config.smartem_api_url, logger=logger
445453
)
446454
smartem_client.gridsquare_registered(
447-
gs.smartem_uuid, count=square_registration_data.count
455+
smartem_uuid, count=square_registration_data.count
456+
)
457+
result = requests.put(
458+
f"{machine_config.smartem_api_url}/gridsquares/{smartem_uuid}",
459+
json={"image_path": square_registration_data.image_path},
448460
)
461+
if not result.status_code == 200:
462+
logger.warning(
463+
f"Post to smartem gridsquares returned {result.status_code}"
464+
)
449465
else:
450466
logger.info("smartem deactivated so did not register square")
451467

src/murfey/util/route_manifest.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ murfey.server.api.session_control.spa_router:
920920
function: register_square
921921
path_params:
922922
- name: gsid
923-
type: int
923+
type: int | str
924924
- name: session_id
925925
type: int
926926
methods:

0 commit comments

Comments
 (0)