fix: streamer and dap process
This commit is contained in:
@@ -23,6 +23,7 @@ class StreamProcessorPx(StreamProcessor):
|
||||
super().__init__(connector, config)
|
||||
self.metadata_consumer = None
|
||||
self.metadata = {}
|
||||
self.num_received_msgs = 0
|
||||
self.queue = Queue()
|
||||
self.start_metadata_consumer()
|
||||
|
||||
@@ -47,31 +48,38 @@ class StreamProcessorPx(StreamProcessor):
|
||||
first_key = next(iter(self.metadata))
|
||||
self.metadata.pop(first_key)
|
||||
proj_nr = int(topic.split("px_stream/projection_")[1].split("/")[0])
|
||||
self.metadata.update({proj_nr : msg.content['signals']})
|
||||
self.queue.put((proj_nr, msg.content['signals']))
|
||||
self.metadata.update({proj_nr: msg.content["signals"]})
|
||||
self.queue.put((proj_nr, msg.content["signals"]))
|
||||
|
||||
def _run_forever(self):
|
||||
""""""
|
||||
#TODO: Check if should skip entries in queue at beginning
|
||||
# TODO: Check if should skip entries in queue at beginning
|
||||
proj_nr, metadata = self.queue.get()
|
||||
self.num_received_msgs = 0
|
||||
data = []
|
||||
while self.queue.empty():
|
||||
start = time.time()
|
||||
data_msgs = self._get_data(proj_nr)
|
||||
data = [msg.content['signals']['data'] for msg in data_msgs if msg is not None]
|
||||
print(f"Processing took {time.time() - start}")
|
||||
data.extend([msg.content["signals"]["data"] for msg in data_msgs if msg is not None])
|
||||
# if len(data) > :
|
||||
result = self.process(data, metadata)
|
||||
if not result:
|
||||
continue
|
||||
msg = BECMessage.ProcessedDataMessage(data=result[0], metadata=result[1]).dumps()
|
||||
msg = BECMessage.ProcessedDataMessage(data=result[0][0], metadata=result[1]).dumps()
|
||||
print("Publishing result")
|
||||
self._publish_result(msg)
|
||||
|
||||
def _get_data(self, proj_nr: int) -> list:
|
||||
msgs = self.producer.lrange(f'px_stream/projection_{proj_nr}/data', 0, -1)
|
||||
msgs = self.producer.lrange(
|
||||
f"px_stream/projection_{proj_nr}/data", self.num_received_msgs, -1
|
||||
)
|
||||
if not msgs:
|
||||
return []
|
||||
self.num_received_msgs += len(msgs)
|
||||
return [BECMessage.DeviceMessage.loads(msg) for msg in msgs]
|
||||
|
||||
|
||||
def process(self, data: list, metadata: dict) -> Optional[Tuple[dict, dict]]:
|
||||
|
||||
if not data:
|
||||
return None
|
||||
# get the event data, hard coded
|
||||
@@ -102,10 +110,8 @@ class StreamProcessorPx(StreamProcessor):
|
||||
out = f2phase
|
||||
|
||||
stream_output = {
|
||||
self.config["output"]: {
|
||||
# 0: {"x": np.asarray(x), "y": np.asarray(y), "z": np.asarray(out)},
|
||||
0: {"z": np.asarray(out)},
|
||||
},
|
||||
# 0: {"x": np.asarray(x), "y": np.asarray(y), "z": np.asarray(out)},
|
||||
0: {"z": np.asarray(out)},
|
||||
# "input": self.config["input_xy"],
|
||||
}
|
||||
metadata["grid_scan"] = out.shape
|
||||
@@ -201,7 +207,7 @@ if __name__ == "__main__":
|
||||
"channels": ["data", "metadata", "q", "norm_sum"],
|
||||
"output": "px_dap_worker",
|
||||
"parameters": {
|
||||
"qranges" : [20,50], #TODO this will be signal from ROI selector
|
||||
"qranges": [20, 50], # TODO this will be signal from ROI selector
|
||||
"contrast": 0, # "contrast_stream" : 'px_contrast_stream',
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user