@@ -20,10 +20,58 @@ def ensure_dcg_exists(
2020 source = _get_source (transferred_file , environment = environment )
2121 if not source :
2222 return None
23+ source_visit_dir = source .parent
24+
25+ session_file = source / "Session.dm"
26+ if not session_file .is_file ():
27+ logger .warning (f"Cannot find session file { str (session_file )} " )
28+ return
29+ with open (session_file , "r" ) as session_xml :
30+ session_data = xmltodict .parse (session_xml .read ())
31+
32+ windows_path = session_data ["TomographySession" ]["AtlasId" ]
33+ logger .info (f"Windows path to atlas metadata found: { windows_path } " )
34+ if not windows_path :
35+ logger .warning ("No atlas metadata path found" )
36+ return
37+ visit_index = windows_path .split ("\\ " ).index (environment .visit )
38+ partial_path = "/" .join (windows_path .split ("\\ " )[visit_index + 1 :])
39+ logger .info ("Partial Linux path successfully constructed from Windows path" )
40+
41+ logger .info (
42+ f"Looking for atlas XML file in metadata directory { str ((source_visit_dir / partial_path ).parent )} "
43+ )
44+ atlas_xml_path = list ((source_visit_dir / partial_path ).parent .glob ("Atlas_*.xml" ))[
45+ 0
46+ ]
47+ logger .info (f"Atlas XML path { str (atlas_xml_path )} found" )
48+ with open (atlas_xml_path , "rb" ) as atlas_xml :
49+ atlas_xml_data = xmltodict .parse (atlas_xml )
50+ atlas_pixel_size = float (
51+ atlas_xml_data ["MicroscopeImage" ]["SpatialScale" ]["pixelSize" ]["x" ][
52+ "numericValue"
53+ ]
54+ )
55+
56+ for p in partial_path .split ("/" ):
57+ if p .startswith ("Sample" ):
58+ sample = int (p .replace ("Sample" , "" ))
59+ break
60+ else :
61+ logger .warning (f"Sample could not be identified for { transferred_file } " )
62+ return
63+ environment .samples [source ] = SampleInfo (atlas = Path (partial_path ), sample = sample )
2364 dcg_tag = str (source ).replace (f"/{ environment .visit } " , "" )
2465 dcg_data = {
2566 "experiment_type_id" : 36 , # Tomo
2667 "tag" : dcg_tag ,
68+ "atlas" : str (
69+ _atlas_destination (environment , source , session_file , token )
70+ / environment .samples [source ].atlas .parent
71+ / atlas_xml_path .with_suffix (".jpg" ).name
72+ ),
73+ "sample" : environment .samples [source ].sample ,
74+ "atlas_pixel_size" : atlas_pixel_size ,
2775 }
2876 capture_post (
2977 base_url = str (environment .url .geturl ()),
@@ -56,77 +104,7 @@ def post_transfer(
56104
57105 if transferred_file .name == "Session.dm" and environment :
58106 logger .info ("Tomography session metadata found" )
59- with open (transferred_file , "r" ) as session_xml :
60- session_data = xmltodict .parse (session_xml .read ())
61-
62- windows_path = session_data ["TomographySession" ]["AtlasId" ]
63- logger .info (f"Windows path to atlas metadata found: { windows_path } " )
64- if not windows_path :
65- logger .warning ("No atlas metadata path found" )
66- return
67- visit_index = windows_path .split ("\\ " ).index (environment .visit )
68- partial_path = "/" .join (windows_path .split ("\\ " )[visit_index + 1 :])
69- logger .info ("Partial Linux path successfully constructed from Windows path" )
70-
71- source = _get_source (transferred_file , environment )
72- if not source :
73- logger .warning (
74- f"Source could not be identified for { str (transferred_file )} "
75- )
76- return
77-
78- source_visit_dir = source .parent
79-
80- logger .info (
81- f"Looking for atlas XML file in metadata directory { str ((source_visit_dir / partial_path ).parent )} "
82- )
83- atlas_xml_path = list (
84- (source_visit_dir / partial_path ).parent .glob ("Atlas_*.xml" )
85- )[0 ]
86- logger .info (f"Atlas XML path { str (atlas_xml_path )} found" )
87- with open (atlas_xml_path , "rb" ) as atlas_xml :
88- atlas_xml_data = xmltodict .parse (atlas_xml )
89- atlas_pixel_size = float (
90- atlas_xml_data ["MicroscopeImage" ]["SpatialScale" ]["pixelSize" ]["x" ][
91- "numericValue"
92- ]
93- )
94-
95- for p in partial_path .split ("/" ):
96- if p .startswith ("Sample" ):
97- sample = int (p .replace ("Sample" , "" ))
98- break
99- else :
100- logger .warning (f"Sample could not be identified for { transferred_file } " )
101- return
102- environment .samples [source ] = SampleInfo (
103- atlas = Path (partial_path ), sample = sample
104- )
105- dcg_tag = "/" .join (
106- p for p in transferred_file .parent .parts if p != environment .visit
107- ).replace ("//" , "/" )
108- dcg_data = {
109- "experiment_type_id" : 36 , # Tomo
110- "tag" : dcg_tag ,
111- "atlas" : str (
112- _atlas_destination (
113- environment , source , transferred_file , self ._token
114- )
115- / environment .samples [source ].atlas .parent
116- / atlas_xml_path .with_suffix (".jpg" ).name
117- ),
118- "sample" : environment .samples [source ].sample ,
119- "atlas_pixel_size" : atlas_pixel_size ,
120- }
121- capture_post (
122- base_url = str (environment .url .geturl ()),
123- router_name = "workflow.router" ,
124- function_name = "register_dc_group" ,
125- token = self ._token ,
126- visit_name = environment .visit ,
127- session_id = environment .murfey_session ,
128- data = dcg_data ,
129- )
107+ ensure_dcg_exists (transferred_file , environment , self ._token )
130108
131109 elif transferred_file .name == "SearchMap.xml" and environment :
132110 logger .info ("Tomography session search map xml found" )
0 commit comments