made motorplot work, added scan number to recon
This commit is contained in:
@ -16,16 +16,17 @@ class BECAdapter:
|
||||
self.redis_connector = redis_connector # this is incoming
|
||||
# self.file_reader = .... # add file reader here
|
||||
self.grum_client_monitor = RPCClient("localhost", 8000) # this is outgoing
|
||||
self.grum_client_motor_pos = RPCClient("localhost", 8000) # this is outgoing
|
||||
self.grum_client_motor_pos_static = RPCClient("localhost", 8000) # this is outgoing
|
||||
self.grum_client_motor_pos_moving = RPCClient("localhost", 8000) # this is outgoing
|
||||
self.grum_client_recon_abs = RPCClient("localhost", 8000) # this is outgoing
|
||||
self.grum_client_recon_phase = RPCClient("localhost", 8000) # this is outgoing
|
||||
|
||||
self.last_plotted_scan_nr = 0
|
||||
self.latest_reconstructed =None
|
||||
self.latest_reconstructed = 5379
|
||||
self.scan_nr = None
|
||||
self.scan_running = False
|
||||
|
||||
self.eaccount = "e20642" # change to e20632 for testing
|
||||
self.eaccount = "e20642"
|
||||
|
||||
# To decide what should be plotted
|
||||
self.monitor = monitor
|
||||
@ -33,15 +34,18 @@ class BECAdapter:
|
||||
self.recon = recon
|
||||
|
||||
if self.monitor:
|
||||
self.grum_client_monitor.new_plot( "monitor",{'xlabel':'time', 'ylabel':"sls_ring_current", "frmt": "time" })
|
||||
self.grum_client_monitor.new_plot( "monitor",{'xlabel':'time', 'ylabel':"sls_ring_current", "time": True, "frmt":"Line" })
|
||||
if self.motor_pos:
|
||||
self.grum_client_motor_pos.new_plot("Motor position", {'xlabel':'average_x_st_fzp', 'ylabel':"average_y_st_fzp" })
|
||||
# self.grum_client_motor_pos_static.new_plot("Motor position static", {'xlabel':'average_x_st_fzp', 'ylabel':"average_y_st_fzp" })
|
||||
self.grum_client_motor_pos_moving.new_plot("Motor position move", {'xlabel':'average_x_st_fzp', 'ylabel':"average_y_st_fzp" , 'frmt':"Motor pos move"})
|
||||
|
||||
def start(self):
|
||||
self.start_scan_status_sub()
|
||||
self.start_monitor_sub()
|
||||
self.start_scan_segment_sub()
|
||||
|
||||
if self.motor_pos:
|
||||
self.start_scan_status_sub()
|
||||
self.start_scan_segment_sub()
|
||||
if self.monitor:
|
||||
self.start_monitor_sub()
|
||||
|
||||
def start_scan_status_sub(self):
|
||||
self._scan_sub = self.redis_connector.consumer(
|
||||
MessageEndpoints.scan_status(), cb=self.scan_status_update
|
||||
@ -50,18 +54,22 @@ class BECAdapter:
|
||||
|
||||
def scan_status_update(self, segment):
|
||||
# whenever a new scan starts or ends, for now changes scan nr both in start and end
|
||||
segment = BECMessage.ScanStatusMessage.loads(segment.value)
|
||||
if segment.content["status"] == "open":
|
||||
segment = BECMessage.ScanStatusMessage.loads(segment.value)
|
||||
print(segment.content)
|
||||
self.grum_client_motor_pos_moving.new_plot("Motor position move", {'xlabel':'average_x_st_fzp', 'ylabel':"average_y_st_fzp" })
|
||||
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
|
||||
# print("Plotting new positions")
|
||||
if self.motor_pos:
|
||||
self.grum_client_motor_pos.new_plot( "Motor position", {"xs": xpos, "ys":ypos, 'xlabel':'average_x_st_fzp', 'ylabel':"average_y_st_fzp", "frmt": "Dots"})
|
||||
print("new plot")
|
||||
self.grum_client_motor_pos_static.new_plot( "Motor position static", {"xs": xpos, "ys":ypos, 'xlabel':'average_x_st_fzp', 'ylabel':"average_y_st_fzp", "frmt": "Dots"})
|
||||
#Trying to update plots with "open new plots" unticked
|
||||
# self.grum_client_motor_pos_static.new_plot( "Motor position static", {"xs": xpos[:-1], "ys":ypos[:-1], 'xlabel':'average_x_st_fzp', 'ylabel':"average_y_st_fzp", "frmt": "Dots"})
|
||||
# self.grum_client_motor_pos_static.append_data( "Motor position static", [xpos[-1], ypos[-1]] )
|
||||
|
||||
else:
|
||||
self.scan_running = False
|
||||
|
||||
@ -83,7 +91,7 @@ class BECAdapter:
|
||||
|
||||
point = [x_val, y_val]
|
||||
if self.motor_pos:
|
||||
self.grum_client_motor_pos.append_data( "Motor position", point)
|
||||
self.grum_client_motor_pos_moving.append_data( "Motor position move", point)
|
||||
|
||||
def start_monitor_sub(self):
|
||||
self._monitor_sub = self.redis_connector.consumer(
|
||||
@ -105,13 +113,14 @@ class BECAdapter:
|
||||
|
||||
def plot_img_from_h5(self):
|
||||
while True:
|
||||
|
||||
# if self.last_plotted_scan_nr !=0:
|
||||
print('Check for new reconstruction')
|
||||
self.update_latest_reconstructed()
|
||||
print('latest_reconstructed: ', self.latest_reconstructed)
|
||||
print("last plotted scan nr: ", self.last_plotted_scan_nr)
|
||||
if self.latest_reconstructed > self.last_plotted_scan_nr:
|
||||
|
||||
|
||||
|
||||
ending_path = self._get_scan_dir(1000, self.latest_reconstructed, leading_zeros = 5)
|
||||
mypath = "/sls/X12SA/data/" + self.eaccount + "/Data10/analysis/" + ending_path
|
||||
recon_file = self.get_recon_file(mypath)
|
||||
@ -123,7 +132,8 @@ class BECAdapter:
|
||||
xlab = str(self.latest_reconstructed)
|
||||
if self.recon:
|
||||
self.grum_client_recon_abs.new_image( "Absorption", {'image': recon_img_abs, "xlabel": xlab})
|
||||
self.grum_client_recon_phase.new_image( f"Phase for scan_nr: {self.latest_reconstructed}", {'image': recon_img_angle, "xlabel": xlab}) #, "colormap":"CET-C1"})
|
||||
# self.grum_client_recon_phase.new_image( f"Phase for scan_nr: {self.latest_reconstructed}", {'image': recon_img_angle, "xlabel": xlab}) #, "colormap":"CET-C1"})
|
||||
self.grum_client_recon_phase.new_image( "Phase", {'image': recon_img_angle, "xlabel": xlab}) #, "colormap":"CET-C1"})
|
||||
self.last_plotted_scan_nr = self.latest_reconstructed
|
||||
|
||||
time.sleep(10)
|
||||
@ -146,6 +156,9 @@ class BECAdapter:
|
||||
recon_object_abs = np.abs(recon_object)
|
||||
recon_object_angle = np.angle(recon_object)
|
||||
|
||||
recon_object_abs = np.rot90(recon_object_abs,3)
|
||||
recon_object_angle = np.rot90(recon_object_angle, 3)
|
||||
|
||||
recon_img_abs = recon_object_abs.tolist()
|
||||
recon_img_angle = recon_object_angle.tolist()
|
||||
return recon_img_abs, recon_img_angle
|
||||
@ -155,7 +168,7 @@ class BECAdapter:
|
||||
file_list = listdir(mypath)
|
||||
scans = [file_name.split('_')[0] for file_name in file_list]
|
||||
self.latest_reconstructed = max([int(scan[1:6]) for scan in scans])
|
||||
print('Max scan nr: ', self.latest_reconstructed)
|
||||
# print('Latest reconstructed: ', self.latest_reconstructed)
|
||||
|
||||
def _get_scan_dir(self, scan_bundle, scan_number, leading_zeros=None):
|
||||
if leading_zeros is None:
|
||||
@ -169,6 +182,6 @@ if __name__ == "__main__":
|
||||
print("initializing redis-connector")
|
||||
redis_url = "129.129.122.75:6379" # for LamNI
|
||||
redis_connector = RedisConnector(redis_url)
|
||||
ba = BECAdapter(redis_connector, recon=True, monitor = True)
|
||||
ba = BECAdapter(redis_connector, recon=True, motor_pos=True, monitor=True)# monitor = True)
|
||||
ba.start()
|
||||
ba.plot_img_from_h5()
|
||||
|
@ -1,6 +1,8 @@
|
||||
import numpy as np
|
||||
import pyqtgraph as pg
|
||||
|
||||
from .theme import pg_legend_style
|
||||
|
||||
|
||||
class ImageDescription:
|
||||
|
||||
@ -35,11 +37,8 @@ class ImageDescription:
|
||||
plotwidget.setTitle(self.title)
|
||||
|
||||
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)
|
||||
vbox = plotwidget.getView()
|
||||
vbox.addItem(pg.LabelItem(self.xlabel, size='50pt'))
|
||||
|
||||
if self.ylabel:
|
||||
plotwidget.setLabel("left", self.ylabel)
|
||||
|
@ -1,5 +1,6 @@
|
||||
from PyQt5.QtCore import Qt, pyqtSignal
|
||||
from PyQt5.QtWidgets import QMainWindow, QSplitter
|
||||
import pyqtgraph as pg
|
||||
|
||||
from . import assets
|
||||
from .dictlist import DictList
|
||||
@ -156,11 +157,14 @@ 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)
|
||||
vbox = sub.pw.getView()
|
||||
allchildren = vbox.allChildren()
|
||||
for child in allchildren:
|
||||
if isinstance(child, pg.LabelItem):
|
||||
# print("Removing label")
|
||||
vbox.removeItem(child)
|
||||
vbox.addItem(pg.LabelItem(desc.xlabel, size='50pt'))
|
||||
|
||||
else:
|
||||
self.sig_make_new_image.emit(name, desc)
|
||||
|
||||
|
@ -33,7 +33,7 @@ class BECConnector(ConnectorBase):
|
||||
|
||||
@staticmethod
|
||||
def scan_status_update(msg, parent):
|
||||
print("scan_status_update", msg)
|
||||
# print("scan_status_update", msg)
|
||||
msg = BECMessage.ScanStatusMessage.loads(msg.value)
|
||||
parent.msg_update.emit(msg)
|
||||
|
||||
|
@ -3,7 +3,7 @@ from collections import deque
|
||||
|
||||
class PlotDescription:
|
||||
|
||||
def __init__(self, name, title=None, xlabel=None, ylabel=None, xs=None, ys=None, frmt=None):
|
||||
def __init__(self, name, title=None, xlabel=None, ylabel=None, xs=None, ys=None, frmt=None, time=False):
|
||||
self.name = name
|
||||
self.title = title
|
||||
self.xlabel = xlabel
|
||||
@ -11,6 +11,7 @@ class PlotDescription:
|
||||
self.xs = deque(maxlen = 5000) if xs is None else deque(xs, maxlen = 5000)
|
||||
self.ys = deque(maxlen = 5000) if ys is None else deque(ys, maxlen = 5000)
|
||||
self.format = frmt
|
||||
self.time = time
|
||||
|
||||
@property
|
||||
def data(self):
|
||||
@ -33,16 +34,16 @@ class PlotDescription:
|
||||
|
||||
|
||||
def make_plot(self, plotwidget, style):
|
||||
# if self.format == "Line":
|
||||
# res = plotwidget.plot(self.xs, self.ys, name=self.name, pen="r") #, **style)
|
||||
# elif self.format == "Dots":
|
||||
# print('Dots for positions')
|
||||
# res = plotwidget.plot(self.xs, self.ys, name=self.name, pen=None, symbol="o") #, **style)
|
||||
# else:
|
||||
# res = plotwidget.plot(self.xs, self.ys, name=self.name, **style)
|
||||
|
||||
res = plotwidget.plot(self.xs, self.ys, name=self.name, **style)
|
||||
if self.format == "time":
|
||||
if self.format == "Line":
|
||||
res = plotwidget.plot(self.xs, self.ys, name=self.name, pen="w") #, **style)
|
||||
elif self.format == "Dots":
|
||||
res = plotwidget.plot(self.xs, self.ys, name=self.name, pen=None, symbol="o", symbolSize = 5) #, **style)
|
||||
elif self.format == "Motor pos move":
|
||||
res = plotwidget.plot(self.xs, self.ys, name=self.name, pen='r', symbol="o", symbolSize = 10)
|
||||
else:
|
||||
res = plotwidget.plot(self.xs, self.ys, name=self.name, **style)
|
||||
|
||||
if self.time:
|
||||
axis = DateAxisItem()
|
||||
plotwidget.setAxisItems({'bottom':axis})
|
||||
|
||||
|
Reference in New Issue
Block a user