Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/pathways' into pathways
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Aug 18, 2024
2 parents 4e8c660 + 0a50d65 commit b72b959
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 40 deletions.
12 changes: 9 additions & 3 deletions premise/electricity.py
Original file line number Diff line number Diff line change
Expand Up @@ -1452,9 +1452,15 @@ def update_efficiency_of_solar_pv(self) -> None:
current_eff = power / max_power

if self.year in module_eff.coords["year"].values:
new_mean_eff = module_eff.sel(technology=pv_tech, year=self.year, efficiency_type="mean").values
new_min_eff = module_eff.sel(technology=pv_tech, year=self.year, efficiency_type="min").values
new_max_eff = module_eff.sel(technology=pv_tech, year=self.year, efficiency_type="max").values
new_mean_eff = module_eff.sel(
technology=pv_tech, year=self.year, efficiency_type="mean"
).values
new_min_eff = module_eff.sel(
technology=pv_tech, year=self.year, efficiency_type="min"
).values
new_max_eff = module_eff.sel(
technology=pv_tech, year=self.year, efficiency_type="max"
).values
else:
new_mean_eff = (
module_eff.sel(technology=pv_tech, efficiency_type="mean")
Expand Down
71 changes: 38 additions & 33 deletions premise/fuels.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ def get_pre_cooling_energy(


def adjust_electrolysis_electricity_requirement(
year: int,
projected_efficiency: dict
year: int, projected_efficiency: dict
) -> [float, float, float]:
"""
Expand Down Expand Up @@ -156,17 +155,23 @@ def adjust_electrolysis_electricity_requirement(
mean = np.interp(
year,
[2020, 2050],
[projected_efficiency[2020]["mean"], projected_efficiency[2050]["mean"]]
[projected_efficiency[2020]["mean"], projected_efficiency[2050]["mean"]],
)
min = np.interp(
year,
[2020, 2050],
[projected_efficiency[2020]["minimum"], projected_efficiency[2050]["minimum"]]
[
projected_efficiency[2020]["minimum"],
projected_efficiency[2050]["minimum"],
],
)
max = np.interp(
year,
[2020, 2050],
[projected_efficiency[2020]["maximum"], projected_efficiency[2050]["maximum"]]
[
projected_efficiency[2020]["maximum"],
projected_efficiency[2050]["maximum"],
],
)

return mean, min, max
Expand Down Expand Up @@ -404,7 +409,6 @@ def __init__(
for activity in activities:
self.rev_fuel_map[activity] = fuel


def find_suppliers(
self,
name: str,
Expand Down Expand Up @@ -504,8 +508,12 @@ def generate_hydrogen_activities(self) -> None:

for fuel_type, dataset_name in self.fuel_map.items():
if fuel_type in hydrogen_parameters:
hydrogen_feedstock_name = hydrogen_parameters[fuel_type].get("feedstock name")
hydrogen_feedstock_unit = hydrogen_parameters[fuel_type].get("feedstock unit")
hydrogen_feedstock_name = hydrogen_parameters[fuel_type].get(
"feedstock name"
)
hydrogen_feedstock_unit = hydrogen_parameters[fuel_type].get(
"feedstock unit"
)
projected_efficiency = hydrogen_parameters[fuel_type].get("efficiency")
floor_value = hydrogen_parameters[fuel_type].get("floor value")

Expand All @@ -531,7 +539,9 @@ def generate_hydrogen_activities(self) -> None:
)

if initial_energy_use is None or initial_energy_use == 0:
print(f"Initial energy consumption for {fuel_type} in {region} is None.")
print(
f"Initial energy consumption for {fuel_type} in {region} is None."
)

# add it to "log parameters"
if "log parameters" not in dataset:
Expand All @@ -550,10 +560,7 @@ def generate_hydrogen_activities(self) -> None:

new_energy_use, min_energy_use, max_energy_use = None, None, None

if (
fuel_type
in self.fuel_efficiencies.variables.values
):
if fuel_type in self.fuel_efficiencies.variables.values:
# Find scaling factor compared to 2020
scaling_factor = 1 / self.find_iam_efficiency_change(
data=self.fuel_efficiencies,
Expand All @@ -566,18 +573,15 @@ def generate_hydrogen_activities(self) -> None:
new_energy_use = scaling_factor * initial_energy_use

# set a floor value/kg H2
new_energy_use = max(
new_energy_use, floor_value
)
new_energy_use = max(new_energy_use, floor_value)

else:
if "from electrolysis" in fuel_type:

# get the electricity consumption
new_energy_use, min_energy_use, max_energy_use = (
adjust_electrolysis_electricity_requirement(
self.year,
projected_efficiency
self.year, projected_efficiency
)
)

Expand All @@ -586,8 +590,7 @@ def generate_hydrogen_activities(self) -> None:
# get the electricity consumption
new_energy_use, min_energy_use, max_energy_use = (
adjust_electrolysis_electricity_requirement(
self.year,
projected_efficiency
self.year, projected_efficiency
)
)

Expand Down Expand Up @@ -629,9 +632,7 @@ def generate_hydrogen_activities(self) -> None:

# add it to "log parameters"
dataset["log parameters"].update(
{
"new energy input for hydrogen production": new_energy_use
}
{"new energy input for hydrogen production": new_energy_use}
)

self.write_log(dataset)
Expand Down Expand Up @@ -680,12 +681,12 @@ def generate_hydrogen_activities(self) -> None:
self.add_to_index(dataset)

datasets = [
"hydrogenation of hydrogen",
"dehydrogenation of hydrogen",
"market group for electricity, low voltage",
"hydrogen embrittlement inhibition",
"hydrogen refuelling station",
]
"hydrogenation of hydrogen",
"dehydrogenation of hydrogen",
"market group for electricity, low voltage",
"hydrogen embrittlement inhibition",
"hydrogen refuelling station",
]

datasets.extend(
[
Expand All @@ -697,7 +698,8 @@ def generate_hydrogen_activities(self) -> None:

datasets.extend(
[
x for k, v in self.fuel_map.items()
x
for k, v in self.fuel_map.items()
for x in v
if k.startswith("hydrogen, from")
]
Expand Down Expand Up @@ -767,7 +769,12 @@ def generate_hydrogen_activities(self) -> None:
# electricity for compression
if state in ["gaseous", "liquid"]:
dataset = self.add_compression_electricity(
state, vehicle, distance, region, dataset, subset
state,
vehicle,
distance,
region,
dataset,
subset,
)

# electricity for hydrogenation, dehydrogenation and
Expand Down Expand Up @@ -2423,10 +2430,8 @@ def generate_fuel_markets(self):
for activity in activities:
self.rev_fuel_map[activity] = fuel


d_fuels = self.get_fuel_mapping()


datasets = [
item
for key in d_fuels
Expand Down
13 changes: 9 additions & 4 deletions premise/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,17 @@ def get_efficiency_solar_photovoltaics() -> xr.DataArray:
EFFICIENCY_RATIO_SOLAR_PV, sep=get_delimiter(filepath=EFFICIENCY_RATIO_SOLAR_PV)
)

dataframe = dataframe.melt(id_vars=["technology", "year"],
value_vars=["mean", "min", "max"],
var_name="efficiency_type", value_name="efficiency")
dataframe = dataframe.melt(
id_vars=["technology", "year"],
value_vars=["mean", "min", "max"],
var_name="efficiency_type",
value_name="efficiency",
)

# Convert the DataFrame to an xarray Dataset
array = dataframe.set_index(["year", "technology", "efficiency_type"])["efficiency"].to_xarray()
array = dataframe.set_index(["year", "technology", "efficiency_type"])[
"efficiency"
].to_xarray()
array = array.interpolate_na(dim="year", method="linear")

return array
Expand Down

0 comments on commit b72b959

Please sign in to comment.