Skip to content

Commit

Permalink
Add fuels validation
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Oct 12, 2024
1 parent 67fbefa commit 4aca8bb
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
12 changes: 12 additions & 0 deletions premise/fuels.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
ws,
)
from .utils import get_crops_properties, rescale_exchanges
from .validation import FuelsValidation

logger = create_logger("fuel")

Expand Down Expand Up @@ -314,6 +315,17 @@ def _update_fuels(scenario, version, system_model):
else:
print("No fuel markets found in IAM data. Skipping.")

validate = FuelsValidation(
model=scenario["model"],
scenario=scenario["pathway"],
year=scenario["year"],
regions=scenario["iam data"].regions,
database=fuels.database,
iam_data=scenario["iam data"],
)

validate.run_fuel_checks()

return scenario


Expand Down
84 changes: 84 additions & 0 deletions premise/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1401,6 +1401,90 @@ def run_electricity_checks(self):
self.check_efficiency()
self.save_log()

class FuelsValidation(BaseDatasetValidator):
def __init__(self, model, scenario, year, regions, database, iam_data):
super().__init__(model, scenario, year, regions, database)
self.iam_data = iam_data

def check_fuel_market_composition(self):
# check that the fuel markets inputs
# equal to 1

fuel_market_names = [
"market for petrol, low-sulfur",
"market for diesel, low-sulfur",
"market for natural gas, high pressure",
"market for hydrogen, gaseous",
"market for kerosene",
"market for liquefied petroleum gas"
]

for ds in self.database:
if (
any(ds["name"].startswith(x) for x in fuel_market_names)
and ds["location"] in self.regions
and ds["location"] != "World"
):
if ds["unit"] == "cubic meter":

total = sum(
[
x["amount"] if x["unit"] == "cubic meter" else x["amount"] / 0.74
for x in ds["exchanges"]
if x["type"] == "technosphere"
and x["unit"] in ("kilogram", "cubic meter")
]
)

else:
total = sum(
[
x["amount"]
for x in ds["exchanges"]
if x["type"] == "technosphere" and x["unit"] in ("kilogram", "cubic meter")
]
)
if total < 0.99 or total > 1.1:
message = f"Fuel market inputs sum to {total}."
self.log_issue(
ds,
"fuel market inputs do not sum to 1",
message,
issue_type="major",
)

def check_electrolysis_electricity_input(self):
# check that the input of electricity for hydrogen production
# is within the expected range

for ds in self.database:
if (
ds["name"].startswith("hydrogen production")
and "electrolysis" in ds["name"]
and ds["location"] in self.regions
):
electricity = sum(
[
x["amount"]
for x in ds["exchanges"]
if x["type"] == "technosphere"
and x["unit"] == "kilowatt hour"
]
)
if electricity < 40 or electricity > 60:
message = f"Electricity use for hydrogen production is {electricity}."
self.log_issue(
ds,
"electricity use for hydrogen production",
message,
issue_type="major",
)

def run_fuel_checks(self):
self.check_fuel_market_composition()
self.check_electrolysis_electricity_input()
self.save_log()


class SteelValidation(BaseDatasetValidator):
def __init__(self, model, scenario, year, regions, database, iam_data):
Expand Down

0 comments on commit 4aca8bb

Please sign in to comment.