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
72 changes: 60 additions & 12 deletions src/murfey/client/analyser.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,12 @@ def _find_context(self, file_path: Path) -> bool:
)
)
):
self._context = CLEMContext("leica", self._basepath, self._token)
self._context = CLEMContext(
"leica",
self._basepath,
self._murfey_config,
self._token,
)
return True

# -----------------------------------------------------------------------------
Expand All @@ -161,7 +166,12 @@ def _find_context(self, file_path: Path) -> bool:
and "Sites" in file_path.parts
)
):
self._context = FIBContext("autotem", self._basepath, self._token)
self._context = FIBContext(
"autotem",
self._basepath,
self._murfey_config,
self._token,
)
return True

# Determine if it's from Maps
Expand All @@ -173,35 +183,58 @@ def _find_context(self, file_path: Path) -> bool:
all(path in file_path.parts for path in ("LayersData", "Layer"))
)
):
self._context = FIBContext("maps", self._basepath, self._token)
self._context = FIBContext(
"maps",
self._basepath,
self._murfey_config,
self._token,
)
return True

# Determine if it's from Meteor
if (
# Image metadata stored in "features.json" file
file_path.name == "features.json" or ()
):
self._context = FIBContext("meteor", self._basepath, self._token)
self._context = FIBContext(
"meteor",
self._basepath,
self._murfey_config,
self._token,
)
return True

# -----------------------------------------------------------------------------
# SXT workflow checks
# -----------------------------------------------------------------------------
if file_path.suffix in (".txrm", ".xrm"):
self._context = SXTContext("zeiss", self._basepath, self._token)
self._context = SXTContext(
"zeiss",
self._basepath,
self._murfey_config,
self._token,
)
return True

# -----------------------------------------------------------------------------
# Tomography and SPA workflow checks
# -----------------------------------------------------------------------------
if "atlas" in file_path.parts:
self._context = AtlasContext(
"serialem" if self._serialem else "epu", self._basepath, self._token
"serialem" if self._serialem else "epu",
self._basepath,
self._murfey_config,
self._token,
)
return True

if "Metadata" in file_path.parts or file_path.name == "EpuSession.dm":
self._context = SPAMetadataContext("epu", self._basepath, self._token)
self._context = SPAMetadataContext(
"epu",
self._basepath,
self._murfey_config,
self._token,
)
return True
elif (
"Batch" in file_path.parts
Expand All @@ -210,7 +243,10 @@ def _find_context(self, file_path: Path) -> bool:
or file_path.name == "Session.dm"
):
self._context = TomographyMetadataContext(
"tomo", self._basepath, self._token
"tomo",
self._basepath,
self._murfey_config,
self._token,
)
return True

Expand All @@ -228,7 +264,10 @@ def _find_context(self, file_path: Path) -> bool:
if not self._context:
logger.info("Acquisition software: EPU")
self._context = SPAModularContext(
"epu", self._basepath, self._token
"epu",
self._basepath,
self._murfey_config,
self._token,
)
self.parameters_model = ProcessingParametersSPA
return True
Expand All @@ -244,7 +283,10 @@ def _find_context(self, file_path: Path) -> bool:
if not self._context:
logger.info("Acquisition software: tomo")
self._context = TomographyContext(
"tomo", self._basepath, self._token
"tomo",
self._basepath,
self._murfey_config,
self._token,
)
self.parameters_model = ProcessingParametersTomo
return True
Expand Down Expand Up @@ -281,7 +323,10 @@ def _analyse(self):
and not self._context
):
self._context = SPAMetadataContext(
"epu", self._basepath, self._token
"epu",
self._basepath,
self._murfey_config,
self._token,
)
elif (
"Batch" in transferred_file.parts
Expand All @@ -290,7 +335,10 @@ def _analyse(self):
and not self._context
):
self._context = TomographyMetadataContext(
"tomo", self._basepath, self._token
"tomo",
self._basepath,
self._murfey_config,
self._token,
)
self.post_transfer(transferred_file)
else:
Expand Down
36 changes: 18 additions & 18 deletions src/murfey/client/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,25 @@
import xmltodict

from murfey.client.instance_environment import MurfeyInstanceEnvironment, SampleInfo
from murfey.util.client import capture_post, get_machine_config_client
from murfey.util.client import capture_post

logger = logging.getLogger("murfey.client.context")


