|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import logging |
4 | | -import re |
5 | 4 | import threading |
6 | 5 | import xml.etree.ElementTree as ET |
7 | 6 | from dataclasses import dataclass, field |
|
11 | 10 | from murfey.client.context import Context |
12 | 11 | from murfey.client.instance_environment import MurfeyInstanceEnvironment |
13 | 12 | from murfey.util.client import capture_post |
| 13 | +from murfey.util.fib import number_from_name |
14 | 14 | from murfey.util.models import ( |
15 | 15 | LamellaSiteInfo, |
16 | 16 | MillingStepInfo, |
|
24 | 24 | lock = threading.Lock() |
25 | 25 |
|
26 | 26 |
|
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 | | - |
43 | 27 | T = TypeVar("T") |
44 | 28 |
|
45 | 29 |
|
@@ -416,7 +400,7 @@ def _parse_autotem_metadata(self, file: Path): |
416 | 400 | if (site_name := _parse_xml_text(site, "Name", str)) is None: |
417 | 401 | logger.warning("Current site doesn't have a name") |
418 | 402 | continue |
419 | | - site_num = _number_from_name(site_name) |
| 403 | + site_num = number_from_name(site_name) |
420 | 404 | site_info = LamellaSiteInfo( |
421 | 405 | project_name=project_name, |
422 | 406 | site_name=site_name, |
@@ -555,7 +539,7 @@ def _make_drift_correction_gif( |
555 | 539 | parts = file.parts |
556 | 540 | try: |
557 | 541 | lamella_name = parts[parts.index("Sites") + 1] |
558 | | - lamella_number = _number_from_name(lamella_name) |
| 542 | + lamella_number = number_from_name(lamella_name) |
559 | 543 | except Exception: |
560 | 544 | logger.warning( |
561 | 545 | f"Could not extract metadata from file {file}", exc_info=True |
|
0 commit comments