fix: gui even horiz_roi
This commit is contained in:
@@ -16,22 +16,36 @@ class SaxsImagingProcessor(StreamProcessor):
|
||||
self.metadata_consumer = None
|
||||
self.parameter_consumer = None
|
||||
self.metadata = {}
|
||||
# self._init_data_output()
|
||||
# Initit
|
||||
self.proj_nr = None
|
||||
self.azi_angle = None
|
||||
self.qranges = [20, 50]
|
||||
self.contrast = 0
|
||||
self.num_received_msgs = 0
|
||||
self.queue = Queue()
|
||||
self._init_metadata(endpoint="px_stream/proj_nr")
|
||||
self.start_metadata_consumer(endpoint="px_stream/projection_*/metadata")
|
||||
self._init_parameter(endpoint="px_stream/gui_event")
|
||||
self.start_parameter_consumer(endpoint="px_stream/gui_event")
|
||||
self._init_metadata_and_proj_nr(endpoint="px_stream/proj_nr")
|
||||
self.start_metadata_consumer(endpoint="px_stream/projection_*/metadata")
|
||||
|
||||
def _init_parameter(self, endpoint: str) -> None:
|
||||
"""Initialize the parameters azi_angle, contrast and horiz_roi.
|
||||
|
||||
Args:
|
||||
endpoint (str): Endpoint for redis topic.
|
||||
|
||||
Returns:
|
||||
None
|
||||
|
||||
"""
|
||||
self.azi_angle = None
|
||||
self.horiz_roi = [20, 50]
|
||||
self.contrast = 0
|
||||
msg = self.producer.get(topic=endpoint)
|
||||
if msg is None:
|
||||
return None
|
||||
msg_raw = BECMessage.DeviceMessage.loads(msg)
|
||||
self._parameter_msg_handler(msg_raw)
|
||||
|
||||
def start_parameter_consumer(self, endpoint: str) -> None:
|
||||
"""Initialize the consumers for gui_event parameters.
|
||||
Consumer is started with a callback function that updates
|
||||
the parameters: azi_angle, contrast and qranges.
|
||||
the parameters: azi_angle, contrast and horiz_roi.
|
||||
|
||||
Args:
|
||||
endpoint (str): Endpoint for redis topic.
|
||||
@@ -62,33 +76,33 @@ class SaxsImagingProcessor(StreamProcessor):
|
||||
"""
|
||||
|
||||
msg_raw = BECMessage.DeviceMessage.loads(msg.value)
|
||||
parent._parameter_msg_handler(msg_raw, msg.topic.decode())
|
||||
parent._parameter_msg_handler(msg_raw)
|
||||
|
||||
def _parameter_msg_handler(self, msg: BECMessage, topic) -> None:
|
||||
def _parameter_msg_handler(self, msg: BECMessage) -> None:
|
||||
"""Handle the parameter message.
|
||||
There can be updates on three different parameters:
|
||||
azi_angle, contrast and qranges.
|
||||
azi_angle, contrast and horiz_roi.
|
||||
|
||||
Args:
|
||||
msg (BECMessage): Message object.
|
||||
topic (str): Topic for the message.
|
||||
|
||||
Returns:
|
||||
None
|
||||
|
||||
"""
|
||||
|
||||
if msg.content["signals"].get("qranges") is not None:
|
||||
self.qranges = msg.content["signals"]["qranges"]
|
||||
if msg.content["signals"].get("horiz_roi") is not None:
|
||||
self.horiz_roi = msg.content["signals"]["horiz_roi"]
|
||||
if msg.content["signals"].get("azi_angles") is not None:
|
||||
self.azi_angle = msg.content["signals"]["azi_angle"]
|
||||
if msg.content["signals"].get("contrast") is not None:
|
||||
self.contrast = msg.content["signals"]["contrast"]
|
||||
if len(self.metadata) > 0:
|
||||
self._update_queue(self.metadata[self.proj_nr], self.proj_nr)
|
||||
# self._init_parameter_updated = True
|
||||
# if len(self.metadata) > 0:
|
||||
# self._update_queue(self.metadata[self.proj_nr], self.proj_nr)
|
||||
|
||||
def _init_metadata(self, endpoint: str) -> None:
|
||||
"""Initialize the metadata.
|
||||
def _init_metadata_and_proj_nr(self, endpoint: str) -> None:
|
||||
"""Initialize the metadata and proj_nr.
|
||||
|
||||
Args:
|
||||
endpoint (str): Endpoint for redis topic.
|
||||
@@ -100,6 +114,7 @@ class SaxsImagingProcessor(StreamProcessor):
|
||||
|
||||
msg = self.producer.get(topic=endpoint)
|
||||
if msg is None:
|
||||
self.proj_nr = None
|
||||
return None
|
||||
msg_raw = BECMessage.DeviceMessage.loads(msg)
|
||||
self.proj_nr = msg_raw.content["signals"]["proj_nr"]
|
||||
@@ -199,15 +214,13 @@ class SaxsImagingProcessor(StreamProcessor):
|
||||
|
||||
proj_nr, metadata = self.queue.get()
|
||||
self.num_received_msgs = 0
|
||||
# TODO initiate output, such that self.process only runs on new data
|
||||
# self._init_data_output()
|
||||
data = []
|
||||
while self.queue.empty():
|
||||
# TODO debug code for timing
|
||||
data_msgs = self._get_data(proj_nr)
|
||||
if data_msgs is None:
|
||||
continue
|
||||
data.extend([msg.content["signals"]["data"] for msg in data_msgs if msg is not None])
|
||||
if data_msgs is not None:
|
||||
data.extend(
|
||||
[msg.content["signals"]["data"] for msg in data_msgs if msg is not None]
|
||||
)
|
||||
# print(f"Loading took {time.time() - start}")
|
||||
# start = time.time()
|
||||
result = self.process(data, metadata)
|
||||
@@ -259,13 +272,13 @@ class SaxsImagingProcessor(StreamProcessor):
|
||||
out = []
|
||||
|
||||
contrast = self.contrast
|
||||
qranges = self.qranges
|
||||
horiz_roi = self.horiz_roi
|
||||
azi_angle = self.azi_angle
|
||||
if azi_angle is None:
|
||||
azi_angle = 0
|
||||
|
||||
f1amp, f2amp, f2phase = self._colorfulplot(
|
||||
qranges=qranges,
|
||||
horiz_roi=horiz_roi,
|
||||
q=q,
|
||||
norm_sum=norm_sum,
|
||||
data=azint_data,
|
||||
@@ -289,7 +302,7 @@ class SaxsImagingProcessor(StreamProcessor):
|
||||
|
||||
def _colorfulplot(
|
||||
self,
|
||||
qranges: list,
|
||||
horiz_roi: list,
|
||||
q: np.ndarray,
|
||||
norm_sum: np.ndarray,
|
||||
data: np.ndarray,
|
||||
@@ -300,7 +313,7 @@ class SaxsImagingProcessor(StreamProcessor):
|
||||
Pending: hsv_to_rgb conversion for colorful output
|
||||
|
||||
Args:
|
||||
qranges (list): List with q edges for binning.
|
||||
horiz_roi (list): List with q edges for binning.
|
||||
q (np.ndarray): q values.
|
||||
norm_sum (np.ndarray): Normalization sum.
|
||||
data (np.ndarray): Data to be binned.
|
||||
@@ -312,7 +325,9 @@ class SaxsImagingProcessor(StreamProcessor):
|
||||
|
||||
"""
|
||||
|
||||
output, output_norm = self._bin_qrange(qranges=qranges, q=q, norm_sum=norm_sum, data=data)
|
||||
output, output_norm = self._bin_qrange(
|
||||
horiz_roi=horiz_roi, q=q, norm_sum=norm_sum, data=data
|
||||
)
|
||||
output_sym = self._sym_data(data=output, norm_sum=output_norm)
|
||||
output_sym = output_sym
|
||||
shape = output_sym.shape[0:2]
|
||||
@@ -347,12 +362,12 @@ class SaxsImagingProcessor(StreamProcessor):
|
||||
|
||||
return f1amp, f2amp, f2phase # , comb_all
|
||||
|
||||
def _bin_qrange(self, qranges, q, norm_sum, data) -> Tuple[np.ndarray, np.ndarray]:
|
||||
def _bin_qrange(self, horiz_roi, q, norm_sum, data) -> Tuple[np.ndarray, np.ndarray]:
|
||||
"""Reintegrate data for given q range.
|
||||
Weighted sum for data using norm_sum as weights
|
||||
|
||||
Args:
|
||||
qranges (list): List with q edges for binning.
|
||||
horiz_roi (list): List with q edges for binning.
|
||||
q (np.ndarray): q values.
|
||||
norm_sum (np.ndarray): Normalization sum.
|
||||
data (np.ndarray): Data to be binned.
|
||||
@@ -362,11 +377,11 @@ class SaxsImagingProcessor(StreamProcessor):
|
||||
np.ndarray: Binned normalization sum.
|
||||
"""
|
||||
|
||||
output = np.zeros((*data.shape[:-1], len(qranges) - 1))
|
||||
output_norm = np.zeros((data.shape[-2], len(qranges) - 1))
|
||||
output = np.zeros((*data.shape[:-1], len(horiz_roi) - 1))
|
||||
output_norm = np.zeros((data.shape[-2], len(horiz_roi) - 1))
|
||||
|
||||
with np.errstate(divide="ignore", invalid="ignore"):
|
||||
q_mask = np.logical_and(q >= q[qranges[0]], q <= q[qranges[1]])
|
||||
q_mask = np.logical_and(q >= q[horiz_roi[0]], q <= q[horiz_roi[1]])
|
||||
output_norm[..., 0] = np.nansum(norm_sum[..., q_mask], axis=-1)
|
||||
output[..., 0] = np.nansum(data[..., q_mask] * norm_sum[..., q_mask], axis=-1)
|
||||
output[..., 0] = np.divide(
|
||||
|
||||
Reference in New Issue
Block a user