Skip to content

Commit 287034e

Browse files
committed
Revert "Moved 'number_from_name' into a FIB utility module"
This reverts commit 04cfb18.
1 parent 921be1b commit 287034e

2 files changed

Lines changed: 19 additions & 20 deletions

File tree

src/murfey/client/contexts/fib.py

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

33
import logging
4+
import re
45
import threading
56
from datetime import datetime
67
from pathlib import Path
@@ -11,7 +12,6 @@
1112
from murfey.client.context import Context
1213
from murfey.client.instance_environment import MurfeyInstanceEnvironment
1314
from murfey.util.client import capture_post
14-
from murfey.util.fib import number_from_name
1515

1616
logger = logging.getLogger("murfey.client.contexts.fib")
1717

@@ -29,6 +29,22 @@ class MillingProgress(NamedTuple):
2929
timestamp: float
3030

3131

32+
def _number_from_name(name: str) -> int:
33+
"""
34+
In the AutoTEM and Maps workflows for the FIB, the sites and images are
35+
auto-incremented with parenthesised numbers (e.g. "Lamella (2)"), with
36+
the first site/image typically not having a number.
37+
38+
This function extracts the number from the file name, and returns 1 if
39+
no such number is found.
40+
"""
41+
return (
42+
int(match.group(1))
43+
if (match := re.search(r"^[\w\s]+\((\d+)\)$", name)) is not None
44+
else 1
45+
)
46+
47+
3248
def _get_source(file_path: Path, environment: MurfeyInstanceEnvironment) -> Path | None:
3349
"""
3450
Returns the Path of the file on the client PC.
@@ -89,7 +105,7 @@ def post_transfer(
89105
parts = transferred_file.parts
90106
if "DCImages" in parts and transferred_file.suffix == ".png":
91107
lamella_name = parts[parts.index("Sites") + 1]
92-
lamella_number = number_from_name(lamella_name)
108+
lamella_number = _number_from_name(lamella_name)
93109
time_from_name = transferred_file.name.split("-")[:6]
94110
timestamp = datetime.timestamp(
95111
datetime(
@@ -155,7 +171,7 @@ def post_transfer(
155171
metadata = xmltodict.parse(for_parsing)
156172
sites = metadata["AutoTEM"]["Project"]["Sites"]["Site"]
157173
for site in sites:
158-
number = number_from_name(site["Name"])
174+
number = _number_from_name(site["Name"])
159175
milling_angle = site["Workflow"]["Recipe"][0]["Activites"][
160176
"MillingAngleActivity"
161177
].get("MillingAngle")

src/murfey/util/fib.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)