Skip to content

Commit

Permalink
Remove entsoe workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
mfleschutz committed May 22, 2024
1 parent 72bbad6 commit 0c1a67b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 31 deletions.
2 changes: 0 additions & 2 deletions elmada/eu_pwl.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ def get_clean_merit_order_for_min_max_approximation(sort_by_fuel=False) -> pd.Da

@lru_cache(maxsize=3)
def prep_installed_generation_capacity(year=2019, country="DE", source="entsoe") -> pd.Series:

if source == "power_plant_list":
ser = (
from_opsd.merit_order(year=year)[["fuel_draf", "capa"]]
Expand Down Expand Up @@ -210,7 +209,6 @@ def get_share_cc(country: str) -> float:
def discretize_merit_order_per_fuel(
mo_f: pd.DataFrame, country: str, pp_size_method: str = "from_geo_scraped"
) -> pd.DataFrame:

concat_list = []
# if country=="DE":
# pp_size_method = "from_Germany"
Expand Down
34 changes: 9 additions & 25 deletions elmada/from_entsoe.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import entsoe
import numpy as np
import pandas as pd
from entsoe import EntsoePandasClient
from entsoe import mappings as entsoe_mp

from elmada import exceptions
from elmada import helper as hp
Expand All @@ -15,12 +13,6 @@
logger = logging.getLogger(__name__)
logger.setLevel(level=logging.WARN)

# workaround for a bug in entsoe package v0.2.* see https://github.com/EnergieID/entsoe-py/issues/51
entsoe_mp.TIMEZONE_MAPPINGS["IT-NORD-AT"] = "Europe/Rome"
entsoe_mp.TIMEZONE_MAPPINGS["IT-NORD-FR"] = "Europe/Rome"
entsoe_mp.TIMEZONE_MAPPINGS["IT-GR"] = "Europe/Rome"
####################################################


def prep_XEFs(year: int = 2019, freq: str = "60min", country: str = "DE") -> pd.DataFrame:
"""Prepare grid mix emission factors from historic generation."""
Expand Down Expand Up @@ -48,8 +40,8 @@ def prep_XEFs(year: int = 2019, freq: str = "60min", country: str = "DE") -> pd.
return df


def _get_client() -> EntsoePandasClient:
return EntsoePandasClient(api_key=hp.get_api_key("entsoe"))
def _get_client() -> entsoe.EntsoePandasClient:
return entsoe.EntsoePandasClient(api_key=hp.get_api_key("entsoe"))


def _get_timestamps(year: int, tz: str) -> Tuple:
Expand Down Expand Up @@ -138,7 +130,6 @@ def load_el_national_generation(
fillna: bool = True,
resample: bool = True,
) -> pd.DataFrame:

assert year in range(2000, 2100), f"{year} is not a valid year"
assert freq in [None, "15min", "30min", "60min"], f"{freq} is not a valid frequency"
assert country in mp.EUROPE_COUNTRIES
Expand Down Expand Up @@ -173,7 +164,7 @@ def load_el_national_generation(

if fillna:
df = fill_special_missing_data_points_for_gen(df=df, country=country, year=year)
df = df.fillna(method="ffill").fillna(method="bfill")
df = df.fillna().ffill().fillna().bfill()

if resample:
df = hp.resample(df, year=year, start_freq=data_freq, target_freq=freq)
Expand Down Expand Up @@ -237,7 +228,6 @@ def _query_generation_monthly(year, country, client, tz) -> pd.DataFrame:

d = {}
for month in range(1, 13):

start, end = _get_timestamps_for_month(year, tz, month)

try:
Expand Down Expand Up @@ -363,21 +353,21 @@ def prep_dayahead_prices(
resample: bool = True,
) -> pd.Series:
assert year in range(2000, 2100), f"{year} is not a valid year"
assert country in entsoe_mp.BIDDING_ZONES
assert country in entsoe.Area.__dict__

fp = paths.CACHE_DIR / f"{year}_{freq}_{country}_dayahead_c_el_entsoe.parquet"

bidding_zone = get_bidding_zone(country, year)
# bidding_zone = get_bidding_zone(country, year)

if cache and fp.exists():
ser = hp.read(fp)

else:
ser = _query_day_ahead_prices(year, bidding_zone)
ser = _query_day_ahead_prices(year, country)

if cache:
hp.write(ser, fp)

if drop_ducplicates:
ser = ser.groupby(ser.index).first()

Expand Down Expand Up @@ -428,18 +418,12 @@ def get_bidding_zone(country: str, year: int) -> str:
else:
country = "DE-AT-LU"

country_to_bidding = {
"NO": "NO-1",
"DK": "DK-2",
"IT": "IT-NORD",
"SE": "SE-1",
"IE": "IE-SEM",
}
country_to_bidding = {"NO": "NO-1", "DK": "DK-2", "IT": "IT-NORD", "SE": "SE-1", "IE": "IE-SEM"}
return country_to_bidding.get(country, country)


def get_timezone(country: str) -> str:
return entsoe_mp.TIMEZONE_MAPPINGS.get(country, "Europe/Brussels")
return entsoe.mappings.lookup_area(country).tz


#############################
Expand Down
6 changes: 3 additions & 3 deletions elmada/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def resample(
func = downsample

return func(
df=df, year=year, start_freq=start_freq, target_freq=target_freq, aggfunc=aggfunc,
df=df, year=year, start_freq=start_freq, target_freq=target_freq, aggfunc=aggfunc
)


Expand Down Expand Up @@ -284,7 +284,7 @@ def upsample(
"""
df = df.copy()
df.index = make_datetimeindex(year, freq=start_freq)
df = df.resample(target_freq).pad()
df = df.resample(target_freq).ffill()
convert_factor = int_from_freq(start_freq) / int_from_freq(target_freq)
if aggfunc == "sum":
df /= convert_factor
Expand Down Expand Up @@ -360,7 +360,7 @@ def remove_outlier(


def fill_outlier_and_nan(
df: Union[pd.Series, pd.DataFrame], zscore_threshold: int = 3, method: str = "linear",
df: Union[pd.Series, pd.DataFrame], zscore_threshold: int = 3, method: str = "linear"
) -> Union[pd.Series, pd.DataFrame]:

df = remove_outlier(df, zscore_threshold)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
install_requires=[
"appdirs",
"beautifulsoup4",
"entsoe-py==0.2.10",
"entsoe-py",
"ipython",
"lxml",
"matplotlib",
Expand Down

0 comments on commit 0c1a67b

Please sign in to comment.