Skip to content

Commit 84ad3b4

Browse files
committed
Moved 'number_from_name' into new module 'murfey.util.fib'
1 parent 3709464 commit 84ad3b4

2 files changed

Lines changed: 24 additions & 19 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/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)