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

Features/#463 black isort #464

Merged
merged 4 commits into from
Oct 7, 2021
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
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ Changed
`#397 <https://github.com/openego/eGon-data/issues/418>`_
* Rename columns subst_id to bus_id
`#335 <https://github.com/openego/eGon-data/issues/335>`_
* Apply black and isort for all python scripts
`#463 <https://github.com/openego/eGon-data/issues/463>`_


Bug fixes
Expand Down
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
12 changes: 4 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# -*- encoding: utf-8 -*-
from __future__ import absolute_import, print_function

from glob import glob
from os.path import basename, dirname, join, splitext
import io
import re
from glob import glob
from os.path import basename, dirname, join, splitext

from setuptools import find_packages, setup

Expand Down 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"]},
)
66 changes: 28 additions & 38 deletions src/egon/data/airflow/dags/pipeline.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,43 @@
import os

import airflow
import egon.data.datasets.gas_grid as gas_grid
import egon.data.importing.zensus as import_zs
import egon.data.processing.calculate_dlr as dlr
import egon.data.processing.gas_areas as gas_areas
import egon.data.processing.loadarea as loadarea
import egon.data.processing.power_to_h2 as power_to_h2
import egon.data.processing.substation as substation
import importlib_resources as resources
from airflow.operators.postgres_operator import PostgresOperator
from airflow.operators.python_operator import PythonOperator
from airflow.utils.dates import days_ago
import airflow
import importlib_resources as resources

from egon.data import db
from egon.data.datasets import database
from egon.data.datasets.chp import Chp
from egon.data.datasets.chp_etrago import ChpEtrago
from egon.data.datasets.data_bundle import DataBundle
from egon.data.datasets.demandregio import DemandRegio
from egon.data.datasets.district_heating_areas import DistrictHeatingAreas
from egon.data.datasets.electricity_demand import (
CtsElectricityDemand,
HouseholdElectricityDemand,
)
from egon.data.datasets.DSM_cts_ind import dsm_Potential
from egon.data.datasets.electricity_demand import (CtsElectricityDemand,
HouseholdElectricityDemand)
from egon.data.datasets.electricity_demand_etrago import ElectricalLoadEtrago
from egon.data.datasets.era5 import WeatherData
from egon.data.datasets.etrago_setup import EtragoSetup
from egon.data.datasets.gas_prod import CH4Production
from egon.data.datasets.heat_demand import HeatDemandImport
from egon.data.datasets.heat_etrago import HeatEtrago
from egon.data.datasets.heat_supply import HeatSupply
from egon.data.datasets.hh_demand_profiles import (hh_demand_setup,
houseprofiles_in_census_cells,
mv_grid_district_HH_electricity_load)
from egon.data.datasets.industrial_gas_demand import IndustrialGasDemand
from egon.data.datasets.industrial_sites import MergeIndustrialSites
from egon.data.datasets.industry import IndustrialDemandCurves
from egon.data.datasets.mastr import mastr_data_setup
from egon.data.datasets.mv_grid_districts import mv_grid_districts_setup
from egon.data.datasets.osm import OpenStreetMap
from egon.data.datasets.hh_demand_profiles import (
hh_demand_setup,
mv_grid_district_HH_electricity_load,
houseprofiles_in_census_cells,
)
from egon.data.datasets.osmtgmod import Osmtgmod
from egon.data.datasets.power_plants import PowerPlants
from egon.data.datasets.re_potential_areas import re_potential_area_setup
Expand All @@ -44,21 +49,6 @@
from egon.data.datasets.vg250_mv_grid_districts import Vg250MvGridDistricts
from egon.data.datasets.zensus_mv_grid_districts import ZensusMvGridDistricts
from egon.data.datasets.zensus_vg250 import ZensusVg250
from egon.data.datasets.DSM_cts_ind import dsm_Potential

import egon.data.datasets.gas_grid as gas_grid
from egon.data.datasets.industrial_gas_demand import IndustrialGasDemand

import egon.data.importing.zensus as import_
import egon.data.importing.zensus as import_zs
import egon.data.processing.calculate_dlr as dlr
import egon.data.processing.gas_areas as gas_areas
import egon.data.processing.loadarea as loadarea
import egon.data.processing.power_to_h2 as power_to_h2
import egon.data.processing.substation as substation

from egon.data import db


with airflow.DAG(
"egon-data-processing-pipeline",
Expand Down Expand Up @@ -254,8 +244,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 +261,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 +316,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 +467,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,
]
)
30 changes: 16 additions & 14 deletions src/egon/data/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@

Also see (1) from http://click.pocoo.org/5/setuptools/#setuptools-integration
"""
from multiprocessing import Process
from pathlib import Path
import os
import socket
import subprocess
import sys
import time
from multiprocessing import Process
from pathlib import Path

from psycopg2 import OperationalError as PSPGOE
from sqlalchemy import create_engine
from sqlalchemy.exc import OperationalError as SQLAOE
from sqlalchemy.orm import Session
import click
import importlib_resources as resources
import yaml
from psycopg2 import OperationalError as PSPGOE

from egon.data import logger
import egon.data
import egon.data.airflow
import egon.data.config as config
import importlib_resources as resources
from egon.data import logger
from sqlalchemy import create_engine
from sqlalchemy.exc import OperationalError as SQLAOE
from sqlalchemy.orm import Session


@click.group(
Expand Down 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
Loading