add temperature data
This commit is contained in:
parent
08cc653a8e
commit
95f5043cc7
27
download.py
27
download.py
|
@ -47,7 +47,7 @@ def fetch_files(now:str):
|
|||
date = yesterday_str
|
||||
for h in range(1, 5 * 24+1):
|
||||
h_str = "{:03d}".format(h)
|
||||
url = f"https://nomads.ncep.noaa.gov/cgi-bin/filter_gfs_0p25_1hr.pl?dir=%2Fgfs.{date}%2F18%2Fatmos&file=gfs.t18z.pgrb2.0p25.f{h_str}&var_DSWRF=on&lev_surface=on"
|
||||
url = f"https://nomads.ncep.noaa.gov/cgi-bin/filter_gfs_0p25_1hr.pl?dir=%2Fgfs.{date}%2F18%2Fatmos&file=gfs.t18z.pgrb2.0p25.f{h_str}&var_DSWRF=on&var_TMP=on&lev_surface=on"
|
||||
logger.info(url)
|
||||
out_path = f"./data/{date}/gfs.t18z.pgrb2.0p25.f{h_str}"
|
||||
if not os.path.exists(out_path):
|
||||
|
@ -61,7 +61,7 @@ def fetch_files(now:str):
|
|||
date = today_str
|
||||
for h in range(1, 5 * 24+1):
|
||||
h_str = "{:03d}".format(h)
|
||||
url = f"https://nomads.ncep.noaa.gov/cgi-bin/filter_gfs_0p25_1hr.pl?dir=%2Fgfs.{date}%2F00%2Fatmos&file=gfs.t00z.pgrb2.0p25.f{h_str}&var_DSWRF=on&lev_surface=on"
|
||||
url = f"https://nomads.ncep.noaa.gov/cgi-bin/filter_gfs_0p25_1hr.pl?dir=%2Fgfs.{date}%2F00%2Fatmos&file=gfs.t00z.pgrb2.0p25.f{h_str}&var_DSWRF=on&var_TMP=on&lev_surface=on"
|
||||
logger.info(url)
|
||||
out_path = f"./data/{date}/gfs.t18z.pgrb2.0p25.f{h_str}"
|
||||
if not os.path.exists(out_path):
|
||||
|
@ -75,7 +75,8 @@ def fetch_files(now:str):
|
|||
def trans_data(date:str) -> np.array:
|
||||
file_path = f"./data/{date}/"
|
||||
files = [f"{file_path}/{x}" for x in os.listdir(file_path) if x.startswith('gfs')]
|
||||
pred = list()
|
||||
rad_list = list()
|
||||
tmp_list = list()
|
||||
for file in files:
|
||||
data = pg.open(file)
|
||||
try:
|
||||
|
@ -85,15 +86,25 @@ def trans_data(date:str) -> np.array:
|
|||
logger.info(f"error occurs when read {file}, {e}")
|
||||
values = np.full([721, 1440], np.nan)
|
||||
finally:
|
||||
pred.append(values)
|
||||
rad_list.append(values)
|
||||
try:
|
||||
grb_tmp = data.select(name="Temperature")[0]
|
||||
values_tmp = grb_tmp.values
|
||||
except Exception as e:
|
||||
logger.info(f"error occurs when read {file}, {e}")
|
||||
values_tmp = np.full([721, 1440], np.nan)
|
||||
finally:
|
||||
tmp_list.append(values_tmp)
|
||||
data.close()
|
||||
rst = np.asarray(pred).tolist()
|
||||
rst_rad = np.asarray(rad_list).tolist()
|
||||
rst_tmp = np.asarray(tmp_list).tolist()
|
||||
# np.save(f"./data/{date}.npy", rst)
|
||||
# TODO: 在这里添加写入数据库的代码
|
||||
|
||||
shutil.rmtree(f"./data/{date}/")
|
||||
return rst
|
||||
# shutil.rmtree(f"./data/{date}/")
|
||||
return rst_rad, rst_tmp
|
||||
|
||||
if __name__ == '__main__':
|
||||
time_range, date = fetch_files(None)
|
||||
rst = trans_data(date)
|
||||
rad, tmp = trans_data(date)
|
||||
print(rad.shape, tmp.shape)
|
41
tools.py
41
tools.py
|
@ -12,9 +12,9 @@ def cal_angle(prov:str, city:str, angle_config:dict):
|
|||
"""_summary_
|
||||
|
||||
Args:
|
||||
prov (str): 省、直辖市、自治区、特别行政区
|
||||
city (str): 地级市、地区、自治州、盟
|
||||
angle_config (dict): _description_
|
||||
prov (str): _ 省、直辖市、自治区、特别行政区
|
||||
city (str): _ 地级市、地区、自治州、盟
|
||||
angle_config (dict): _
|
||||
|
||||
Returns:
|
||||
_type_: _description_
|
||||
|
@ -35,3 +35,38 @@ def cal_generation(cap: [int, float], angle, best_angle, dhi_list):
|
|||
"""
|
||||
dhi_list = np.asarray(dhi_list)
|
||||
return list(cap * math.cos(math.radians(abs(angle - best_angle))) * dhi_list)
|
||||
|
||||
|
||||
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, t_a_noct:[float, int]=20, g_noct:[float, int]=800, ita:float=0.083/0.9)->list:
|
||||
"""复杂的计算出力的方式
|
||||
|
||||
Args:
|
||||
cap (float): _装机容量(KW).
|
||||
angle (float): _光伏安装倾角(°).
|
||||
best_angle (float): _当地最佳安装倾角
|
||||
dhi_list (list): _未来120h辐照预测值,W/m2
|
||||
t_list (list): _未来120气温预测值,℃
|
||||
materials (str): _晶体材料
|
||||
sigma (float, optional): _温度系数(%/℃)取值一般为[-0.45 ~ -0.33],当该值不为None时,不通过晶体材料计算sigma. Defaults to None.
|
||||
t_noct (int, optional): _电池片结温. Defaults to 45.
|
||||
t_a_noct (int, optional): _NOCT下的环境温度. Defaults to 20.
|
||||
g_noct (int, optional): _NOCT下的辐照(W/m2). Defaults to 800.
|
||||
ita (_type_, optional): _常数系数. Defaults to 0.083/0.9=0.0922
|
||||
|
||||
Returns:
|
||||
power_list(list[float]): 未来120h的小时出力,KW
|
||||
"""
|
||||
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 + (t_noct - t_a_noct)*(dhi_list / g_noct)*(1-ita)
|
||||
if sigma is None:
|
||||
sigma = sigma_dict.get(materials, -0.42)
|
||||
K = 1 + sigma / 100 * (t_cell - t_a_noct)
|
||||
return list(cap * math.cos(math.radians(abs(angle - best_angle))) * dhi_list) * K
|
Loading…
Reference in New Issue