diff --git a/premise/clean_datasets.py b/premise/clean_datasets.py index d6b1dc46..7536e08f 100644 --- a/premise/clean_datasets.py +++ b/premise/clean_datasets.py @@ -40,11 +40,10 @@ def remove_uncertainty(database): for dataset in database: for exchange in dataset["exchanges"]: - if not exchange.get("preserve uncertainty", False): - exchange["uncertainty type"] = 0 - exchange["loc"] = exchange["amount"] - for key in uncertainty_keys: - exchange[key] = nan_value + exchange["uncertainty type"] = 0 + exchange["loc"] = exchange["amount"] + for key in uncertainty_keys: + exchange[key] = nan_value return database diff --git a/premise/data/additional_inventories/lci-hydrogen-electrolysis.xlsx b/premise/data/additional_inventories/lci-hydrogen-electrolysis.xlsx index c43bcb8a..73ad2515 100644 Binary files a/premise/data/additional_inventories/lci-hydrogen-electrolysis.xlsx and b/premise/data/additional_inventories/lci-hydrogen-electrolysis.xlsx differ diff --git a/premise/data/fuels/hydrogen_efficiency_parameters.yml b/premise/data/fuels/hydrogen_efficiency_parameters.yml index 7a1f3590..98924b53 100644 --- a/premise/data/fuels/hydrogen_efficiency_parameters.yml +++ b/premise/data/fuels/hydrogen_efficiency_parameters.yml @@ -3,7 +3,7 @@ from electrolysis: var: hydrogen, from electrolysis feedstock name: electricity, low voltage feedstock unit: kilowatt hour - floor value: 48.0 + floor value: 48.9 from SMR of biogas, with CCS: name: hydrogen production, steam methane reforming, from biomethane, with CCS var: hydrogen, from biogas, with CCS diff --git a/premise/external.py b/premise/external.py index 87391dc5..90820dc5 100644 --- a/premise/external.py +++ b/premise/external.py @@ -3,6 +3,7 @@ """ import logging +import math import uuid from collections import defaultdict from functools import lru_cache @@ -1461,6 +1462,19 @@ def relink_to_new_datasets( if isinstance(new_loc, str): new_loc = [(new_loc, 1.0)] + def redefine_loc(e): + if e.get("uncertainty type") in [0, 3, 4]: + return e["amount"] * ratio * share + + elif e.get("uncertainty type") == 5: + return e.get("loc", 0) * (e["amount"] * ratio * share / e["amount"]) + + elif e.get("uncertainty type") == 2: + return math.log(e["amount"] * ratio * share) + + else: + return None + if len(new_loc) > 0: for loc, share in new_loc: # add new exchange @@ -1472,6 +1486,11 @@ def relink_to_new_datasets( "location": loc, "name": new_name, "product": new_ref, + "uncertainty type": exc.get("uncertainty type", 0), + "loc": redefine_loc(exc), + "scale": exc.get("scale", 0) if "scale" in exc else None, + "minimum": exc.get("minimum", 0) * (exc["amount"] * ratio * share / exc["amount"]) if "minimum" in exc else None, + "maximum": exc.get("maximum", 0) * (exc["amount"] * ratio * share / exc["amount"]) if "maximum" in exc else None, } ) diff --git a/premise/transformation.py b/premise/transformation.py index c71443c0..3d5b7a89 100644 --- a/premise/transformation.py +++ b/premise/transformation.py @@ -7,6 +7,7 @@ import copy import logging.config +import math import uuid from collections import defaultdict from collections.abc import ValuesView @@ -46,6 +47,20 @@ logger = logging.getLogger("module") +def redefine_loc(e): + if e.get("uncertainty type") in [0, 3, 4]: + return e["amount"] + + elif e.get("uncertainty type") == 5: + return e["amount"] + + elif e.get("uncertainty type") == 2: + return math.log(e["amount"]) + + else: + return None + + def get_suppliers_of_a_region( database: List[dict], locations: List[str], @@ -1066,16 +1081,8 @@ def relink_datasets(self, excludes_datasets=None, alt_names=None): (exc["name"], exc.get("product"), exc["unit"]) ] = { "uncertainty type": exc.get("uncertainty type", 0), - "loc": ( - exc.get("loc", 0) / exc["amount"] - if exc.get("loc", None) is not None - else None - ), - "scale": ( - exc.get("scale", 0) / exc["amount"] - if exc.get("scale", None) is not None - else None - ), + "loc": redefine_loc(exc) if exc.get("loc") else None, + "scale": exc.get("scale"), "minimum": ( exc.get("minimum", 0) / exc["amount"] if exc.get("minimum", None) is not None @@ -1124,6 +1131,7 @@ def relink_datasets(self, excludes_datasets=None, alt_names=None): exc["uncertainty type"] = old_uncertainty[key][ "uncertainty type" ] + #TODO: fix this for k, v in old_uncertainty[key].items(): if k != "uncertainty type": if v is not None: