Skip to content

Commit

Permalink
Apply black
Browse files Browse the repository at this point in the history
  • Loading branch information
IlkaCu committed Oct 7, 2021
1 parent ee2b2d0 commit d5db7a5
Show file tree
Hide file tree
Showing 47 changed files with 2,889 additions and 2,013 deletions.
50 changes: 24 additions & 26 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,42 @@
import os

extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.coverage',
'sphinx.ext.doctest',
'sphinx.ext.extlinks',
'sphinx.ext.ifconfig',
'sphinx.ext.napoleon',
'sphinx.ext.todo',
'sphinx.ext.viewcode',
'sphinx.ext.autosectionlabel'
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.coverage",
"sphinx.ext.doctest",
"sphinx.ext.extlinks",
"sphinx.ext.ifconfig",
"sphinx.ext.napoleon",
"sphinx.ext.todo",
"sphinx.ext.viewcode",
"sphinx.ext.autosectionlabel",
]
source_suffix = '.rst'
master_doc = 'index'
project = 'eGo^N Data'
year = '2020-2022'
author = 'Guido Pleßmann, Ilka Cußman, Stephan Günther'
copyright = '{0}, {1}'.format(year, author)
version = release = '0.0.0'
source_suffix = ".rst"
master_doc = "index"
project = "eGo^N Data"
year = "2020-2022"
author = "Guido Pleßmann, Ilka Cußman, Stephan Günther"
copyright = "{0}, {1}".format(year, author)
version = release = "0.0.0"

pygments_style = 'trac'
templates_path = ['.']
pygments_style = "trac"
templates_path = ["."]
extlinks = {
"issue": ("https://github.com/openego/eGon-data/issues/%s", "issue #"),
"pr": ("https://github.com/openego/eGon-data/pull/%s", "PR #"),
}
# on_rtd is whether we are on readthedocs.org
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
on_rtd = os.environ.get("READTHEDOCS", None) == "True"

if not on_rtd: # only set the theme if we're building docs locally
html_theme = 'sphinx_rtd_theme'
html_theme = "sphinx_rtd_theme"

html_use_smartypants = True
html_last_updated_fmt = '%b %d, %Y'
html_last_updated_fmt = "%b %d, %Y"
html_split_index = False
html_sidebars = {
'**': ['searchbox.html', 'globaltoc.html', 'sourcelink.html'],
}
html_short_title = '%s-%s' % (project, version)
html_sidebars = {"**": ["searchbox.html", "globaltoc.html", "sourcelink.html"]}
html_short_title = "%s-%s" % (project, version)

napoleon_use_ivar = True
napoleon_use_rtype = False
Expand Down
8 changes: 2 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,13 @@ def read(*names, **kwargs):
"xarray",
"xlrd",
"rioxarray",
"omi"
"omi",
],
extras_require={
"dev": ["black", "flake8", "isort>=5", "pre-commit", "pytest", "tox"]
# eg:
# 'rst': ['docutils>=0.11'],
# ':python_version=="2.6"': ['argparse'],
},
entry_points={
"console_scripts": [
"egon-data = egon.data.cli:main",
]
},
entry_points={"console_scripts": ["egon-data = egon.data.cli:main"]},
)
22 changes: 11 additions & 11 deletions src/egon/data/airflow/dags/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,7 @@

# Gas grid import
gas_grid_insert_data = PythonOperator(
task_id="insert-gas-grid",
python_callable=gas_grid.insert_gas_data,
task_id="insert-gas-grid", python_callable=gas_grid.insert_gas_data
)

etrago_input_data >> gas_grid_insert_data
Expand All @@ -272,8 +271,7 @@

# Create gas voronoi
create_gas_polygons = PythonOperator(
task_id="create-gas-voronoi",
python_callable=gas_areas.create_voronoi,
task_id="create-gas-voronoi", python_callable=gas_areas.create_voronoi
)

gas_grid_insert_data >> create_gas_polygons
Expand Down Expand Up @@ -328,8 +326,7 @@

