Skip to content

Commit 83b9481

Browse files
authored
Register FIB data in ISPyB (#805)
* Moved 'number_from_name' into new module 'murfey.util.fib' * Adjust logic to register only the latest FIB atlas acquired for a FIB sample slot * Updated registration logic so that 'add' and 'commit' always happen at the end of the function, and both new and old entries are populated or updated correctly * Added logic to register data collection group and atlas rows in ISPyB using FIB atlas data * Updated the FIB atlas registration workflow so that it is passed to and run through the RabbitMQ feedback queue instead of being loaded directly * Add minimal logic needed to create, save, and register thumbnail images of the FIB atlases
1 parent 62f45b7 commit 83b9481

9 files changed

Lines changed: 491 additions & 162 deletions

File tree

src/murfey/client/contexts/fib.py

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
import logging
4-
import re
54
import threading
65
import xml.etree.ElementTree as ET
76
from dataclasses import dataclass, field
@@ -11,6 +10,7 @@
1110
from murfey.client.context import Context
1211
from murfey.client.instance_environment import MurfeyInstanceEnvironment
1312
from murfey.util.client import capture_post
13+
from murfey.util.fib import number_from_name
1414
from murfey.util.models import (
1515
LamellaSiteInfo,
1616
MillingStepInfo,
@@ -24,22 +24,6 @@
2424
lock = threading.Lock()
2525

2626

27-
def _number_from_name(name: str) -> int:
28-
"""
29-
In the AutoTEM and Maps workflows for the FIB, the sites and images are
30-
auto-incremented with parenthesised numbers (e.g. "Lamella (2)"), with
31-
the first site/image typically not having a number.
32-
33-
This function extracts the number from the file name, and returns 1 if
34-
no such number is found.
35-
"""
36-
return (
37-
int(match.group(1))
38-
if (match := re.search(r"^[\w\s]+\((\d+)\)$", name)) is not None
39-
else 1
40-
)
41-
42-
4327
T = TypeVar("T")
4428

4529

@@ -416,7 +400,7 @@ def _parse_autotem_metadata(self, file: Path):
416400
if (site_name := _parse_xml_text(site, "Name", str)) is None:
417401
logger.warning("Current site doesn't have a name")
418402
continue
419-
site_num = _number_from_name(site_name)
403+
site_num = number_from_name(site_name)
420404
site_info = LamellaSiteInfo(
421405
project_name=project_name,
422406
site_name=site_name,
@@ -555,7 +539,7 @@ def _make_drift_correction_gif(
555539
parts = file.parts
556540
try:
557541
lamella_name = parts[parts.index("Sites") + 1]
558-
lamella_number = _number_from_name(lamella_name)
542+
lamella_number = number_from_name(lamella_name)
559543
except Exception:
560544
logger.warning(
561545
f"Could not extract metadata from file {file}", exc_info=True

src/murfey/server/api/workflow_fib.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import json
22
import logging
33
import os
4-
from importlib.metadata import entry_points
54
from pathlib import Path
65

76
import numpy as np
@@ -11,6 +10,7 @@
1110
from sqlmodel import Session, select
1211

1312
import murfey.util.db as MurfeyDB
13+
from murfey.server import _transport_object
1414
from murfey.server.api.auth import validate_instrument_token
1515
from murfey.server.murfey_db import murfey_db
1616
from murfey.util import sanitise_path
@@ -26,30 +26,25 @@
2626
)
2727

2828

29-
class FIBAtlasInfo(BaseModel):
30-
file: Path | None = None
29+
class FIBAtlasFile(BaseModel):
30+
file: Path
3131

3232

3333
@router.post("/sessions/{session_id}/register_atlas")
3434
def register_fib_atlas(
3535
session_id: int,
36-
fib_atlas_info: FIBAtlasInfo,
37-
db: Session = murfey_db,
36+
fib_atlas: FIBAtlasFile,
3837
):
39-
# See if the relevant workflow is available
40-
if not (
41-
workflow_search := list(
42-
entry_points(group="murfey.workflows", name="fib.register_atlas")
43-
)
44-
):
45-
raise RuntimeError("Unable to find Murfey workflow to register FIB atlas")
46-
workflow = workflow_search[0]
47-
48-
# Run the workflow
49-
workflow.load()(
50-
session_id=session_id,
51-
file=fib_atlas_info.file,
52-
murfey_db=db,
38+
if _transport_object is None:
39+
logger.error("No Transport Manager object was set up")
40+
return None
41+
_transport_object.send(
42+
_transport_object.feedback_queue,
43+
{
44+
"register": "fib.register_atlas",
45+
"session_id": session_id,
46+
"atlas_file": str(fib_atlas.file),
47+
},
5348
)
5449

5550

src/murfey/util/db.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
from sqlmodel import Enum, Field, Relationship, SQLModel, create_engine
1111

1212
"""
13+
=======================================================================================
1314
GENERAL
15+
=======================================================================================
1416
"""
1517

1618

@@ -173,7 +175,9 @@ class ImagingSite(SQLModel, table=True): # type: ignore
173175

174176

175177
"""
178+
=======================================================================================
176179
TEM SESSION AND PROCESSING WORKFLOW
180+
=======================================================================================
177181
"""
178182

179183

@@ -1072,7 +1076,9 @@ class CryoemInitialModel(SQLModel, table=True): # type: ignore
10721076

10731077

10741078
"""
1079+
=======================================================================================
10751080
FUNCTIONS
1081+
=======================================================================================
10761082
"""
10771083

10781084

src/murfey/util/fib.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
General functinos specific to the FIB workflow
3+
"""
4+
5+
import re
6+
7+
8+
def number_from_name(name: str) -> int:
9+
"""
10+
In the AutoTEM and Maps workflows for the FIB, the sites and images are
11+
auto-incremented with parenthesised numbers (e.g. "Lamella (2)"), with
12+
the first site/image typically not having a number.
13+
14+
This function extracts the number from the file name, and returns 1 if
15+
no such number is found.
16+
"""
17+
return (
18+
int(match.group(1))
19+
if (match := re.search(r"^[\w\s]+\((\d+)\)$", name)) is not None
20+
else 1
21+
)

0 commit comments

Comments
 (0)