Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
3709464
More noticeable dividers between different database table categories
tieneupin May 20, 2026
84ad3b4
Moved 'number_from_name' into new module 'murfey.util.fib'
tieneupin May 20, 2026
5e6b5be
Adjust logic to register only the latest FIB atlas acquired for a FIB…
tieneupin May 20, 2026
ff3a3ab
Updated DB test to check that only one file was registered
tieneupin May 20, 2026
cb0a651
Migrated 'number_from_name' test to its own test module
tieneupin May 21, 2026
94d95a8
Updated registratino logic so that 'add' and 'commit' always happen a…
tieneupin May 21, 2026
409f9a4
Fixed broken test
tieneupin May 21, 2026
fe18692
Added logic to register data collection group and atlas rows in ISPyB…
tieneupin May 21, 2026
06d9cac
Added tests for the ISPyB database registration components of the wor…
tieneupin May 21, 2026
89f34b0
Module import can occur in the test function instead, since it's only…
tieneupin May 22, 2026
a89f102
Merged recent changes from 'main' branch
tieneupin May 28, 2026
032ea3b
Updated the FIB atlas registration workflow so that it is passed to a…
tieneupin May 28, 2026
e038617
Updated Pydantic model name and removed DB dependency for 'register_f…
tieneupin May 28, 2026
ec7cf48
Updated test for 'register_fib_atlas' API endpoint
tieneupin May 28, 2026
c778394
Updated test for 'register_atlas' FIB workflow
tieneupin May 28, 2026
29e8668
Add minimal logic needed to create, save, and register thumbnail imag…
tieneupin May 29, 2026
6eb8416
Added minimal changes needed to test the '_make_thumbnail' function
tieneupin May 29, 2026
6164a9d
Do not manually chmod 'processed' directory; just inherit permissions…
tieneupin May 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 3 additions & 19 deletions src/murfey/client/contexts/fib.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import logging
import re
import threading
import xml.etree.ElementTree as ET
from dataclasses import dataclass, field
Expand All @@ -11,6 +10,7 @@
from murfey.client.context import Context
from murfey.client.instance_environment import MurfeyInstanceEnvironment
from murfey.util.client import capture_post
from murfey.util.fib import number_from_name
from murfey.util.models import (
LamellaSiteInfo,
MillingStepInfo,
Expand All @@ -24,22 +24,6 @@
lock = threading.Lock()


def _number_from_name(name: str) -> int:
"""
In the AutoTEM and Maps workflows for the FIB, the sites and images are
auto-incremented with parenthesised numbers (e.g. "Lamella (2)"), with
the first site/image typically not having a number.

This function extracts the number from the file name, and returns 1 if
no such number is found.
"""
return (
int(match.group(1))
if (match := re.search(r"^[\w\s]+\((\d+)\)$", name)) is not None
else 1
)


T = TypeVar("T")


Expand Down Expand Up @@ -416,7 +400,7 @@ def _parse_autotem_metadata(self, file: Path):
if (site_name := _parse_xml_text(site, "Name", str)) is None:
logger.warning("Current site doesn't have a name")
continue
site_num = _number_from_name(site_name)
site_num = number_from_name(site_name)
site_info = LamellaSiteInfo(
project_name=project_name,
site_name=site_name,
Expand Down Expand Up @@ -555,7 +539,7 @@ def _make_drift_correction_gif(
parts = file.parts
try:
lamella_name = parts[parts.index("Sites") + 1]
lamella_number = _number_from_name(lamella_name)
lamella_number = number_from_name(lamella_name)
except Exception:
logger.warning(
f"Could not extract metadata from file {file}", exc_info=True
Expand Down
33 changes: 14 additions & 19 deletions src/murfey/server/api/workflow_fib.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json
import logging
import os
from importlib.metadata import entry_points
from pathlib import Path

import numpy as np
Expand All @@ -11,6 +10,7 @@
from sqlmodel import Session, select

import murfey.util.db as MurfeyDB
from murfey.server import _transport_object
from murfey.server.api.auth import validate_instrument_token
from murfey.server.murfey_db import murfey_db
from murfey.util import sanitise_path
Expand All @@ -26,30 +26,25 @@
)


class FIBAtlasInfo(BaseModel):
file: Path | None = None
class FIBAtlasFile(BaseModel):
file: Path


@router.post("/sessions/{session_id}/register_atlas")
def register_fib_atlas(
session_id: int,
fib_atlas_info: FIBAtlasInfo,
db: Session = murfey_db,
fib_atlas: FIBAtlasFile,
):
# See if the relevant workflow is available
if not (
workflow_search := list(
entry_points(group="murfey.workflows", name="fib.register_atlas")
)
):
raise RuntimeError("Unable to find Murfey workflow to register FIB atlas")
workflow = workflow_search[0]

# Run the workflow
workflow.load()(
session_id=session_id,
file=fib_atlas_info.file,
murfey_db=db,
if _transport_object is None:
logger.error("No Transport Manager object was set up")
return None
_transport_object.send(
_transport_object.feedback_queue,
{
"register": "fib.register_atlas",
"session_id": session_id,
"atlas_file": str(fib_atlas.file),
},
)


Expand Down
6 changes: 6 additions & 0 deletions src/murfey/util/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
from sqlmodel import Enum, Field, Relationship, SQLModel, create_engine

"""
=======================================================================================
GENERAL
=======================================================================================
"""


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


"""
=======================================================================================
TEM SESSION AND PROCESSING WORKFLOW
=======================================================================================
"""


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


"""
=======================================================================================
FUNCTIONS
=======================================================================================
"""


Expand Down
21 changes: 21 additions & 0 deletions src/murfey/util/fib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
General functinos specific to the FIB workflow
"""

import re


def number_from_name(name: str) -> int:
"""
In the AutoTEM and Maps workflows for the FIB, the sites and images are
auto-incremented with parenthesised numbers (e.g. "Lamella (2)"), with
the first site/image typically not having a number.

This function extracts the number from the file name, and returns 1 if
no such number is found.
"""
return (
int(match.group(1))
if (match := re.search(r"^[\w\s]+\((\d+)\)$", name)) is not None
else 1
)
Loading