changes to BECAdapter
This commit is contained in:
@ -4,6 +4,7 @@ from bec_utils import RedisConnector
|
||||
from os import listdir
|
||||
from os.path import isfile, join
|
||||
import h5py
|
||||
import time
|
||||
|
||||
|
||||
class BECAdapter:
|
||||
@ -15,14 +16,18 @@ class BECAdapter:
|
||||
# add file reader here
|
||||
# self.file_reader = ....
|
||||
# this is outgoing
|
||||
self.grum_client = RPCClient()
|
||||
self.grum_client = RPCClient("localhost", 8000)
|
||||
|
||||
self.i = 1
|
||||
self.last_plotted_scan_nr = 6755
|
||||
self.scan_nr = 6757
|
||||
|
||||
def start(self):
|
||||
self.start_scan_status_sub()
|
||||
self.start_scan_segment_sub()
|
||||
|
||||
# to test
|
||||
cfg = {'xs': [1, 2, 3], 'ys': [3, 4, 5]}
|
||||
cfg = {'xs': [1, 2, 3, 4], 'ys': [3, 4, 5, 99]}
|
||||
self.grum_client.new_plot("test", cfg)
|
||||
|
||||
def start_scan_status_sub(self):
|
||||
@ -38,40 +43,58 @@ class BECAdapter:
|
||||
self._scan_segment_sub.start()
|
||||
|
||||
def scan_status_update(self, segment):
|
||||
# whenever a new scan starts or ends
|
||||
print("scan_status_update", segment)
|
||||
segment = BECMessage.ScanStatusMessage.loads(segment.value)
|
||||
# not clear how to do the next:
|
||||
name = segment.scan_number
|
||||
self.scan_nr = segment.content["info"]["scan_number"]
|
||||
# fill whatever you need:
|
||||
cfg = {'xs': [1, 2, 3], 'ys': [3, 4, 5]}
|
||||
self.grum_client.new_plot(name, cfg)
|
||||
self.grum_client.new_plot(self.scan_nr, cfg)
|
||||
|
||||
def scan_segment_update(self, segment):
|
||||
# every scan segment of a scan
|
||||
print("scan_segment_update", segment)
|
||||
segment = BECMessage.ScanMessage.loads(segment.value)
|
||||
# not clear how to do the next:
|
||||
|
||||
# use filewriter
|
||||
name = segment.scan_number
|
||||
# fill whatever you need:
|
||||
# get the right point
|
||||
point = [2, 3]
|
||||
self.grum_client.append_data(name, point)
|
||||
|
||||
def get_data_from_file(self):
|
||||
|
||||
def get_data_from_file():
|
||||
scan = "S06755"
|
||||
mypath = "/sls/X12SA/data/e20632/Data10/analysis/S06000-06999/" + scan
|
||||
while True:
|
||||
print('checking for new scan_nr')
|
||||
self.check_for_new_scan_nr()
|
||||
if self.scan_nr > self.last_plotted_scan_nr:
|
||||
|
||||
files = [f for f in listdir(mypath) if isfile(join(mypath, f))]
|
||||
recon_files = [file for file in files if file.endswith("recons.h5")]
|
||||
scan = "S0" + str(self.last_plotted_scan_nr + 1)
|
||||
mypath = "/sls/X12SA/data/e20632/Data10/analysis/S06000-06999/" + scan
|
||||
# mypath = "/home/stalbe_j/Documents" # for test on own computer
|
||||
files = [f for f in listdir(mypath) if isfile(join(mypath, f))]
|
||||
print(files)
|
||||
recon_files = []
|
||||
while not recon_files:
|
||||
recon_files = [
|
||||
file for file in files if file.endswith("recons.h5")]
|
||||
print('this are recon_files: ', recon_files)
|
||||
time.sleep(10)
|
||||
|
||||
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)
|
||||
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)
|
||||
|
||||
time.sleep(10)
|
||||
|
||||
def check_for_new_scan_nr(self):
|
||||
print('from checking: ', self.scan_nr)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
@ -81,4 +104,4 @@ if __name__ == "__main__":
|
||||
redis_connector = RedisConnector(redis_url)
|
||||
ba = BECAdapter(redis_connector)
|
||||
ba.start()
|
||||
get_data_from_file()
|
||||
ba.get_data_from_file()
|
||||
|
Reference in New Issue
Block a user