Skip to content

Commit

Permalink
Merge branch for alternative replacement for datasets previously crea…
Browse files Browse the repository at this point in the history
…ted with partial

Propose alternative replacements for partial.
  • Loading branch information
birgits authored Aug 11, 2023
2 parents af31b60 + 32b93b5 commit e10ab8b
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 35 deletions.
5 changes: 5 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,8 @@

add_module_names = False
modindex_common_prefix = ["egon.data.", "egon.data.datasets."]

autodoc_type_aliases = {
"Dependencies": "egon.data.datasets.Dependencies",
"Tasks": "egon.data.datasets.Tasks"
}
6 changes: 5 additions & 1 deletion src/egon/data/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ def __init__(self, graph: TaskGraph):
)


#: A dataset can depend on other datasets or the tasks of other datasets.
Dependencies = Iterable[Union["Dataset", Task]]


@dataclass
class Dataset:
#: The name of the Dataset
Expand All @@ -176,7 +180,7 @@ class Dataset:
#: downstream of any of the listed dependencies. In case of bare
#: :class:`Task`, a direct link will be created whereas for a
#: :class:`Dataset` the link will be made to all of its last tasks.
dependencies: Iterable[Union[Dataset, Task]] = ()
dependencies: Dependencies = ()
#: The tasks of this :class:`Dataset`. A :class:`TaskGraph` will
#: automatically be converted to :class:`Tasks_`.
tasks: Tasks = ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
assigned to OSM-buildings.
"""
from dataclasses import dataclass

import random

from geoalchemy2 import Geometry
Expand All @@ -14,7 +14,7 @@
import pandas as pd

from egon.data import db
from egon.data.datasets import Dataset, Tasks
from egon.data.datasets import Dataset
from egon.data.datasets.electricity_demand_timeseries.hh_profiles import (
HouseholdElectricityProfilesInCensusCells,
get_iee_hh_demand_profiles_raw,
Expand All @@ -38,7 +38,9 @@ class HouseholdElectricityProfilesOfBuildings(Base):
Mapping of demand timeseries and buildings and cell_id. This table is created within
:py:func:`hh_buildings.map_houseprofiles_to_buildings()`.
"""

__tablename__ = "egon_household_electricity_profile_of_buildings"
__table_args__ = {"schema": "demand"}

Expand Down Expand Up @@ -753,7 +755,6 @@ def map_houseprofiles_to_buildings():
)


@dataclass
class setup(Dataset):
"""
Household electricity demand time series for scenarios in 2035 and 2050
Expand Down Expand Up @@ -850,30 +851,38 @@ class setup(Dataset):
.. code-block:: SQL
SELECT t1.cell_id, building_count, hh_count, hh_types
FROM (
SELECT
cell_id,
Count(distinct(building_id)) as building_count,
count(profile_id) as hh_count
FROM demand.egon_household_electricity_profile_of_buildings
GROUP BY cell_id
) as t1
SELECT t1.cell_id, building_count, hh_count, hh_types FROM (
SELECT
cell_id,
COUNT(DISTINCT(building_id)) AS building_count,
COUNT(profile_id) AS hh_count
FROM demand.egon_household_electricity_profile_of_buildings
GROUP BY cell_id
) AS t1
FULL OUTER JOIN (
SELECT
cell_id,
array_agg(
array[cast(hh_10types as char), hh_type]
) as hh_types
array[CAST(hh_10types AS char), hh_type]
) AS hh_types
FROM society.egon_destatis_zensus_household_per_ha_refined
GROUP BY cell_id
) as t2
) AS t2
ON t1.cell_id = t2.cell_id
"""

#:
name: str = "Demand_Building_Assignment"
#:
version: str = "0.0.5"
#:
tasks: Tasks = (map_houseprofiles_to_buildings, get_building_peak_loads)
tasks = (map_houseprofiles_to_buildings, get_building_peak_loads)

