From a501c5e658f42770fcbae985786ceffd237ed171 Mon Sep 17 00:00:00 2001 From: Eu-Pin Tien Date: Mon, 26 Jan 2026 16:25:49 +0000 Subject: [PATCH] Use safe placholder atlas name if atlas XML not found --- src/murfey/client/context.py | 80 ++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 36 deletions(-) diff --git a/src/murfey/client/context.py b/src/murfey/client/context.py index 6edf95cb..2bf6cc18 100644 --- a/src/murfey/client/context.py +++ b/src/murfey/client/context.py @@ -94,31 +94,6 @@ def ensure_dcg_exists( logger.info( f"Looking for atlas XML file in metadata directory {str((source_visit_dir / partial_path).parent)}" ) - atlas_xml_path = list( - (source_visit_dir / partial_path).parent.glob("Atlas_*.xml") - )[0] - logger.info(f"Atlas XML path {str(atlas_xml_path)} found") - with open(atlas_xml_path, "rb") as atlas_xml: - atlas_xml_data = xmltodict.parse(atlas_xml) - atlas_original_pixel_size = float( - atlas_xml_data["MicroscopeImage"]["SpatialScale"]["pixelSize"]["x"][ - "numericValue" - ] - ) - # need to calculate the pixel size of the downscaled image - atlas_pixel_size = atlas_original_pixel_size * 7.8 - logger.info(f"Atlas image pixel size determined to be {atlas_pixel_size}") - - for p in partial_path.split("/"): - if p.startswith("Sample"): - sample = int(p.replace("Sample", "")) - break - else: - logger.warning(f"Sample could not be identified for {metadata_source}") - return None - environment.samples[metadata_source] = SampleInfo( - atlas=Path(partial_path), sample=sample - ) dcg_search_dir = ( str(metadata_source).replace(f"/{environment.visit}", "").replace("//", "/") @@ -137,17 +112,50 @@ def ensure_dcg_exists( dcg_images_dirs = [Path(dcg_search_dir) / "Images-Disc1"] dcg_tag = str(dcg_images_dirs[-1]) - dcg_data = { - "experiment_type_id": experiment_type_id, - "tag": dcg_tag, - "atlas": str( - _atlas_destination(environment, metadata_source, token) - / environment.samples[metadata_source].atlas.parent - / atlas_xml_path.with_suffix(".jpg").name - ).replace("//", "/"), - "sample": environment.samples[metadata_source].sample, - "atlas_pixel_size": atlas_pixel_size, - } + for p in partial_path.split("/"): + if p.startswith("Sample"): + sample = int(p.replace("Sample", "")) + break + else: + logger.warning(f"Sample could not be identified for {metadata_source}") + return None + environment.samples[metadata_source] = SampleInfo( + atlas=Path(partial_path), sample=sample + ) + + if atlas_xml_search := list( + (source_visit_dir / partial_path).parent.glob("Atlas_*.xml") + ): + atlas_xml_path = atlas_xml_search[0] + logger.info(f"Atlas XML path {str(atlas_xml_path)} found") + with open(atlas_xml_path, "rb") as atlas_xml: + atlas_xml_data = xmltodict.parse(atlas_xml) + atlas_original_pixel_size = float( + atlas_xml_data["MicroscopeImage"]["SpatialScale"]["pixelSize"]["x"][ + "numericValue" + ] + ) + # need to calculate the pixel size of the downscaled image + atlas_pixel_size = atlas_original_pixel_size * 7.8 + logger.info(f"Atlas image pixel size determined to be {atlas_pixel_size}") + + dcg_data = { + "experiment_type_id": experiment_type_id, + "tag": dcg_tag, + "atlas": str( + _atlas_destination(environment, metadata_source, token) + / environment.samples[metadata_source].atlas.parent + / atlas_xml_path.with_suffix(".jpg").name + ).replace("//", "/"), + "sample": environment.samples[metadata_source].sample, + "atlas_pixel_size": atlas_pixel_size, + } + else: + dcg_data = { + "experiment_type_id": experiment_type_id, + "tag": dcg_tag, + "sample": environment.samples[metadata_source].sample, + } capture_post( base_url=str(environment.url.geturl()), router_name="workflow.router",