欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

2020-12-08 Python 导入实验数据,一键求解电化学活性表面积,ECSA

程序员文章站 2022-04-02 11:02:39
# !/usr/bin/env python# -*- coding: utf-8 -*-# Author:# Date:2020.10.13 23:31# Description: open a txt including unrelvant characters(titles) and exiperiment raw data(f(x) two-column data likeimport tkinter as tkfrom tkinter.filedialog import as....
# !/usr/bin/env python
#  -*- coding: utf-8 -*-
# Author: Liye Zhu
# Date:2020.12.09   18:11
# Description: the input text is exported from chi760e with a select circle of CV, 6th circle, etc. Open the experiment
# raw data with chi760e,select 【File】->【Text file format】-> select starting and ending segments, and the export the
# data.

import tkinter as tk
from tkinter.filedialog import askopenfilename
from itertools import islice
import sys
import fileinput
import matplotlib.pylab as pylab
import matplotlib.pyplot as plt
import numpy as np
data_file_name= askopenfilename(title='Select a data', filetypes=[('TXT', '*.txt')],
                                initialdir='D:\\')
data_file_path=data_file_name[0:data_file_name.rfind('/', 1) + 1];
new_dat= data_file_path + '/data.dat'
data = []
#打开txt,读取数据
with open(data_file_name) as txtfile:
    line = txtfile.readlines()
    for i, rows in enumerate(line):
        if i in range(28, len(line) - 1):  # 指定数据行:28行--到最后一行
            data.append(rows)
print("length", len(data))
txtfile.close()
E = np.zeros(len(data))
I = np.zeros(len(data))
E1 = np.zeros(len(data))
I1 = np.zeros(len(data))
E2 = np.zeros(len(data))
I2 = np.zeros(len(data))
j = 0
#打开dat,导出数据,可用于Origin作图
with open(new_dat, "w", ) as f:
    for i in range((len(data))):
        f.writelines(data[i])
        [variable1, variable2] = data[i].split(',', 1)
        E[i] = float(variable1)
        I[i] = float(variable2)
f.close()
# Reference   http://www.360doc.com/content/19/0828/10/47812380_857519286.shtml
# Say thanks to the author of the docment.
# Calculate ECSA
# fig.suptitle('Hupd')  # 添加标题以便我们辨别
# 在0.2- 0.4V vs SCE 之间寻找电双层,经验值
for i in range((len(data))):
    if (E[i] < 0.4) & (E[i] > 0.2) & (I[i] > 0):
        E2[j] = E[i]
        I2[j] = I[i]
        j = j + 1
i0 = max(I2);
#以电双层中最大电流值作为氢区电流背景扣除。
#选出氢区数据范围,经验值: 电势小于0.4, 电流大于0,也就是左上角区域。
for i in range((len(data))):
    if (E[i] < 0.4) & (I[i] > 0):
        E1[j] = E[i]
        I1[j] = I[i]
        j = j + 1
#扣除电双层电流,得到Hupd净电流
I10 = I1 - i0;  # 原始单位未变换,为 安培/A
#因测量误差等,扣除氢区最大电流值后,可能出现负值(非常接近0), 于是将所有负值归0.
for i in range((len(data))):
    if (I10[i] < 0):
        I10[i] = 0
# 消除坏点
I10[0] = 0;  # 消除初始坏点
QI0 = sum(I10) * 1 / 50;
# 求峰面积,Q = ΣI(t)dt, 数据间隔1mV,即dE=1mV,扫速为50mv/s,则 dt=1/50=0.02s,Q单位为库伦,
#I(t)为chi760e原始数据,单位一般是A。
QI0 = QI0 * 1000;  # 单位转化为 毫库伦/mC
area = QI0 / 0.21;  # 单位为 cm2
str = "surface of Hupd is %f" % (area)
print(str)
fig1 = plt.figure(figsize=(16, 10))  # 定义一个图像窗口
plt.plot(E1, I10, '.')  # 绘制曲线 y1
import matplotlib.pyplot as plt
plt.grid(True)
plt.xlabel('E vs SCE')
plt.ylabel('Current/A')
plt.title("surface of Hupd is %f cm2" % (area))
plt.show()
plt.xlim(-0.3, 0.4)
plt.title(str)
# plt.ylim(520, -20)



本文地址:https://blog.csdn.net/you_us/article/details/110880876