part 1 measurements available
This commit is contained in:
parent
f660b77335
commit
c01b53403b
@ -1,46 +1,50 @@
|
||||
import matplotlib.pyplot as plt
|
||||
import random
|
||||
import voltmeter
|
||||
import amperemeter
|
||||
|
||||
from numpy import tanh
|
||||
|
||||
|
||||
# Значения part = 1, 2 соответствуют режимам считывания с первой и второй пары приборов соответственно
|
||||
# (currently not available), режимы 3 и 4 являются тестовыми и генерируют значения самостоятельно
|
||||
def get_point(part, num):
|
||||
# Значения part = 1, 2 соответствуют режимам считывания с первой и второй пары приборов соответственно,
|
||||
# режимы 3 и 4 являются тестовыми и генерируют значения самостоятельно
|
||||
|
||||
def start_measure(part):
|
||||
if part == 1:
|
||||
v1 = open('voltmeter1.txt')
|
||||
i1 = open('ampere-meter1.txt')
|
||||
vol[0].append(float(v1.readline()))
|
||||
cur[0].append(float(i1.readline()))
|
||||
newv1 = v1.read().replace(str(vol[0][-1]) + '\n', '')
|
||||
newi1 = i1.read().replace(str(cur[0][-1]) + '\n', '')
|
||||
v1.close()
|
||||
i1.close()
|
||||
v1 = open('voltmeter1.txt', 'w')
|
||||
v1.write(newv1)
|
||||
i1 = open('ampere-meter1.txt', 'w')
|
||||
i1.write(newi1)
|
||||
v1.close()
|
||||
i1.close()
|
||||
global v1, i1
|
||||
v1 = voltmeter.AKIP('/dev/usbtmc0')
|
||||
i1 = amperemeter.B7_78('/dev/ttyUSB0')
|
||||
i1.getCurrentDC()
|
||||
|
||||
elif part == 2:
|
||||
v2 = open('voltmeter2.txt')
|
||||
i2 = open('ampere-meter2.txt')
|
||||
vol[1].append(float(v2.readline()))
|
||||
cur[1].append(float(i2.readline()))
|
||||
newv2 = v2.read().replace(str(vol[1][-1]) + '\n', '')
|
||||
newi2 = i2.read().replace(str(cur[1][-1]) + '\n', '')
|
||||
v2.close()
|
||||
i2.close()
|
||||
v2 = open('voltmeter2.txt', 'w')
|
||||
v2.write(newv2)
|
||||
i2 = open('ampere-meter2.txt', 'w')
|
||||
i2.write(newi2)
|
||||
v2.close()
|
||||
i2.close()
|
||||
global v2, i2
|
||||
v2 = voltmeter.AKIP('/dev/usbtmc0')
|
||||
i2 = amperemeter.B7_78('/dev/ttyUSB1')
|
||||
i2.getCurrentDC()
|
||||
|
||||
elif part == 0:
|
||||
global i
|
||||
ir = amperemeter.B7_78('/dev/ttyUSB0')
|
||||
i = float(ir.getCurrentDC()) * 10 ** 3
|
||||
i = float(ir.getCurrentDC()) * 10 ** 3
|
||||
|
||||
|
||||
def get_point(part, num):
|
||||
if part == 1:
|
||||
vol[0][num].append(v1.getVoltageDC())
|
||||
cur[0][num].append(i1.getCurrentDC() * 10 ** 3)
|
||||
|
||||
elif part == 2:
|
||||
# global i
|
||||
vol[1][num].append(v2.getVoltageDC())
|
||||
cur[1][num].append(i2.getCurrentDC() * 10 ** 6)
|
||||
# i = amperemeter.B7_78('/dev/ttyUSB0').getCurrentDC() * 10 ** 3
|
||||
# print(vol[1], cur[1])
|
||||
|
||||
elif part == 3:
|
||||
vol[2][num].append(random.random() * 100)
|
||||
cur[2][num].append(random.random() * 100)
|
||||
|
||||
elif part == 4:
|
||||
vol[3][num].append(random.random() * 50 - 25)
|
||||
if experiment % 3 == 0:
|
||||
@ -54,17 +58,16 @@ def get_point(part, num):
|
||||
(22 * tanh(4.4 / 22 * vol[3][num][-1]) + 0.5 * vol[3][num][-1]) * (0.98 + random.random() / 25))
|
||||
|
||||
|
||||
def update_plot(part, num):
|
||||
for i in range(10):
|
||||
get_point(part, num)
|
||||
|
||||
|
||||
def saveplot(part):
|
||||
plt.figure(figsize=(8, 6))
|
||||
for i in range(len(vol[part - 1])):
|
||||
plt.scatter(vol[part - 1][i], cur[part - 1][i], marker='o')
|
||||
for j in range(len(vol[part - 1])):
|
||||
# print(vol[part - 1][j], cur[part - 1][j])
|
||||
plt.scatter(vol[part - 1][j], cur[part - 1][j], marker='o')
|
||||
plt.grid()
|
||||
plt.xlabel('Напряжение, В')
|
||||
if part == 1:
|
||||
plt.ylabel('Ток, мА')
|
||||
else:
|
||||
plt.ylabel('Ток, мкА')
|
||||
plt.savefig('tmpplots/tmpplot' + str(part) + '.jpg', dpi=200)
|
||||
plt.close()
|
||||
@ -74,7 +77,7 @@ def empty_plot(part):
|
||||
vol[part - 1] = [[]]
|
||||
cur[part - 1] = [[]]
|
||||
plt.figure(figsize=(8, 6))
|
||||
plt.scatter(cur[part - 1], vol[part - 1], marker='o')
|
||||
plt.scatter(cur[part - 1][0], vol[part - 1][0], marker='o')
|
||||
plt.grid()
|
||||
plt.savefig('tmpplots/tmpplot' + str(part) + '.jpg', dpi=200)
|
||||
plt.close()
|
||||
@ -94,7 +97,7 @@ def minus_plot(part):
|
||||
vol[part - 1].append([])
|
||||
cur[part - 1].append([])
|
||||
|
||||
|
||||
vol = [[], [], [[]], [[]]]
|
||||
cur = [[], [], [[]], [[]]]
|
||||
i = 0
|
||||
vol = [[[]], [[]], [[]], [[]]]
|
||||
cur = [[[]], [[]], [[]], [[]]]
|
||||
experiment = 0
|
||||
|
@ -72,7 +72,7 @@ class Part1(QtWidgets.QWidget):
|
||||
self.started = False
|
||||
self.q = QtGui.QScreen.availableGeometry(QtWidgets.QApplication.primaryScreen())
|
||||
h = self.q.height() * 0.2
|
||||
plots.empty_plot(3)
|
||||
plots.empty_plot(1)
|
||||
|
||||
self.points = QtWidgets.QLabel(self)
|
||||
self.points.setGeometry(QtCore.QRect(7.5 * h - 60, 3 * h - 80, 140, 20))
|
||||
@ -117,6 +117,7 @@ class Part1(QtWidgets.QWidget):
|
||||
self.back_button.setGeometry(QtCore.QRect(20, self.q.height() - 20, 80, 40))
|
||||
self.back_button.setText("Назад")
|
||||
|
||||
plots.empty_plot(1)
|
||||
self.pixmap0 = QtGui.QPixmap('tmpplots/tmpplot1.jpg')
|
||||
self.pixmap = self.pixmap0.scaledToHeight(3 * h)
|
||||
self.plot1 = QtWidgets.QLabel(self)
|
||||
@ -158,7 +159,7 @@ class Part1(QtWidgets.QWidget):
|
||||
|
||||
timer = QtCore.QTimer(self)
|
||||
timer.timeout.connect(self.upd_plot)
|
||||
timer.start(500)
|
||||
timer.start(3000)
|
||||
|
||||
@QtCore.Slot()
|
||||
def save_plot(self):
|
||||
@ -166,7 +167,7 @@ class Part1(QtWidgets.QWidget):
|
||||
file, check = QtWidgets.QFileDialog.getSaveFileName(None, "Сохранить график 1",
|
||||
r"C:\Users\Vadim\Desktop\plot1.jpg", "Images (*.png *.jpg)")
|
||||
if check:
|
||||
plot1 = PIL.Image.open('tmpplots/tmpplot3.jpg')
|
||||
plot1 = PIL.Image.open('tmpplots/tmpplot1.jpg')
|
||||
plot1.save(file)
|
||||
|
||||
def save_values(self):
|
||||
@ -174,7 +175,7 @@ class Part1(QtWidgets.QWidget):
|
||||
file, check = QtWidgets.QFileDialog.getSaveFileName(None, "Сохранить значения",
|
||||
r"C:\Users\Vadim\Desktop\experiment1.xlsx", "Table (.xlsx)")
|
||||
if check:
|
||||
data = {'U_р, В': plots.vol[2][0], 'I_р, мА': plots.cur[2][0]}
|
||||
data = {'U_р, В': plots.vol[0][0], 'I_р, мА': plots.cur[0][0]}
|
||||
df = pd.DataFrame(data)
|
||||
df.to_excel(file, index=False)
|
||||
|
||||
@ -196,19 +197,20 @@ class Part1(QtWidgets.QWidget):
|
||||
|
||||
def show_plot(self):
|
||||
self.points.setText('Измеренных точек: ' + str(self.n))
|
||||
self.pixmap0 = QtGui.QPixmap('tmpplots/tmpplot3.jpg')
|
||||
self.pixmap0 = QtGui.QPixmap('tmpplots/tmpplot1.jpg')
|
||||
self.pixmap = self.pixmap0.scaledToHeight(0.6 * self.q.height())
|
||||
self.plot1.setPixmap(self.pixmap)
|
||||
|
||||
def upd_plot(self):
|
||||
if self.started:
|
||||
plots.update_plot(3, 0)
|
||||
plots.saveplot(3)
|
||||
self.n += 10
|
||||
plots.get_point(1, 0)
|
||||
plots.saveplot(1)
|
||||
self.n += 1
|
||||
self.show_plot()
|
||||
|
||||
def start_stop(self):
|
||||
if not self.started:
|
||||
plots.start_measure(1)
|
||||
self.start_btn.setText("Стоп")
|
||||
self.started = True
|
||||
self.save_plot_btn.hide()
|
||||
@ -229,7 +231,7 @@ class Part1(QtWidgets.QWidget):
|
||||
self.save_values_btn.hide()
|
||||
self.hint_btn.show()
|
||||
self.n = 0
|
||||
plots.empty_plot(3)
|
||||
plots.empty_plot(1)
|
||||
self.show_plot()
|
||||
|
||||
|
||||
@ -243,7 +245,7 @@ class Part2(QtWidgets.QWidget):
|
||||
self.started = False
|
||||
self.q = QtGui.QScreen.availableGeometry(QtWidgets.QApplication.primaryScreen())
|
||||
h = self.q.height() * 0.2
|
||||
plots.empty_plot(4)
|
||||
plots.empty_plot(2)
|
||||
|
||||
self.button = QtWidgets.QPushButton(self)
|
||||
self.button.setGeometry(QtCore.QRect(20, 20, 40, 40))
|
||||
@ -298,7 +300,7 @@ class Part2(QtWidgets.QWidget):
|
||||
self.hint_btn.setText('?')
|
||||
self.hint_btn.setGeometry(QtCore.QRect(self.q.width() - 60, 20, 40, 40))
|
||||
|
||||
self.pixmap0 = QtGui.QPixmap('tmpplots/tmpplot4.jpg')
|
||||
self.pixmap0 = QtGui.QPixmap('tmpplots/tmpplot2.jpg')
|
||||
self.pixmap = self.pixmap0.scaledToHeight(3 * h)
|
||||
self.plot1 = QtWidgets.QLabel(self)
|
||||
self.plot1.setPixmap(self.pixmap)
|
||||
@ -336,28 +338,24 @@ class Part2(QtWidgets.QWidget):
|
||||
|
||||
timer = QtCore.QTimer(self)
|
||||
timer.timeout.connect(self.upd_plot)
|
||||
timer.start(500)
|
||||
timer.start(3000)
|
||||
|
||||
timer2 = QtCore.QTimer(self)
|
||||
timer2.timeout.connect(self.cur_check)
|
||||
timer2.start(1000)
|
||||
timer2.start(10000)
|
||||
|
||||
@QtCore.Slot()
|
||||
def cur_check(self):
|
||||
if plots.experiment % 3 == 0:
|
||||
self.i = 5
|
||||
elif plots.experiment % 3 == 1:
|
||||
self.i = 3
|
||||
else:
|
||||
self.i = 1.5
|
||||
self.current.setText('Текущий ток разряда: ' + str(self.i) + 'мА')
|
||||
plots.start_measure(0)
|
||||
# plots.get_point(2, self.num)
|
||||
self.current.setText('Текущий ток разряда: ' + str(plots.i) + 'мА')
|
||||
|
||||
def save_plot(self):
|
||||
# при замене устройства директорию надо изменить
|
||||
file, check = QtWidgets.QFileDialog.getSaveFileName(None, "Сохранить график 2",
|
||||
r"C:\Users\Vadim\Desktop\plot2.jpg", "Images (*.png *.jpg)")
|
||||
if check:
|
||||
plot1 = PIL.Image.open('tmpplots/tmpplot4.jpg')
|
||||
plot1 = PIL.Image.open('tmpplots/tmpplot2.jpg')
|
||||
plot1.save(file)
|
||||
|
||||
def save_values(self):
|
||||
@ -365,21 +363,21 @@ class Part2(QtWidgets.QWidget):
|
||||
file, check = QtWidgets.QFileDialog.getSaveFileName(None, "Сохранить значения",
|
||||
r"C:\Users\Vadim\Desktop\experiment2.xlsx", "Table (.xlsx)")
|
||||
if check:
|
||||
data = {'U_1, В': plots.vol[3][0], 'I_1, мкА': plots.cur[3][0]}
|
||||
data = {'U_1, В': plots.vol[1][0], 'I_1, мкА': plots.cur[1][0]}
|
||||
I_0, k_0, A = [], [], []
|
||||
params = fitting.fit(plots.vol[3][0], plots.cur[3][0])
|
||||
params = fitting.fit(plots.vol[1][0], plots.cur[1][0])
|
||||
I_0.append(params[0])
|
||||
k_0.append(params[1])
|
||||
A.append(params[2])
|
||||
for i in range(len(plots.vol[3]) - 1):
|
||||
mes = {'U_' + str(i+2) + ', В': plots.vol[3][i + 1], 'I_' + str(i + 2) + ', мкА': plots.cur[3][i + 1]}
|
||||
for i in range(len(plots.vol[1]) - 1):
|
||||
mes = {'U_' + str(i+2) + ', В': plots.vol[1][i + 1], 'I_' + str(i + 2) + ', мкА': plots.cur[1][i + 1]}
|
||||
data.update(mes)
|
||||
params = fitting.fit(plots.vol[3][i + 1], plots.cur[3][i + 1])
|
||||
params = fitting.fit(plots.vol[1][i + 1], plots.cur[1][i + 1])
|
||||
I_0.append(params[0])
|
||||
k_0.append(params[1])
|
||||
A.append(params[2])
|
||||
|
||||
data.update({'I_0, мкА': I_0, 'k_0, мкА/В': k_0, 'A, мкА/В': A})
|
||||
data.update({'I_0, мкА': I_0, 'T_e, K': k_0, 'A, мкА/В': A})
|
||||
|
||||
df = pd.DataFrame(dict([(k, pd.Series(v)) for k, v in data.items()]))
|
||||
df.to_excel(file, index=False)
|
||||
@ -402,26 +400,27 @@ class Part2(QtWidgets.QWidget):
|
||||
|
||||
def show_plot(self):
|
||||
self.points.setText('Измеренных точек в текущей серии: ' + str(self.n))
|
||||
self.pixmap0 = QtGui.QPixmap('tmpplots/tmpplot4.jpg')
|
||||
self.pixmap0 = QtGui.QPixmap('tmpplots/tmpplot2.jpg')
|
||||
self.pixmap = self.pixmap0.scaledToHeight(0.6 * self.q.height())
|
||||
self.plot1.setPixmap(self.pixmap)
|
||||
|
||||
def upd_plot(self):
|
||||
if self.started:
|
||||
plots.update_plot(4, self.num - 1)
|
||||
plots.saveplot(4)
|
||||
self.n += 10
|
||||
plots.get_point(2, self.num - 1)
|
||||
plots.saveplot(2)
|
||||
self.n += 1
|
||||
self.show_plot()
|
||||
|
||||
def start_stop(self):
|
||||
if not self.started:
|
||||
plots.start_measure(2)
|
||||
self.start_btn.setText("Стоп")
|
||||
self.started = True
|
||||
self.save_plot_btn.hide()
|
||||
self.save_values_btn.hide()
|
||||
self.hint_btn.hide()
|
||||
if self.num != 0:
|
||||
plots.plus_plot(4)
|
||||
plots.plus_plot(2)
|
||||
self.num += 1
|
||||
self.n = 0
|
||||
|
||||
@ -440,8 +439,8 @@ class Part2(QtWidgets.QWidget):
|
||||
self.save_values_btn.hide()
|
||||
self.hint_btn.show()
|
||||
self.n = 0
|
||||
plots.minus_plot(4)
|
||||
plots.saveplot(4)
|
||||
plots.minus_plot(2)
|
||||
plots.saveplot(2)
|
||||
self.show_plot()
|
||||
self.num -= 1
|
||||
if self.num == 0:
|
||||
|
Loading…
Reference in New Issue
Block a user