python提取各个扇区不同机位点风速风向表

Reading time: 4 minutes and 17 seconds with 945 words. 本文总阅读量

背景介绍

我们依然来处理windsim导出的风廓线信息(Tools->Export vertical profile)在前面perl拆分大文件一文中我们得到各个机位点在不同扇区下的物理量信息,并存放在一个excel表里头

而其实我们更关心的是轮毂高度处的风速风向信息,即形成下面的轮毂高度处不同扇区和机位点的风速风向

windSpeedAngle

每个风场均需要修改对应风机信息!

技术分解

  1. 遍历
  2. 建立一个扇区表和特征物理量【标识信息即可】, 该特征物理量为velocity表示提取偶数行,物理量为Angle表示提取奇数行
  3. 对特定的物理量进行atan2计算,atan2(vx,vy)得到[-pi,+pi]范围值,加上180°就变成了[0,2pi]
  4. 导出数据

技术实现

  1. 建立扇区表, 即excel表列信息
columnMe=['0','22','45','67','90','112','135','157','180','202','225','247','270','292','315','337'];
  1. 建立机位风速、风向信息,即excel表行信息

        indexMe=["T12_Velocity", "T12_Angle", "T11_Velocity", "T11_Angle", "T10_Velocity", "T10_Angle", "T1_Velocity", "T1_Angle",
         "T3_Velocity", "T3_Angle", "T2_Velocity", "T2_Angle", "T4_Velocity", "T4_Angle", "T5_Velocity", "T5_Angle",
         "T9_Velocity", "T9_Angle", "T8_Velocity", "T8_Angle", "T7_Velocity", "T7_Angle", "T6_Velocity", "T6_Angle",
         "T13_Velocity", "T13_Angle", "T14_Velocity", "T14_Angle", "T15_Velocity", "T15_Angle", "T16_Velocity", "T16_Angle",
         "T17_Velocity", "T17_Angle", "T23_Velocity", "T23_Angle", "T22_Velocity", "T22_Angle", "T21_Velocity", "T21_Angle",
         "T20_Velocity", "T20_Angle", "T19_Velocity", "T19_Angle", "T18_Velocity", "T18_Angle", "HL387_24035001_Velocity",
         "HL387_24035001_Angle"]
        

如果换了个风电场该信息得重新编排,按照实际风电场需求

  1. 使用pandas创建数组、存储文件

根据扇区和机位信息建立pandas空数组

results=pd.DataFrame([],index=indexMe,columns=columnMe)

并通过iloc进行精确定位,同时赋值

results.iloc[turbineVId,sectorId]=speed2d
results.iloc[turbineAId,sectorId]=actualAngle

最终的全部实现如下:

import numpy as np
import pandas as pd
import os
import re
import math as ma


#headDir=r"C:\Users\yezhaoliang\Desktop\work\AIWind\processWindSim\HuaiLaiTurbine"

headDir=r"C:\Users\yezhaoliang\Desktop\work\AIWind\processWindSim\HuaiLaiTurbineZhuFengxiang"

## 遍历所有csv文件

def get_files(path=headDir, rule=".csv"):
    all = []
    for fpathe,dirs,fs in os.walk(path):   # os.walk是获取所有的目录

        for f in fs:
            filename = os.path.join(fpathe,f)
            if filename.endswith(rule):  # 判断是否是"xxx"结尾

                all.append(filename)
    return all

if __name__ == "__main__":
## 定义计算的扇区表

    columnMe=['0','22','45','67','90','112','135','157','180','202','225','247','270','292','315','337'];
## 定义风向风速表的行信息

    indexMe=["T12_Velocity", "T12_Angle", "T11_Velocity", "T11_Angle", "T10_Velocity", "T10_Angle", "T1_Velocity", "T1_Angle",
     "T3_Velocity", "T3_Angle", "T2_Velocity", "T2_Angle", "T4_Velocity", "T4_Angle", "T5_Velocity", "T5_Angle",
     "T9_Velocity", "T9_Angle", "T8_Velocity", "T8_Angle", "T7_Velocity", "T7_Angle", "T6_Velocity", "T6_Angle",
     "T13_Velocity", "T13_Angle", "T14_Velocity", "T14_Angle", "T15_Velocity", "T15_Angle", "T16_Velocity", "T16_Angle",
     "T17_Velocity", "T17_Angle", "T23_Velocity", "T23_Angle", "T22_Velocity", "T22_Angle", "T21_Velocity", "T21_Angle",
     "T20_Velocity", "T20_Angle", "T19_Velocity", "T19_Angle", "T18_Velocity", "T18_Angle", "HL387_24035001_Velocity",
     "HL387_24035001_Angle"]
## 创建一个空的DataFrame空结构,结构index由indexMe组成,结构的columns信息由columnMe组成

    results=pd.DataFrame([],index=indexMe,columns=columnMe)
    b = get_files()
    altitudesName=[]
    for i in b:
        them=i.split("\\")
        currentFilename=them[them.__len__()-1]
        turbinesAndSectors=re.split(r'[.|-]',currentFilename)
## 文件名第一项为风机信息

        currentTurbine=turbinesAndSectors[0]
## 文件名倒数第二项为扇区信息---拆分的时候识别sector信息

        currentSector=turbinesAndSectors[turbinesAndSectors.__len__()-2]
        # sheetName=them[them.__len__()-3]+them[them.__len__()-2]+them[them.__len__()-1]

## 得到SectorID index用于存储数据

        sectorId=columnMe.index(currentSector);
        turbineVId=indexMe.index(currentTurbine+"_Velocity")
        turbineAId=indexMe.index(currentTurbine+"_Angle")
        sd=pd.read_csv(i,skiprows=2)
        ## 去除Null行(注意空格,数字也一样处理)

## 确认了第九行信息为所需要的信息 ,也可以做个线性化操作

        UCRT=sd.iloc[9,2]
        VCRT=sd.iloc[9,3]
        speed2d=sd.iloc[9,5]
## 有趣的是: python atan2(y,x) 而在excel对应的为 atan2(x,y) -->只是针对和x轴夹角

##   如果需要针对y轴夹角必须采用python的atan2(x,y), 或者 excel的atan2(y,x)才是扇区角度的意思

        actualAngle=ma.atan2(UCRT,VCRT)*180/3.1415926+180
## 赋值

        results.iloc[turbineVId,sectorId]=speed2d
        results.iloc[turbineAId,sectorId]=actualAngle

    results.to_csv("Results-WindSimSpeedTableZhuFengxiagn.csv",index=indexMe,columns=columnMe)
Avatar
Ye Zhaoliang
Engineer of offshore wind turbine technique research

My research interests include distributed energy, wind turbine power generation technique , Computational fluid dynamic and programmable matter.

Related

本站访问量: