Skip to content

Commit

Permalink
Change variables for MESSAGE
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Oct 11, 2023
1 parent a6c4663 commit a1b25b4
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 87 deletions.
2 changes: 1 addition & 1 deletion premise/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__all__ = ("NewDatabase", "clear_cache", "get_regions_definition")
__version__ = (1, 7, 7)
__version__ = (1, 7, 8)


from .ecoinvent_modification import NewDatabase
Expand Down
167 changes: 84 additions & 83 deletions premise/electricity.py
Original file line number Diff line number Diff line change
Expand Up @@ -1919,105 +1919,106 @@ def adjust_coal_power_plant_emissions(self) -> None:
]

for tech in coal_techs:
datasets = ws.get_many(
self.database,
ws.either(*[ws.contains("name", n) for n in self.powerplant_map[tech]]),
ws.equals("unit", "kilowatt hour"),
ws.doesnt_contain_any("name", ["mine", "critical"]),
)

for dataset in datasets:
loc = dataset["location"][:2]
if loc in self.iam_data.coal_power_plants.country.values:
# Find current efficiency
ei_eff = self.find_fuel_efficiency(
dataset, self.powerplant_fuels_map[tech], 3.6
)
if tech in self.powerplant_map:
datasets = ws.get_many(
self.database,
ws.either(*[ws.contains("name", n) for n in self.powerplant_map[tech]]),
ws.equals("unit", "kilowatt hour"),
ws.doesnt_contain_any("name", ["mine", "critical"]),
)

new_eff = self.iam_data.coal_power_plants.sel(
country=loc,
fuel="Anthracite coal"
if "hard coal" in dataset["name"]
else "Lignite coal",
CHP=True if "co-generation" in dataset["name"] else False,
variable="efficiency",
)
for dataset in datasets:
loc = dataset["location"][:2]
if loc in self.iam_data.coal_power_plants.country.values:
# Find current efficiency
ei_eff = self.find_fuel_efficiency(
dataset, self.powerplant_fuels_map[tech], 3.6
)