def __init__(self, dependencies):
super().__init__(
name=self.name,
version=self.version,
dependencies=dependencies,
tasks=self.tasks,
)
22 changes: 14 additions & 8 deletions src/egon/data/datasets/mastr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
"""

from dataclasses import dataclass
from pathlib import Path
from urllib.request import urlretrieve
import os

from egon.data.datasets import Dataset, Tasks
from egon.data.datasets import Dataset
import egon.data.config

WORKING_DIR_MASTR_OLD = Path(".", "bnetza_mastr", "dump_2021-05-03")
Expand Down Expand Up @@ -50,7 +49,6 @@ def download(dataset_name, download_dir):
download(dataset_name="mastr_new", download_dir=WORKING_DIR_MASTR_NEW)


@dataclass
class mastr_data_setup(Dataset):
"""
Download Marktstammdatenregister (MaStR) datasets unit registry.
Expand All @@ -59,10 +57,10 @@ class mastr_data_setup(Dataset):
Dump 2021-05-03
* Source: https://sandbox.zenodo.org/record/808086
* Used technologies: PV plants, wind turbines, biomass, hydro plants, combustion,
nuclear, gsgk, storage
* Data is further processed in dataset :py:class:`PowerPlants
<egon.data.datasets.power_plants.PowerPlants>`
* Used technologies: PV plants, wind turbines, biomass, hydro plants,
combustion, nuclear, gsgk, storage
* Data is further processed in the :py:class:`PowerPlants
<egon.data.datasets.power_plants.PowerPlants>` dataset
Dump 2022-11-17
* Source: https://sandbox.zenodo.org/record/1132839
Expand All @@ -81,4 +79,12 @@ class mastr_data_setup(Dataset):
#:
version: str = "0.0.1"
#:
tasks: Tasks = (download_mastr_data,)
tasks = (download_mastr_data,)

def __init__(self, dependencies):
super().__init__(
name=self.name,
version=self.version,
dependencies=dependencies,
tasks=self.tasks,
)
15 changes: 9 additions & 6 deletions src/egon/data/datasets/mv_grid_districts.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
"""

from dataclasses import dataclass

from geoalchemy2.types import Geometry
from sqlalchemy import (
ARRAY,
Expand All @@ -23,7 +21,7 @@
from sqlalchemy.ext.declarative import declarative_base

from egon.data import db
from egon.data.datasets import Dataset, Tasks
from egon.data.datasets import Dataset
from egon.data.datasets.osmtgmod.substation import EgonHvmvSubstation
from egon.data.datasets.substation_voronoi import EgonHvmvSubstationVoronoi
from egon.data.db import session_scope
Expand Down Expand Up @@ -796,7 +794,6 @@ def define_mv_grid_districts():
MvGridDistrictsDissolved.__table__.drop(bind=engine, checkfirst=True)


@dataclass
class mv_grid_districts_setup(Dataset):
"""
Maps MV grid districts to federal states and writes it to database.
Expand Down Expand Up @@ -882,5 +879,11 @@ class mv_grid_districts_setup(Dataset):
name: str = "MvGridDistricts"
#:
version: str = "0.0.2"
#:
tasks: Tasks = define_mv_grid_districts

def __init__(self, dependencies):
super().__init__(
name=self.name,
version=self.version,
dependencies=dependencies,
tasks=define_mv_grid_districts,
)
14 changes: 10 additions & 4 deletions src/egon/data/datasets/re_potential_areas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
potential areas for wind onshore and ground-mounted PV.
"""

from dataclasses import dataclass
from pathlib import Path

from geoalchemy2 import Geometry
Expand All @@ -11,7 +10,7 @@
import geopandas as gpd

from egon.data import db
from egon.data.datasets import Dataset, Tasks
from egon.data.datasets import Dataset
import egon.data.config

Base = declarative_base()
Expand Down Expand Up @@ -121,7 +120,6 @@ def insert_data():
)


@dataclass
class re_potential_area_setup(Dataset):
"""
Downloads potential areas for PV and wind power plants from data bundle and
Expand All @@ -142,4 +140,12 @@ class re_potential_area_setup(Dataset):
#:
version: str = "0.0.1"
#:
tasks: Tasks = (create_tables, insert_data)
tasks = (create_tables, insert_data)

def __init__(self, dependencies):
super().__init__(
name=self.name,
version=self.version,
dependencies=dependencies,
tasks=self.tasks,
)

0 comments on commit e10ab8b

Please sign in to comment.