# Calculate dynamic line rating for HV trans lines
calculate_dlr = PythonOperator(
task_id="calculate_dlr",
python_callable=dlr.Calculate_DLR,
task_id="calculate_dlr", python_callable=dlr.Calculate_DLR
)
osmtgmod_pypsa >> calculate_dlr
download_data_bundle >> calculate_dlr
Expand Down Expand Up @@ -480,8 +477,11 @@
# CHP to eTraGo
chp_etrago = ChpEtrago(dependencies=[chp, heat_etrago])

# DSM
components_dsm = dsm_Potential(
dependencies = [cts_electricity_demand_annual,
demand_curves_industry,
osmtgmod_pypsa])
# DSM
components_dsm = dsm_Potential(
dependencies=[
cts_electricity_demand_annual,
demand_curves_industry,
osmtgmod_pypsa,
]
)
14 changes: 8 additions & 6 deletions src/egon/data/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@
),
show_default=True,
)

@click.option(
"--compose-project-name",
default="egon-data",
Expand All @@ -133,15 +132,13 @@
),
show_default=True,
)

@click.option(
"--airflow-port",
default=8080,
metavar="AIRFLOW_PORT",
help=("Specify the port on which airflow runs."),
show_default=True,
)

@click.option(
"--random-seed",
default=42,
Expand All @@ -154,7 +151,6 @@
),
show_default=True,
)

@click.version_option(version=egon.data.__version__)
@click.pass_context
def egon_data(context, **kwargs):
Expand Down Expand Up @@ -313,8 +309,14 @@ def render(template, target, update=True, inserts={}, **more_inserts):
)
if code != 0:
subprocess.run(
["docker-compose", "-p", options["--compose-project-name"],
"up", "-d", "--build"],
[
"docker-compose",
"-p",
options["--compose-project-name"],
"up",
"-d",
"--build",
],
cwd=str((Path(".") / "docker").absolute()),
)
time.sleep(1.5) # Give the container time to boot.
Expand Down
2 changes: 1 addition & 1 deletion src/egon/data/datasets/chp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def assign_heat_bus(scenario="eGon2035"):
el_capacity=row.el_capacity,
th_capacity=row.th_capacity,
electrical_bus_id=row.electrical_bus_id,
ch4_bus_id = row.ch4_bus_id,
ch4_bus_id=row.ch4_bus_id,
district_heating_area_id=row.district_heating_area_id,
district_heating=row.district_heating,
voltage_level=row.voltage_level,
Expand Down
2 changes: 1 addition & 1 deletion src/egon/data/datasets/chp/match_nep.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ def insert_large_chp(sources, target, EgonChp):
th_capacity=row.th_capacity,
voltage_level=row.voltage_level,
electrical_bus_id=row.bus_id,
ch4_bus_id = row.gas_bus_id,
ch4_bus_id=row.gas_bus_id,
district_heating=row.district_heating,
scenario="eGon2035",
geom=f"SRID=4326;POINT({row.geometry.x} {row.geometry.y})",
Expand Down
8 changes: 2 additions & 6 deletions src/egon/data/datasets/chp/small_chp.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,18 +254,14 @@ def extension_to_areas(
areas.area_id == selected_areas.area_id.values[0]
],
"demand",
] -= (
selected_chp.th_capacity * flh
)
] -= (selected_chp.th_capacity * flh)
else:
areas.loc[
areas.index[
areas.osm_id == selected_areas.osm_id.values[0]
],
"demand",
] -= (
selected_chp.th_capacity * flh
)
] -= (selected_chp.th_capacity * flh)
areas = areas[areas.demand > 0]

else:
Expand Down
99 changes: 54 additions & 45 deletions src/egon/data/datasets/chp_etrago.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

"""
The central module containing all code dealing with chp for eTraGo.
"""
Expand All @@ -19,6 +18,7 @@ def __init__(self, dependencies):
tasks=(insert),
)


def insert():

sources = config.datasets()["chp_etrago"]["sources"]
Expand All @@ -30,7 +30,8 @@ def insert():
DELETE FROM {targets['link']['schema']}.{targets['link']['table']}
WHERE carrier LIKE '%%CHP%%'
AND scn_name = 'eGon2035'
""")
"""
)

