代码拉取完成,页面将自动刷新
同步操作将从 xzbh666/不同气候变化情景下风力发电的不确定性及极端事件研究 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#李--csv--cf批量解决代码--最终
import os
import csv
import pandas as pd
import shutil
def calculate_wind_capacity_factor(speed, height):
speed = speed * ((height / 10) ** 0.143)
if speed <= 3:
return 0
elif speed >= 14.5 and speed <= 25:
return 1
elif speed > 25:
return 0
elif speed >= 3 and speed <= 6:
k = 1.78 * (speed ** 5) - 40.636 * (speed ** 4) + 365.88 * (speed ** 3) - 1604.4 * (
speed ** 2) + 3460 * speed - 2960.184
k = k / 1500 # Capacity factor calculation
return k
elif speed > 6 and speed <= 9:
k = (-2.93333) * (speed ** 5) + 107.7 * (speed ** 4) - 1573.27 * (speed ** 3) + 11460.158 * (
speed ** 2) - 41528.1 * speed + 59908.2
k = k / 1500 # Capacity factor calculation
return k
else:
k = 0.15247 * (speed ** 6) - 11.090005 * (speed ** 5) + 334.2735 * (speed ** 4) - 5339.027 * (
speed ** 3) + 47583.517 * (speed ** 2) - 223812 * speed + 433774.2
k = k / 1500 # Capacity factor calculation
return k
def process_files(input_folder, output_folder):
j = 0
for folder in os.listdir(input_folder):
in_folder_path = os.path.join(input_folder, folder)
out_folder_path = os.path.join(output_folder, f"cf_{folder}")
os.makedirs(out_folder_path, exist_ok=True)
for file in os.listdir(in_folder_path):
print(f"{j} Processing file: {file}")
file_path = os.path.join(in_folder_path, file)
out_file_path = os.path.join(out_folder_path, file)
data = []
with open(file_path, 'r') as f:
reader = csv.reader(f)
data = list(reader)
data[0].append("cf_80")
data[0].append("cf_100")
data[0].append("cf_150")
for row in data[1:]:
wind_speed = float(row[1]) # Assuming wind speed is in the second column
cf_80 = calculate_wind_capacity_factor(wind_speed, 80)
cf_100 = calculate_wind_capacity_factor(wind_speed, 100)
cf_150 = calculate_wind_capacity_factor(wind_speed, 150)
row.append(cf_80)
row.append(cf_100)
row.append(cf_150)
with open(out_file_path, 'w', newline='') as file:
writer = csv.writer(file)
writer.writerows(data)
print(f"Processing folder {folder} completed")
j += 1
# Move processed folder to specified location
#shutil.move(in_folder_path, os.path.join(r"F:\data\CMIP6\ccsv_history", folder))
if __name__ == "__main__":
input_folder_path = r"F:\data\CMIP6\csv_test" # Input folder path
output_folder_path = r"F:\data\CMIP6\cff_test" # Output folder path
process_files(input_folder_path, output_folder_path)
# 开启D:\py-demo\csv_cf.py内的操作
#os.system("python D:\py-demo\\aver_test.py")
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。