Commit 8c621529 authored by Bognár, Á.'s avatar Bognár, Á.
Browse files

Bug fixes and developement of irrad analysis

parent 2b212fce
......@@ -47,13 +47,11 @@ def grid_2d_depr1(bbox_2d, n):
grid = np.meshgrid(xv, yv)
return grid
def grid_2d(bbox_2d, d):
"""Creates a grid over the bbox with sided divided to n. TODO: n-ratio"""
def grid_2d(bbox_2d, d, edges):
"""Creates a grid over the bbox with siden divided to n. TODO: n-ratio"""
a = abs((bbox_2d[0] - bbox_2d[2])[0])
b = abs((bbox_2d[0] - bbox_2d[2])[1])
n = d * a * b
#y = (n/(b/a + 1)) - 1
#x = (b/a) * y
y1 = (-(a/b + 1) + np.sqrt((a/b + 1)**2 - 4*a/b*(1 - a*b*d))) / (2 * a/b)
y2 = (-(a/b + 1) - np.sqrt((a/b + 1)**2 - 4*a/b*(1 - a*b*d))) / (2 * a/b)
x1 = y1* a/b
......@@ -65,10 +63,20 @@ def grid_2d(bbox_2d, d):
ys = (bbox_2d.vertices_list[0][1], bbox_2d.vertices_list[2][1])
xv = np.linspace(xs[0], xs[1], round(x+1, 0))
yv = np.linspace(ys[0], ys[1], round(y+1, 0)) # this should be a func of the reatio of width height of the bbox
#xv = np.linspace(xs[0], xs[1], a/x, 0)
#yv = np.linspace(ys[0], ys[1], b/y, 0) # this should be a func of the reatio of width height of the bbox
grid = np.meshgrid(xv, yv)
return grid
if edges == False:
lr = max(grid[0].max() - grid[0].min(), grid[1].max() - grid[1].min()) # calc the length of the module in the row-direction (longer direction)
lc = min(grid[0].max() - grid[0].min(), grid[1].max() - grid[1].min()) # calc the length of the module in the column-direction (shorter direction)
n_row = grid[0].shape[0]
n_col = grid[0].shape[1]
dr = (lr/n_row) / 2
dc = (lc/n_col) / 2
grid_transp = [grid[0] + dr, grid[1] + dc] # Pushing the grid to the center of the cells. Now we have a row and column of points off the surface of the pv. These are needed to be removed with gridpoints_in_poly_2d func!
return grid_transp
elif edges == True:
return grid
else:
raise ValueError('"edges" should be = "True" or "False"')
def grid_2d_pvmodule_depr1(n_row, n_col, bbox_2d):
"This makes a rectangular grid over the pv cells. Use the gridpoints_in_poly_2d on the list of arrays it returns, because this produces some extra points as well, that are needed to be clipped off -- # This was not correct, because we used d which is not spoint density here, but the number of points"
......@@ -102,7 +110,7 @@ def grid_2d_pvmodule(n_row, n_col, bbox_2d):
b = abs((bbox_2d[0] - bbox_2d[2])[1])
area = a * b
d = ((n_col*n_row) + (n_row + 1) + (n_col + 1) - 1) / area # calc the point density to have 1 sp over each cell
test_grid = grid_2d(bbox_2d=bbox_2d, d=d) # make a 2D test grid on the x-y plane (daypym) This grid contains the edges as well. Not good yet. We will push this with half cell-size in eac direction.
test_grid = grid_2d(bbox_2d=bbox_2d, d=d, edges=True) # make a 2D test grid on the x-y plane (daypym) This grid contains the edges as well. Not good yet. We will push this with half cell-size in eac direction.
lr = max(test_grid[0].max() - test_grid[0].min(), test_grid[1].max() - test_grid[1].min()) # calc the length of the module in the row-direction (longer direction)
lc = min(test_grid[0].max() - test_grid[0].min(), test_grid[1].max() - test_grid[1].min()) # calc the length of the module in the column-direction (shorter direction)
dr = (lr/n_row) / 2
......@@ -224,7 +232,7 @@ def create_sensor_points(surf_name, points_in_poly_2d, row_index, col_index, ori
sensor_points_surf = {'surf_name':surf_name, 'surf_coords':original_poly.vertices_list, 'sensor_points':sensor_points, 'ri':row_index, 'ci':col_index, 'sp_ori':list(normal_vectors)} # make a dict for the sensor points with name points and vectors, later export this to DS file
return sensor_points_surf
def translate_to_ds_pts(surf_sensor_points, p_name):
def translate_to_ds_pts(surf_sensor_points, p_name, grid_method):
"""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:
......@@ -236,9 +244,14 @@ def translate_to_ds_pts(surf_sensor_points, p_name):
vy.append(surf['sp_ori'][1])
vz.append(surf['sp_ori'][2])
surf_name.append(surf['surf_name'])
ri.append(surf['ri'][i])
ci.append(surf['ci'][i])
spdf = pd.DataFrame(data={'x':x, 'y':y, 'z':z, 'vx':vx, 'vy':vy, 'vz':vz, 'ri':ri, 'ci':ci, 'surf_name':surf_name})
if grid_method == 'pv_module':
ri.append(surf['ri'][i])
ci.append(surf['ci'][i])
spdf = pd.DataFrame(data={'x':x, 'y':y, 'z':z, 'vx':vx, 'vy':vy, 'vz':vz, 'ri':ri, 'ci':ci, 'surf_name':surf_name})
elif grid_method == 'point_density':
spdf = pd.DataFrame(data={'x':x, 'y':y, 'z':z, 'vx':vx, 'vy':vy, 'vz':vz, 'surf_name':surf_name})
else:
raise ValueError('"grid_method" should be = "pv_module" or "point_density"')
spdf.index.name = 'sp_index'
ptsfile = open('pts/{}.pts'.format(p_name), 'w')
for p in spdf.index:
......
......@@ -10,8 +10,12 @@ def ill_to_df(p_name):
surfnames = list(pts['surf_name']) # read the surf names fom the csv
# make a list of unique names for the ptss. These will be the col names for the ill dataframe
ptsnames = []
for i in list(range(len(surfnames))):
ptsnames.append(surfnames[i] + 'c{}r{}'.format(pts.loc[i, 'ci'], pts.loc[i, 'ri']))
if 'ci' in pts.columns and 'ri' in pts.columns:
for i in list(range(len(surfnames))):
ptsnames.append(surfnames[i] + 'c{}r{}'.format(pts.loc[i, 'ci'], pts.loc[i, 'ri']))
else:
for i in list(range(len(surfnames))):
ptsnames.append(surfnames[i] + 'spi{}'.format(pts.index[i]))
ill = pd.read_csv(r'res\{}.ill'.format(p_name), sep=' ', skipinitialspace=True, header=None, dtype=np.float64)
# converting fraction hours seems complicated because of rounding errors, so for now, lazily we generate our own timestamps from the first two rows
timestepmins = pd.Timedelta(minutes=int(round((ill[2][1] - ill[2][0]) * 60)))
......
......@@ -4,8 +4,8 @@ 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(os.path.dirname(os.getcwd()) + r'\\daypym')
sys.path.append(r'c:\TUe\SEAC\Git\daypym_gl2\daypym\daypym')
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,9 +32,15 @@ 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]
act_surfs = []
for i in surfaces:
if i.Construction_Name == 'PV_Construction':
act_surfs.append(i)
# 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
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)
......@@ -42,16 +48,17 @@ for surface in act_surfs: # consider making this for a function already. The on
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=10) # make a 2D test grid on the x-y plane (daypym)
#test_grid = grid_2d(bbox_2d=poly_trans_bbox_2d, d=9, 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=10, n_col=6, test_grid_transp=test_grid)
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)
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)
translate_to_ds_pts(surf_sensor_points=sps, p_name=project_name, grid_method='pv_module')
## 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)
......@@ -64,7 +71,7 @@ rad_obj2rad(input_obj=project_name + r'.obj', output_rad=project_name)
site_info = {
'ground_eflectance':0,
'first_weekday':1,
'time_step':5, # if this is not 60, we need to run the ds_ds_shortterm
'time_step':20, # 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
......@@ -75,7 +82,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:\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
write_ds_hea(p_name=project_name, p_dir=cwd, bin_dir=r'c:\DAYSIM\bin\\', uni_mat_file=r'c:\TUe\PhD\Simulations\Daysim\materials\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)
......
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