-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFemtoScan.py
130 lines (103 loc) · 4.07 KB
/
FemtoScan.py
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# -*- coding: utf-8 -*-
"""
@author: Steinn Ymir Agustsson
Copyright (C) 2018 Steinn Ymir Agustsson, Vladimir Grigorev
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import sys, os
import time
import logging
from logging.config import fileConfig
from PyQt5 import QtWidgets, QtCore
import numpy as np
from utilities.settings import parse_setting
if not os.path.isfile('SETTINGS.ini'):
from utilities.settings import make_settings, parse_setting
make_settings()
_MODE = parse_setting('launcher', 'mode')
""" 'cmd' to run command line execution, 'gui' to start the graphical interface"""
_RECOMPILE = parse_setting('launcher', 'recompile')
_MODE = 'gui'
def launch_cmd():
from measurement.experiment import StepScan
from instruments.lockinamplifier import SR830, LockInAmplifier
from instruments.delaystage import DelayStage, NewportXPS
from instruments.cryostat import Cryostat
time.sleep(2)
exp = StepScan()
logger.info('Created Stepscan Instance')
lockin = exp.add_instrument('lockin', LockInAmplifier())
stage = exp.add_instrument('delay_stage', DelayStage())
cryo = exp.add_instrument('cryo', Cryostat())
exp.print_setup()
time.sleep(1)
exp.add_parameter_iteration('temperature','K',cryo, 'change_temperature', [10,20])
# exp.set_name = 'somename'
exp.averages = 2
exp.stage_positions = np.linspace(-1,10,30)
exp.time_zero = 5.23
# lockin.time_constant.set(.01)
exp.create_file()
exp.start_measurement()
exp.disconnect_all()
def launch_gui():
from gui.mainwindow import MainWindow
from utilities.qt import my_exception_hook, recompile
# used to see errors generated by PyQt5 in pycharm:
sys._excepthook = sys.excepthook
# Set the exception hook to our wrapping function
sys.excepthook = my_exception_hook
if _RECOMPILE:
recompile('the/right/folder/whit/ui_stuff.ui')
app = QtCore.QCoreApplication.instance()
if app is None:
app = QtWidgets.QApplication(sys.argv)
# Create handle prg for the Graphic Interface
prg = MainWindow()
print('showing GUI')
prg.show()
if __name__ == '__main__':
# create logger with 'spam_application'
# print(os.path.isfile('./utilities/logging_config.ini'))
fileConfig('./cfg/logging_config.ini')
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
# logger.propagate = True
logger.debug('Started logger')
# create file handler which logs even debug messages
# fh = logging.FileHandler('./cfg/event_log.log')
# fh.setLevel(logging.DEBUG)
# # create console handler with a higher log level
# ch = logging.StreamHandler()
# ch.setLevel(logging.WARNING)
# # create formatter and add it to the handlers
# file_formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# stream_formatter = logging.Formatter('%(levelname)-8s - %(name)-50s - %(message)s')
# # fh.setFormatter(file_formatter)
# # ch.setFormatter(stream_formatter)
# # add the handlers to the logger
# logging.getLogger('').addHandler(fh)
# logging.getLogger('').addHandler(ch)
logger.critical('started logger')
app = QtCore.QCoreApplication.instance()
if app is None:
app = QtWidgets.QApplication(sys.argv)
if _MODE == 'cmd':
launch_cmd()
elif _MODE == 'gui':
launch_gui()
else:
print('unrecognized mode {}'.format(_MODE))
try:
app.exec_()
except:
print('app.exec_() failed: exiting')