logic for continous running

This commit is contained in:
Stalberg Jonathan
2023-04-14 14:31:54 +02:00
parent 1ccde730e0
commit 59de72ba04

View File

@ -11,24 +11,17 @@ 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("localhost", 8000)
self.i = 1
self.redis_connector = redis_connector # this is incoming
# self.file_reader = .... # add file reader here
self.grum_client = RPCClient("localhost", 8000) # this is outgoing
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, 4], 'ys': [3, 4, 5, 99]}
self.grum_client.new_plot("test", cfg)
# self.start_scan_segment_sub()
def start_scan_status_sub(self):
self._scan_sub = self.redis_connector.consumer(
@ -36,32 +29,28 @@ class BECAdapter:
)
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 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
# whenever a new scan starts or ends, for now cahnges scan nr both in start and end
print("scan_status_update", segment)
segment = BECMessage.ScanStatusMessage.loads(segment.value)
# not clear how to do the next:
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(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)
# use filewriter
name = segment.scan_number
# get the right point
point = [2, 3]
self.grum_client.append_data(name, 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 get_data_from_file(self):
@ -80,6 +69,9 @@ class BECAdapter:
recon_files = [
file for file in files if file.endswith("recons.h5")]
print('this are recon_files: ', recon_files)
if recon_files:
break
print('sleeping 1')
time.sleep(10)
hf = h5py.File(mypath + '/' + recon_files[0], 'r')
@ -90,11 +82,17 @@ class BECAdapter:
recon_probes = hf.get('reconstruction/probes')
print(recon_object)
print(recon_probes)
# PLOT self.grum_client.new_image(self.last_plotted_scan_nr+1, {'img': recon_object})
self.last_plotted_scan_nr +=1
time.sleep(10)
print('sleeping 2')
time.sleep(5)
def check_for_new_scan_nr(self):
print('from checking: ', self.scan_nr)
print('From checking: ')
print('scan_nr: ', self.scan_nr)
print('last_plotted_scan_nr: ', self.last_plotted_scan_nr)
if __name__ == "__main__":