Skip to content
Snippets Groups Projects
Commit 014edde3 authored by David Hammer's avatar David Hammer
Browse files

Small tweaks, respect image data path configuration

parent ecf63922
No related branches found
No related tags found
1 merge request!74Refactor DetectorAssembler
import enum
from timeit import default_timer
import functools
import re
from karabo.bound import (
......@@ -98,11 +97,17 @@ class DetectorAssembler(TrainMatcher.TrainMatcher):
.commit(),
STRING_ELEMENT(expected)
.key("pathToStack")
.key("imageDataPath")
.assignmentOptional()
.defaultValue("image.data")
.commit(),
STRING_ELEMENT(expected)
.key("imageMaskPath")
.assignmentOptional()
.defaultValue("image.mask")
.commit(),
OUTPUT_CHANNEL(expected)
.key("assembledOutput")
.dataSchema(schemas.preview_schema(wrap_image_in_imagedata=False))
......@@ -191,7 +196,8 @@ class DetectorAssembler(TrainMatcher.TrainMatcher):
super().initialization()
self._preview_friend = preview_utils.PreviewFriend(self)
self._path_to_stack = self.get("pathToStack")
self._image_data_path = self.get("imageDataPath")
self._image_mask_path = self.get("imageMaskPath")
self._geometry = None
self._stack_input_buffer = None
# set up source to index mapping
......@@ -331,8 +337,6 @@ class DetectorAssembler(TrainMatcher.TrainMatcher):
earliest_source_timestamp = float("inf")
self._stack_input_buffer.mask.fill(False)
for source, (data, source_timestamp) in sources.items():
if source not in self._source_to_index:
continue
# regular TrainMatcher output
self.output.write(
data, ChannelMetaData(source, source_timestamp), copyAllData=False
......@@ -340,15 +344,19 @@ class DetectorAssembler(TrainMatcher.TrainMatcher):
if bridge_output_choice is BridgeOutputOptions.MATCHED:
self.zmq_output.write(source, data, source_timestamp)
if source not in self._source_to_index:
continue
# prepare for assembly
# TODO: handle failure to "parse" source, get data out
image_data = data["image.data"]
if not data.has(self._image_data_path):
continue
image_data = data[self._image_data_path]
if isinstance(image_data, ImageData):
# TODO: maybe glance encoding here
image_data = image_data.getData()
image_data = image_data.astype(np.float32, copy=False) # TODO: set dtype based on input?
if data.has("image.mask"):
image_mask = data["image.mask"]
if data.has(self._image_mask_path):
image_mask = data[self._image_mask_path]
if isinstance(image_mask, ImageData):
image_mask = image_mask.getData()
else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment