pv_forecasting/tools.py

81 lines
2.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*-utf8-*-
import numpy as np
import json
import math
from logzero import logger
def load_config(path):
with open(path, 'r', encoding='utf-8') as fr:
config = json.load(fr)
return config
def cal_angle(prov:str, city:str, angle_config:dict):
"""_summary_
Args:
prov (str): _ 省、直辖市、自治区、特别行政区
city (str): _ 地级市、地区、自治州、盟
angle_config (dict): _
Returns:
_type_: _description_
"""
prov_values = angle_config.get(prov)
if not prov_values:
return False
city_values = prov_values.get(city)
if not prov_values:
values = np.mean(list(prov_values.values), axis=0)
else:
values = city_values
return values
def cal_generation(cap:float, angle, best_angle, dhi_list):
"""_summary_
G = Y * cos(|x - y|)* 0.9 * GHI
"""
dhi_list = np.asarray(dhi_list)
logger.info(dhi_list)
index = math.cos(math.radians(abs(angle - best_angle)))
return list(cap * index * 0.9 * dhi_list / 1000)
def cal_complex_gen(cap:float, angle:float, best_angle:float,
dhi_list:list, t_list:list, materials:str, sigma:float=None,
t_noct:[float, int]=45)->list:
"""复杂的计算出力的方式
Args:
cap (float): _装机容量(KW).
angle (float): _光伏安装倾角(°).
best_angle (float): _当地最佳安装倾角
dhi_list (list): _未来120h辐照预测值W/m2
t_list (list): _未来120h气温预测值,℃
materials (str): _晶体材料
sigma (float, optional): _温度系数%/℃)取值一般为[-0.45 ~ -0.33]当该值不为None时不通过晶体材料计算sigma. Defaults to None.
t_noct (int, optional): _电池片结温. Defaults to 45.
Returns:
power_list(list[float]): 未来120h的小时出力KW
"""
t_a_noct = 20
g_noct = 800
ita = 0.083 / 0.9
sigma_dict = {
"N型单晶": -0.38,
"P型单晶": -0.42,
"P型多晶": -0.42
}
t_list = np.asarray(t_list)
dhi_list = np.asarray(dhi_list)
t_cell = t_list + (float(t_noct) - t_a_noct)*(dhi_list / g_noct)*(1-ita)
if sigma is None:
sigma = sigma_dict.get(materials, -0.42)
else:
sigma = float(sigma)
K = 1 + sigma / 100 * (t_cell - t_a_noct)
return list(cap * math.cos(math.radians(abs(angle - best_angle))) * dhi_list) * K
if __name__ == '__main__':
print(cal_generation(200., 32, 33, [15., 21., 33., 94.]))