Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 15, 2023
1 parent dd998fe commit 49abb1f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion data/AL_production.csv
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ GR,184,2019,https://en.wikipedia.org/wiki/List_of_countries_by_aluminium_product
SE,126,2019,https://en.wikipedia.org/wiki/List_of_countries_by_aluminium_production
VE,108,2019,https://en.wikipedia.org/wiki/List_of_countries_by_aluminium_production
NG,0,2019
BJ,0,2019
BJ,0,2019
2 changes: 1 addition & 1 deletion scripts/build_base_energy_totals.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def calc_sector(sector):

# Get the files from the path provided in the OP
all_files = list(Path("data/demand/unsd/data").glob("*.txt"))

# Create a dataframe from all downloaded files
df = pd.concat(
(pd.read_csv(f, encoding="utf8", sep=";") for f in all_files), ignore_index=True
Expand Down
5 changes: 3 additions & 2 deletions scripts/build_base_industry_totals.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def create_industry_base_totals(df):
# Converting values of mass (ktons) to energy (TWh)
index_mass = df.loc[df["Unit"] == "Metric tons, thousand"].index
df.loc[index_mass, "Quantity_TWh"] = df.loc[index_mass].apply(
lambda x: x["Quantity"] * fuels_conv_toTWh.get(x["Commodity"], "not found"), axis=1
lambda x: x["Quantity"] * fuels_conv_toTWh.get(x["Commodity"], "not found"),
axis=1,
)

# Converting values of energy (GWh) to energy (TWh)
Expand Down Expand Up @@ -156,7 +157,7 @@ def create_industry_base_totals(df):

# Get the files from the path provided in the OP
all_files = list(Path(snakemake.input["unsd_path"]).glob("*.txt"))

# Create a dataframe from all downloaded files
df = pd.concat(
(pd.read_csv(f, encoding="utf8", sep=";") for f in all_files), ignore_index=True
Expand Down
18 changes: 13 additions & 5 deletions scripts/build_industry_demand.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,26 +220,34 @@ def match_technology(df):
pass # Code to handle the KeyError
industry_base_totals = industry_base_totals.sort_index()

all_carriers = ["electricity", "gas", "coal", "oil", "hydrogen", "biomass", "low-temperature heat"]
all_carriers = [
"electricity",
"gas",
"coal",
"oil",
"hydrogen",
"biomass",
"low-temperature heat",
]

for country in countries:
carriers_present = industry_base_totals.xs(country, level='country').index
carriers_present = industry_base_totals.xs(country, level="country").index
missing_carriers = set(all_carriers) - set(carriers_present)
for carrier in missing_carriers:
# Add the missing carrier with a value of 0
industry_base_totals.loc[(country, carrier), :] = 0


nodal_df = pd.DataFrame()

for country in countries:
nodal_production_tom_co = nodal_production_tom[nodal_production_tom.index.to_series().str.startswith(country)]
nodal_production_tom_co = nodal_production_tom[
nodal_production_tom.index.to_series().str.startswith(country)
]
industry_base_totals_co = industry_base_totals.loc[country]
# final energy consumption per node and industry (TWh/a)
nodal_df_co = nodal_production_tom_co.dot(industry_base_totals_co.T)
nodal_df = pd.concat([nodal_df, nodal_df_co])


rename_sectors = {
"elec": "electricity",
"biomass": "solid biomass",
Expand Down
6 changes: 4 additions & 2 deletions scripts/prepare_sector_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -2428,9 +2428,11 @@ def add_rail_transport(n, costs):
# TODO follow the same structure as land transport and heat

# Load industry demand data
industrial_demand = pd.read_csv(snakemake.input.industrial_demand, index_col=0, header=0) # * 1e6
industrial_demand = pd.read_csv(
snakemake.input.industrial_demand, index_col=0, header=0
) # * 1e6

#industrial_demand.set_index("TWh/a (MtCO2/a)", inplace=True)
# industrial_demand.set_index("TWh/a (MtCO2/a)", inplace=True)

##########################################################################
############## Functions adding different carrires and sectors ###########
Expand Down

0 comments on commit 49abb1f

Please sign in to comment.