Skip to content

Commit 3bb456d

Browse files
Catch case of wrong atlas when registering dcgs (#744)
If the atlas is not in the visit folder we want to avoid crashing. This takes a guess at where the atlas should have been, and will then fall into the else statement below when it tries to glob for an atlas in that location. Also puts a try-catch around the call from the multigrid control. Means the analyser will not crash but could leave us without a dcg message.
1 parent ab2130d commit 3bb456d

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

src/murfey/client/context.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,18 @@ def ensure_dcg_exists(
8989
if not windows_path:
9090
logger.warning("No atlas metadata path found")
9191
return None
92-
visit_index = windows_path.split("\\").index(environment.visit)
93-
partial_path = "/".join(windows_path.split("\\")[visit_index + 1 :])
94-
logger.info("Partial Linux path successfully constructed from Windows path")
92+
if environment.visit in windows_path.split("\\"):
93+
# Case of atlas in the correct location
94+
visit_index = windows_path.split("\\").index(environment.visit)
95+
partial_path = "/".join(windows_path.split("\\")[visit_index + 1 :])
96+
logger.info(
97+
f"Partial Linux path successfully constructed from Windows path: {partial_path}"
98+
)
99+
else:
100+
# Atlas not in visit, so come up with where it should have been
101+
# Assumes /structure/to/Supervisor/Sample/Atlas/Atlas.dm
102+
partial_path = "atlas/" + "/".join(windows_path.split("\\")[-4:])
103+
logger.info(f"Partial Linux path estimated: {partial_path}")
95104

96105
logger.info(
97106
f"Looking for atlas XML file in metadata directory {str((source_visit_dir / partial_path).parent)}"

src/murfey/client/multigrid_control.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -566,12 +566,15 @@ def _start_dc(self, metadata_json):
566566
+ "/".join(source.parts[-2:])
567567
)
568568
metadata_source = Path(metadata_source_as_str.replace("//", "/"))
569-
ensure_dcg_exists(
570-
collection_type="spa",
571-
metadata_source=metadata_source,
572-
environment=self._environment,
573-
token=self.token,
574-
)
569+
try:
570+
ensure_dcg_exists(
571+
collection_type="spa",
572+
metadata_source=metadata_source,
573+
environment=self._environment,
574+
token=self.token,
575+
)
576+
except Exception as e:
577+
log.error(f"Failed to register data collection group: {e}")
575578
data = {
576579
"voltage": metadata_json["voltage"],
577580
"pixel_size_on_image": metadata_json["pixel_size_on_image"],

0 commit comments

Comments
 (0)