|
2 | 2 | from pathlib import Path |
3 | 3 | from typing import Optional |
4 | 4 |
|
| 5 | +import xmltodict |
| 6 | + |
5 | 7 | from murfey.client.context import Context |
6 | 8 | from murfey.client.contexts.spa import _get_source |
7 | 9 | from murfey.client.contexts.spa_metadata import _atlas_destination |
@@ -49,3 +51,55 @@ def post_transfer( |
49 | 51 | logger.info( |
50 | 52 | f"Submitted request to create JPG image of atlas {str(transferred_atlas_name)!r}" |
51 | 53 | ) |
| 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