chp_dh = db.select_dataframe(
f"""
Expand All @@ -52,53 +53,59 @@ def insert():
AND NOT district_heating_area_id IS NULL
GROUP BY (
electrical_bus_id, ch4_bus_id, a.carrier, c.bus_id)
""")
"""
)

# Create geodataframes for CHP plants
chp_el = link_geom_from_buses(
gpd.GeoDataFrame(
index=chp_dh.index,
data={
'scn_name': 'eGon2035',
'bus0': chp_dh.ch4_bus_id,
'bus1': chp_dh.electrical_bus_id,
'p_nom': chp_dh.el_capacity,
'carrier': 'urban central gas CHP'
}),
'eGon2035')

chp_el['link_id'] = range(
db.next_etrago_id('link'),
len(chp_el)+db.next_etrago_id('link'))
"scn_name": "eGon2035",
"bus0": chp_dh.ch4_bus_id,
"bus1": chp_dh.electrical_bus_id,
"p_nom": chp_dh.el_capacity,
"carrier": "urban central gas CHP",
},
),
"eGon2035",
)

chp_el["link_id"] = range(
db.next_etrago_id("link"), len(chp_el) + db.next_etrago_id("link")
)

chp_el.to_postgis(
targets["link"]["table"],
schema=targets["link"]["schema"],
con=db.engine(),
if_exists="append")
if_exists="append",
)

chp_heat = link_geom_from_buses(
gpd.GeoDataFrame(
index=chp_dh.index,
data={
'scn_name': 'eGon2035',
'bus0': chp_dh.ch4_bus_id,
'bus1': chp_dh.heat_bus_id,
'p_nom': chp_dh.th_capacity,
'carrier': 'urban central gas CHP heat'
}),
'eGon2035')

chp_heat['link_id'] = range(
db.next_etrago_id('link'),
len(chp_heat)+db.next_etrago_id('link'))
"scn_name": "eGon2035",
"bus0": chp_dh.ch4_bus_id,
"bus1": chp_dh.heat_bus_id,
"p_nom": chp_dh.th_capacity,
"carrier": "urban central gas CHP heat",
},
),
"eGon2035",
)

chp_heat["link_id"] = range(
db.next_etrago_id("link"), len(chp_heat) + db.next_etrago_id("link")
)

chp_heat.to_postgis(
targets["link"]["table"],
schema=targets["link"]["schema"],
con=db.engine(),
if_exists="append")

if_exists="append",
)

chp_industry = db.select_dataframe(
f"""
Expand All @@ -108,28 +115,30 @@ def insert():
WHERE scenario='eGon2035'
AND district_heating_area_id IS NULL
GROUP BY (electrical_bus_id, ch4_bus_id, carrier)
""")
"""
)

chp_el_ind = link_geom_from_buses(
gpd.GeoDataFrame(
index=chp_industry.index,
data={
'scn_name': 'eGon2035',
'bus0': chp_industry.ch4_bus_id,
'bus1': chp_industry.electrical_bus_id,
'p_nom': chp_industry.el_capacity,
'carrier': 'industrial gas CHP'
}),
'eGon2035')

chp_el_ind['link_id'] = range(
db.next_etrago_id('link'),
len(chp_el_ind)+db.next_etrago_id('link'))
"scn_name": "eGon2035",
"bus0": chp_industry.ch4_bus_id,
"bus1": chp_industry.electrical_bus_id,
"p_nom": chp_industry.el_capacity,
"carrier": "industrial gas CHP",
},
),
"eGon2035",
)

chp_el_ind["link_id"] = range(
db.next_etrago_id("link"), len(chp_el_ind) + db.next_etrago_id("link")
)

chp_el_ind.to_postgis(
targets["link"]["table"],
schema=targets["link"]["schema"],
targets["link"]["table"],
schema=targets["link"]["schema"],
con=db.engine(),
if_exists="append")


if_exists="append",
)
3 changes: 2 additions & 1 deletion src/egon/data/datasets/data_bundle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
from pathlib import Path
import shutil


def download():
"""
Download small scale imput data from Zenodo
Parameters
----------
"""
data_bundle_path = Path(".") / 'data_bundle_egon_data'
data_bundle_path = Path(".") / "data_bundle_egon_data"
# Delete folder if it already exists
if data_bundle_path.exists() and data_bundle_path.is_dir():
shutil.rmtree(data_bundle_path)
Expand Down
Loading

0 comments on commit d5db7a5

Please sign in to comment.