11from __future__ import annotations
22
33import logging
4+ import re
45import threading
56from datetime import datetime
67from pathlib import Path
1112from murfey .client .context import Context
1213from murfey .client .instance_environment import MurfeyInstanceEnvironment
1314from murfey .util .client import capture_post
14- from murfey .util .fib import number_from_name
1515
1616logger = 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+
3248def _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" )
0 commit comments