if not np.isnan(new_eff.values.item(0)):
wurst.change_exchanges_by_constant_factor(
dataset,
ei_eff / new_eff.values.item(0),
new_eff = self.iam_data.coal_power_plants.sel(
country=loc,
fuel="Anthracite coal"
if "hard coal" in dataset["name"]
else "Lignite coal",
CHP=True if "co-generation" in dataset["name"] else False,
variable="efficiency",
)

if "log parameters" not in dataset:
dataset["log parameters"] = {}
if not np.isnan(new_eff.values.item(0)):
wurst.change_exchanges_by_constant_factor(
dataset,
ei_eff / new_eff.values.item(0),
)

dataset["log parameters"].update(
{
f"ecoinvent original efficiency": ei_eff,
f"Oberschelp et al. efficiency": new_eff.values.item(0),
f"efficiency change": ei_eff / new_eff.values.item(0),
}
)
if "log parameters" not in dataset:
dataset["log parameters"] = {}

self.update_ecoinvent_efficiency_parameter(
dataset, ei_eff, new_eff.values.item(0)
)
dataset["log parameters"].update(
{
f"ecoinvent original efficiency": ei_eff,
f"Oberschelp et al. efficiency": new_eff.values.item(0),
f"efficiency change": ei_eff / new_eff.values.item(0),
}
)

substances = [
("CO2", "Carbon dioxide, fossil"),
("SO2", "Sulfur dioxide"),
("CH4", "Methane, fossil"),
("NOx", "Nitrogen oxides"),
("PM <2.5", "Particulate Matter, < 2.5 um"),
("PM 10 - 2.5", "Particulate Matter, > 2.5 um and < 10um"),
("PM > 10", "Particulate Matter, > 10 um"),
]
self.update_ecoinvent_efficiency_parameter(
dataset, ei_eff, new_eff.values.item(0)
)

for substance in substances:
species, flow = substance
substances = [
("CO2", "Carbon dioxide, fossil"),
("SO2", "Sulfur dioxide"),
("CH4", "Methane, fossil"),
("NOx", "Nitrogen oxides"),
("PM <2.5", "Particulate Matter, < 2.5 um"),
("PM 10 - 2.5", "Particulate Matter, > 2.5 um and < 10um"),
("PM > 10", "Particulate Matter, > 10 um"),
]

emission_factor = self.iam_data.coal_power_plants.sel(
country=loc,
fuel="Anthracite coal"
if "hard coal" in dataset["name"]
else "Lignite coal",
CHP=True if "co-generation" in dataset["name"] else False,
variable=species,
) / (
self.iam_data.coal_power_plants.sel(
for substance in substances:
species, flow = substance

emission_factor = self.iam_data.coal_power_plants.sel(
country=loc,
fuel="Anthracite coal"
if "hard coal" in dataset["name"]
else "Lignite coal",
CHP=True
if "co-generation" in dataset["name"]
else False,
variable="generation",
CHP=True if "co-generation" in dataset["name"] else False,
variable=species,
) / (
self.iam_data.coal_power_plants.sel(
country=loc,
fuel="Anthracite coal"
if "hard coal" in dataset["name"]
else "Lignite coal",
CHP=True
if "co-generation" in dataset["name"]
else False,
variable="generation",
)
* 1e3
)
* 1e3
)

if not np.isnan(emission_factor.values.item(0)):
for exc in ws.biosphere(dataset):
if exc["name"] == flow:
scaling_factor = (
emission_factor.values.item(0) / exc["amount"]
)
exc["amount"] = float(
emission_factor.values.item(0)
)

if "log parameters" not in dataset:
dataset["log parameters"] = {}

dataset["log parameters"].update(
{
f"{species} scaling factor": scaling_factor,
}
)
if not np.isnan(emission_factor.values.item(0)):
for exc in ws.biosphere(dataset):
if exc["name"] == flow:
scaling_factor = (
emission_factor.values.item(0) / exc["amount"]
)
exc["amount"] = float(
emission_factor.values.item(0)
)

if "log parameters" not in dataset:
dataset["log parameters"] = {}

dataset["log parameters"].update(
{
f"{species} scaling factor": scaling_factor,
}
)

self.write_log(dataset=dataset, status="updated")
self.write_log(dataset=dataset, status="updated")

def create_missing_power_plant_datasets(self) -> None:
"""
Expand Down
1 change: 1 addition & 0 deletions premise/iam_variables_mapping/electricity_variables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,7 @@ Wave:
Storage, Flow Battery:
iam_aliases:
image: Secondary Energy|Electricity|Storage
message: Secondary Energy|Electricity|Storage
ecoinvent_aliases:
fltr:
- electricity supply, high voltage, from vanadium-redox flow battery system
Expand Down
4 changes: 2 additions & 2 deletions premise/iam_variables_mapping/fuels_variables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ diesel:
iam_aliases:
remind: SE|Liquids|Fossil|+|Oil
image: Secondary Energy|Consumption|Liquids|Fossil
message: Secondary Energy|Liquids|Oil
message: Secondary Energy|Liquids|Oil|Fuel
eff_aliases:
remind: Tech|Liquids|Fossil|Oil|Efficiency
ecoinvent_aliases:
Expand Down Expand Up @@ -268,7 +268,7 @@ gasoline:
iam_aliases:
remind: SE|Liquids|Fossil|+|Oil
image: Secondary Energy|Consumption|Liquids|Fossil
message: Secondary Energy|Liquids|Oil
message: Secondary Energy|Liquids|Oil|Fuel
eff_aliases:
remind: Tech|Liquids|Fossil|Oil|Efficiency
ecoinvent_aliases:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def package_files(directory):

setup(
name="premise",
version="1.7.7",
version="1.7.8",
python_requires=">=3.9,<3.11",
packages=packages,
author="Romain Sacchi <[email protected]>, Alois Dirnaichner <[email protected]>, Chris Mutel "
Expand Down

0 comments on commit a1b25b4

Please sign in to comment.