Create nice images from Sensospot Array scans
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.8 KiB

from pathlib import Path
from collections import namedtuple
from defusedxml import ElementTree
ArrayParameters = namedtuple(
"ArrayParameters", ["size_x", "size_y", "dist_x", "dist_y"]
)
SpotParameters = namedtuple(
"SpotParameters",
["radius_spot", "radius_bkg", "roi_x", "roi_y", "crop_x", "crop_y"],
)
def _to_micro_meters(value):
as_float = float(value)
return int(as_float * 1000)
def array_parameters_from_xml(tree):
layout = tree.find("Layout")
sx = int(layout.attrib["NofSpotsX"])
sy = int(layout.attrib["NofSpotsY"])
dx = _to_micro_meters(layout.attrib["SpotDistMmX"])
dy = _to_micro_meters(layout.attrib["SpotDistMmY"])
return ArrayParameters(sx, sy, dx, dy)
def spot_parameters_from_xml(tree, array_parameters):
array = tree.find("MicroArrayAnalysis").find("Settings")
reg = tree.find("Registration").find("Settings")
rs = _to_micro_meters(array.attrib["MinSpotSizeMm"])
rb = _to_micro_meters(array.attrib["MaxSpotSizeMm"])
rx = array_parameters.dist_x
ry = array_parameters.dist_y
# ROI is strangely named in params file, it's actually the outside crop
cx = _to_micro_meters(reg.attrib["ROIMarginWidth"])
cy = _to_micro_meters(reg.attrib["ROIMarginHeight"])
return SpotParameters(rs, rb, rx, ry, cx, cy)
def get_array_parameters(params_file):
svary_file = Path(params_file).with_suffix(".svary")
with svary_file.open("r") as file_handle:
tree = ElementTree.parse(file_handle)
return array_parameters_from_xml(tree)
def get_spot_parameters(params_file, array_parameters):
svalg_file = Path(params_file).with_suffix(".svalg")
with svalg_file.open("r") as file_handle:
tree = ElementTree.parse(file_handle)
return spot_parameters_from_xml(tree, array_parameters)