Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 14 additions & 6 deletions src/murfey/util/fib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
General functinos specific to the FIB workflow
"""

import re
from pathlib import Path


def number_from_name(name: str) -> int:
Expand All @@ -11,11 +11,19 @@ def number_from_name(name: str) -> int:
auto-incremented with parenthesised numbers (e.g. "Lamella (2)"), with
the first site/image typically not having a number.

For sites set up and acquired manually, they will be saved in folders
labelled "Site #1", "Site #2", etc.

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
)
# Ensure only the stem is extracted for parsing
stem = Path(name).stem
# Handle naming pattern for sites acquired without autoTEM
if "#" in stem:
return int(stem.rpartition("#")[-1])
# Handle naming pattern for sites acquired with autoTEM
if "(" in stem and stem.endswith(")"):
return int(stem[stem.rfind("(") + 1 : -1])
# Names without '()' or '#' should return 1
return 1
Loading