Commit 8c621529 by Bognár, Á.

### Bug fixes and developement of irrad analysis

parent 2b212fce
No preview for this file type
No preview for this file type
 ... ... @@ -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))) ... ...