-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrestart.py
More file actions
77 lines (61 loc) · 2.51 KB
/
restart.py
File metadata and controls
77 lines (61 loc) · 2.51 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
import shutil
import os
import time
import sys
import datetime
import logging
import yaml
import pandas as pd
from pathlib import Path
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
suffix = datetime.datetime.now().strftime("%Y-%m-%d_%H%M%S")
logfile = 'runoneyear_{}.log'.format(suffix)
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)
# this is pretty neat --- we can provide a relative path as argument adn get the full path
directory = Path(sys.argv[1]).resolve()
setupfile = directory.joinpath('setup.yaml')
# create the setup instance
setup = SetMeUp(setupfile)
# ----- main ------
calibrationfile = 'calib_params.tbl'
# start the logging with some handy info
logger.info('starting {}. using {} setup parameters and {}' .format(__name__, setupfile, calibrationfile))
logger.info('Logging to file: {}/{}'.format(os.getcwd(), logfile))
# ---- run 'sanity checks' -----
#if not RunPreCheck(setupfile).run_all(): sys.exit()
#if not RunCalibCheck(setupfile).run_all(): sys.exit()
# create the setup instance
setup = SetMeUp(setupfile)
calib = Calibration(setupfile)
calib.AdjustCalibTable()
param_cmd = "SELECT * FROM PARAMETERS"
param = pd.read_sql(sql = param_cmd, con="sqlite:///{}/Calibration.db".format(setup.clbdirc))
lastState = param.loc[param.iteration == param.iteration.iloc[-1]]
lastState.set_index('parameter', inplace=True)
calib.df.update(lastState)
calib.df.nextValue = calib.df.currentValue
# update the iteration
calib.iteration = int(lastState.iteration.iloc[0])+1
# now run the calibration
calib()
## clean up
logger.info('----- Calibration Complete -----')
logger.info('moving logfile {} to directory {}'.format(logfile, clbdirc))
shutil.move(logfile, setup.clbdirc+'/'+logfile) # move the log file to the directory
# make some plots or something ....
#