added repeat feature to Scanner

This commit is contained in:
2021-03-04 19:45:43 +01:00
parent 719331bec0
commit 59b57f4cdc
2 changed files with 27 additions and 5 deletions
+24 -3
View File
@@ -10,7 +10,7 @@ from .scaninfo import ScanInfo
class ScanBackend:
def __init__(self, adjustables, values, acquisitions, filename, detectors, channels, pvs, n_pulses, data_base_dir, scan_info_dir, make_scan_sub_dir, condition, return_to_initial_values):
def __init__(self, adjustables, values, acquisitions, filename, detectors, channels, pvs, n_pulses, data_base_dir, scan_info_dir, make_scan_sub_dir, condition, return_to_initial_values, repeat):
self.adjustables = adjustables
self.values = values
self.acquisitions = acquisitions
@@ -32,6 +32,8 @@ class ScanBackend:
check_trinary(return_to_initial_values)
self.return_to_initial_values = return_to_initial_values
self.repeat = repeat
self.store_initial_values()
self.running = False
@@ -42,8 +44,12 @@ class ScanBackend:
self.store_initial_values()
self.create_output_dirs()
#TODO which test? None for infinite? 0?
scan_loop = self.repeated_scan_loop if self.repeat > 1 else self.scan_loop
try:
self.scan_loop(step_info=step_info)
self.running = True #TODO: need to set this True here now
scan_loop(step_info=step_info)
except KeyboardInterrupt:
print() # print new line after ^C
self.stop()
@@ -63,12 +69,27 @@ class ScanBackend:
self.change_to_initial_values()
def repeated_scan_loop(self, step_info=None):
base_fname = self.filename
nreps = self.repeat
for i in range(nreps):
if not self.running:
break
print("Repetition {} of {}".format(i+1, nreps))
self.filename = f"{base_fname}_{i+1:03}" #TODO: this needs work!
print("File:", self.filename)
self.scan_loop(step_info=step_info)
self.filename = base_fname
def scan_loop(self, step_info=None):
do_step = self.do_checked_step if self.condition else self.do_step
values = self.values
ntotal = len(values)
self.running = True
# self.running = True #TODO: with repeat, this cannot be set here anymore
for n, val in enumerate(values):
if not self.running:
break
+3 -2
View File
@@ -38,7 +38,7 @@ class Scanner:
#TODO: detectors and pvs only for sf_daq
def make_scan(self, adjustables, positions, n_pulses, filename, detectors=None, channels=None, pvs=None, acquisitions=(), start_immediately=True, step_info=None, return_to_initial_values=None):
def make_scan(self, adjustables, positions, n_pulses, filename, detectors=None, channels=None, pvs=None, acquisitions=(), start_immediately=True, step_info=None, return_to_initial_values=None, repeat=1):
"""N-dimensional scan
Parameters:
@@ -50,6 +50,7 @@ class Scanner:
start_immediately (bool, optional): If True (default), start the scan immediately. If False, the returned scan can be started via its run method.
step_info: Arbitrary data that is appended to the ScanInfo in each step.
return_to_initial_values: (bool or None, optional): Return to initial values after scan. If None (default) ask for user input.
repeat: (int): Number of times the scan is repeated. If 1 (default), the filename will be used verbatim. If >1, a three-digit counter will be appended.
Returns:
ScanBackend: Scan instance.
@@ -61,7 +62,7 @@ class Scanner:
acquisitions = self.default_acquisitions
#TODO: detectors and pvs only for sf_daq
scan = ScanBackend(adjustables, positions, acquisitions, filename, detectors, channels, pvs, n_pulses=n_pulses, data_base_dir=self.data_base_dir, scan_info_dir=self.scan_info_dir, make_scan_sub_dir=self.make_scan_sub_dir, condition=self.condition, return_to_initial_values=return_to_initial_values)
scan = ScanBackend(adjustables, positions, acquisitions, filename, detectors, channels, pvs, n_pulses=n_pulses, data_base_dir=self.data_base_dir, scan_info_dir=self.scan_info_dir, make_scan_sub_dir=self.make_scan_sub_dir, condition=self.condition, return_to_initial_values=return_to_initial_values, repeat=repeat)
if start_immediately:
scan.run(step_info=step_info)