-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
60 lines (47 loc) · 1.86 KB
/
test.py
File metadata and controls
60 lines (47 loc) · 1.86 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
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
# 文件路径,替换为您的文件路径
file_path = './50mv-1231-1-10000th_C01.csv' ## 需要进行计算分析的CSV文件
output_file = './cycle_C_integral_output.csv' ## 保存计算结果为新文件(名称可自定义)
# 读取CSV文件
df = pd.read_csv(file_path)
# 常数设置(咪需要你对应自己实际的实验情况)
A = 0.01 # 面积
v = 0.05 # 扫速
delta_V = 1.0 # 电压窗口
# 计算每个循环次数下的C值
cycle_numbers = df['cycle number'].unique()
C_values = []
integrals = []
cycle_data_list = []
# 设置更高精度的浮点数
np.set_printoptions(precision=10)
for cycle in cycle_numbers:
# 获取当前循环次数下的Ewe/V和<I>/mA数据
cycle_data = df[df['cycle number'] == cycle]
# 计算Ewe/V和<I>/mA的积分,使用辛普森法则(更高精度的数值积分方法)
Ewe_V = cycle_data['Ewe/V'].values
I_mA = cycle_data['<I>/mA'].values
# 数值积分(梯形法则)
area = np.trapz(I_mA, Ewe_V) # 梯形法则
# area = scipy.integrate.simps(I_mA, Ewe_V) # 如果您安装了SciPy,可以使用更精确的辛普森法则
# 计算C值
C = area / (A * v * delta_V) / 2
C_values.append(C)
integrals.append(area)
cycle_data_list.append([cycle, C, area])
# 打印每轮的积分值和对应C值
print(f"Cycle {cycle}: Integral area = {area:.10f}, C = {C:.10f}")
# 将结果保存为CSV文件
cycle_df = pd.DataFrame(cycle_data_list, columns=['Cycle', 'C', 'Integral'])
cycle_df.to_csv(output_file, index=False)
print(f"Results saved to {output_file}")
# 绘制循环次数与C的关系图
plt.figure(figsize=(8, 6))
plt.plot(cycle_numbers, C_values, marker='o', linestyle='-', color='b')
plt.title('Cycle Number vs C')
plt.xlabel('Cycle Number')
plt.ylabel('C')
plt.grid(True)
plt.show()