added BECAdapter
This commit is contained in:
84
grum/BECAdapter
Normal file
84
grum/BECAdapter
Normal file
@ -0,0 +1,84 @@
|
||||
from grum.rpc import RPCClient
|
||||
from bec_utils import BECMessage, MessageEndpoints
|
||||
from bec_utils import RedisConnector
|
||||
from os import listdir
|
||||
from os.path import isfile, join
|
||||
import h5py
|
||||
|
||||
|
||||
class BECAdapter:
|
||||
|
||||
def __init__(self, redis_connector) -> None:
|
||||
super().__init__()
|
||||
# this is incoming
|
||||
self.redis_connector = redis_connector
|
||||
# add file reader here
|
||||
# self.file_reader = ....
|
||||
# this is outgoing
|
||||
self.grum_client = RPCClient()
|
||||
|
||||
def start(self):
|
||||
self.start_scan_status_sub()
|
||||
self.start_scan_segment_sub()
|
||||
|
||||
# to test
|
||||
cfg = {'xs': [1, 2, 3], 'ys': [3, 4, 5]}
|
||||
self.grum_client.new_plot("test", cfg)
|
||||
|
||||
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):
|
||||
print("scan_status_update", segment)
|
||||
segment = BECMessage.ScanStatusMessage.loads(segment.value)
|
||||
# not clear how to do the next:
|
||||
name = segment.scan_number
|
||||
# fill whatever you need:
|
||||
cfg = {'xs': [1, 2, 3], 'ys': [3, 4, 5]}
|
||||
self.grum_client.new_plot(name, cfg)
|
||||
|
||||
def scan_segment_update(self, segment):
|
||||
print("scan_segment_update", segment)
|
||||
segment = BECMessage.ScanMessage.loads(segment.value)
|
||||
# not clear how to do the next:
|
||||
name = segment.scan_number
|
||||
# fill whatever you need:
|
||||
point = [2, 3]
|
||||
self.grum_client.append_data(name, point)
|
||||
|
||||
|
||||
def get_data_from_file():
|
||||
scan = "S06755"
|
||||
mypath = "/sls/X12SA/data/e20632/Data10/analysis/S06000-06999/" + scan
|
||||
|
||||
files = [f for f in listdir(mypath) if isfile(join(mypath, f))]
|
||||
recon_files = [file for file in files if file.endswith("recons.h5")]
|
||||
|
||||
if recon_files[0]:
|
||||
hf = h5py.File(mypath + '/' + recon_files[0], 'r')
|
||||
print(hf.keys())
|
||||
recon = hf.get('reconstruction')
|
||||
print(recon.keys())
|
||||
recon_object = hf.get('reconstruction/object')
|
||||
recon_probes = hf.get('reconstruction/probes')
|
||||
print(recon_object)
|
||||
print(recon_probes)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print('starts BECAdapter')
|
||||
print("initializing redis-connector")
|
||||
redis_url = "129.129.122.75:6379" # for LamNI
|
||||
redis_connector = RedisConnector(redis_url)
|
||||
ba = BECAdapter(redis_connector)
|
||||
ba.start()
|
||||
get_data_from_file()
|
@ -13,9 +13,6 @@ from .rpc import RPCServerThread
|
||||
from .shortcut import shortcut
|
||||
from .webview import WebView
|
||||
|
||||
from bec_utils import RedisConnector
|
||||
from .plot_recon import plot_recon, BECConnector, DataAccess
|
||||
|
||||
|
||||
class MainWindow(QMainWindow):
|
||||
|
||||
@ -23,13 +20,6 @@ class MainWindow(QMainWindow):
|
||||
|
||||
def __init__(self, *args, title="grum", host="localhost", port=8000, offline=False, add_examples=False, window_mode=MDIWindowMode.MULTI, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
|
||||
print("initializing redis-connector")
|
||||
redis_url = "129.129.122.75:6379" # for LamNI
|
||||
redis_connector = RedisConnector(redis_url)
|
||||
connector = BECConnector(redis_connector)
|
||||
data_access = DataAccess(connector)
|
||||
|
||||
|
||||
if offline:
|
||||
@ -102,8 +92,6 @@ class MainWindow(QMainWindow):
|
||||
|
||||
self.sig_make_new_plot.connect(self.on_make_new_plot)
|
||||
|
||||
plot_recon()
|
||||
|
||||
|
||||
def keyPressEvent(self, event):
|
||||
if event.key() == Qt.Key_F1:
|
||||
|
@ -1,19 +1,10 @@
|
||||
from os import listdir
|
||||
from os.path import isfile, join
|
||||
import h5py
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
from collections import defaultdict, deque
|
||||
from bec_utils import BECMessage, MessageEndpoints
|
||||
from PyQt5.QtCore import QObject, pyqtSignal
|
||||
from collections import deque
|
||||
from PyQt5.QtCore import QObject, pyqtSignal
|
||||
from bec_utils import BECMessage
|
||||
|
||||
|
||||
pyqtWrapperType = type(QObject)
|
||||
|
||||
|
||||
class FinalMeta(pyqtWrapperType, ABC):
|
||||
pass
|
||||
|
||||
@ -94,39 +85,4 @@ class DataAccess(QObject):
|
||||
self.connector.msg_update.connect(self.on_msg_update)
|
||||
|
||||
|
||||
def get_files(path):
|
||||
|
||||
return [f for f in listdir(path) if isfile(join(path, f))]
|
||||
|
||||
|
||||
def plot_recon():
|
||||
scan = "S06755"
|
||||
mypath = "/sls/X12SA/data/e20632/Data10/analysis/S06000-06999/" + scan
|
||||
|
||||
files = get_files(mypath)
|
||||
# print("files:", files)
|
||||
recon_files = [file for file in files if file.endswith("recons.h5")]
|
||||
|
||||
if recon_files[0]:
|
||||
hf = h5py.File(mypath + '/' + recon_files[0],'r')
|
||||
print(hf.keys())
|
||||
|
||||
# measurement = hf.get('measurement')
|
||||
recon = hf.get('reconstruction')
|
||||
# print(measurement.keys())
|
||||
print(recon.keys())
|
||||
recon_object = hf.get('reconstruction/object')
|
||||
recon_probes = hf.get('reconstruction/probes')
|
||||
print(recon_object)
|
||||
print(recon_probes)
|
||||
|
||||
# import matplotlib.pyplot as plt
|
||||
# plt.imshow(recon_object)
|
||||
|
||||
|
||||
# while True:
|
||||
|
||||
# print("plot_recon")
|
||||
# self.new_plot("recon"+str(i), {'xs':[1*i,2*1,3*1], 'ys':[3*i,4*i,5*i]})
|
||||
# time.sleep(10)
|
||||
|
||||
|
Reference in New Issue
Block a user