Commit 5db526f9 authored by Bognár, Á.'s avatar Bognár, Á.
Browse files

add postprocess module and an example for using irradiance results with PVMismatch

parent bce09be9
......@@ -5,6 +5,7 @@ from geomeppy import view_geometry
import pathlib
from matplotlib import pyplot as plt
import os
import json
import subprocess # This should be used instead of os.system. Fix it later.
from geomeppy.geom.polygons import (
break_polygons,
......@@ -210,7 +211,7 @@ def create_sensor_points(surf_name, points_in_poly_2d, row_index, col_index, ori
return sensor_points_surf
def translate_to_ds_pts(surf_sensor_points, p_name):
"""Translates and saves the sensorpoints as Daysim .pts file. Also saves a csv with additional info useful for postprocessing"""
"""Translates and saves the sensorpoints as Daysim .pts file. Also saves a csv or json with additional info useful for postprocessing"""
x, y, z, vx, vy, vz, surf_name, ri, ci = ([] for i in list(range(9)))
for surf in surf_sensor_points:
for i in list(range(len(surf['sensor_points']))):
......@@ -229,7 +230,13 @@ def translate_to_ds_pts(surf_sensor_points, p_name):
for p in spdf.index:
ptsfile.write(str(spdf['x'][p]) +' '+ str(spdf['y'][p]) +' '+ str(spdf['z'][p]) +' '+ str(spdf['vx'][p]) +' '+ str(spdf['vy'][p]) +' '+ str(spdf['vz'][p]) + '\n')
ptsfile.close()
# saving metadatata of sensor points in csv or json format
spdf.to_csv('pts/{}.csv'.format(p_name))
for s in surf_sensor_points:
spi = spdf[spdf['surf_name']==s['surf_name']].index.tolist()
s.update({'sp_index':[int(i) for i in spi]})
with open('pts/{}.json'.format(p_name), 'w') as fp:
json.dump(surf_sensor_points, fp, indent=4)
return
def translate_to_ds_pts_depr1(surf_sensor_points, outputpath_pts, outputpath_kts):
......
......@@ -47,10 +47,10 @@ for surface in act_surfs: # consider making this for a function already. The on
ri, ci = pos_in_module(n_row=10, n_col=6, test_grid_transp=test_grid)
sp = create_sensor_points(surf_name=surface['Name'], points_in_poly_2d=pip, row_index=ri, col_index=ci, original_poly=poly, sp_offset=0.01, sp_pos_round=3) # sensor point data dict (daypym)
sps.append(sp)
output = open(r'{}.pkl'.format(project_name), 'wb') # dumping the sps structure to a picke, because we need it later for posprocess
pickle.dump(sps, output)
output.close()
# use the sensor-point data dicts to make .pts and .kts files (daypym)
#output = open(r'{}.pkl'.format(project_name), 'wb') # dumping the sps structure to a picke, because we need it later for posprocess
#pickle.dump(sps, output)
#output.close()
# use the sensor-point data dicts to make .pts and .kts files (daypym). Alsoe we can save a .csv or .json file with more info for later use
translate_to_ds_pts(surf_sensor_points=sps, p_name=project_name)
## great.. but now it would be nice to visualize if the sps are in the right place:
view_idf_and_sps(p_name=project_name, idf_name=source_idf_name, sps=sps) # plot the sensorpoints and the idf together (daypym-geomeppy)
......@@ -75,7 +75,7 @@ site_info = {
# add wea file data to the site info
site_info.update(wea_data)
# write hea
write_ds_hea(p_name=project_name, p_dir=cwd, bin_dir=r'c:\DAYSIM4\bin\\', uni_mat_file=r'daysim_all_mat.rad', site_info=site_info, model_info=None, radiance_params=None) # set bim_dir to the "...\DAYSIM\bin" folder on your computer
write_ds_hea(p_name=project_name, p_dir=cwd, bin_dir=r'c:\DAYSIM\bin\\', uni_mat_file=r'daysim_all_mat.rad', site_info=site_info, model_info=None, radiance_params=None) # set bim_dir to the "...\DAYSIM\bin" folder on your computer
#run conversion, dc and ill
ds_radfiles2daysim(p_name=project_name, hea_file_name=None)
ds_ds_shortterm(project_name, hea_file_name=None)
......
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
import json
import os
import sys
#sys.path.append(os.path.dirname(os.getcwd()) + r'\\daypym')
sys.path.append(r'c:\TUe\SEAC\Git\daypym_gl2\daypym\daypym')
from postprocess import *
from pvmismatch.pvmismatch_lib import pvcell, pvconstants, pvmodule, pvstring, pvsystem
# func to set the irradiance values for the PVMM pv modules
def ill_to_mod_suns(pv_mod, ill_t, si, mi):
nb = len(pv_mod.cell_pos)
nc = len(pv_mod.cell_pos[0]) * nb
nr = len(pv_mod.cell_pos[0][0])
mod_cell_idxs = [cell['idx'] for cell in np.array(pv_mod.cell_pos).flatten()]
Ee = []
for c in range(nc):
for r in range(nr):
Ee.append(ill_t['s{}m{}c{}r{}'.format(si, mi, c, r)] / 1000)
return Ee, mod_cell_idxs
# project name
for f in os.listdir():
if f.endswith('.hea'):
project_name = f[:-4]
# read (part of the) irradiance output
start = pd.Timestamp('2001-03-06 07:02:30')
end = pd.Timestamp('2001-03-06 19:57:30')
ill = ill_to_df(p_name=project_name)[start:end]
# read sensor point metadata json
with open('pts/{}.json'.format(project_name), 'r') as fp:
sps = json.load(fp)
# read pv system layout
system_layout = pd.read_csv(r'{}_pv_sys_layout.csv'.format(project_name), index_col='mod_nr')
str_len = len(system_layout)
str_num = len(system_layout.columns)
# set cell parameters and build the pv modules, strings and system
v_bypass = np.float64(-0.5) # [V] trigger voltage of bypass diode
cell_area = np.float64(246.49) # [cm^2] cell area
pv_mod_pattern = pvmodule.standard_cellpos_pat(nrows=10, ncols_per_substr=[2]*3)
pv_mod = pvmodule.PVmodule(cell_pos=pv_mod_pattern, pvcells=None, pvconst=None, Vbypass=v_bypass, cellArea=cell_area)
pv_str = pvstring.PVstring(numberMods=str_len, pvmods=[pv_mod]*str_len)
pv_sys = pvsystem.PVsystem(numberStrs=str_num, pvstrs=[pv_str]*str_num, numberMods=[str_len]*str_num, pvmods=[pv_mod]*str_len)
# calulate dc power
dc_power = []
for t in ill.index:
for s in list(system_layout.columns):
for m in list(system_layout.index):
Ee , mod_cell_idxs = ill_to_mod_suns(pv_mod=pv_mod, ill_t=ill.loc[t], si=s, mi=m)
pv_sys.setSuns({s:{m:[Ee, mod_cell_idxs]}})
dc_power.append(pv_sys.calcSystem()[2].max())
system_power = pd.Series(index=ill.index, data=dc_power)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment