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

Fix/#368 power capacities in datapackage and app differ #370

Merged
merged 6 commits into from
Sep 27, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project tries to adhere to [Semantic Versioning](https://semver.org/spe
- swap mapping of PV roof and PV ground in result calculation
- heat per capita calculation in results
- round chart values to decent fps
- diverging capacities in digipipe datapackage and app due to operational status

## [0.6.0] - 2023-09-01
### Added
Expand Down
25 changes: 5 additions & 20 deletions digiplan/map/calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import pandas as pd
from django.conf import settings
from django.db.models import Sum
from django.utils.translation import gettext_lazy as _
from django_oemof.models import Simulation
from django_oemof.results import get_results
Expand Down Expand Up @@ -110,21 +109,7 @@ def capacities_per_municipality() -> pd.DataFrame:
pd.DataFrame
Capacity per municipality (index) and technology (column)
"""
capacities = []
for technology in (
models.WindTurbine,
models.PVroof,
models.PVground,
models.Hydro,
models.Biomass,
models.Storage,
):
res_capacity = pd.DataFrame.from_records(
technology.objects.values("mun_id").annotate(capacity=Sum("capacity_net")).values("mun_id", "capacity"),
).set_index("mun_id")
res_capacity.columns = [technology._meta.verbose_name] # noqa: SLF001
capacities.append(res_capacity)
return pd.concat(capacities, axis=1).fillna(0.0) * 1e-3
return datapackage.get_capacities_from_datapackage()


def capacities_per_municipality_2045(simulation_id: int) -> pd.DataFrame:
Expand Down Expand Up @@ -165,8 +150,8 @@ def energies_per_municipality() -> pd.DataFrame:
Energy per municipality (index) and technology (column)
"""
capacities = capacities_per_municipality()
full_load_hours = datapackage.get_full_load_hours(year=2022)
full_load_hours = full_load_hours.reindex(index=["wind", "pv_roof", "pv_ground", "ror", "bioenergy", "st"])
full_load_hours = datapackage.get_full_load_hours(year=2022).drop("st").rename({"ror": "hydro"})
full_load_hours = full_load_hours.reindex(index=["wind", "pv_roof", "pv_ground", "hydro", "bioenergy"])
return capacities * full_load_hours.values / 1e3


Expand Down Expand Up @@ -600,7 +585,7 @@ def electricity_overview(year: int) -> pd.Series:
containing electricity productions and demands (including heat sector demand for electricity)
"""
demand = electricity_demand_per_municipality(year).sum()
production = datapackage.get_full_load_hours(year) * datapackage.get_capacities(year)
production = datapackage.get_full_load_hours(year) * datapackage.get_capacities_from_sliders(year)
production = production[production.notna()] * 1e-3
return pd.concat([demand, production])

Expand Down Expand Up @@ -685,7 +670,7 @@ def get_regional_independency(simulation_id: int) -> tuple[int, int, int, int]:
# 2022
demand = datapackage.get_hourly_electricity_demand(2022)
full_load_hours = datapackage.get_full_load_hours(2022)
capacities = datapackage.get_capacities(2022)
capacities = datapackage.get_capacities_from_sliders(2022)
technology_mapping = {
"ABW-wind-onshore": "wind",
"ABW-solar-pv_ground": "pv_ground",
Expand Down
21 changes: 19 additions & 2 deletions digiplan/map/datapackage.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,25 @@ def get_full_load_hours(year: int) -> pd.Series:
return full_load_hours


def get_capacities(year: int) -> pd.Series:
"""Return renewable capacities for given year."""
def get_capacities_from_datapackage() -> pd.DataFrame:
"""Return renewable capacities for given year from datapackage."""
capacities = pd.concat(
[
pd.read_csv(
settings.DIGIPIPE_DIR.path("scalars").path(f"bnetza_mastr_{tech}_stats_muns.csv"),
index_col="municipality_id",
usecols=["municipality_id", "capacity_net"],
).rename(columns={"capacity_net": tech})
for tech in ["wind", "pv_roof", "pv_ground", "hydro", "biomass"]
],
axis=1,
)
capacities.index.name = "mun_id"
return capacities


def get_capacities_from_sliders(year: int) -> pd.Series:
"""Return renewable capacities for given year from slider settings (totals for each technology)."""
if year == 2022: # noqa: PLR2004
lookup = "status_quo"
elif year == 2045: # noqa: PLR2004
Expand Down