Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 44 additions & 36 deletions src/murfey/client/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,31 +94,6 @@ def ensure_dcg_exists(
logger.info(
f"Looking for atlas XML file in metadata directory {str((source_visit_dir / partial_path).parent)}"
)
atlas_xml_path = list(
(source_visit_dir / partial_path).parent.glob("Atlas_*.xml")
)[0]
logger.info(f"Atlas XML path {str(atlas_xml_path)} found")
with open(atlas_xml_path, "rb") as atlas_xml:
atlas_xml_data = xmltodict.parse(atlas_xml)
atlas_original_pixel_size = float(
atlas_xml_data["MicroscopeImage"]["SpatialScale"]["pixelSize"]["x"][
"numericValue"
]
)
# need to calculate the pixel size of the downscaled image
atlas_pixel_size = atlas_original_pixel_size * 7.8
logger.info(f"Atlas image pixel size determined to be {atlas_pixel_size}")

for p in partial_path.split("/"):
if p.startswith("Sample"):
sample = int(p.replace("Sample", ""))
break
else:
logger.warning(f"Sample could not be identified for {metadata_source}")
return None
environment.samples[metadata_source] = SampleInfo(
atlas=Path(partial_path), sample=sample
)

dcg_search_dir = (
str(metadata_source).replace(f"/{environment.visit}", "").replace("//", "/")
Expand All @@ -137,17 +112,50 @@ def ensure_dcg_exists(
dcg_images_dirs = [Path(dcg_search_dir) / "Images-Disc1"]
dcg_tag = str(dcg_images_dirs[-1])

dcg_data = {
"experiment_type_id": experiment_type_id,
"tag": dcg_tag,
"atlas": str(
_atlas_destination(environment, metadata_source, token)
/ environment.samples[metadata_source].atlas.parent
/ atlas_xml_path.with_suffix(".jpg").name
).replace("//", "/"),
"sample": environment.samples[metadata_source].sample,
"atlas_pixel_size": atlas_pixel_size,
}
for p in partial_path.split("/"):
if p.startswith("Sample"):
sample = int(p.replace("Sample", ""))
break
else:
logger.warning(f"Sample could not be identified for {metadata_source}")
return None
environment.samples[metadata_source] = SampleInfo(
atlas=Path(partial_path), sample=sample
)

if atlas_xml_search := list(
(source_visit_dir / partial_path).parent.glob("Atlas_*.xml")
):
atlas_xml_path = atlas_xml_search[0]
logger.info(f"Atlas XML path {str(atlas_xml_path)} found")
with open(atlas_xml_path, "rb") as atlas_xml:
atlas_xml_data = xmltodict.parse(atlas_xml)
atlas_original_pixel_size = float(
atlas_xml_data["MicroscopeImage"]["SpatialScale"]["pixelSize"]["x"][
"numericValue"
]
)
# need to calculate the pixel size of the downscaled image
atlas_pixel_size = atlas_original_pixel_size * 7.8
logger.info(f"Atlas image pixel size determined to be {atlas_pixel_size}")

dcg_data = {
"experiment_type_id": experiment_type_id,
"tag": dcg_tag,
"atlas": str(
_atlas_destination(environment, metadata_source, token)
/ environment.samples[metadata_source].atlas.parent
/ atlas_xml_path.with_suffix(".jpg").name
).replace("//", "/"),
"sample": environment.samples[metadata_source].sample,
"atlas_pixel_size": atlas_pixel_size,
}
else:
dcg_data = {
"experiment_type_id": experiment_type_id,
"tag": dcg_tag,
"sample": environment.samples[metadata_source].sample,
}
capture_post(
base_url=str(environment.url.geturl()),
router_name="workflow.router",
Expand Down