import os
import pandas as pd
import numpy as np
path ='.\\谐波\\' #文件夹路径
def FirstPart(i, j): # 1次分量平均值
Pn = float(i[:-1]) * 1000 # 从文件夹名字提取额定功率
In = Pn / 3 / 220 # 三相四线 电压220
data = pd.read_csv(path + i + '.\\' + j, header=100)
store = pd.DataFrame(data, columns=['I-E1(1)[A]', 'I-E2(1)[A]', 'I-E3(1)[A]'])
store2 = store.mean()
print(j)
print(store2.round(3))
def THD(i, j): # 总谐波畸变率最大值
Pn = float(i[:-1]) * 1000 # 从文件夹名字提取额定功率
In = Pn / 3 / 220
data = pd.read_csv(path + i + '.\\' + j, header=100)
store = pd.DataFrame(data, columns=['Ithd-E1[%]', 'Ithd-E2[%]', 'Ithd-E3[%]'])
store2 = store.max()
print(j)
print(store2)
def Idc(i, j): # 直流分量 绝对值,最大值
Pn = float(i[:-1]) * 1000 # 从文件夹名字提取额定功率
In = Pn / 3 / 220
data = pd.read_csv(path + i + '.\\' + j, header=100)
store = pd.DataFrame(data, columns=['Idc-E1[A]', 'Idc-E2[A]', 'Idc-E3[A]'])
store2 = store.abs().max()
print(j)
print(store2.round(3))
def Cosphi(i, j): # 功率因数 平均值
Pn = float(i[:-1]) * 1000 # 从文件夹名字提取额定功率
In = Pn / 3 / 220
data = pd.read_csv(path + i + '.\\' + j, header=100)
store = pd.DataFrame(data, columns=['PF-E1', 'PF-E2', 'PF-E3'])
store2 = store.mean()
print(j)
print(store2.round(4))
def harmonic(i, j):
Pn = float(i[:-1]) * 1000
In = Pn / 3 / 220
data = pd.read_csv(path + i + '.\\' + j, header=100)
limit = [1.00, 4.00, 1.00, 4.00, 1.00, 4.00, 1.00, 4.00, 1.00, 2.00, 0.50, 2.00, 0.50, 2.00, 0.50, 1.50, 0.38,
1.50, 0.38, 1.50, 0.38, 0.60, 0.15, 0.60, 0.15, 0.60, 0.15, 0.60, 0.15, 0.60, 0.15, 0.60, 0.15, 0.30,
0.08, 0.30, 0.08, 0.30, 0.08]
name1 = ['I-E1(2)[A]', 'I-E1(3)[A]', 'I-E1(4)[A]', 'I-E1(5)[A]', 'I-E1(6)[A]', 'I-E1(7)[A]', 'I-E1(8)[A]',
'I-E1(9)[A]', 'I-E1(10)[A]', 'I-E1(11)[A]', 'I-E1(12)[A]', 'I-E1(13)[A]', 'I-E1(14)[A]', 'I-E1(15)[A]',
'I-E1(16)[A]', 'I-E1(17)[A]', 'I-E1(18)[A]', 'I-E1(19)[A]', 'I-E1(20)[A]', 'I-E1(21)[A]',
'I-E1(22)[A]', 'I-E1(23)[A]', 'I-E1(24)[A]', 'I-E1(25)[A]', 'I-E1(26)[A]', 'I-E1(27)[A]',
'I-E1(28)[A]', 'I-E1(29)[A]', 'I-E1(30)[A]', 'I-E1(31)[A]', 'I-E1(32)[A]', 'I-E1(33)[A]',
'I-E1(34)[A]', 'I-E1(35)[A]', 'I-E1(36)[A]', 'I-E1(37)[A]', 'I-E1(38)[A]', 'I-E1(39)[A]',
'I-E1(40)[A]']
name2 = ['I-E2(2)[A]', 'I-E2(3)[A]', 'I-E2(4)[A]', 'I-E2(5)[A]', 'I-E2(6)[A]', 'I-E2(7)[A]', 'I-E2(8)[A]',
'I-E2(9)[A]', 'I-E2(10)[A]', 'I-E2(11)[A]', 'I-E2(12)[A]', 'I-E2(13)[A]', 'I-E2(14)[A]', 'I-E2(15)[A]',
'I-E2(16)[A]', 'I-E2(17)[A]', 'I-E2(18)[A]', 'I-E2(19)[A]', 'I-E2(20)[A]', 'I-E2(21)[A]',
'I-E2(22)[A]', 'I-E2(23)[A]', 'I-E2(24)[A]', 'I-E2(25)[A]', 'I-E2(26)[A]', 'I-E2(27)[A]',
'I-E2(28)[A]', 'I-E2(29)[A]', 'I-E2(30)[A]', 'I-E2(31)[A]', 'I-E2(32)[A]', 'I-E2(33)[A]',
'I-E2(34)[A]', 'I-E2(35)[A]', 'I-E2(36)[A]', 'I-E2(37)[A]', 'I-E2(38)[A]', 'I-E2(39)[A]',
'I-E2(40)[A]']
name3 = ['I-E3(2)[A]', 'I-E3(3)[A]', 'I-E3(4)[A]', 'I-E3(5)[A]', 'I-E3(6)[A]', 'I-E3(7)[A]', 'I-E3(8)[A]',
'I-E3(9)[A]', 'I-E3(10)[A]', 'I-E3(11)[A]', 'I-E3(12)[A]', 'I-E3(13)[A]', 'I-E3(14)[A]', 'I-E3(15)[A]',
'I-E3(16)[A]', 'I-E3(17)[A]', 'I-E3(18)[A]', 'I-E3(19)[A]', 'I-E3(20)[A]', 'I-E3(21)[A]',
'I-E3(22)[A]', 'I-E3(23)[A]', 'I-E3(24)[A]', 'I-E3(25)[A]', 'I-E3(26)[A]', 'I-E3(27)[A]',
'I-E3(28)[A]', 'I-E3(29)[A]', 'I-E3(30)[A]', 'I-E3(31)[A]', 'I-E3(32)[A]', 'I-E3(33)[A]',
'I-E3(34)[A]', 'I-E3(35)[A]', 'I-E3(36)[A]', 'I-E3(37)[A]', 'I-E3(38)[A]', 'I-E3(39)[A]',
'I-E3(40)[A]']
store1 = pd.DataFrame(data, columns=name1).mean() # 求平均值
store2 = pd.DataFrame(data, columns=name2).mean()
store3 = pd.DataFrame(data, columns=name3).mean()
num1 = np.array(store1) # Phase A 为了凑三列数据
num2 = np.array(store2) # Phase B
num3 = np.array(store3) # Phase C
num4 = num1 / In * 100 # Phase A/norminal current*100
num5 = num2 / In * 100
num6 = num3 / In * 100
num = np.array([num1, num4, num2, num5, num3, num6]) # connect A B C
num = num.T # 转置
store = pd.DataFrame(num, columns=['L1', 'L11', 'L2', 'L22', 'L3', 'L33'], index=range(2, 41)) # 谐波电流从2开始计算
pd.set_option('max_row', 1000) # 打印1000列
print(j)
print(store)
# store.to_csv(j[:-4] + '.xlsx')
###########################################################################################################################################
a = os.listdir(path) # 不同电压的机型--a,i
for i in a[:-1]: # 去除掉python运行生成的文件
b = os.listdir(path + i) # 文件名称
for j in b:
harmonic(i,j)
print("complete")
谐波数据处理
于 2022-04-14 23:58:58 首次发布