PQ3000导出格式:CSV(时间戳+各通道电压/电流/功率/谐波)、COMTRADE(录波文件)、PQAnalyzer原生格式。
环境搭建:pip install pandas numpy matplotlib scipy
数据读取:
```python
import pandas as pd
import numpy as np
from scipy import fft
df = pd.read_csv('pq3000_data.csv', parse_dates=['Time'])
df = df.fillna(method='ffill')
df.set_index('Time', inplace=True)
```
谐波分析:
```python
u_a = df['U_A'].values
N = len(u_a)
T = 1.0 / 51200
yf = fft.fft(u_a)
xf = np.fft.fftfreq(N, T)[:N//2]
harmonics = {}
for i in range(1, 51):
idx = np.argmin(np.abs(xf - i * 50))
harmonics[i] = 2.0/N * np.abs(yf[idx])
fundamental = harmonics[1]
h_sum = np.sqrt(sum([h**2 for h in harmonics.values() if h != fundamental]))
thd = h_sum / fundamental * 100
print(f"THD = {thd:.2f}%")
```
电压暂降检测:
```python
u_rms = df['U_A_RMS']
threshold = 0.9 * u_rms.mean()
dips = u_rms < threshold
from scipy import ndimage
labeled, num_features = ndimage.label(dips)
print(f"共检测到 {num_features} 次电压暂降")
```
PQ3000的开放数据格式+Python生态,让电能质量分析从"封闭"到"开放"。