-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmotion_correction.py
More file actions
57 lines (50 loc) · 1.93 KB
/
Copy pathmotion_correction.py
File metadata and controls
57 lines (50 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from logging import getLogger
from sqlmodel import Session, select
from murfey.util.config import get_machine_config
from murfey.util.db import (
Movie,
Session as MurfeySession,
)
logger = getLogger("murfey.workflows.spa.motion_correction")
try:
from smartem_backend.api_client import SmartEMAPIClient
from smartem_backend.model.http_request import MicrographUpdateRequest
from smartem_backend.model.http_response import MicrographResponse
from smartem_common.entity_status import MicrographStatus
SMARTEM_ACTIVE = True
except ImportError:
SMARTEM_ACTIVE = False
def motion_corrected(message: dict, murfey_db: Session) -> dict[str, bool]:
if not SMARTEM_ACTIVE:
return {"success": True}
movie = murfey_db.exec(
select(Movie).where(Movie.murfey_id == message["motion_correction_id"])
).one()
if movie.smartem_uuid:
try:
session = murfey_db.exec(
select(MurfeySession).where(MurfeySession.id == message["session_id"])
).one()
machine_config = get_machine_config(
instrument_name=session.instrument_name
)[session.instrument_name]
if machine_config.smartem_api_url:
smartem_client = SmartEMAPIClient(
base_url=machine_config.smartem_api_url, logger=logger
)
update = MicrographUpdateRequest(
status=MicrographStatus.MOTION_CORRECTION_COMPLETED
)
smartem_client._request(
"put",
f"micrographs/{movie.smartem_uuid}",
update,
MicrographResponse,
)
except Exception:
logger.warning(
"Failed to emit motion correction complete event to smartem",
exc_info=True,
)
return {"success": False}
return {"success": True}