-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Description
eGo currently includes functions which analyze only the transmission grid side. It would be better to migrate them to eTraGo, or replace them with existing eTraGo-functions.
Lines 117 to 162 in d121771
| def etrago_convert_overnight_cost(annuity_cost, json_file, t=40, p=0.05): | |
| """Get annuity cost of simulation and calculation total | |
| ``overnight_costs`` by given capital costs and lifetime. | |
| Parameters | |
| ---------- | |
| json_file : :obj:dict | |
| Dictionary of the ``scenario_setting.json`` file | |
| _start_snapshot : int | |
| Start point of calculation from ``scenario_setting.json`` file | |
| _end_snapshot : int | |
| End point of calculation from ``scenario_setting.json`` file | |
| _p : numeric | |
| interest rate of investment | |
| _T : int | |
| lifetime of investment | |
| Returns | |
| ------- | |
| overnight_cost : numeric | |
| Scenario and calculation total ``overnight_costs`` by given | |
| annuity capital costs and lifetime. | |
| Examples | |
| -------- | |
| .. math:: | |
| PVA = (1 / p) - (1 / (p*(1 + p)^t)) | |
| K_{ON} = K_a*PVA*((t/(period+1)) | |
| """ | |
| # Based on eTraGo calculation in | |
| # https://github.com/openego/eTraGo/blob/dev/etrago/tools/utilities.py#L651 | |
| # Calculate present value of an annuity (PVA) | |
| PVA = (1 / p) - (1 / (p * (1 + p) ** t)) | |
| year = 8760 | |
| # get period of calculation | |
| period = json_file["eTraGo"]["end_snapshot"] - json_file["eTraGo"]["start_snapshot"] | |
| # calculation of overnight_cost | |
| overnight_cost = annuity_cost * (PVA * (year / (period + 1))) | |
| return overnight_cost |
-> should be moved to eTraGo and needs to be adjusted
Lines 78 to 111 in d121771
| def carriers_colore(): | |
| """Return matplotlib colore set per carrier (technologies of | |
| generators) of eTraGo. | |
| Returns | |
| ------- | |
| colors : :obj:`dict` | |
| List of carriers and matplotlib colores | |
| """ | |
| colors = { | |
| "biomass": "green", | |
| "coal": "k", | |
| "gas": "orange", | |
| "eeg_gas": "olive", | |
| "geothermal": "purple", | |
| "lignite": "brown", | |
| "oil": "darkgrey", | |
| "other_non_renewable": "pink", | |
| "reservoir": "navy", | |
| "run_of_river": "aqua", | |
| "pumped_storage": "steelblue", | |
| "solar": "yellow", | |
| "uranium": "lime", | |
| "waste": "sienna", | |
| "wind": "skyblue", | |
| "slack": "pink", | |
| "load shedding": "red", | |
| "nan": "m", | |
| "imports": "salmon", | |
| "": "m", | |
| } | |
| return colors |
-> can be replaced by etrago.carrier_colors
Lines 132 to 433 in d121771
| def plot_storage_expansion( | |
| ego, filename=None, dpi=300, column="overnight_costs", scaling=1 | |
| ): | |
| """Plot line expantion | |
| Parameters | |
| ---------- | |
| ego : :class:`ego.tools.io.eGo` | |
| eGo ``eGo`` inclueds eTraGo and eDisGo results | |
| filename: str | |
| Filename and/or path of location to store graphic | |
| dpi: int | |
| dpi value of graphic | |
| column: str | |
| column name of eTraGo's line costs. Default: ``overnight_costs`` in EURO. | |
| Also available ``s_nom_expansion`` in MVA or | |
| annualized ``investment_costs`` in EURO | |
| scaling: numeric | |
| Factor to scale storage size of bus_sizes | |
| Returns | |
| ------- | |
| plot :obj:`matplotlib.pyplot.show` | |
| https://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.show | |
| """ | |
| network = ego.etrago.network | |
| json_file = ego.json_file | |
| # get storage values | |
| if "storage" in ego.json_file["eTraGo"]["extendable"]: | |
| storage_inv = network.storage_units[network.storage_units.capital_cost > 0.0] | |
| storage_inv["investment_costs"] = ( | |
| storage_inv.capital_cost * storage_inv.p_nom_opt | |
| ) | |
| storage_inv["overnight_costs"] = etrago_convert_overnight_cost( | |
| storage_inv["investment_costs"], json_file | |
| ) | |
| msd_max = storage_inv[column].max() | |
| msd_median = storage_inv[column].median() | |
| msd_min = storage_inv[column].min() | |
| if (msd_max - msd_min) > 1.0e5: | |
| if msd_max != 0: | |
| LabelVal = int(log10(msd_max)) | |
| else: | |
| LabelVal = 0 | |
| if LabelVal < 0: | |
| LabelUnit = "€" | |
| msd_max, msd_median, msd_min = ( | |
| msd_max * 1000, | |
| msd_median * 1000, | |
| msd_min * 1000, | |
| ) | |
| storage_inv[column] = storage_inv[column] * 1000 | |
| elif LabelVal < 3: | |
| LabelUnit = "k €" | |
| else: | |
| LabelUnit = "M €" | |
| msd_max, msd_median, msd_min = ( | |
| msd_max / 1000, | |
| msd_median / 1000, | |
| msd_min / 1000, | |
| ) | |
| storage_inv[column] = storage_inv[column] / 1000 | |
| else: | |
| LabelUnit = "€" | |
| # start plotting | |
| figsize = 6, 6 | |
| fig, ax = plt.subplots(1, 1, figsize=(figsize)) | |
| bus_sizes = storage_inv[column] * scaling | |
| if column == "investment_costs": | |
| title = "Annualized Storage costs per timestep" | |
| ltitel = "Storage costs" | |
| if column == "overnight_costs": | |
| title = "Total Expansion Costs Overnight" | |
| ltitel = "Storage costs" | |
| if column == "p_nom_opt": | |
| title = "Storage Expansion in MVA" | |
| ltitel = "Storage size" | |
| LabelUnit = "kW" | |
| if column not in ["investment_costs", "overnight_costs", "p_nom_opt"]: | |
| title = "unknown" | |
| ltitel = "unknown" | |
| LabelUnit = "unknown" | |
| if sum(storage_inv[column]) == 0: | |
| sc = network.plot(bus_sizes=0, ax=ax, title="No storage expantion") | |
| else: | |
| sc = network.plot( | |
| bus_sizes=bus_sizes, | |
| bus_colors="g", | |
| # bus_cmap= | |
| # line_colors='gray', | |
| title=title, | |
| line_widths=0.3, | |
| ) | |
| ax.set_alpha(0.4) | |
| # add legend | |
| for area in [msd_max, msd_median, msd_min]: | |
| plt.scatter( | |
| [], | |
| [], | |
| c="white", | |
| s=area * scaling, | |
| label="= " + str(round(area, 0)) + LabelUnit + " ", | |
| ) | |
| plt.legend( | |
| scatterpoints=1, | |
| labelspacing=1, | |
| title=ltitel, | |
| loc="upper left", | |
| shadow=True, | |
| fontsize="x-large", | |
| ) | |
| ax.autoscale(tight=True) | |
| if filename is None: | |
| plt.show() | |
| else: | |
| fig = ax.get_figure() | |
| fig.set_size_inches(10, 8, forward=True) | |
| fig.savefig(filename, dpi=dpi) | |
| plt.close() | |
| def plot_line_expansion(ego, filename=None, dpi=300, column="overnight_costs"): | |
| """Plot line expantion | |
| Parameters | |
| ---------- | |
| ego : :class:`ego.tools.io.eGo` | |
| eGo ``eGo`` inclueds eTraGo and eDisGo results | |
| filename: str | |
| Filename and or path of location to store graphic | |
| dpi: int | |
| dpi value of graphic | |
| column: str | |
| column name of eTraGo's line costs. Default: ``overnight_costs`` in EUR. | |
| Also available ``s_nom_expansion`` in MVA or | |
| annualized ``investment_costs`` in EUR | |
| Returns | |
| ------- | |
| plot :obj:`matplotlib.pyplot.show` | |
| https://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.show | |
| """ | |
| network = ego.etrago.network | |
| json_file = ego.json_file | |
| # get values | |
| if "network" in ego.json_file["eTraGo"]["extendable"]: | |
| network.lines["s_nom_expansion"] = network.lines.s_nom_opt.subtract( | |
| network.lines.s_nom, axis="index" | |
| ) | |
| network.lines["investment_costs"] = network.lines.s_nom_expansion.multiply( | |
| network.lines.capital_cost, axis="index" | |
| ) | |
| network.lines["overnight_costs"] = etrago_convert_overnight_cost( | |
| network.lines["investment_costs"], json_file | |
| ) | |
| else: | |
| network.lines["s_nom_expansion"] = None | |
| network.lines["investment_costs"] = None | |
| network.lines["overnight_costs"] = None | |
| # start plotting | |
| figsize = 10, 8 | |
| fig, ax = plt.subplots(1, 1, figsize=(figsize)) | |
| cmap = plt.cm.jet | |
| if column == "s_nom_expansion": | |
| line_value = network.lines[column] | |
| title = "Line expansion in MVA" | |
| if column == "overnight_costs": | |
| line_value = network.lines[column] | |
| title = "Total Expansion Costs in € per line" | |
| if column == "investment_costs": | |
| line_value = network.lines[column] | |
| title = "Annualized Expansion Costs in € per line and time step" | |
| line_widths = line_value / line_value.max() | |
| lc = network.plot( | |
| ax=ax, | |
| line_colors=line_value, | |
| line_cmap=cmap, | |
| title=title, | |
| line_widths=line_widths, | |
| ) | |
| boundaries = [min(line_value), max(line_value)] | |
| v = np.linspace(boundaries[0], boundaries[1], 101) | |
| print(v.dtype.name) | |
| # colorbar | |
| cb = plt.colorbar(lc[1], boundaries=v, ticks=v[0:101:10], ax=ax) | |
| cb.set_clim(vmin=boundaries[0], vmax=boundaries[1]) | |
| if column == "s_nom_expansion": | |
| cb.set_label("Expansion in MVA per line") | |
| if column == "overnight_costs": | |
| cb.set_label("Total Expansion Costs in € per line") | |
| if column == "investment_costs": | |
| cb.set_label("Annualized Expansion Costs in € per line") | |
| ax.autoscale(tight=True) | |
| if filename is None: | |
| plt.show() | |
| else: | |
| fig = ax.get_figure() | |
| fig.set_size_inches(10, 8, forward=True) | |
| fig.savefig(filename, dpi=dpi) | |
| plt.close() | |
| def plot_grid_storage_investment(costs_df, filename, display, var=None): | |
| """Plot total grid and storage investment. | |
| Parameters | |
| ---------- | |
| costs_df: :pandas:`pandas.DataFrame<dataframe>` | |
| Dataframe containing total_investment_costs of ego | |
| filename: str | |
| Filename and or path of location to store graphic | |
| display: bool | |
| Display plot | |
| var: str | |
| Cost variable of ``overnight_cost`` by default displays annualized | |
| costs of timesteps | |
| Returns | |
| ------- | |
| plot :obj:`matplotlib.pyplot.show` | |
| https://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.show | |
| """ | |
| colors = ego_colore() | |
| bar_width = 0.35 | |
| opacity = 0.4 | |
| if var == "overnight_cost": | |
| tic = costs_df[ | |
| ["component", "overnight_costs", "voltage_level", "differentiation"] | |
| ] | |
| tic.set_index(["voltage_level", "component", "differentiation"], inplace=True) | |
| ax = tic.unstack().plot( | |
| kind="bar", | |
| stacked=False, | |
| rot=0, | |
| color=([colors.get(key) for key in ["egoblue1", "egoblue2", "egoblue4"]]), | |
| legend=False, | |
| ) | |
| ax.set_ylabel("Overnight costs of simulation") | |
| ax.set_title( | |
| "Total costs of simulation, " "voltage level and component", y=1.08 | |
| ) | |
| else: | |
| tic = costs_df[ | |
| ["component", "capital_cost", "voltage_level", "differentiation"] | |
| ] | |
| tic.set_index(["voltage_level", "component", "differentiation"], inplace=True) | |
| ax = tic.unstack().plot( | |
| kind="bar", | |
| rot=0, | |
| stacked=False, | |
| color=([colors.get(key) for key in ["egoblue1", "egoblue2", "egoblue3"]]), | |
| legend=False, | |
| ) | |
| ax.set_ylabel("Annualized costs per simulation periods") | |
| ax.set_title( | |
| "Annualized costs per simulation periods, " "voltage level and component", | |
| y=1.08, | |
| ) | |
| ax.set_xlabel("Voltage level and component") | |
| ax.set_yscale("symlog") | |
| ax.legend(("cross-border", "domestic", "foreign")) | |
| ax.autoscale() | |
| if display is True: | |
| plt.show() | |
| else: | |
| fig = ax.get_figure() | |
| fig.set_size_inches(10, 8, forward=True) | |
| fig.savefig(filename, dpi=100) | |
| plt.close() |
-> in case these are only plotting results from eTraGo, they can be replaced by existing eTraGo plots
Lines 436 to 527 in d121771
| def power_price_plot(ego, filename, display): | |
| """ | |
| Plot power price of calculated scenario of timesteps and carrier | |
| Parameters | |
| ---------- | |
| ego : :class:`ego.tools.io.eGo` | |
| eGo ``eGo`` inclueds eTraGo and eDisGo results | |
| filename: str | |
| Filename and or path of location to store graphic | |
| display: bool | |
| Display plot | |
| Returns | |
| ------- | |
| plot :obj:`matplotlib.pyplot.show` | |
| https://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.show | |
| """ | |
| plt.rcdefaults() | |
| # colors = ego_colore() | |
| carrier_colors = coloring() | |
| fig, ax = plt.subplots() | |
| # plot power_price | |
| prc = ego.etrago.generator["power_price"] | |
| bar_width = 0.35 | |
| opacity = 0.4 | |
| ind = np.arange(len(prc.index)) # the x locations for the groups | |
| width = 0.35 # the width of the bars: can also be len(x) sequence | |
| plt_colors = [carrier_colors[carrier] for carrier in prc.index] | |
| # plt_colors = colors['egoblue1'] | |
| ax.barh(ind, prc, align="center", color=plt_colors) | |
| ax.set_yticks(ind) | |
| ax.set_yticklabels(prc.index) | |
| ax.invert_yaxis() | |
| ax.set_xlabel("Power price in €/MWh") | |
| ax.set_title("Power Costs per Carrier") | |
| ax.autoscale(tight=True) | |
| if display is True: | |
| plt.show() | |
| else: | |
| fig = ax.get_figure() | |
| fig.set_size_inches(10, 8, forward=True) | |
| fig.savefig(filename, dpi=100) | |
| def plot_storage_use(ego, filename, display): | |
| """Plot storage use by charge and discharge values | |
| Parameters | |
| ---------- | |
| ego : :class:`ego.tools.io.eGo` | |
| eGo ``eGo`` inclueds eTraGo and eDisGo results | |
| filename: str | |
| Filename and or path of location to store graphic | |
| display: bool | |
| Display plot | |
| Returns | |
| ------- | |
| plot :obj:`matplotlib.pyplot.show` | |
| https://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.show | |
| """ | |
| colors = ego_colore() | |
| ax = ego.etrago.storage_charges[["charge", "discharge"]].plot( | |
| kind="bar", | |
| title="Storage usage", | |
| stacked=True, | |
| color=([colors.get(key) for key in ["egoblue1", "egoblue2"]]), | |
| figsize=(15, 10), | |
| legend=True, | |
| fontsize=12, | |
| ) | |
| ax.set_xlabel("Kind of Storage", fontsize=12) | |
| ax.set_ylabel("Charge and Discharge in MWh", fontsize=12) | |
| ax.autoscale(tight=False) | |
| if display is True: | |
| plt.show() | |
| else: | |
| fig = ax.get_figure() | |
| fig.set_size_inches(10, 8, forward=True) | |
| fig.subplots_adjust(bottom=0.25) | |
| fig.savefig(filename, dpi=100) |
-> sth like this is currently not part of eTraGo. If we need it, it needs to be adjusted and moved to eTraGo
Lines 530 to 576 in d121771
| def get_country(session, region=None): | |
| """Get Geometries of scenario Countries. | |
| Parameters | |
| ---------- | |
| session : :sqlalchemy:`sqlalchemy.orm.session.Session<orm/session_basics.html>` | |
| SQLAlchemy session to the OEDB | |
| region: list | |
| List of background countries e.g. ['DE', 'DK'] | |
| Returns | |
| ------- | |
| country: ``geopandas.GeoDataFrame`` | |
| GeoDataFrame inclueds MultiPolygon of selected regions or countries | |
| """ | |
| if region is None: | |
| # Define regions 'FR', | |
| region = ["DE", "DK", "BE", "LU", "NO", "PL", "CH", "CZ", "SE", "NL"] | |
| else: | |
| region | |
| # get database tabel | |
| query = session.query( | |
| RenpassGisParameterRegion.gid, | |
| RenpassGisParameterRegion.stat_level, | |
| RenpassGisParameterRegion.u_region_id, | |
| RenpassGisParameterRegion.geom, | |
| RenpassGisParameterRegion.geom_point, | |
| ) | |
| # get regions by query and filter | |
| Regions = [ | |
| (gid, u_region_id, stat_level, shape.to_shape(geom), shape.to_shape(geom_point)) | |
| for gid, u_region_id, stat_level, geom, geom_point in query.filter( | |
| RenpassGisParameterRegion.u_region_id.in_(region) | |
| ).all() | |
| ] | |
| # define SRID | |
| crs = {"init": "epsg:4326"} | |
| country = gpd.GeoDataFrame( | |
| Regions, | |
| columns=["gid", "stat_level", "u_region_id", "geometry", "point_geom"], | |
| crs=crs, | |
| ) | |
| return country |
-> not working anymore, no data from renpass gis, do we need it?
Metadata
Metadata
Assignees
Labels
No labels