Commit 56b55d88 authored by bliss administrator's avatar bliss administrator
Browse files

Improve tomo and pcotomo displays to avoid print running when window width

is too small
parent 766e59cb
......@@ -120,6 +120,7 @@ class ScanDisplay(DataWatchCallback):
for lima in self.__limas:
self.__infos[lima.name] = 0
self.__last_saved = 0
self.__nb_str = []
def on_scan_end(self, info):
"""
......@@ -201,20 +202,21 @@ class ScanDisplay(DataWatchCallback):
terminal_width = shutil.get_terminal_size()[0]
msg_nonbold = msg.replace('\033[1m','')
msg_nonbold = msg_nonbold.replace('\033[0m','')
self.__nb_str = []
if len(msg_nonbold) >= terminal_width:
lstr = []
#divide the entire string into multiples strings each one fitting terminal width
for part in range(int(len(msg_nonbold)/terminal_width)):
lstr.append(msg_nonbold[terminal_width*part:terminal_width*(part+1)])
lstr.append(msg_nonbold[terminal_width*(part+1):])
for msg in lstr:
self.__nb_str.append(msg_nonbold[terminal_width*part:terminal_width*(part+1)])
self.__nb_str.append(msg_nonbold[terminal_width*(part+1):])
for msg in self.__nb_str:
bold_words = [word for word in msg_nonbold.split(' ') if word in self.__infos.keys()]
for word in bold_words:
msg = msg.replace(word,BOLD(word))
print(msg)
#put cursor back to previous lines allowing to overwriting each printed line
print("\033[F"*(len(lstr)+1))
print("\033[F"*(len(self.__nb_str)+1))
else:
self.__nb_str.append(msg)
print(msg + "\r", end="")
for cam in self.__limas:
......@@ -226,8 +228,10 @@ class ScanDisplay(DataWatchCallback):
diff = last_acq - last_saved
if cam._proxy.saving_mode == 'AUTO_FRAME':
if last_acq == cam._proxy.acq_nb_frames and diff != 0:
for line in range(len(self.__nb_str)):
print("\033[2K\033[1G")
print("\033[F"*(len(self.__nb_str)+1))
while diff != 0:
print("\033[2K\033[1G",end="")
time.sleep(0.5)
if 'pco' in cam.camera_type.lower() and 'dimax' in cam.camera.cam_name.lower():
last_acq = int(cam.camera.last_img_recorded/abs(cam._proxy.acc_nb_frames))
......@@ -239,19 +243,23 @@ class ScanDisplay(DataWatchCallback):
terminal_width = shutil.get_terminal_size()[0]
msg_nonbold = msg.replace('\033[1m','')
msg_nonbold = msg_nonbold.replace('\033[0m','')
self.__nb_str=[]
if len(msg_nonbold) >= terminal_width:
lstr = []
#divide the entire string into multiples strings each one fitting terminal width
for part in range(int(len(msg_nonbold)/terminal_width)):
lstr.append(msg_nonbold[terminal_width*part:terminal_width*(part+1)])
lstr.append(msg_nonbold[terminal_width*(part+1):])
for msg in lstr:
self.__nb_str.append(msg_nonbold[terminal_width*part:terminal_width*(part+1)])
self.__nb_str.append(msg_nonbold[terminal_width*(part+1):])
for msg in self.__nb_str:
msg = msg.replace(cam.name,BOLD(cam.name))
print(msg)
#put cursor back to previous lines allowing to overwriting each printed line
print("\033[F"*(len(lstr)+1))
print("\033[F"*(len(self.__nb_str)+1))
else:
self.__nb_str.append(msg)
print(msg + "\r", end="")
for line in range(len(self.__nb_str)):
print("\033[2K\033[1G")
print("\033[F"*(len(self.__nb_str)+1))
return
......@@ -293,7 +301,7 @@ class ScanWatchdog(WatchdogCallback):
"""
def __init__(self, musst_card, trigger_name=None, limas=list(), trig_difference=2):
self.__trig_difference = trig_difference
self.__watchdog_timeout = 20.0
self.__watchdog_timeout = 10.0
self.__musst = musst_card
self.__limas = limas
self.__trig_name = trigger_name
......
......@@ -79,6 +79,7 @@ class PcoTomoScanDisplay(DataWatchCallback):
self.__prepare_time[lima.name] = 0
self.__musst_acq_dev = scan.acq_chain.nodes_list[1]
self.__end = False
self.__nb_str = []
def on_scan_end(self, info):
"""
......@@ -177,19 +178,18 @@ class PcoTomoScanDisplay(DataWatchCallback):
self.__infos[cam.name] = "{0} (saved {1} diff {2} scan {3})".format(last_rec, last_saved, diff_trigger, scan)
else:
self.__infos[cam.name] = "{0} (saved {1} scan {2})".format(last_rec, last_saved, scan)
total_scan = info['technique']['scan']['nb_tomo']*info['technique']['scan']['nb_loop']
if self.__acq_time != 0 and self.__saving_time != 0 and last_saved % info['technique']['scan']['tomo_n'] == 0 and not self.__end:
#print('\033[2K\033[1G', end="")
msg = f"Acquisition of scan {scan} / {total_scan} took {round(self.__acq_time,2)} s or {round(self.__acq_time/60,2)} min"
print("\n\n" + msg, end="")
msg = f"\nReadout/Saving of scan {scan} / {total_scan} took {round(self.__saving_time,2)} s or {round(self.__saving_time/60,2)} min\n"
print(msg + "\r", end="")
#put cursor back to previous lines allowing to overwriting each printed line
if scan != total_scan:
print("\033[F"*5)
self.__end = True
total_scan = info['technique']['scan']['nb_tomo']*info['technique']['scan']['nb_loop']
if self.__acq_time != 0 and self.__saving_time != 0 and last_saved % info['technique']['scan']['tomo_n'] == 0 and not self.__end:
msg = f"Acquisition of scan {scan} / {total_scan} took {round(self.__acq_time,2)} s or {round(self.__acq_time/60,2)} min"
print("\n\n" + msg, end="")
msg = f"\nReadout/Saving of scan {scan} / {total_scan} took {round(self.__saving_time,2)} s or {round(self.__saving_time/60,2)} min\n"
print(msg + "\r", end="")
#put cursor back to previous lines allowing to overwriting each printed line
if scan != total_scan:
print("\033[F"*(len(self.__nb_str)+3))
self.__end = True
msg = ""
for (name, value) in self.__infos.items():
msg += "{0} {1} ".format(BOLD(name), value)
......@@ -198,20 +198,21 @@ class PcoTomoScanDisplay(DataWatchCallback):
terminal_width = shutil.get_terminal_size()[0]
msg_nonbold = msg.replace('\033[1m','')
msg_nonbold = msg_nonbold.replace('\033[0m','')
self.__nb_str=[]
if len(msg_nonbold) >= terminal_width:
lstr = []
#divide the entire string into multiples strings each one fitting terminal width
for part in range(int(len(msg_nonbold)/terminal_width)):
lstr.append(msg_nonbold[terminal_width*part:terminal_width*(part+1)])
lstr.append(msg_nonbold[terminal_width*(part+1):])
for msg in lstr:
self.__nb_str.append(msg_nonbold[terminal_width*part:terminal_width*(part+1)])
self.__nb_str.append(msg_nonbold[terminal_width*(part+1):])
for msg in self.__nb_str:
bold_words = [word for word in msg_nonbold.split(' ') if word in self.__infos.keys()]
for word in bold_words:
msg = msg.replace(word,BOLD(word))
msg = msg.replace(word,BOLD(word))
print(msg)
#put cursor back to previous lines allowing to overwriting each printed line
print("\033[F"*(len(lstr)+1))
print("\033[F"*(len(self.__nb_str)+1))
else:
self.__nb_str.append(msg)
print(msg + "\r", end="")
for cam in self.__limas:
......@@ -230,6 +231,9 @@ class PcoTomoScanDisplay(DataWatchCallback):
acq_time = (datetime.datetime.fromtimestamp(time.time()) - datetime.datetime.fromtimestamp(self.__start_acq_time)).total_seconds()
if self.__acq_time == 0:
self.__acq_time = acq_time
for line in range(len(self.__nb_str)):
print("\033[2K\033[1G")
print("\033[F"*(len(self.__nb_str)+1))
while last_saved != self.__infos["trig"] and cam.acquisition.status == 'Running':
if info['technique']['scan']['no_saving_between_tomo']:
last_saved = cam._proxy.last_image_saved + 1
......@@ -242,20 +246,23 @@ class PcoTomoScanDisplay(DataWatchCallback):
terminal_width = shutil.get_terminal_size()[0]
msg_nonbold = msg.replace('\033[1m','')
msg_nonbold = msg_nonbold.replace('\033[0m','')
print('\033[2K\033[1G', end="")
self.__nb_str=[]
if len(msg_nonbold) >= terminal_width:
lstr = []
#divide the entire string into multiples strings each one fitting terminal width
for part in range(int(len(msg_nonbold)/terminal_width)):
lstr.append(msg_nonbold[terminal_width*part:terminal_width*(part+1)])
lstr.append(msg_nonbold[terminal_width*(part+1):])
for msg in lstr:
self.__nb_str.append(msg_nonbold[terminal_width*part:terminal_width*(part+1)])
self.__nb_str.append(msg_nonbold[terminal_width*(part+1):])
for msg in self.__nb_str:
msg = msg.replace(cam.name,BOLD(cam.name))
print(msg)
#put cursor back to previous lines allowing to overwriting each printed line
print("\033[F"*(len(lstr)+1))
print("\033[F"*(len(self.__nb_str)+1))
else:
self.__nb_str.append(msg)
print(msg + "\r", end="")
for line in range(len(self.__nb_str)):
print("\033[2K\033[1G")
print("\033[F"*(len(self.__nb_str)+1))
saving_time = (datetime.datetime.fromtimestamp(time.time()) - datetime.datetime.fromtimestamp(self.__start_saving_time)).total_seconds()
if round(saving_time) != 0:
self.__saving_time = saving_time
......@@ -296,10 +303,12 @@ class PcoTomoScanWatchdog(WatchdogCallback):
**watchdog_timeout**
"""
for cam in self.__limas:
#check if lima is saving
if cam.camera.last_img_recorded != cam._proxy.acq_nb_frames:
#check if lima is saving
if cam.camera.last_img_recorded != cam._proxy.acq_nb_frames and cam.last.image_saved == self.__last_saved:
self.__stop_reason = f'No data received since {self.__watchdog_timeout} seconds'
raise Exception
else:
self.__last_saved = cam.last.image_saved
def on_scan_new(self, scan, scan_info):
"""
......@@ -307,6 +316,7 @@ class PcoTomoScanWatchdog(WatchdogCallback):
"""
self.__state = None
self.__trig = 0
self.__last_saved = -1
def on_scan_data(self, data_events, nodes, scan_info):
"""
......@@ -319,7 +329,7 @@ class PcoTomoScanWatchdog(WatchdogCallback):
state = scan_info.get("state", None)
if state != self.__state:
if state == ScanState.STARTING:
self.__watchdog_timeout = 20.0
self.__watchdog_timeout = 10.0
self.__state = state
if self.__state == ScanState.STARTING:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment