@@ -94,31 +94,6 @@ def ensure_dcg_exists(
9494 logger .info (
9595 f"Looking for atlas XML file in metadata directory { str ((source_visit_dir / partial_path ).parent )} "
9696 )
97- atlas_xml_path = list (
98- (source_visit_dir / partial_path ).parent .glob ("Atlas_*.xml" )
99- )[0 ]
100- logger .info (f"Atlas XML path { str (atlas_xml_path )} found" )
101- with open (atlas_xml_path , "rb" ) as atlas_xml :
102- atlas_xml_data = xmltodict .parse (atlas_xml )
103- atlas_original_pixel_size = float (
104- atlas_xml_data ["MicroscopeImage" ]["SpatialScale" ]["pixelSize" ]["x" ][
105- "numericValue"
106- ]
107- )
108- # need to calculate the pixel size of the downscaled image
109- atlas_pixel_size = atlas_original_pixel_size * 7.8
110- logger .info (f"Atlas image pixel size determined to be { atlas_pixel_size } " )
111-
112- for p in partial_path .split ("/" ):
113- if p .startswith ("Sample" ):
114- sample = int (p .replace ("Sample" , "" ))
115- break
116- else :
117- logger .warning (f"Sample could not be identified for { metadata_source } " )
118- return None
119- environment .samples [metadata_source ] = SampleInfo (
120- atlas = Path (partial_path ), sample = sample
121- )
12297
12398 dcg_search_dir = (
12499 str (metadata_source ).replace (f"/{ environment .visit } " , "" ).replace ("//" , "/" )
@@ -137,17 +112,50 @@ def ensure_dcg_exists(
137112 dcg_images_dirs = [Path (dcg_search_dir ) / "Images-Disc1" ]
138113 dcg_tag = str (dcg_images_dirs [- 1 ])
139114
140- dcg_data = {
141- "experiment_type_id" : experiment_type_id ,
142- "tag" : dcg_tag ,
143- "atlas" : str (
144- _atlas_destination (environment , metadata_source , token )
145- / environment .samples [metadata_source ].atlas .parent
146- / atlas_xml_path .with_suffix (".jpg" ).name
147- ).replace ("//" , "/" ),
148- "sample" : environment .samples [metadata_source ].sample ,
149- "atlas_pixel_size" : atlas_pixel_size ,
150- }
115+ for p in partial_path .split ("/" ):
116+ if p .startswith ("Sample" ):
117+ sample = int (p .replace ("Sample" , "" ))
118+ break
119+ else :
120+ logger .warning (f"Sample could not be identified for { metadata_source } " )
121+ return None
122+ environment .samples [metadata_source ] = SampleInfo (
123+ atlas = Path (partial_path ), sample = sample
124+ )
125+
126+ if atlas_xml_search := list (
127+ (source_visit_dir / partial_path ).parent .glob ("Atlas_*.xml" )
128+ ):
129+ atlas_xml_path = atlas_xml_search [0 ]
130+ logger .info (f"Atlas XML path { str (atlas_xml_path )} found" )
131+ with open (atlas_xml_path , "rb" ) as atlas_xml :
132+ atlas_xml_data = xmltodict .parse (atlas_xml )
133+ atlas_original_pixel_size = float (
134+ atlas_xml_data ["MicroscopeImage" ]["SpatialScale" ]["pixelSize" ]["x" ][
135+ "numericValue"
136+ ]
137+ )
138+ # need to calculate the pixel size of the downscaled image
139+ atlas_pixel_size = atlas_original_pixel_size * 7.8
140+ logger .info (f"Atlas image pixel size determined to be { atlas_pixel_size } " )
141+
142+ dcg_data = {
143+ "experiment_type_id" : experiment_type_id ,
144+ "tag" : dcg_tag ,
145+ "atlas" : str (
146+ _atlas_destination (environment , metadata_source , token )
147+ / environment .samples [metadata_source ].atlas .parent
148+ / atlas_xml_path .with_suffix (".jpg" ).name
149+ ).replace ("//" , "/" ),
150+ "sample" : environment .samples [metadata_source ].sample ,
151+ "atlas_pixel_size" : atlas_pixel_size ,
152+ }
153+ else :
154+ dcg_data = {
155+ "experiment_type_id" : experiment_type_id ,
156+ "tag" : dcg_tag ,
157+ "sample" : environment .samples [metadata_source ].sample ,
158+ }
151159 capture_post (
152160 base_url = str (environment .url .geturl ()),
153161 router_name = "workflow.router" ,
0 commit comments