started to implement monitor and motor pos
This commit is contained in:
@ -7,6 +7,7 @@ import h5py
|
||||
import time
|
||||
import numpy as np
|
||||
from PIL import Image
|
||||
import random
|
||||
|
||||
|
||||
class BECAdapter:
|
||||
@ -18,51 +19,94 @@ class BECAdapter:
|
||||
# self.file_reader = .... # add file reader here
|
||||
self.grum_client = RPCClient("localhost", 8000) # this is outgoing
|
||||
|
||||
self.last_plotted_scan_nr = 6760
|
||||
self.last_plotted_scan_nr = 0
|
||||
self.scan_nr = None
|
||||
|
||||
#uncomment for monitor and motor pos start plots
|
||||
# self.grum_client.new_plot("monitor",{'xlabel':'time', 'ylabel':"sls_ring_current" })
|
||||
# self.grum_client.new_plot("Motor position", {'xlabel':'average_x_st_fzp', 'ylabel':"average_y_st_fzp" })
|
||||
|
||||
self.scan_running = False
|
||||
|
||||
def start(self):
|
||||
self.start_scan_status_sub()
|
||||
# self.start_scan_segment_sub()
|
||||
self.start_monitor_sub()
|
||||
self.start_scan_segment_sub()
|
||||
|
||||
def start_scan_status_sub(self):
|
||||
self._scan_sub = self.redis_connector.consumer(
|
||||
MessageEndpoints.scan_status(), cb=self.scan_status_update
|
||||
)
|
||||
self._scan_sub.start()
|
||||
|
||||
# def start_scan_segment_sub(self):
|
||||
# self._scan_segment_sub = self.redis_connector.consumer(
|
||||
# MessageEndpoints.scan_segment(), cb=self.scan_segment_update
|
||||
# )
|
||||
# self._scan_segment_sub.start()
|
||||
|
||||
|
||||
def scan_status_update(self, segment):
|
||||
# whenever a new scan starts or ends, for now cahnges scan nr both in start and end
|
||||
print("scan_status_update", segment)
|
||||
# whenever a new scan starts or ends, for now changes scan nr both in start and end
|
||||
segment = BECMessage.ScanStatusMessage.loads(segment.value)
|
||||
# not clear how to do the next:
|
||||
self.scan_nr = segment.content["info"]["scan_number"]
|
||||
self.positions = segment.content["info"]["positions"]
|
||||
xpos = [x for x,y in self.positions]
|
||||
ypos = [y for x,y in self.positions]
|
||||
if len(segment.content["info"]["primary"]) == 2:
|
||||
self.scan_running = True
|
||||
# uncomment for plot a new plot for every motor scan
|
||||
# self.grum_client.new_plot(f"Motor position for scan: {self.scan_nr}", {"xs": xpos, "ys":ypos, 'xlabel':'average_x_st_fzp', 'ylabel':"average_y_st_fzp" })
|
||||
# uncomment for plot in the same plot for motor pos, how to append array?
|
||||
# self.grum_client.new_plot(f"Motor position {self.scan_nr}", {"xs": xpos, "ys":ypos, 'xlabel':'average_x_st_fzp', 'ylabel':"average_y_st_fzp" })
|
||||
|
||||
else:
|
||||
self.scan_running = False
|
||||
|
||||
if len(segment.content["info"]["primary"]) == 1:
|
||||
print("umv")
|
||||
|
||||
def start_scan_segment_sub(self):
|
||||
self._scan_segment_sub = self.redis_connector.consumer(
|
||||
MessageEndpoints.scan_segment(), cb=self.scan_segment_update
|
||||
)
|
||||
self._scan_segment_sub.start()
|
||||
|
||||
|
||||
def scan_segment_update(self, segment):
|
||||
# every scan segment of a scan
|
||||
if self.scan_running:
|
||||
segment = BECMessage.ScanMessage.loads(segment.value)
|
||||
x_val = segment[0].content["data"]["average_x_st_fzp"]["value"]
|
||||
y_val = segment[0].content["data"]["average_y_st_fzp"]["value"]
|
||||
|
||||
point = [x_val, y_val]
|
||||
#self.grum_client.append_data(f"Motor position for scan: {self.scan_nr}", point)
|
||||
|
||||
def start_monitor_sub(self):
|
||||
self._monitor_sub = self.redis_connector.consumer(
|
||||
pattern = MessageEndpoints.device_readback('*'),
|
||||
cb=self.monitor_update
|
||||
)
|
||||
self._monitor_sub.start()
|
||||
|
||||
def monitor_update(self, msg):
|
||||
# Whenever we get a new monitor value
|
||||
dev = msg.topic.decode().split(MessageEndpoints._device_readback + '/')[-1].split(':sub')[0]
|
||||
msg = BECMessage.DeviceMessage.loads(msg.value)
|
||||
if dev == "sls_ring_current":
|
||||
x = msg.content["signals"][dev]['timestamp']
|
||||
y = msg.content["signals"][dev]['value']
|
||||
point = [x,y]
|
||||
#uncomment to plot monitor values
|
||||
self.grum_client.append_data("monitor", point)
|
||||
|
||||
|
||||
# use for plotting motor pos
|
||||
# def scan_segment_update(self, segment):
|
||||
# # every scan segment of a scan
|
||||
# print("scan_segment_update", segment)
|
||||
# segment = BECMessage.ScanMessage.loads(segment.value)
|
||||
# name = segment.scan_number
|
||||
# # get the right point
|
||||
# point = [2, 3]
|
||||
# self.grum_client.append_data(name, point)
|
||||
|
||||
def plot_img_from_h5(self):
|
||||
|
||||
while True:
|
||||
print('update for new scan_nr')
|
||||
self.update_scan_nr()
|
||||
print('scan_nr: ', self.scan_nr)
|
||||
print("last plotted scan nr: ", self.last_plotted_scan_nr)
|
||||
if self.scan_nr > self.last_plotted_scan_nr:
|
||||
|
||||
# scan = "S0" + str(self.last_plotted_scan_nr + 1)
|
||||
ending_path = self._get_scan_dir(1000, self.last_plotted_scan_nr + 1, leading_zeros = 5)
|
||||
ending_path = self._get_scan_dir(1000, self.scan_nr, leading_zeros = 5)
|
||||
mypath = "/sls/X12SA/data/e20632/Data10/analysis/" + ending_path
|
||||
|
||||
files = [f for f in listdir(mypath) if isfile(join(mypath, f))]
|
||||
@ -85,21 +129,21 @@ class BECAdapter:
|
||||
recon_img_angle = recon_object_angle.tolist()
|
||||
|
||||
# PLOT
|
||||
self.grum_client.new_image("Absorption", {'image': recon_img_abs, "xlabel": str(self.scan_nr)})
|
||||
self.grum_client.new_image("Phase", {'image': recon_img_angle, "xlabel": str(self.scan_nr), "colormap":"CET-C1"})
|
||||
|
||||
print('plotting new image with scan_nr: ', self.scan_nr )
|
||||
xlab = str(self.scan_nr)
|
||||
self.grum_client.new_image("Absorption", {'image': recon_img_abs, "xlabel": xlab})
|
||||
self.grum_client.new_image("Phase", {'image': recon_img_angle, "xlabel": xlab, "colormap":"CET-C1"})
|
||||
print("done with plotting")
|
||||
self.last_plotted_scan_nr = self.scan_nr
|
||||
|
||||
time.sleep(10)
|
||||
|
||||
def update_scan_nr(self):
|
||||
# return (self.last_plotted_scan_nr == self.scan_nr)
|
||||
mypath = '/sls/X12SA/Data10/e20632/analysis/online/ptycho/gallery'
|
||||
mypath = '/sls/X12SA/Data10/e20632/analysis/online/ptycho/gallery' #TODO: change hardcoded eaccount
|
||||
file_list = listdir(mypath)
|
||||
scans = [file_name.split('_')[0] for file_name in file_list]
|
||||
max_scan_nr = max([int(scan[1:6]) for scan in scans])
|
||||
print(max_scan_nr)
|
||||
|
||||
print('Max scan nr: ', max_scan_nr)
|
||||
self.scan_nr = max_scan_nr
|
||||
|
||||
def _get_scan_dir(self, scan_bundle, scan_number, leading_zeros=None):
|
||||
|
@ -37,6 +37,7 @@ class ImageDescription:
|
||||
if self.xlabel:
|
||||
# vbox = plotwidget.getView()
|
||||
# vbox.addItem(pg.LabelItem(self.xlabel))
|
||||
print('trying to set a new label: ', self.xlabel)
|
||||
plotwidget.setHistogramLabel(self.xlabel)
|
||||
# plotwidget.setLabel("bottom", self.xlabel)
|
||||
|
||||
|
@ -156,6 +156,11 @@ class MainWindow(QMainWindow):
|
||||
sub = self.mdi.findSubWindow(name)
|
||||
if sub:
|
||||
sub.pw.setImage(desc.data) #TODO lacks the list sync
|
||||
# print("trying to update the label with new scan_nr: ", desc.xlabel)
|
||||
# sub.pw.setHistogramLabel(desc.xlabel) # Also updates the label, doesn't work ...
|
||||
|
||||
# error message: QObject: Cannot create children for a parent that is in a different thread.
|
||||
# (Parent is QTextDocument(0x5588636f2b70), parent's thread is QThread(0x5588628461a0), current thread is QThread(0x7f16540058f0)
|
||||
else:
|
||||
self.sig_make_new_image.emit(name, desc)
|
||||
|
||||
|
Reference in New Issue
Block a user