diff options
-rw-r--r-- | eitControl.py | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/eitControl.py b/eitControl.py index 2a033e0..a409724 100644 --- a/eitControl.py +++ b/eitControl.py @@ -4,12 +4,13 @@ from pyqtgraph.dockarea import * from pyqtgraph.exporters import ImageExporter import platform +import os import argparse from threading import Thread import time # For sleep, clock, time and perf_counter -from datetime import datetime, timedelta +from datetime import datetime, timedelta, date import numpy as np import csv @@ -22,6 +23,16 @@ class Experiment: def __init__(self, root, args): self.root = root + if args.save_prefix: + self.save_prefix = args.save_prefix + else: + self.save_prefix = "set_the_prefix" + if args.data_dir: + self.data_dir = args.data_dir + else: + self.data_dir = "set_the_data_dir" + + self.save_cnt = 0 self.tic = 0 self.channelsNames2grab={'tic', 'x','rfFreq','dac0', 'dac1', 'adc0', 'adc1', 'adc2', 'adc3'} alpha=100 @@ -113,8 +124,30 @@ class Experiment: self.clearData() self.sweeper.cmdRestart() + def getNewDataFileName(self, ext="csv"): + data_dir = self.data_dir + if not os.path.exists(data_dir): + os.mkdir(data_dir) + if not os.path.isdir(data_dir): + print(f"ERROR: cannot create directory for data: {data_dir}") + print(f"Will use current dir for storage") + data_dir = "." + + prefix = self.save_prefix + today = date.today() + datestr = today.strftime("%Y%m%d") + self.save_cnt += 1 + + base_name = f"{prefix}_{datestr}_{self.save_cnt:#04}" + file_name = f"{base_name}.{ext}" + data_file = os.path.join(data_dir, file_name) + if os.path.exists(data_file): + data_file = self.getNewDataFileName(ext=ext) + return data_file + def saveCmd(self): - csv_file = 'data.csv' + csv_file = self.getNewDataFileName(ext='csv') + print(f"Saving to {csv_file}") data = self.data try: with open(csv_file, 'w') as csvfile: @@ -243,6 +276,9 @@ if __name__ == '__main__': mw.show() + args.save_prefix="eit" + args.data_dir="VAMPIRE.Data" + experiment=Experiment(l, args) app.exec() |