Skip to content

Commit 8fb34a2

Browse files
Use safe placholder atlas name if atlas XML not found (#734)
The search for an atlas XML file currently fails if no search results were returned for the atlas. This PR adjusts that logic so that it proceeds with the post to the backend server with the minimum amount of information present and safe-ish placeholder name for the atlas. --------- Co-authored-by: yxd92326 <stephen.riggs@diamond.ac.uk>
1 parent 29519b8 commit 8fb34a2

File tree

2 files changed

+38
-29
lines changed

2 files changed

+38
-29
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ classifiers = [
3131
dependencies = [
3232
"aiohttp",
3333
"defusedxml", # For safely parsing XML files
34-
"fastapi[standard-no-fastapi-cloud-cli]>=0.116.0",
34+
"fastapi[standard-no-fastapi-cloud-cli]>=0.116.0,<0.128.1",
3535
"pydantic>=2",
3636
"pydantic-settings",
3737
"python-jose",

src/murfey/client/context.py

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,10 @@ def ensure_dcg_exists(
9696
logger.info(
9797
f"Looking for atlas XML file in metadata directory {str((source_visit_dir / partial_path).parent)}"
9898
)
99-
atlas_xml_path = list(
100-
(source_visit_dir / partial_path).parent.glob("Atlas_*.xml")
101-
)[0]
102-
logger.info(f"Atlas XML path {str(atlas_xml_path)} found")
103-
with open(atlas_xml_path, "rb") as atlas_xml:
104-
atlas_xml_data = xmltodict.parse(atlas_xml)
105-
atlas_original_pixel_size = float(
106-
atlas_xml_data["MicroscopeImage"]["SpatialScale"]["pixelSize"]["x"][
107-
"numericValue"
108-
]
109-
)
110-
# need to calculate the pixel size of the downscaled image
111-
atlas_pixel_size = atlas_original_pixel_size * 7.8
112-
logger.info(f"Atlas image pixel size determined to be {atlas_pixel_size}")
99+
100+
dcg_tag = "/".join(
101+
[part for part in metadata_source.parts if part != environment.visit]
102+
).replace("//", "/")
113103

114104
for p in partial_path.split("/"):
115105
if p.startswith("Sample"):
@@ -122,20 +112,39 @@ def ensure_dcg_exists(
122112
atlas=Path(partial_path), sample=sample
123113
)
124114

125-
dcg_tag = "/".join(
126-
[part for part in metadata_source.parts if part != environment.visit]
127-
).replace("//", "/")
128-
dcg_data = {
129-
"experiment_type_id": experiment_type_id,
130-
"tag": dcg_tag,
131-
"atlas": str(
132-
_atlas_destination(environment, session_file.parent, token)
133-
/ environment.samples[metadata_source].atlas.parent
134-
/ atlas_xml_path.with_suffix(".jpg").name
135-
).replace("//", "/"),
136-
"sample": environment.samples[metadata_source].sample,
137-
"atlas_pixel_size": atlas_pixel_size,
138-
}
115+
if atlas_xml_search := list(
116+
(source_visit_dir / partial_path).parent.glob("Atlas_*.xml")
117+
):
118+
atlas_xml_path = atlas_xml_search[0]
119+
logger.info(f"Atlas XML path {str(atlas_xml_path)} found")
120+
with open(atlas_xml_path, "rb") as atlas_xml:
121+
atlas_xml_data = xmltodict.parse(atlas_xml)
122+
atlas_original_pixel_size = float(
123+
atlas_xml_data["MicroscopeImage"]["SpatialScale"]["pixelSize"]["x"][
124+
"numericValue"
125+
]
126+
)
127+
# need to calculate the pixel size of the downscaled image
128+
atlas_pixel_size = atlas_original_pixel_size * 7.8
129+
logger.info(f"Atlas image pixel size determined to be {atlas_pixel_size}")
130+
131+
dcg_data = {
132+
"experiment_type_id": experiment_type_id,
133+
"tag": dcg_tag,
134+
"atlas": str(
135+
_atlas_destination(environment, session_file.parent, token)
136+
/ environment.samples[metadata_source].atlas.parent
137+
/ atlas_xml_path.with_suffix(".jpg").name
138+
).replace("//", "/"),
139+
"sample": environment.samples[metadata_source].sample,
140+
"atlas_pixel_size": atlas_pixel_size,
141+
}
142+
else:
143+
dcg_data = {
144+
"experiment_type_id": experiment_type_id,
145+
"tag": dcg_tag,
146+
"sample": environment.samples[metadata_source].sample,
147+
}
139148
capture_post(
140149
base_url=str(environment.url.geturl()),
141150
router_name="workflow.router",

0 commit comments

Comments
 (0)