Skip to content

Commit babfea4

Browse files
committed
Register dcg for atlases
1 parent 36511c9 commit babfea4

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

src/murfey/client/contexts/atlas.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from pathlib import Path
33
from typing import Optional
44

5+
import xmltodict
6+
57
from murfey.client.context import Context
68
from murfey.client.contexts.spa import _get_source
79
from murfey.client.contexts.spa_metadata import _atlas_destination
@@ -49,3 +51,55 @@ def post_transfer(
4951
logger.info(
5052
f"Submitted request to create JPG image of atlas {str(transferred_atlas_name)!r}"
5153
)
54+
elif (
55+
environment
56+
and "Atlas_" in transferred_file.stem
57+
and transferred_file.suffix == ".xml"
58+
):
59+
source = _get_source(transferred_file, environment)
60+
if source:
61+
atlas_mrc = transferred_file.with_suffix(".mrc")
62+
transferred_atlas_name = _atlas_destination(
63+
environment, source, atlas_mrc, self._token
64+
) / atlas_mrc.relative_to(source.parent)
65+
66+
with open(transferred_file, "rb") as atlas_xml:
67+
atlas_xml_data = xmltodict.parse(atlas_xml)
68+
atlas_original_pixel_size = float(
69+
atlas_xml_data["MicroscopeImage"]["SpatialScale"]["pixelSize"][
70+
"x"
71+
]["numericValue"]
72+
)
73+
74+
# need to calculate the pixel size of the downscaled image
75+
atlas_pixel_size = atlas_original_pixel_size * 7.8
76+
77+
for p in transferred_file.parts:
78+
if p.startswith("Sample"):
79+
sample = int(p.replace("Sample", ""))
80+
break
81+
else:
82+
logger.warning(
83+
f"Sample could not be identified for {transferred_file}"
84+
)
85+
return
86+
87+
dcg_data = {
88+
"experiment_type_id": 44, # Atlas
89+
"tag": str(transferred_file.parent),
90+
"atlas": str(transferred_atlas_name),
91+
"sample": sample,
92+
"atlas_pixel_size": atlas_pixel_size,
93+
}
94+
capture_post(
95+
base_url=str(environment.url.geturl()),
96+
router_name="workflow.router",
97+
function_name="register_dc_group",
98+
token=self._token,
99+
visit_name=environment.visit,
100+
session_id=environment.murfey_session,
101+
data=dcg_data,
102+
)
103+
logger.info(
104+
f"Registered data collection group for atlas {str(transferred_atlas_name)!r}"
105+
)

0 commit comments

Comments
 (0)