def _file_transferred_to(
environment: MurfeyInstanceEnvironment, source: Path, file_path: Path, token: str
environment: MurfeyInstanceEnvironment,
source: Path,
file_path: Path,
rsync_basepath: Path,
):
machine_config = get_machine_config_client(
str(environment.url.geturl()),
token,
instrument_name=environment.instrument_name,
)
if environment.visit in environment.default_destinations[source]:
return (
Path(machine_config.get("rsync_basepath", ""))
rsync_basepath
/ Path(environment.default_destinations[source])
/ file_path.relative_to(source) # need to strip out the rsync_module name
)
return (
Path(machine_config.get("rsync_basepath", ""))
rsync_basepath
/ Path(environment.default_destinations[source])
/ environment.visit
/ file_path.relative_to(source)
Expand All @@ -52,22 +50,19 @@ def _get_source(file_path: Path, environment: MurfeyInstanceEnvironment) -> Path


def _atlas_destination(
environment: MurfeyInstanceEnvironment, source: Path, token: str
environment: MurfeyInstanceEnvironment,
source: Path,
rsync_basepath: Path,
) -> Path:
machine_config = get_machine_config_client(
str(environment.url.geturl()),
token,
instrument_name=environment.instrument_name,
)
for i, destination_part in enumerate(
Path(environment.default_destinations[source]).parts
):
if destination_part == environment.visit:
return Path(machine_config.get("rsync_basepath", "")) / "/".join(
return rsync_basepath / "/".join(
Path(environment.default_destinations[source]).parent.parts[: i + 1]
)
return (
Path(machine_config.get("rsync_basepath", ""))
rsync_basepath
/ Path(environment.default_destinations[source]).parent
/ environment.visit
)
Expand All @@ -77,6 +72,7 @@ def ensure_dcg_exists(
collection_type: str,
metadata_source: Path,
environment: MurfeyInstanceEnvironment,
machine_config: dict,
token: str,
) -> str | None:
"""Create a data collection group"""
Expand Down Expand Up @@ -183,7 +179,11 @@ def ensure_dcg_exists(
"experiment_type_id": experiment_type_id,
"tag": dcg_tag,
"atlas": str(
_atlas_destination(environment, session_file.parent, token)
_atlas_destination(
environment,
session_file.parent,
Path(machine_config.get("rsync_basepath", "")),
)
/ environment.samples[metadata_source].atlas.parent
/ atlas_xml_path.with_suffix(".jpg").name
).replace("//", "/"),
Expand Down
17 changes: 14 additions & 3 deletions src/murfey/client/contexts/atlas.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@


class AtlasContext(Context):
def __init__(self, acquisition_software: str, basepath: Path, token: str):
def __init__(
self,
acquisition_software: str,
basepath: Path,
machine_config: dict,
token: str,
):
super().__init__("Atlas", acquisition_software, token)
self._basepath = basepath
self._machine_config = machine_config

def post_transfer(
self,
Expand Down Expand Up @@ -69,7 +76,9 @@ def post_transfer_epu(
source = _get_source(transferred_file, environment)
if source:
transferred_atlas_name = _atlas_destination(
environment, source, self._token
environment,
source,
Path(self._machine_config.get("rsync_basepath", "")),
) / transferred_file.relative_to(source.parent)
capture_post(
base_url=str(environment.url.geturl()),
Expand All @@ -91,7 +100,9 @@ def post_transfer_epu(
if source:
atlas_mrc = transferred_file.with_suffix(".mrc")
transferred_atlas_jpg = _atlas_destination(
environment, source, self._token
environment,
source,
Path(self._machine_config.get("rsync_basepath", "")),
) / atlas_mrc.relative_to(source.parent).with_suffix(".jpg")

with open(transferred_file, "rb") as atlas_xml:
Expand Down
30 changes: 16 additions & 14 deletions src/murfey/client/contexts/clem.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,23 @@

from murfey.client.context import Context
from murfey.client.instance_environment import MurfeyInstanceEnvironment
from murfey.util.client import capture_post, get_machine_config_client
from murfey.util.client import capture_post

# Create logger object
logger = logging.getLogger("murfey.client.contexts.clem")


def _file_transferred_to(
environment: MurfeyInstanceEnvironment, source: Path, file_path: Path, token: str
environment: MurfeyInstanceEnvironment,
source: Path,
file_path: Path,
rsync_basepath: Path,
) -> Optional[Path]:
"""
Returns the Path of the transferred file on the DLS file system.
"""
machine_config = get_machine_config_client(
str(environment.url.geturl()),
token,
instrument_name=environment.instrument_name,
)

# Construct destination path
base_destination = Path(machine_config.get("rsync_basepath", "")) / Path(
environment.default_destinations[source]
)
base_destination = rsync_basepath / Path(environment.default_destinations[source])
# Add visit number to the path if it's not present in default destination
if environment.visit not in environment.default_destinations[source]:
base_destination = base_destination / environment.visit
Expand Down Expand Up @@ -87,9 +82,16 @@ def _find_elements_recursively(


class CLEMContext(Context):
def __init__(self, acquisition_software: str, basepath: Path, token: str):
def __init__(
self,
acquisition_software: str,
basepath: Path,
machine_config: dict,
token: str,
):
super().__init__("CLEM", acquisition_software, token)
self._basepath = basepath
self._machine_config = machine_config
# CLEM contexts for "auto-save" acquisition mode
self._tiff_series: Dict[str, List[str]] = {} # {Series name : TIFF path list}
self._series_metadata: Dict[str, str] = {} # {Series name : Metadata file path}
Expand Down Expand Up @@ -125,7 +127,7 @@ def post_transfer(
environment=environment,
source=source,
file_path=transferred_file,
token=self._token,
rsync_basepath=Path(self._machine_config.get("rsync_basepath", "")),
)
if not destination_file:
logger.warning(
Expand Down Expand Up @@ -301,7 +303,7 @@ def post_transfer(
environment=environment,
source=source,
file_path=transferred_file,
token=self._token,
rsync_basepath=Path(self._machine_config.get("rsync_basepath", "")),
)
if not destination_file:
logger.warning(
Expand Down
Loading
Loading