Commit 0b00e065 authored by Bognár, Á.'s avatar Bognár, Á.
Browse files

Update tutorials

parent 6f626cd8
......@@ -4,8 +4,7 @@ from geomeppy import IDF
from geomeppy import view_geometry
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')
sys.path.append(r'c:\TUe\SEAC\Git\daypym_gl2\daypym\daypym') # set this to the daypym folder on your computer
from daypym import *
from geomeppy.geom.polygons import (break_polygons, Polygon2D, Polygon3D, Vector2D, Vector3D)
from geomeppy.geom.transformations import align_face, invert_align_face
......@@ -32,31 +31,17 @@ surfaces = surface=source_idf.idfobjects['BUILDINGSURFACE:DETAILED']
act_surf_id = 'PV_Construction' # 'BIPV_Construction' this is the active surface identifier. Surfaces with construction names like this will get a sensor point mesh over them
act_surfs = [surface for surface in surfaces if surface.Construction_Name == act_surf_id]
# loop trough the surfaces and make a list of sensor-point data dicts which will be used to make the pts and kts files
n_row=10
n_col=6
# loop trough the surfaces and make a list of sensor-point data dicts which will be used to make the pts files
n_row=10 # number of cell rows in the PV modules we want to model
n_col=6 # number of cell columns in the PV modules we want to model
sps = []
for surface in act_surfs: # consider making this for a function already. The only external input we need here is the IDF surface, n and the sp_offset
poly = IDFsurf_to_poly(surface=surface) # make poly from idf (daypym)
poly_trans = align_face(poly).order_points('upperleftcorner') # translate poly to the x-y plane (geomeppy)
poly_trans_2d = poly_trans.project_to_2D() # make the poly 2D (geomeppy)
poly_trans_bbox_2d = poly_trans.bounding_box.project_to_2D() # make a 2d bbox of the translated surface on the xy pane (geomeppy)
test_grid = grid_2d_pvmodule(n_row=n_row, n_col=n_col, bbox_2d=poly_trans_bbox_2d) # makes an offset grid over the cells (daypym)
#test_grid = grid_2d(bbox_2d=poly_trans_bbox_2d, d=6, edges=False) # make a 2D test grid on the x-y plane (daypym)
pip = gridpoints_in_poly_2d(grid_2d=test_grid, poly_2d=poly_trans_2d) # makes a list of points, that are inside the 2D poly (daypym)
ri, ci = pos_in_module(n_row=n_row, n_col=n_col, 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)
#sp = create_sensor_points(surf_name=surface['Name'], points_in_poly_2d=pip, row_index=[0], col_index=[0], original_poly=poly, sp_offset=0.01, sp_pos_round=3) # sensor point data dict (daypym)
for surface in act_surfs:
sp = pointgrid_over_pvmodule(surface, n_row, n_col, sp_offset=0.01)
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). 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, grid_method='pv_module')
#translate_to_ds_pts(surf_sensor_points=sps, p_name=project_name, grid_method='point_density')
## 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)
translate_to_ds_pts(surf_sensor_points=sps, p_name=project_name,
grid_method='pv_module')
# visualize if the sps are in the right place:
view_idf_and_sps(p_name=project_name, idf_name=source_idf_name, sps=sps)
## this is the running Daysim part
# make wea file from epw
......@@ -67,7 +52,7 @@ rad_obj2rad(input_obj=project_name + r'.obj', output_rad=project_name)
site_info = {
'ground_eflectance':0,
'first_weekday':1,
'time_step':20, # if this is not 60, we need to run the ds_ds_shortterm
'time_step':60, # if this is not 60, we need to run the ds_ds_shortterm
'wea_data_file':cwd + '/wea//' + project_name + '.wea', # this needs full abs path
'weather_data_file_units':1,
'wea_data_short_file':'/wea//' + project_name + '_short.wea', # this is an output and an input in this case
......@@ -78,7 +63,9 @@ 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:\DAYSIM\bin\\', uni_mat_file=r'daysim_all_mat.rad', site_info=site_info, model_info=None, radiance_params=None) # set bin_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 bin_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)
......
......@@ -4,15 +4,15 @@ 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')
sys.path.append(r'c:\TUe\SEAC\Git\daypym_gl2\daypym\daypym') # set this to the daypym folder on your computer
from postprocess import *
from pvmismatch.pvmismatch_lib import pvcell, pvconstants, pvmodule, pvstring, pvsystem
# In this example for the PV power simulations we use PVMismatch, developed by Mark Mikofski, Bennet Meyers and Chetan Chaudhari at SunPower Corporation, Richmond, CA.
# In this example for the PV power simulations we use PVMismatch, developed by
# Mark Mikofski, Bennet Meyers and Chetan Chaudhari at SunPower Corporation, Richmond, CA.
# PVMismatch Project: https://github.com/SunPower/PVMismatch
# func to set the irradiance values for the PVMM pv modules
def ill_to_mod_suns(pv_mod, ill_t, si, mi):
def ill_to_mod_suns(pv_mod, ill_t, mod_name, d=0.000001):
nb = len(pv_mod.cell_pos)
nc = len(pv_mod.cell_pos[0]) * nb
nr = len(pv_mod.cell_pos[0][0])
......@@ -20,18 +20,31 @@ def ill_to_mod_suns(pv_mod, ill_t, si, mi):
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)
Ee.append(ill_t['{}c{}r{}'.format(mod_name, c, r)] / 1000 + d)
return Ee, mod_cell_idxs
# func for naming the sensorpoints according to their position in the module
def make_pts_names(pts_csv):
pts = pd.read_csv(pts_csv)
surfnames = list(pts['surf_name']) # read the surf names fom the csv
# make a list of unique names for the ptss
ptsnames = []
for i in list(range(len(surfnames))):
ptsnames.append(surfnames[i] + 'c{}r{}'.format(pts.loc[i, 'ci'],
pts.loc[i, 'ri']))
return ptsnames
# 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')
start = pd.Timestamp('2001-06-06 00:30:00')
end = pd.Timestamp('2001-06-08 23:30:00')
ill = ill_to_df(p_name=project_name)[start:end]
pts_names = make_pts_names(pts_csv=r'pts/{}.csv'.format(project_name))
ill.rename(columns=dict(zip(ill.columns, pts_names)), inplace=True)
ill_mean = ill.mean(axis=1)
# read sensor point metadata json
......@@ -52,21 +65,35 @@ pv_mod = pvmodule.PVmodule(cell_pos=pv_mod_pattern, pvcells=None, pvconst=None,
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 with cell level and mean irradiance
dc_power = []
# calulate dc power with cell level irradiance
p = []
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())
if ill.loc[t].mean() < 0.1: # this is to speed up simulations. (Not to simulate when solar irrad is wery low)
print(t, 'DC_power_cell_level (W):', 0)
p.append(0)
else:
for s in list(system_layout.columns):
for m in list(system_layout.index):
mod_name = system_layout.loc[m, s]
Ee , mod_cell_idxs = ill_to_mod_suns(pv_mod=pv_mod,
ill_t=ill.loc[t], mod_name=mod_name)
pv_sys.setSuns({s:{m:[Ee, mod_cell_idxs]}})
print(t, 'DC_power_cell_level (W):', pv_sys.Pmp)
p.append(pv_sys.Pmp)
dc_power_ill_mean = []
# calculating DC power with the mean irradiance of all sensorpoints as
# irradiance input for all cells: light is uniform on the system, no mismatch effects
p_mean = []
for t in ill.index:
pv_sys.setSuns(ill_mean[t] / 1000)
dc_power_ill_mean.append(pv_sys.calcSystem()[2].max())
if ill.loc[t].mean() < 0.1: # this is to speed up simulations. (Not to simulate when solar irrad is wery low)
print(t, 'DC_power_mean_irrad (W):', 0)
p_mean.append(0)
else:
pv_sys.setSuns(ill_mean[t] / 1000)
print(t, 'DC_power_mean_irrad (W):', pv_sys.Pmp)
p_mean.append(pv_sys.Pmp)
system_power = pd.DataFrame(index=ill.index, data={'dc_power_cell_level_irrad':dc_power, 'dc_power_mean_irrad':dc_power_ill_mean})
system_power = pd.DataFrame(index=ill.index, data={'dc_power_cell_level_irrad':p, 'dc_power_mean_irrad':p_mean})
system_power.plot()
plt.ylabel('Pdc [W]')
plt.show(block=False)
......@@ -4,7 +4,7 @@ from matplotlib import pyplot as plt
import json
import os
import sys
sys.path.append(r'c:\TUe\SEAC\Git\daypym_gl2\daypym\daypym')
sys.path.append(r'c:\TUe\SEAC\Git\daypym_gl2\daypym\daypym') # set this to the daypym folder on your computer
from postprocess import *
from daypym import *
......@@ -14,25 +14,25 @@ for f in os.listdir():
if f.endswith('.hea'):
project_name = f[:-4]
source_idf_name = r'{}.idf'.format(project_name)
# load teh previously calculated irradiance
# load the previously calculated irradiance
ill = ill_to_df(p_name=project_name)
# read sensor point metadata json
with open('pts/{}.json'.format(project_name), 'r') as fp:
sps = json.load(fp)
# plot the sensor-point irradiance at a given timestep
t = pd.Timestamp('2001-06-06 15:10:00')
t = pd.Timestamp('2001-06-06 15:30:00')
view_idf_and_ill(p_name=project_name, idf_name=source_idf_name, sps=sps,
ill=ill.loc[t, : ], save_fig=False)
# animated visualization of the results:
starttime = pd.Timestamp('2001-06-06 07:30:00')
endtime = pd.Timestamp('2001-06-06 19:50:00')
ill_t = ill.loc[starttime:endtime]
endtime = pd.Timestamp('2001-06-06 20:30:00')
t_period = ill.loc[starttime:endtime].index
with open('pts/{}.json'.format(project_name), 'r') as fp:
sps2 = json.load(fp)
for t in ill_t.index:
for t in t_period:
ax = view_idf_and_ill(p_name=project_name, idf_name=source_idf_name,
sps=sps2, ill=ill.loc[t], save_fig=False,
return_ax=True)
......@@ -40,6 +40,6 @@ for t in ill_t.index:
max_irrad = ill.loc[t].max()
mean_irrad = np.round(ill.loc[t].mean())
ax.set_title(str(t) + '\n'
+ 'G_min={}\n G_mean={}\n G_max={}'.format(min_irrad, mean_irrad, max_irrad))
+ 'I_min={}\n I_mean={}\n I_max={}'.format(min_irrad, mean_irrad, max_irrad))
plt.draw()
plt.pause(0.02)
plt.pause(0.08)
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