[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2024-07-18 13:43:38 +00:00
parent 957176a20d
commit 8cc23945b5
2 changed files with 37 additions and 29 deletions

View File

@ -465,7 +465,6 @@ def idees_per_country(ct: str, base_dir: str) -> pd.DataFrame:
assert df.index[61] == "Passenger cars" assert df.index[61] == "Passenger cars"
ct_totals["passenger car efficiency"] = df.iloc[61] ct_totals["passenger car efficiency"] = df.iloc[61]
df = pd.read_excel(fn_transport, "TrRail_ene", index_col=0) df = pd.read_excel(fn_transport, "TrRail_ene", index_col=0)
ct_totals["total rail"] = df.loc["by fuel"] ct_totals["total rail"] = df.loc["by fuel"]
@ -507,7 +506,6 @@ def idees_per_country(ct: str, base_dir: str) -> pd.DataFrame:
assert df.index[9] == "Domestic" assert df.index[9] == "Domestic"
ct_totals["total domestic aviation freight"] = df.iloc[9] ct_totals["total domestic aviation freight"] = df.iloc[9]
assert df.index[10] == "International - Intra-EEAwUK" assert df.index[10] == "International - Intra-EEAwUK"
assert df.index[11] == "International - Extra-EEAwUK" assert df.index[11] == "International - Extra-EEAwUK"
ct_totals["total international aviation freight"] = df.iloc[[10, 11]].sum() ct_totals["total international aviation freight"] = df.iloc[[10, 11]].sum()
@ -679,8 +677,9 @@ def build_energy_totals(
for use in uses: for use in uses:
fuel_use = df[f"electricity {sector} {use}"] fuel_use = df[f"electricity {sector} {use}"]
fuel = (df[f"electricity {sector}"] fuel = (
.replace(0, np.nan).infer_objects(copy=False)) df[f"electricity {sector}"].replace(0, np.nan).infer_objects(copy=False)
)
avg = fuel_use.div(fuel).mean() avg = fuel_use.div(fuel).mean()
logger.debug( logger.debug(
f"{sector}: average fraction of electricity for {use} is {avg:.3f}" f"{sector}: average fraction of electricity for {use} is {avg:.3f}"
@ -811,8 +810,9 @@ def build_energy_totals(
mean_BA = df.loc["BA"].loc[2014:2021, "total residential"].mean() mean_BA = df.loc["BA"].loc[2014:2021, "total residential"].mean()
mean_RS = df.loc["RS"].loc[2014:2021, "total residential"].mean() mean_RS = df.loc["RS"].loc[2014:2021, "total residential"].mean()
ratio = mean_BA / mean_RS ratio = mean_BA / mean_RS
df.loc["BA"] = (df.loc["BA"].replace(0.0, np.nan) df.loc["BA"] = (
.infer_objects(copy=False).values) df.loc["BA"].replace(0.0, np.nan).infer_objects(copy=False).values
)
df.loc["BA"] = df.loc["BA"].combine_first(ratio * df.loc["RS"]).values df.loc["BA"] = df.loc["BA"].combine_first(ratio * df.loc["RS"]).values
return df return df
@ -1394,6 +1394,7 @@ def update_residential_from_eurostat(energy: pd.DataFrame) -> pd.DataFrame:
"Updated energy balances for residential using disaggregate final energy consumption data in Households from Eurostat" "Updated energy balances for residential using disaggregate final energy consumption data in Households from Eurostat"
) )
# %% # %%
if __name__ == "__main__": if __name__ == "__main__":
if "snakemake" not in globals(): if "snakemake" not in globals():

View File

@ -6,23 +6,26 @@
Retrieve and extract JRC IDEES 2021 data. Retrieve and extract JRC IDEES 2021 data.
""" """
import os
import requests
from pathlib import Path
from bs4 import BeautifulSoup
from _helpers import configure_logging, progress_retrieve, set_scenario_config
import zipfile
import logging import logging
import os
import zipfile
from pathlib import Path
import requests
from _helpers import configure_logging, progress_retrieve, set_scenario_config
from bs4 import BeautifulSoup
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
# Define the base URL # Define the base URL
url_jrc = "https://jeodpp.jrc.ec.europa.eu/ftp/jrc-opendata/JRC-IDEES/JRC-IDEES-2021_v1/" url_jrc = (
"https://jeodpp.jrc.ec.europa.eu/ftp/jrc-opendata/JRC-IDEES/JRC-IDEES-2021_v1/"
)
if __name__ == "__main__": if __name__ == "__main__":
if "snakemake" not in globals(): if "snakemake" not in globals():
from _helpers import mock_snakemake from _helpers import mock_snakemake
snakemake = mock_snakemake("retrieve_jrc_idees") snakemake = mock_snakemake("retrieve_jrc_idees")
rootpath = ".." rootpath = ".."
else: else:
@ -40,11 +43,16 @@ if __name__ == "__main__":
# get the list of zip files from the JRC URL # get the list of zip files from the JRC URL
response = requests.get(url_jrc) response = requests.get(url_jrc)
soup = BeautifulSoup(response.text, 'html.parser') soup = BeautifulSoup(response.text, "html.parser")
zip_files = [link.get('href') for link in soup.find_all('a') zip_files = [
if link.get('href').endswith('.zip')] link.get("href")
for link in soup.find_all("a")
if link.get("href").endswith(".zip")
]
logger.info(f"Downloading {len(zip_files)} .zip files for JRC IDEES from '{url_jrc}'.") logger.info(
f"Downloading {len(zip_files)} .zip files for JRC IDEES from '{url_jrc}'."
)
# download and unpack each zip file # download and unpack each zip file
for zip_file in zip_files: for zip_file in zip_files:
@ -52,4 +60,3 @@ if __name__ == "__main__":
zip_url = url_jrc + zip_file zip_url = url_jrc + zip_file
to_fn = local_dir + "/" + zip_file[:-4] to_fn = local_dir + "/" + zip_file[:-4]
progress_retrieve(zip_url, to_fn, disable=disable_progress) progress_retrieve(zip_url, to_fn, disable=disable_progress)