diff --git a/bw2io/__init__.py b/bw2io/__init__.py index 11e77c1..52ca8c8 100644 --- a/bw2io/__init__.py +++ b/bw2io/__init__.py @@ -44,7 +44,7 @@ "SingleOutputEcospold2Importer", "unlinked_data", "UnlinkedData", - "useeio11", + "useeio20", ] from .version import version as __version__ @@ -164,9 +164,9 @@ def bw2setup(): create_core_migrations() -def useeio11(name="USEEIO-1.1", collapse_products=False, prune=False): +def useeio20(name="USEEIO-2.0", collapse_products=False, prune=False): """""" - URL = "https://www.lcacommons.gov/lca-collaboration/ws/public/download/json/repository_US_Environmental_Protection_Agency@USEEIO" + URL = "https://www.lcacommons.gov/lca-collaboration/ws/public/download/json/repository_US_Environmental_Protection_Agency@USEEIO_v2" if name in databases: print(f"{name} already present") @@ -182,7 +182,7 @@ def useeio11(name="USEEIO-1.1", collapse_products=False, prune=False): with tempfile.TemporaryDirectory() as td: dp = Path(td) - print("Downloading US EEIO 1.1") + print("Downloading US EEIO 2.0") filepath = Path(download_with_progressbar(URL, dirpath=td)) print("Unzipping file") diff --git a/bw2io/importers/json_ld.py b/bw2io/importers/json_ld.py index 0c04744..4abc5ce 100644 --- a/bw2io/importers/json_ld.py +++ b/bw2io/importers/json_ld.py @@ -117,23 +117,23 @@ def write_separate_biosphere_database(self): self.write_database(data=self.biosphere_database, db_name=db_name) def flows_as_biosphere_database(self, data, database_name, suffix=" biosphere"): - def boolcheck(lst): - return tuple([elem for elem in lst if elem is not None]) - - category_mapping = { - obj["@id"]: boolcheck( - obj.get("category", {}).get("categoryPath", []) - + [obj.get("category", {}).get("name")] - + [obj["name"]] - ) - for obj in data["categories"].values() - } + # def boolcheck(lst): + # return tuple([elem for elem in lst if elem is not None]) + + # category_mapping = { + # obj["@id"]: boolcheck( + # obj.get("category", {}).get("categoryPath", []) + # + [obj.get("category", {}).get("name")] + # + [obj["name"]] + # ) + # for obj in data["categories"].values() + # } return [ { "code": obj["@id"], "name": obj["name"], - "categories": category_mapping[obj["category"]["@id"]], + "categories": obj.get("category", "Unknown").split("/"), "CAS number": obj.get("cas"), "database": database_name + suffix, "exchanges": [], @@ -145,23 +145,23 @@ def boolcheck(lst): ] def flows_as_products(self, data): - def boolcheck(lst): - return tuple([elem for elem in lst if elem is not None]) - - category_mapping = { - obj["@id"]: boolcheck( - obj.get("category", {}).get("categoryPath", []) - + [obj.get("category", {}).get("name")] - + [obj["name"]] - ) - for obj in data["categories"].values() - } + # def boolcheck(lst): + # return tuple([elem for elem in lst if elem is not None]) + + # category_mapping = { + # obj["@id"]: boolcheck( + # obj.get("category", {}).get("categoryPath", []) + # + [obj.get("category", {}).get("name")] + # + [obj["name"]] + # ) + # for obj in data["categories"].values() + # } return [ { "code": obj["@id"], "name": obj["name"], - "categories": category_mapping[obj["category"]["@id"]], + "categories": obj.get("category", "Unknown").split("/"), "location": obj["location"]["name"] if "location" in obj else None, "exchanges": [], "unit": "", diff --git a/bw2io/strategies/json_ld.py b/bw2io/strategies/json_ld.py index 27add8d..d7a9254 100644 --- a/bw2io/strategies/json_ld.py +++ b/bw2io/strategies/json_ld.py @@ -232,7 +232,7 @@ def json_ld_add_activity_unit(db): production_exchanges = [ exc for exc in ds["exchanges"] - if exc["flow"]["flowType"] == "PRODUCT_FLOW" and not exc["input"] + if exc["flow"]["flowType"] == "PRODUCT_FLOW" and not exc.get("isInput") ] assert len(production_exchanges) == 1, "Failed allocation" ds["unit"] = production_exchanges[0]["unit"] @@ -514,7 +514,7 @@ def json_ld_label_exchange_type(db): if exc.get("input"): raise ValueError("Avoided products are outputs, not inputs") exc["type"] = "substitution" - elif exc["input"]: + elif exc.get("isInput"): if not exc.get("flow", {}).get("flowType") == "PRODUCT_FLOW": raise ValueError("Inputs must be products") exc["type"] = "technosphere" diff --git a/tests/useeio.py b/tests/useeio.py index e1f6b58..13556fe 100644 --- a/tests/useeio.py +++ b/tests/useeio.py @@ -2,13 +2,13 @@ import pytest from bw2data.tests import bw2test -from bw2io import useeio11 +from bw2io import useeio20 @pytest.mark.slow @bw2test def test_useeio_import(): - useeio11("foo") + useeio20("foo") assert "foo" in bd.databases assert len(bd.Database("foo")) > 2000 @@ -16,7 +16,7 @@ def test_useeio_import(): @pytest.mark.slow @bw2test def test_useeio_import_collapse_products(): - useeio11("foo", collapse_products=True) + useeio20("foo", collapse_products=True) assert "foo" in bd.databases assert len(bd.Database("foo")) > 2000 assert not sum(1 for ds in bd.Database("foo") if ds["type"] == "product") @@ -34,7 +34,7 @@ def test_useeio_import_collapse_products(): @pytest.mark.slow @bw2test def test_useeio_import_prune(): - useeio11("foo", collapse_products=True, prune=True) + useeio20("foo", collapse_products=True, prune=True) assert "foo" in bd.databases assert len(bd.Database("foo")) > 2000 assert not sum(1 for ds in bd.Database("foo") if ds["type"] == "product")