Commit 66d14eab by Bognár, Á.

### Merge branch 'develop' into 'master'

```Develop

See merge request !2```
parents 2b212fce 3722440c
.gitignore 0 → 100644
 # files *.pyc # build __pycache__/ # docs .ipynb_checkpoints
 """ This is the Daypym Package. """
File deleted
File deleted
 ... ... @@ -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 ... ... @@ -160,6 +168,23 @@ def point_in_poly(point, poly): no_inter_d = len(inter_d[0]) return True if no_inter_r == 3 or no_inter_l == 3 or no_inter_u == 3 or no_inter_d == 3 else False # we will see how robust this is # check this again later def supress_points(xyz, vertices, zmax, apothem): """Return an xyz with the points supressed to zmax within the vertices of the polygon. This is to use with a cropped xyz made with tiff2xyz().""" vert_vects = [Vector2D(v[0]-apothem, v[1]-apothem) for v in vertices] poly = Polygon2D(vert_vects) x_min = min(poly.xs) x_max = max(poly.xs) y_min = min(poly.ys) y_max = max(poly.ys) for i in xyz.index: if ((xyz.loc[i, 'x'] > x_min and xyz.loc[i, 'x'] < x_max) and (xyz.loc[i, 'y'] > y_min and xyz.loc[i, 'y'] < y_max)): point = Vector2D(xyz.loc[i, 'x'], xyz.loc[i, 'y']) if point_in_poly(point, poly): xyz.loc[i, 'z'] = zmax return xyz def gridpoints_in_poly_2d(grid_2d, poly_2d): "Returns a list of points, that are inside a 2d poly. Takes a meshgrid (made with grid_2d) and a 2d poly as input" pip = [] # list of points in poly ... ... @@ -224,7 +249,17 @@ 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 xyz_coords_from_sps(sps): """Takes sps dict as input. Extracts x, y, z coords from an sps dict made with the create_sensor_points() or the pointgrid_over_surface() function""" x, y, z = ([] for i in list(range(3))) for p in sps: x += [c[0] for c in p['sensor_points']] y += [c[1] for c in p['sensor_points']] z += [c[2] for c in p['sensor_points']] return pd.DataFrame(data={'x':x, 'y':y, 'z':z}) 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 +271,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: ... ... @@ -450,3 +490,29 @@ def ds_ds_illum(p_name, hea_file_name=None): else: cstr = r'ds_illum {} -dds'.format(hea_file_name) os.system(cstr) ### Wrapper functions to onelinify certain workflows: def pointgrid_over_surface(surface, d=5, edges=True, sp_offset=0.01): """Wrapper function for create_sensor_points(). Inputs: surface: IDF urface (via geomeppy), d: desired point density sps/m2 edges: bool to decide if we want poits on the edge of the surface, sp_offset: offset of sensorpoints from teh surface in m. Returns a dict: {'surf_name':surface name, 'sensor_points':list of sensor points, 'ri':row_index, 'ci':col_index, 'sp_ori':list of normal vectors}.""" # make poly from idf (daypym) poly = IDFsurf_to_poly(surface=surface) # translate poly to the x-y plane (geomeppy) poly_trans = align_face(poly).order_points('upperleftcorner') # make the poly 2D (geomeppy) poly_trans_2d = poly_trans.project_to_2D() # make a 2d bbox of the translated surface on the xy pane (geomeppy) poly_trans_bbox_2d = poly_trans.bounding_box.project_to_2D() # make a 2D test grid on the x-y plane (daypym) test_grid = grid_2d(bbox_2d=poly_trans_bbox_2d, d=d, edges=edges) # makes a list of points, that are inside the 2D poly (daypym) pip = gridpoints_in_poly_2d(grid_2d=test_grid, poly_2d=poly_trans_2d) # 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=sp_offset, sp_pos_round=3) return sp
 ... ... @@ -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))) ... ...
 ... ... @@ -4295,4 +4295,3 @@ Output:Variable, Output:SQLite, SimpleAndTabular; !- Option Type