Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/#359 add re energy share result #362

Merged
merged 3 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ and this project tries to adhere to [Semantic Versioning](https://semver.org/spe

## [Unreleased]
### Added

- RES share charts and choropleth for user scenario

### Changed


### Fixed
- various fixes in charts, texts and units
- RES share calculation for SQ

## [0.6.0] - 2023-09-01
### Added
Expand Down
7 changes: 7 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,12 @@ def __getitem__(self, item): # noqa: D105, ANN001, ANN204
title=_("Anteil Erneuerbare Energien am Strombedarf"),
unit="%",
),
setup.Choropleth(
"energy_share_2045",
layers=["municipality"],
title=_("Anteil Erneuerbare Energien am Strombedarf"),
unit="%",
),
setup.Choropleth(
"energy_capita_statusquo",
layers=["municipality"],
Expand Down Expand Up @@ -510,6 +516,7 @@ def __getitem__(self, item): # noqa: D105, ANN001, ANN204
"energy_statusquo",
"energy_2045",
"energy_share_statusquo",
"energy_share_2045",
"energy_capita_statusquo",
"energy_capita_2045",
"energy_square_statusquo",
Expand Down
58 changes: 56 additions & 2 deletions digiplan/map/calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,25 @@ def energy_shares_per_municipality() -> pd.DataFrame:
"""
Calculate energy shares of renewables from electric demand per municipality.
Returns
-------
pd.DataFrame
Energy share per municipality (index) and technology (column)
"""
energies = energies_per_municipality()
demands = datapackage.get_power_demand()
total_demand = pd.concat([d["2022"] for d in demands.values()], axis=1).sum(axis=1)
energy_shares = energies.mul(1e3).div(total_demand, axis=0)
return energy_shares.mul(1e2)


def energy_shares_region() -> pd.DataFrame:
"""
Calculate energy shares of renewables from electric demand for region.
Like energy_shares_per_municipality() but with weighted demand for correct
totals.
Returns
-------
pd.DataFrame
Expand All @@ -211,8 +230,8 @@ def energy_shares_per_municipality() -> pd.DataFrame:
demands = datapackage.get_power_demand()
total_demand = pd.concat([d["2022"] for d in demands.values()], axis=1).sum(axis=1)
total_demand_share = total_demand / total_demand.sum()
energies = energies.reindex(range(20))
return energies.mul(total_demand_share, axis=0)
energy_shares = energies.mul(1e3).div(total_demand, axis=0).mul(total_demand_share, axis=0).sum(axis=0)
return energy_shares.mul(1e2)


def electricity_demand_per_municipality(year: int = 2022) -> pd.DataFrame:
Expand All @@ -234,6 +253,41 @@ def electricity_demand_per_municipality(year: int = 2022) -> pd.DataFrame:
return demands_per_sector * 1e-3


def energy_shares_2045_per_municipality(simulation_id: int) -> pd.DataFrame:
"""
Calculate energy shares of renewables from electric demand per municipality in 2045.
Returns
-------
pd.DataFrame
Energy share per municipality (index) and technology (column)
"""
energies = energies_per_municipality_2045(simulation_id).mul(1e-3)
demands = electricity_demand_per_municipality_2045(simulation_id).sum(axis=1)
energy_shares = energies.div(demands, axis=0)
return energy_shares.astype(float).mul(1e2)


def energy_shares_2045_region(simulation_id: int) -> pd.DataFrame:
"""
Calculate energy shares of renewables from electric demand for region in 2045.
Like energy_shares_2045_per_municipality() but with weighted demand for
correct totals.
Returns
-------
pd.DataFrame
Energy share per municipality (index) and technology (column)
"""
energies = energies_per_municipality_2045(simulation_id)
demands = electricity_demand_per_municipality_2045(simulation_id).sum(axis=1).mul(1e3)

demand_share = demands / demands.sum()
energy_shares = energies.div(demands, axis=0).mul(demand_share, axis=0).sum(axis=0)
return energy_shares.astype(float).mul(1e2)


def electricity_demand_per_municipality_2045(simulation_id: int) -> pd.DataFrame:
"""
Calculate electricity demand per sector per municipality in GWh in 2045.
Expand Down
25 changes: 23 additions & 2 deletions digiplan/map/charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,13 +487,13 @@ def get_chart_options(self) -> dict:


class EnergyShareRegionChart(Chart):
"""Chart for regional energy shares."""
"""Calculate RES energy shares for whole region."""

lookup = "capacity"

def get_chart_data(self) -> None:
"""Calculate capacities for whole region."""
return calculations.energy_shares_per_municipality().sum().round(1)
return calculations.energy_shares_region().round(1)

def get_chart_options(self) -> dict:
"""Overwrite title and unit."""
Expand All @@ -503,6 +503,26 @@ def get_chart_options(self) -> dict:
return chart_options


class EnergyShare2045RegionChart(SimulationChart):
"""Chart for regional energy shares."""

lookup = "capacity"

def get_chart_data(self) -> None:
"""Calculate RES energy shares for whole region."""
status_quo_data = calculations.energy_shares_region().round(1)
future_data = calculations.energy_shares_2045_region(self.simulation_id).round(1)
return list(zip(status_quo_data, future_data))

def get_chart_options(self) -> dict:
"""Overwrite title and unit."""
chart_options = super().get_chart_options()
del chart_options["title"]["text"]
chart_options["yAxis"]["name"] = _("%")
chart_options["xAxis"]["data"] = ["2022", "Dein\nSzenario"]
return chart_options


class EnergyCapitaRegionChart(Chart):
"""Chart for regional energy shares per capita."""

Expand Down Expand Up @@ -956,6 +976,7 @@ def get_chart_options(self) -> dict:
"energy_statusquo_region": EnergyRegionChart,
"energy_2045_region": Energy2045RegionChart,
"energy_share_statusquo_region": EnergyShareRegionChart,
"energy_share_2045_region": EnergyShare2045RegionChart,
"energy_capita_statusquo_region": EnergyCapitaRegionChart,
"energy_capita_2045_region": EnergyCapita2045RegionChart,
"energy_square_statusquo_region": EnergySquareRegionChart,
Expand Down
8 changes: 7 additions & 1 deletion digiplan/map/choropleths.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ def render(self) -> JsonResponse:

class EnergyShareChoropleth(Choropleth): # noqa: D101
def get_values_per_feature(self) -> dict[int, float]: # noqa: D102
return calculations.energy_shares_per_municipality().sum(axis=1).to_dict()
return calculations.energy_shares_per_municipality().sum(axis=1).round().to_dict()


class EnergyShare2045Choropleth(Choropleth): # noqa: D101
def get_values_per_feature(self) -> dict[int, float]: # noqa: D102
return calculations.energy_shares_2045_per_municipality(self.map_state["simulation_id"]).sum(axis=1).to_dict()


class EnergyChoropleth(Choropleth): # noqa: D101
Expand Down Expand Up @@ -271,6 +276,7 @@ def get_values_per_feature(self) -> dict[int, float]: # noqa: D102
"energy_statusquo": EnergyChoropleth,
"energy_2045": Energy2045Choropleth,
"energy_share_statusquo": EnergyShareChoropleth,
"energy_share_2045": EnergyShare2045Choropleth,
"energy_capita_statusquo": EnergyCapitaChoropleth,
"energy_capita_2045": EnergyCapita2045Choropleth,
"energy_square_statusquo": EnergySquareChoropleth,
Expand Down
27 changes: 26 additions & 1 deletion digiplan/map/popups.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ class EnergySharePopup(RegionPopup):
title = _("Anteil Energie aus EE")

def get_detailed_data(self) -> pd.DataFrame: # noqa: D102
return calculations.energy_shares_per_municipality()
return calculations.energy_shares_per_municipality().round(1)

def get_chart_options(self) -> dict:
"""Overwrite title and unit."""
Expand All @@ -346,6 +346,30 @@ def get_chart_options(self) -> dict:
return chart_options


class EnergyShare2045Popup(RegionPopup):
"""Popup to show energy shares."""

lookup = "capacity"
title = _("Anteil Energie aus EE")

def get_detailed_data(self) -> pd.DataFrame: # noqa: D102
return calculations.energy_shares_2045_per_municipality(self.map_state["simulation_id"])

def get_chart_options(self) -> dict:
"""Overwrite title and unit."""
chart_options = super().get_chart_options()
chart_options["title"]["text"] = _("Energieanteile pro Technologie")
chart_options["yAxis"]["name"] = _("%")
chart_options["xAxis"]["data"] = ["2022", "Dein Szenario"]
return chart_options

def get_chart_data(self) -> Iterable:
"""Create capacity chart data for SQ and future scenario."""
status_quo_data = calculations.energy_shares_per_municipality().loc[self.selected_id].round(1)
future_data = super().get_chart_data().round(1)
return list(zip(status_quo_data, future_data))


class EnergyCapitaPopup(RegionPopup):
"""Popup to show energy shares per population."""

Expand Down Expand Up @@ -885,6 +909,7 @@ def get_chart_options(self) -> dict:
"energy_statusquo": EnergyPopup,
"energy_2045": Energy2045Popup,
"energy_share_statusquo": EnergySharePopup,
"energy_share_2045": EnergyShare2045Popup,
"energy_capita_statusquo": EnergyCapitaPopup,
"energy_capita_2045": EnergyCapita2045Popup,
"energy_square_statusquo": EnergySquarePopup,
Expand Down
2 changes: 1 addition & 1 deletion digiplan/templates/components/panel_3_results.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ <h2 class="panel-item__heading panel-item__heading--nopadding">
<select id="result_views" class="form-select" aria-label="Default select example">
<option value="" title="{% translate "Keine Auswahl" %}" selected>{% translate "Keine Auswahl" %}</option>
<optgroup label="{% translate "Renewable Energies (RE)" %}">
<option value="re_power_percentage"
<option value="energy_share_2045"
title="{% translate "Annual balance sheet share of renewable energy (wind energy, photovoltaic, hydroelectric power) in the electricity demand of the sectors agriculture, GHG (trade, commerce, services), households and industry in percent. The demand is the net electricity consumption, i.e. transmission losses and power plant consumption are not taken into account. 49.7% of the electricity demand in Germany was covered by renewable energies in 2022." %}">
{% translate "Renewable Energy Share of Demand" %} (%)
</option>
Expand Down