-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcalibrate.py
More file actions
93 lines (65 loc) · 2.2 KB
/
calibrate.py
File metadata and controls
93 lines (65 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import sys
import datetime
import logging
import os
import shutil
libPathList = ['./lib/Python', './util']
for libPath in libPathList:
sys.path.insert(0, libPath)
from SetMeUp import SetMeUp
from Calibration import Calibration
from Validation import Validation
from sanityPreCheck import RunPreCheck, RunCalibCheck, RunPreSubmitTest
import accessories as acc
import argparse
# ---- PARSE INPUT ARGS----
parser = argparse.ArgumentParser()
parser.add_argument("--overwrite", action="store_true", help="Overwrite exixting directory")
# ---- PARSE INPUT ARGS----
parser = argparse.ArgumentParser()
parser.add_argument("--overwrite", action="store_true", help="Overwrite exixting directory")
# ----- log -----
suffix = datetime.datetime.now().strftime("%Y-%m-%d_%H%M%S")
logfile = 'testing.log'
file_handler = logging.FileHandler(filename=logfile)
stdout_handler = logging.StreamHandler(sys.stdout)
logging.basicConfig(level=logging.INFO,
format='%(asctime)s %(name)15s %(levelname)-8s %(message)s',
datefmt='%a, %d %b %Y %H:%M:%S',
handlers=[file_handler, stdout_handler]
)
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
# ----- main ------
setupfile = 'setup.yaml'
calibrationfile = 'calib_params.tbl'
# create the setup instance
setup = SetMeUp(setupfile)
# ---- overwrite teh directory if it already exists ----
args = parser.parse_args()
if setup.parent_directory.exists():
if args.overwrite == True:
shutil.rmtree(setup.parent_directory, ignore_errors=True)
else:
logger.error("directory already exists. exiting. use overwrite flag to delete")
sys.exit()
# do checks ...
if not RunPreCheck(setupfile).run_all(): sys.exit()
if not RunCalibCheck(setupfile).run_all(): sys.exit()
# get the current directory
cwd = os.getcwd()
# Calibrate
calib = Calibration(setupfile)
calib.PrepareCalibration()
calib.AdjustCalibTable()
#logger.info(calib.df)
calib()
logger.info(calib.failed_iterations)
# make sure we are in the parent directory...
os.chdir(cwd)
# Validate
#---------
valid = Validation(setupfile)
valid.PrepareValidation()
valid.run_validation()
valid.aggregate_results()