moved dir creation directly to where files are written into the respective dir, cleaned up parameter names between Scanner and ScanBackend, make_dir is in utils now
This commit is contained in:
@@ -5,6 +5,7 @@ EVERYTHING = "*"
|
||||
DIGITS = "[0-9]"
|
||||
|
||||
|
||||
|
||||
class RunFilenameGenerator:
|
||||
|
||||
def __init__(self, path, prefix="run", n_digits=4, separator="_", extension="json"):
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import os
|
||||
import colorama
|
||||
|
||||
from ..utils import json_dump
|
||||
from ..utils import json_dump, make_dir
|
||||
from ..utils.printing import printable_dict
|
||||
from ..utils.ask_yes_no import ask_Yes_no
|
||||
|
||||
@@ -9,13 +9,13 @@ from ..utils.ask_yes_no import ask_Yes_no
|
||||
|
||||
class ScanBackend:
|
||||
|
||||
def __init__(self, adjustables, values, counters, filename, n_pulses=100, basepath="", scan_info_dir="", make_scan_sub_dir=False, checker=None, checker_sleep_time=0.2):
|
||||
def __init__(self, adjustables, values, counters, filename, n_pulses, data_base_dir, scan_info_dir, make_scan_sub_dir, checker, checker_sleep_time=0.2):
|
||||
self.adjustables = adjustables
|
||||
self.values = values
|
||||
self.counters = counters
|
||||
self.filename = filename
|
||||
self.n_pulses_per_step = n_pulses #TODO: to rename or not to rename?
|
||||
self.basepath = basepath
|
||||
self.data_base_dir = data_base_dir
|
||||
|
||||
self.scan_info = ScanInfo(filename, scan_info_dir, adjustables, values)
|
||||
|
||||
@@ -31,6 +31,8 @@ class ScanBackend:
|
||||
|
||||
do_step = self.do_checked_step if self.checker else self.do_step
|
||||
|
||||
self.create_output_dirs()
|
||||
|
||||
values = self.values
|
||||
ntotal = len(values)
|
||||
for n, val in enumerate(values):
|
||||
@@ -63,8 +65,19 @@ class ScanBackend:
|
||||
self.scan_info.update(step_values, step_readbacks, step_filenames, step_info)
|
||||
|
||||
|
||||
def create_output_dirs(self):
|
||||
make_dir(self.scan_info.path)
|
||||
|
||||
for counter in self.counters:
|
||||
default_path = counter.default_path
|
||||
if default_path is None:
|
||||
continue
|
||||
data_dir = default_path + self.data_base_dir
|
||||
make_dir(data_dir)
|
||||
|
||||
|
||||
def get_filename(self, istep):
|
||||
filename = os.path.join(self.basepath, self.filename)
|
||||
filename = os.path.join(self.data_base_dir, self.filename)
|
||||
|
||||
if self.make_scan_sub_dir:
|
||||
filebase = os.path.basename(self.filename)
|
||||
@@ -125,6 +138,7 @@ def wait_for_all(runners):
|
||||
class ScanInfo:
|
||||
|
||||
def __init__(self, filename_base, path, adjustables, values):
|
||||
self.path = path
|
||||
self.filename = os.path.join(path, filename_base)
|
||||
self.filename += "_scan_info.json"
|
||||
|
||||
|
||||
+3
-34
@@ -1,4 +1,3 @@
|
||||
from pathlib import Path
|
||||
import numpy as np
|
||||
|
||||
from .scanbackend import ScanBackend
|
||||
@@ -6,60 +5,30 @@ from .runname import RunFilenameGenerator
|
||||
from ..devices.general.adjustable import DummyAdjustable
|
||||
|
||||
|
||||
|
||||
def make_dir(p):
|
||||
p = Path(p)
|
||||
if p.exists():
|
||||
return
|
||||
printable = p.absolute().as_posix()
|
||||
print(f"Path \"{printable}\" does not exist, will try to create it...")
|
||||
#TODO:
|
||||
# p.mkdir(parents=True)
|
||||
# p.chmod(0o775)
|
||||
|
||||
|
||||
|
||||
def make_positions(start, end, n):
|
||||
return np.linspace(start, end, n + 1)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class Scanner:
|
||||
|
||||
def __init__(self, data_base_dir="", scan_info_dir="", default_counters=[], checker=None, scan_directories=False):
|
||||
def __init__(self, data_base_dir="", scan_info_dir="", default_counters=[], checker=None, make_scan_sub_dir=True):
|
||||
self.data_base_dir = data_base_dir
|
||||
self.scan_info_dir = scan_info_dir
|
||||
self.default_counters = default_counters
|
||||
self.checker = checker
|
||||
self.scan_directories = scan_directories
|
||||
self.make_scan_sub_dir = make_scan_sub_dir
|
||||
|
||||
make_dir(scan_info_dir)
|
||||
self.filename_generator = RunFilenameGenerator(scan_info_dir)
|
||||
|
||||
for counter in default_counters:
|
||||
default_path = counter.default_path
|
||||
if default_path is None:
|
||||
continue
|
||||
data_dir = default_path + data_base_dir
|
||||
make_dir(data_dir)
|
||||
|
||||
|
||||
def make_scan(self, adjustables, positions, n_pulses, filename, counters=[], start_immediately=True, step_info=None):
|
||||
|
||||
#TODO
|
||||
print(adjustables)#, adjustables.shape, adjustables.dtype)
|
||||
print(list(positions))#, positions.shape, positions.dtype)
|
||||
return
|
||||
#TODO
|
||||
|
||||
filename = self.filename_generator.get_next_run_filename(filename)
|
||||
|
||||
if not counters:
|
||||
counters = self.default_counters
|
||||
|
||||
s = ScanSimple(adjustables, positions, counters, filename, Npulses=n_pulses, basepath=self.data_base_dir, scan_info_dir=self.scan_info_dir, checker=self.checker, scan_directories=self.scan_directories)
|
||||
s = ScanBackend(adjustables, positions, counters, filename, 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, checker=self.checker)
|
||||
|
||||
if start_immediately:
|
||||
s.scan(step_info=step_info)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
from IPython import get_ipython
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from .printing import printable_dict
|
||||
from ..devices.basedevice import BaseDevice
|
||||
|
||||
@@ -11,6 +13,18 @@ def json_dump(what, filename):
|
||||
json.dump(what, f, indent=4, sort_keys=True)
|
||||
|
||||
|
||||
|
||||
def make_dir(p):
|
||||
p = Path(p)
|
||||
if p.exists():
|
||||
return
|
||||
printable = p.absolute().as_posix()
|
||||
print(f"Path \"{printable}\" does not exist, will try to create it...")
|
||||
p.mkdir(parents=True)
|
||||
p.chmod(0o775)
|
||||
|
||||
|
||||
|
||||
def singleton(cls):
|
||||
return cls()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user