Skip to content

Commit

Permalink
Better handle zero values in efficiency variables
Browse files Browse the repository at this point in the history
Fix scenario report generation
  • Loading branch information
romainsacchi committed Dec 13, 2023
1 parent c1083b1 commit b43bb3a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
13 changes: 13 additions & 0 deletions premise/data_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ def __init__(
if any(x in k for x in ["biogas", "methane", "natural gas"])
},
)

self.hydrogen_efficiencies = self.get_iam_efficiencies(
data=data,
efficiency_labels={
Expand Down Expand Up @@ -866,6 +867,12 @@ def get_iam_efficiencies(
eff_data.coords["variables"] = [
rev_eff_labels[x] for x in eff_data.variables.values
]
# convert zero values to nan
# and back-fill and forward-fill missing values with nearest available
eff_data = eff_data.where(eff_data != 0)
eff_data = eff_data.bfill(dim="year")
eff_data = eff_data.ffill(dim="year")

else:
return None

Expand All @@ -883,6 +890,10 @@ def get_iam_efficiencies(
data.loc[:, energy_labels[k], :].sum(dim="variables")
/ data.loc[:, v, :]
)
# back-fill nans
d = d.bfill(dim="year")
# forward-fill nans
d = d.ffill(dim="year")

else:
# fill d with ones
Expand Down Expand Up @@ -1016,6 +1027,7 @@ def __get_carbon_capture_rate(
.sum(dim=["variables", "region"])
.values
)

except ZeroDivisionError:
rate.loc[dict(region="World", variables="cement")] = 0

Expand All @@ -1033,6 +1045,7 @@ def __get_carbon_capture_rate(
].sum(
dim=["variables", "region"]
)

except ZeroDivisionError:
rate.loc[dict(region="World", variables="steel")] = 0

Expand Down
1 change: 1 addition & 0 deletions premise/iam_variables_mapping/cement_variables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ cement, dry feed rotary kiln:
message: Production|Non-Metallic Minerals|Cement
gcam: Production|Industry|Cement
tiam: Production|Cement

energy_use_aliases:
remind: FE|Industry|+++|Cement
image:
Expand Down
10 changes: 10 additions & 0 deletions premise/iam_variables_mapping/iam_region_to_climate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ gcam:
Brazil: tropical
Canada: temperate
Central America and Caribbean: tropical
Central Asia: temperate
China: temperate
Colombia: tropical
EU-15: temperate
EU-12: temperate
India: tropical
Indonesia: tropical
Japan: temperate
Expand All @@ -80,6 +82,14 @@ gcam:
Southeast Asia: tropical
Taiwan: tropical
USA: temperate
Africa_Eastern: tropical
Africa_Southern: tropical
Africa_Western: tropical
Europe_Eastern: temperate
European Free Trade Association: temperate
Europe_Non_EU: temperate
South America_Northern: tropical
South Asia: tropical

tiam:
AFR: tropical
Expand Down
8 changes: 5 additions & 3 deletions premise/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,22 +183,24 @@ def generate_summary_report(scenarios: list, filename: Path) -> None:
},
"Fuel (gasoline) - generation": {
"filepath": IAM_FUELS_VARS,
"filter": ["gasoline", "ethanol"],
"filter": ["gasoline", "ethanol", "bioethanol", "methanol"],
},
"Fuel (gasoline) - efficiency": {
"filepath": IAM_FUELS_VARS,
"filter": ["gasoline", "ethanol"],
"filter": ["gasoline", "ethanol", "bioethanol", "methanol"],
},
"Fuel (diesel) - generation": {
"filepath": IAM_FUELS_VARS,
"filter": [
"diesel",
"biodiesel",
],
},
"Fuel (diesel) - efficiency": {
"filepath": IAM_FUELS_VARS,
"filter": [
"diesel",
"biodiesel",
],
},
"Fuel (gas) - generation": {
Expand Down Expand Up @@ -296,7 +298,7 @@ def generate_summary_report(scenarios: list, filename: Path) -> None:
variables = get_variables(filepath["filepath"])
if "filter" in filepath:
variables = [
x for x in variables if any(y in x for y in filepath["filter"])
x for x in variables if any(x.startswith(y) for y in filepath["filter"])
]

worksheet = workbook.create_sheet(sector)
Expand Down

0 comments on commit b43bb3a

Please sign in to comment.