else: raise AssertionError( 'Config key `potential` should be one of "simple" (default) or "conservative",' ' not "{}"'.format(p_nom_max_meth)) layout = xr.DataArray( np.asarray(potmatrix.sum(axis=0)).reshape(cutout.shape), [cutout.meta.indexes[ax] for ax in ['y', 'x']]) # Determine weighted average distance from substation cell_coords = cutout.grid_coordinates() average_distance = [] for i in regions.index: row = layoutmatrix[i] distances = haversine(regions.loc[i, ['x', 'y']], cell_coords[row.indices])[0] average_distance.append( (distances * (row.data / row.data.sum())).sum()) average_distance = xr.DataArray(average_distance, [buses]) ds = xr.merge([(correction_factor * profile).rename('profile'), capacities.rename('weight'), p_nom_max.rename('p_nom_max'), layout.rename('potential'), average_distance.rename('average_distance')]) if snakemake.wildcards.technology.startswith("offwind"): import geopandas as gpd from shapely.geometry import LineString
f'(default) or "conservative", not "{p_nom_max_meth}"') logger.info("Calculate average distances.") layoutmatrix = (layout * availability).stack(spatial=["y", "x"]) coords = cutout.grid[["x", "y"]] bus_coords = regions[["x", "y"]] average_distance = [] centre_of_mass = [] for bus in buses: row = layoutmatrix.sel(bus=bus).data nz_b = row != 0 row = row[nz_b] co = coords[nz_b] distances = haversine(bus_coords.loc[bus], co) average_distance.append((distances * (row / row.sum())).sum()) centre_of_mass.append(co.values.T @ (row / row.sum())) average_distance = xr.DataArray(average_distance, [buses]) centre_of_mass = xr.DataArray(centre_of_mass, [buses, ("spatial", ["x", "y"])]) ds = xr.merge([ (correction_factor * profile).rename("profile"), capacities.rename("weight"), p_nom_max.rename("p_nom_max"), potential.rename("potential"), average_distance.rename("average_distance"), ])