diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index 2df3128..5e3cdeb 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -15,6 +15,8 @@ on: - "**.ya?ml" # captures both .yml and .yaml - "LICENSE" - ".gitignore" + - "**.ipynb" # ignore Jupyter notebooks + pull_request: branches: [main, dev] types: [opened, reopened] # excludes syncronize to avoid redundant trigger from commits on PRs @@ -24,6 +26,7 @@ on: - "**.ya?ml" - "LICENSE" - ".gitignore" + - "**.ipynb" # ignore Jupyter notebooks workflow_dispatch: # also allow manual trigger, for testing purposes jobs: @@ -32,6 +35,8 @@ jobs: strategy: fail-fast: false matrix: + os: [ubuntu-latest] # , windows-latest, macos-latest + py-version: ["3.10", "3.11", "3.12"] os: [ubuntu-latest, windows-latest, macos-latest] py-version: ["3.10"] @@ -47,7 +52,7 @@ jobs: # Create the conda environment - name: Create conda environment - run: conda env create -f timex-environment.yaml + run: conda create -n timex -c conda-forge -c cmutel brightway25 bw_temporalis matplotlib seaborn # Install testing dependencies from pyproject.toml - name: Install testing dependencies diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..36ce426 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,75 @@ +exclude: '^docs/conf.py' + +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: trailing-whitespace + - id: check-added-large-files + - id: check-ast + - id: check-json + - id: check-merge-conflict + - id: check-xml + - id: check-yaml + - id: debug-statements + - id: end-of-file-fixer + - id: requirements-txt-fixer + - id: mixed-line-ending + args: ['--fix=auto'] # replace 'auto' with 'lf' to enforce Linux/Mac line endings or 'crlf' for Windows + +## If you want to avoid flake8 errors due to unused vars or imports: +# - repo: https://github.com/myint/autoflake +# rev: v1.4 +# hooks: +# - id: autoflake +# args: [ +# --in-place, +# --remove-all-unused-imports, +# --remove-unused-variables, +# ] + +# https://github.com/PyCQA/flake8/issues/234 +- repo: https://github.com/john-hen/Flake8-pyproject + rev: 1.2.3 + hooks: + - id: Flake8-pyproject + +- repo: https://github.com/pycqa/isort + rev: 5.13.2 + hooks: + - id: isort + args: [--settings-path=pyproject.toml] + +- repo: https://github.com/psf/black + rev: 24.1.1 + hooks: + - id: black + args: [--config=pyproject.toml] + +## If like to embrace black styles even in the docs: +# - repo: https://github.com/asottile/blacken-docs +# rev: v1.12.0 +# hooks: +# - id: blacken-docs +# additional_dependencies: [black] + +- repo: https://github.com/PyCQA/flake8 + rev: 7.0.0 + hooks: + - id: flake8 + additional_dependencies: [Flake8-pyproject] + # You can add flake8 plugins via `additional_dependencies`: + # additional_dependencies: [flake8-bugbear] + +- repo: local + hooks: + - id: pylint + name: pylint + entry: pylint + language: system + types: [python] + args: + [ + "-rn", # Only display messages + "-sn", # Don't display the score + ] \ No newline at end of file diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..d190fea --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1 @@ +from .fixtures.vehicle_db_fixture import vehicle_db diff --git a/tests/databases.py b/tests/databases.py deleted file mode 100644 index b641a29..0000000 --- a/tests/databases.py +++ /dev/null @@ -1,3384 +0,0 @@ -import bw2data as bd -import numpy as np - -from bw_temporalis import ( - easy_timedelta_distribution, - TemporalDistribution, - easy_datetime_distribution, -) - - -def db_electrolysis(): - if "__test_electrolysis__" in bd.projects: - bd.projects.delete_project("__test_electrolysis__") - bd.projects.purge_deleted_directories() - - bd.projects.set_current("__test_electrolysis__") - - bd.Database("temporalis-bio").write( - { - ("temporalis-bio", "CO2"): { - "type": "emission", - "name": "carbon dioxide", - "temporalis code": "co2", - }, - } - ) - - bd.Database("background_2024").write( - { - ("background_2024", "electricity_mix"): { - "name": "Electricity mix", - "location": "somewhere", - "reference product": "electricity mix", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2024", "electricity_mix"), - }, - { - "amount": 1, - "type": "technosphere", - "input": ("background_2024", "electricity_wind"), - }, - ], - }, - ("background_2024", "electricity_wind"): { - "name": "Electricity production, wind", - "location": "somewhere", - "reference product": "electricity, wind", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2024", "electricity_wind"), - }, - { - "amount": 1, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - }, - ], - }, - } - ) - - bd.Database("background_2020").write( - { - ("background_2020", "electricity_mix"): { - "name": "Electricity mix", - "location": "somewhere", - "reference product": "electricity mix", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2020", "electricity_mix"), - }, - { - "amount": 1, - "type": "technosphere", - "input": ("background_2020", "electricity_wind"), - }, - ], - }, - ("background_2020", "electricity_wind"): { - "name": "Electricity production, wind", - "location": "somewhere", - "reference product": "electricity, wind", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2020", "electricity_wind"), - }, - { - "amount": 1, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - }, - ], - }, - } - ) - - bd.Database("foreground").write( - { - ("foreground", "electrolysis"): { - "name": "Hydrogen production, electrolysis", - "location": "somewhere", - "reference product": "hydrogen", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "electrolysis"), - }, - { - "amount": 5, - "type": "technosphere", - "input": ("background_2024", "electricity_mix"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [-1, 0, 1], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([0.2, 0.6, 0.2]), - ), - }, - ], - }, - ("foreground", "electrolysis2"): { - "name": "Hydrogen production, electrolysis2", - "location": "somewhere", - "reference product": "hydrogen", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "electrolysis2"), - }, - { - "amount": 13, - "type": "technosphere", - "input": ("foreground", "electrolysis"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [-3], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([1]), - ), - }, - ], - }, - ("foreground", "heat_from_hydrogen"): { - "name": "Heat production, hydrogen", - "location": "somewhere", - "reference product": "heat", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "heat_from_hydrogen"), - }, - { - "amount": 0.7, - "type": "technosphere", - "input": ("foreground", "electrolysis2"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [-2, 0], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([0.9, 0.1]), - ), - }, - ], - }, - } - ) - - bd.Method(("GWP", "example")).write( - [ - (("temporalis-bio", "CO2"), 1), - ] - ) - - -def db_abc_simple(): - if "__test_abc_simple__" in bd.projects: - bd.projects.delete_project("__test_abc_simple__") - bd.projects.purge_deleted_directories() - - bd.projects.set_current("__test_abc_simple__") - - bd.Database("temporalis-bio").write( - { - ("temporalis-bio", "CO2"): { - "type": "emission", - "name": "carbon dioxide", - "temporalis code": "co2", - }, - } - ) - - bd.Database("background_2024").write( - { - ("background_2024", "C"): { - "name": "C", - "location": "somewhere", - "reference product": "c", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2024", "C"), - }, - { - "amount": 1, - "type": "technosphere", - "input": ("background_2024", "electricity_wind"), - }, - ], - }, - ("background_2024", "electricity_wind"): { - "name": "Electricity production, wind", - "location": "somewhere", - "reference product": "electricity, wind", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2024", "electricity_wind"), - }, - { - "amount": 0.9, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - }, - ], - }, - } - ) - - bd.Database("background_2008").write( - { - ("background_2008", "C"): { - "name": "C", - "location": "somewhere", - "reference product": "c", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2008", "C"), - }, - { - "amount": 1, - "type": "technosphere", - "input": ("background_2008", "electricity_wind"), - }, - ], - }, - ("background_2008", "electricity_wind"): { - "name": "Electricity production, wind", - "location": "somewhere", - "reference product": "electricity, wind", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2008", "electricity_wind"), - }, - { - "amount": 1.2, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - }, - ], - }, - } - ) - - bd.Database("foreground").write( - { - ("foreground", "E"): { - "name": "E", - "location": "somewhere", - "reference product": "e", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "E"), - }, - ], - }, - ("foreground", "D"): { - "name": "D", - "location": "somewhere", - "reference product": "d", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "D"), - }, - { - "amount": 5, - "type": "technosphere", - "input": ("foreground", "B"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [ - -1, - ], - dtype="timedelta64[Y]", - ), # `M` is months - amount=np.array([1]), - ), - }, - { - "amount": 2, - "type": "technosphere", - "input": ("foreground", "E"), - }, - ], - }, - ("foreground", "B"): { - "name": "B", - "location": "somewhere", - "reference product": "b", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "B"), - }, - { - "amount": 13, - "type": "technosphere", - "input": ("background_2024", "C"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [-5], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([1]), - ), - }, - ], - }, - ("foreground", "A"): { - "name": "A", - "location": "somewhere", - "reference product": "a", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "A"), - }, - { - "amount": 4, - "type": "technosphere", - "input": ("foreground", "B"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [-20, 15], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([0.9, 0.1]), - ), - }, - { - "amount": 0.5, - "type": "technosphere", - "input": ("foreground", "D"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [-2, -1], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([0.7, 0.3]), - ), - }, - ], - }, - } - ) - - bd.Method(("GWP", "example")).write( - [ - (("temporalis-bio", "CO2"), 1), - ] - ) - - -def db_abc_C_to_E(): - if "__test_abc_C_to_E__" in bd.projects: - bd.projects.delete_project("__test_abc_C_to_E__") - bd.projects.purge_deleted_directories() - - bd.projects.set_current("__test_abc_C_to_E__") - - bd.Database("temporalis-bio").write( - { - ("temporalis-bio", "CO2"): { - "type": "emission", - "name": "carbon dioxide", - "temporalis code": "co2", - }, - } - ) - - bd.Database("background_2024").write( - { - ("background_2024", "C"): { - "name": "C", - "location": "somewhere", - "reference product": "c", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2024", "C"), - }, - { - "amount": 1, - "type": "technosphere", - "input": ("background_2024", "electricity_wind"), - }, - ], - }, - ("background_2024", "electricity_wind"): { - "name": "Electricity production, wind", - "location": "somewhere", - "reference product": "electricity, wind", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2024", "electricity_wind"), - }, - { - "amount": 0.9, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - }, - ], - }, - } - ) - - bd.Database("background_2008").write( - { - ("background_2008", "C"): { - "name": "C", - "location": "somewhere", - "reference product": "c", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2008", "C"), - }, - { - "amount": 1, - "type": "technosphere", - "input": ("background_2008", "electricity_wind"), - }, - ], - }, - ("background_2008", "electricity_wind"): { - "name": "Electricity production, wind", - "location": "somewhere", - "reference product": "electricity, wind", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2008", "electricity_wind"), - }, - { - "amount": 1.2, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - }, - ], - }, - } - ) - - bd.Database("foreground").write( - { - ("foreground", "E"): { - "name": "E", - "location": "somewhere", - "reference product": "e", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "E"), - }, - { - "amount": 11, - "type": "technosphere", - "input": ("background_2024", "C"), - "temporal_distribution": TemporalDistribution( - date=np.array([10, 5], dtype="timedelta64[Y]"), - amount=np.array([0.3, 0.7]), - ), - }, - ], - }, - ("foreground", "D"): { - "name": "D", - "location": "somewhere", - "reference product": "d", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "D"), - }, - { - "amount": 5, - "type": "technosphere", - "input": ("foreground", "B"), - "temporal_distribution": TemporalDistribution( - date=np.array( - [ - -1, - ], - dtype="timedelta64[Y]", - ), - amount=np.array([1]), - ), - }, - { - "amount": 2, - "type": "technosphere", - "input": ("foreground", "E"), - }, - ], - }, - ("foreground", "B"): { - "name": "B", - "location": "somewhere", - "reference product": "b", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "B"), - }, - { - "amount": 13, - "type": "technosphere", - "input": ("background_2024", "C"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [-5], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([1]), - ), - }, - ], - }, - ("foreground", "A"): { - "name": "A", - "location": "somewhere", - "reference product": "a", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "A"), - }, - { - "amount": 4, - "type": "technosphere", - "input": ("foreground", "B"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [-20, 15], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([0.9, 0.1]), - ), - }, - { - "amount": 0.5, - "type": "technosphere", - "input": ("foreground", "D"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [-2, -1], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([0.7, 0.3]), - ), - }, - ], - }, - } - ) - - bd.Method(("GWP", "example")).write( - [ - (("temporalis-bio", "CO2"), 1), - ] - ) - - -def db_abc_C_and_B_to_E(): - if "__test_abc_C_and_B_to_E__" in bd.projects: - bd.projects.delete_project("__test_abc_C_and_B_to_E__") - bd.projects.purge_deleted_directories() - - bd.projects.set_current("__test_abc_C_and_B_to_E__") - - bd.Database("temporalis-bio").write( - { - ("temporalis-bio", "CO2"): { - "type": "emission", - "name": "carbon dioxide", - "temporalis code": "co2", - }, - } - ) - - bd.Database("background_2024").write( - { - ("background_2024", "C"): { - "name": "C", - "location": "somewhere", - "reference product": "c", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2024", "C"), - }, - { - "amount": 1, - "type": "technosphere", - "input": ("background_2024", "electricity_wind"), - }, - ], - }, - ("background_2024", "electricity_wind"): { - "name": "Electricity production, wind", - "location": "somewhere", - "reference product": "electricity, wind", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2024", "electricity_wind"), - }, - { - "amount": 0.9, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - }, - ], - }, - } - ) - - bd.Database("background_2008").write( - { - ("background_2008", "C"): { - "name": "C", - "location": "somewhere", - "reference product": "c", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2008", "C"), - }, - { - "amount": 1, - "type": "technosphere", - "input": ("background_2008", "electricity_wind"), - }, - ], - }, - ("background_2008", "electricity_wind"): { - "name": "Electricity production, wind", - "location": "somewhere", - "reference product": "electricity, wind", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2008", "electricity_wind"), - }, - { - "amount": 1.2, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - }, - ], - }, - } - ) - - bd.Database("foreground").write( - { - ("foreground", "E"): { - "name": "E", - "location": "somewhere", - "reference product": "e", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "E"), - }, - { - "amount": 11, - "type": "technosphere", - "input": ("background_2024", "C"), - "temporal_distribution": TemporalDistribution( - date=np.array([10, 5], dtype="timedelta64[Y]"), - amount=np.array([0.3, 0.7]), - ), - }, - { - "amount": 8, - "type": "technosphere", - "input": ("foreground", "B"), - "temporal_distribution": TemporalDistribution( - date=np.array([-4, -2], dtype="timedelta64[Y]"), - amount=np.array([0.4, 0.6]), - ), - }, - ], - }, - ("foreground", "D"): { - "name": "D", - "location": "somewhere", - "reference product": "d", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "D"), - }, - { - "amount": 5, - "type": "technosphere", - "input": ("foreground", "B"), - "temporal_distribution": TemporalDistribution( - date=np.array( - [ - -1, - ], - dtype="timedelta64[Y]", - ), - amount=np.array([1]), - ), - }, - { - "amount": 2, - "type": "technosphere", - "input": ("foreground", "E"), - }, - ], - }, - ("foreground", "B"): { - "name": "B", - "location": "somewhere", - "reference product": "b", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "B"), - }, - { - "amount": 13, - "type": "technosphere", - "input": ("background_2024", "C"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [-5], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([1]), - ), - }, - ], - }, - ("foreground", "A"): { - "name": "A", - "location": "somewhere", - "reference product": "a", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "A"), - }, - { - "amount": 4, - "type": "technosphere", - "input": ("foreground", "B"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [-20, 15], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([0.9, 0.1]), - ), - }, - { - "amount": 0.5, - "type": "technosphere", - "input": ("foreground", "D"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [-2, -1], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([0.7, 0.3]), - ), - }, - ], - }, - } - ) - - bd.Method(("GWP", "example")).write( - [ - (("temporalis-bio", "CO2"), 1), - ] - ) - - -def db_abc_B_to_E(): - if "__test_abc_B_to_E__" in bd.projects: - bd.projects.delete_project("__test_abc_B_to_E__") - bd.projects.purge_deleted_directories() - - bd.projects.set_current("__test_abc_B_to_E__") - - bd.Database("temporalis-bio").write( - { - ("temporalis-bio", "CO2"): { - "type": "emission", - "name": "carbon dioxide", - "temporalis code": "co2", - }, - } - ) - - bd.Database("background_2024").write( - { - ("background_2024", "C"): { - "name": "C", - "location": "somewhere", - "reference product": "c", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2024", "C"), - }, - { - "amount": 1, - "type": "technosphere", - "input": ("background_2024", "electricity_wind"), - }, - ], - }, - ("background_2024", "electricity_wind"): { - "name": "Electricity production, wind", - "location": "somewhere", - "reference product": "electricity, wind", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2024", "electricity_wind"), - }, - { - "amount": 0.9, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - }, - ], - }, - } - ) - - bd.Database("background_2008").write( - { - ("background_2008", "C"): { - "name": "C", - "location": "somewhere", - "reference product": "c", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2008", "C"), - }, - { - "amount": 1, - "type": "technosphere", - "input": ("background_2008", "electricity_wind"), - }, - ], - }, - ("background_2008", "electricity_wind"): { - "name": "Electricity production, wind", - "location": "somewhere", - "reference product": "electricity, wind", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2008", "electricity_wind"), - }, - { - "amount": 1.2, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - }, - ], - }, - } - ) - - bd.Database("foreground").write( - { - ("foreground", "E"): { - "name": "E", - "location": "somewhere", - "reference product": "e", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "E"), - }, - { - "amount": 8, - "type": "technosphere", - "input": ("foreground", "B"), - "temporal_distribution": TemporalDistribution( - date=np.array([-4, -2], dtype="timedelta64[Y]"), - amount=np.array([0.4, 0.6]), - ), - }, - ], - }, - ("foreground", "D"): { - "name": "D", - "location": "somewhere", - "reference product": "d", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "D"), - }, - { - "amount": 5, - "type": "technosphere", - "input": ("foreground", "B"), - "temporal_distribution": TemporalDistribution( - date=np.array( - [ - -1, - ], - dtype="timedelta64[Y]", - ), - amount=np.array([1]), - ), - }, - { - "amount": 2, - "type": "technosphere", - "input": ("foreground", "E"), - }, - ], - }, - ("foreground", "B"): { - "name": "B", - "location": "somewhere", - "reference product": "b", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "B"), - }, - { - "amount": 13, - "type": "technosphere", - "input": ("background_2024", "C"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [-5], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([1]), - ), - }, - ], - }, - ("foreground", "A"): { - "name": "A", - "location": "somewhere", - "reference product": "a", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "A"), - }, - { - "amount": 4, - "type": "technosphere", - "input": ("foreground", "B"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [-20, 15], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([0.9, 0.1]), - ), - }, - { - "amount": 0.5, - "type": "technosphere", - "input": ("foreground", "D"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [-2, -1], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([0.7, 0.3]), - ), - }, - ], - }, - } - ) - - bd.Method(("GWP", "example")).write( - [ - (("temporalis-bio", "CO2"), 1), - ] - ) - - -def db_abc_B_to_E_simplified(): - if "__test_abc_B_to_E_simplified__" in bd.projects: - bd.projects.delete_project("__test_abc_B_to_E_simplified__") - bd.projects.purge_deleted_directories() - - bd.projects.set_current("__test_abc_B_to_E_simplified__") - - bd.Database("temporalis-bio").write( - { - ("temporalis-bio", "CO2"): { - "type": "emission", - "name": "carbon dioxide", - "temporalis code": "co2", - }, - } - ) - - bd.Database("background_2024").write( - { - ("background_2024", "C"): { - "name": "C", - "location": "somewhere", - "reference product": "c", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2024", "C"), - }, - { - "amount": 1, - "type": "technosphere", - "input": ("background_2024", "electricity_wind"), - }, - ], - }, - ("background_2024", "electricity_wind"): { - "name": "Electricity production, wind", - "location": "somewhere", - "reference product": "electricity, wind", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2024", "electricity_wind"), - }, - { - "amount": 1, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - }, - ], - }, - } - ) - - bd.Database("background_2008").write( - { - ("background_2008", "C"): { - "name": "C", - "location": "somewhere", - "reference product": "c", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2008", "C"), - }, - { - "amount": 1, - "type": "technosphere", - "input": ("background_2008", "electricity_wind"), - }, - ], - }, - ("background_2008", "electricity_wind"): { - "name": "Electricity production, wind", - "location": "somewhere", - "reference product": "electricity, wind", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2008", "electricity_wind"), - }, - { - "amount": 1, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - }, - ], - }, - } - ) - - bd.Database("foreground").write( - { - ("foreground", "E"): { - "name": "E", - "location": "somewhere", - "reference product": "e", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "E"), - }, - { - "amount": 8, - "type": "technosphere", - "input": ("foreground", "B"), - "temporal_distribution": TemporalDistribution( - date=np.array([-4, -2], dtype="timedelta64[Y]"), - amount=np.array([0.4, 0.6]), - ), - }, - ], - }, - ("foreground", "D"): { - "name": "D", - "location": "somewhere", - "reference product": "d", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "D"), - }, - { - "amount": 5, - "type": "technosphere", - "input": ("foreground", "B"), - "temporal_distribution": TemporalDistribution( - date=np.array( - [ - -1, - ], - dtype="timedelta64[Y]", - ), - amount=np.array([1]), - ), - }, - { - "amount": 2, - "type": "technosphere", - "input": ("foreground", "E"), - }, - ], - }, - ("foreground", "B"): { - "name": "B", - "location": "somewhere", - "reference product": "b", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "B"), - }, - { - "amount": 13, - "type": "technosphere", - "input": ("background_2024", "C"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [-5], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([1]), - ), - }, - ], - }, - ("foreground", "A"): { - "name": "A", - "location": "somewhere", - "reference product": "a", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "A"), - }, - { - "amount": 0.5, - "type": "technosphere", - "input": ("foreground", "D"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [-2, -1], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([0.7, 0.3]), - ), - }, - ], - }, - } - ) - - bd.Method(("GWP", "example")).write( - [ - (("temporalis-bio", "CO2"), 1), - ] - ) - - -def db_abc_B_to_E_simplified_and_E_with_TD(): - if "__test_abc_B_to_E_simplified_and_E_with_TD__" in bd.projects: - bd.projects.delete_project("__test_abc_B_to_E_simplified_and_E_with_TD__") - bd.projects.purge_deleted_directories() - - bd.projects.set_current("__test_abc_B_to_E_simplified_and_E_with_TD__") - - bd.Database("temporalis-bio").write( - { - ("temporalis-bio", "CO2"): { - "type": "emission", - "name": "carbon dioxide", - "temporalis code": "co2", - }, - } - ) - - bd.Database("background_2024").write( - { - ("background_2024", "C"): { - "name": "C", - "location": "somewhere", - "reference product": "c", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2024", "C"), - }, - { - "amount": 1, - "type": "technosphere", - "input": ("background_2024", "electricity_wind"), - }, - ], - }, - ("background_2024", "electricity_wind"): { - "name": "Electricity production, wind", - "location": "somewhere", - "reference product": "electricity, wind", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2024", "electricity_wind"), - }, - { - "amount": 0.9, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - }, - ], - }, - } - ) - - bd.Database("background_2008").write( - { - ("background_2008", "C"): { - "name": "C", - "location": "somewhere", - "reference product": "c", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2008", "C"), - }, - { - "amount": 1, - "type": "technosphere", - "input": ("background_2008", "electricity_wind"), - }, - ], - }, - ("background_2008", "electricity_wind"): { - "name": "Electricity production, wind", - "location": "somewhere", - "reference product": "electricity, wind", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2008", "electricity_wind"), - }, - { - "amount": 1.2, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - }, - ], - }, - } - ) - - bd.Database("foreground").write( - { - ("foreground", "E"): { - "name": "E", - "location": "somewhere", - "reference product": "e", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "E"), - }, - { - "amount": 8, - "type": "technosphere", - "input": ("foreground", "B"), - "temporal_distribution": TemporalDistribution( - date=np.array([-4, -2], dtype="timedelta64[Y]"), - amount=np.array([0.4, 0.6]), - ), - }, - ], - }, - ("foreground", "D"): { - "name": "D", - "location": "somewhere", - "reference product": "d", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "D"), - }, - { - "amount": 5, - "type": "technosphere", - "input": ("foreground", "B"), - "temporal_distribution": TemporalDistribution( - date=np.array( - [ - -1, - ], - dtype="timedelta64[Y]", - ), - amount=np.array([1]), - ), - }, - { - "amount": 2, - "type": "technosphere", - "input": ("foreground", "E"), - "temporal_distribution": TemporalDistribution( - date=np.array( - [ - -1, - ], - dtype="timedelta64[Y]", - ), - amount=np.array([1]), - ), - }, - ], - }, - ("foreground", "B"): { - "name": "B", - "location": "somewhere", - "reference product": "b", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "B"), - }, - { - "amount": 13, - "type": "technosphere", - "input": ("background_2024", "C"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [-5], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([1]), - ), - }, - ], - }, - ("foreground", "A"): { - "name": "A", - "location": "somewhere", - "reference product": "a", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "A"), - }, - { - "amount": 0.5, - "type": "technosphere", - "input": ("foreground", "D"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [-2, -1], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([0.7, 0.3]), - ), - }, - ], - }, - } - ) - - bd.Method(("GWP", "example")).write( - [ - (("temporalis-bio", "CO2"), 1), - ] - ) - - -def db_abc_loopA(): - if "__test_abc_loopA__" in bd.projects: - bd.projects.delete_project("__test_abc_loopA__") - bd.projects.purge_deleted_directories() - - bd.projects.set_current("__test_abc_loopA__") - - bd.Database("temporalis-bio").write( - { - ("temporalis-bio", "CO2"): { - "type": "emission", - "name": "carbon dioxide", - "temporalis code": "co2", - }, - } - ) - - bd.Database("background_2024").write( - { - ("background_2024", "C"): { - "name": "C", - "location": "somewhere", - "reference product": "c", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2024", "C"), - }, - { - "amount": 1, - "type": "technosphere", - "input": ("background_2024", "electricity_wind"), - }, - ], - }, - ("background_2024", "electricity_wind"): { - "name": "Electricity production, wind", - "location": "somewhere", - "reference product": "electricity, wind", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2024", "electricity_wind"), - }, - { - "amount": 1, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - }, - ], - }, - } - ) - - bd.Database("background_2008").write( - { - ("background_2008", "C"): { - "name": "C", - "location": "somewhere", - "reference product": "c", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2008", "C"), - }, - { - "amount": 1, - "type": "technosphere", - "input": ("background_2008", "electricity_wind"), - }, - ], - }, - ("background_2008", "electricity_wind"): { - "name": "Electricity production, wind", - "location": "somewhere", - "reference product": "electricity, wind", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2008", "electricity_wind"), - }, - { - "amount": 1, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - }, - ], - }, - } - ) - - bd.Database("foreground").write( - { - ("foreground", "E"): { - "name": "E", - "location": "somewhere", - "reference product": "e", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "E"), - }, - { - "amount": 11, - "type": "technosphere", - "input": ("background_2024", "C"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [10, 5], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([0.3, 0.7]), - ), - }, - { - "amount": 8, - "type": "technosphere", - "input": ("foreground", "B"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [-4, -2], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([0.4, 0.6]), - ), - }, - { - "amount": 0.1, - "type": "technosphere", - "input": ("foreground", "A"), - # 'temporal_distribution': # e.g. because some hydrogen was stored in the meantime - # TemporalDistribution( - # date=np.array([-3,-1], dtype='timedelta64[Y]'), # `M` is months - # amount=np.array([0.2,0.8]) - # ), - }, - ], - }, - ("foreground", "D"): { - "name": "D", - "location": "somewhere", - "reference product": "d", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "D"), - }, - { - "amount": 5, - "type": "technosphere", - "input": ("foreground", "B"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [ - -1, - ], - dtype="timedelta64[Y]", - ), # `M` is months - amount=np.array([1]), - ), - }, - { - "amount": 2, - "type": "technosphere", - "input": ("foreground", "E"), - }, - ], - }, - ("foreground", "B"): { - "name": "B", - "location": "somewhere", - "reference product": "b", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "B"), - }, - { - "amount": 13, - "type": "technosphere", - "input": ("background_2024", "C"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [-5], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([1]), - ), - }, - ], - }, - ("foreground", "A"): { - "name": "A", - "location": "somewhere", - "reference product": "a", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "A"), - }, - { - "amount": 4, - "type": "technosphere", - "input": ("foreground", "B"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [-20, 15], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([0.9, 0.1]), - ), - }, - { - "amount": 0.5, - "type": "technosphere", - "input": ("foreground", "D"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [-2, -1], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([0.7, 0.3]), - ), - }, - ], - }, - } - ) - - bd.Method(("GWP", "example")).write( - [ - (("temporalis-bio", "CO2"), 1), - ] - ) - - -def db_abc_loopA_with_biosphere(): - if "__test_abc_loopA_with_biosphere__" in bd.projects: - bd.projects.delete_project("__test_abc_loopA_with_biosphere__") - bd.projects.purge_deleted_directories() - - bd.projects.set_current("__test_abc_loopA_with_biosphere__") - - bd.Database("temporalis-bio").write( - { - ("temporalis-bio", "CO2"): { - "type": "emission", - "name": "carbon dioxide", - "temporalis code": "co2", - }, - } - ) - - bd.Database("background_2024").write( - { - ("background_2024", "C"): { - "name": "C", - "location": "somewhere", - "reference product": "c", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2024", "C"), - }, - { - "amount": 1, - "type": "technosphere", - "input": ("background_2024", "electricity_wind"), - }, - ], - }, - ("background_2024", "electricity_wind"): { - "name": "Electricity production, wind", - "location": "somewhere", - "reference product": "electricity, wind", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2024", "electricity_wind"), - }, - { - "amount": 1, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - }, - ], - }, - } - ) - - bd.Database("background_2008").write( - { - ("background_2008", "C"): { - "name": "C", - "location": "somewhere", - "reference product": "c", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2008", "C"), - }, - { - "amount": 1, - "type": "technosphere", - "input": ("background_2008", "electricity_wind"), - }, - ], - }, - ("background_2008", "electricity_wind"): { - "name": "Electricity production, wind", - "location": "somewhere", - "reference product": "electricity, wind", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2008", "electricity_wind"), - }, - { - "amount": 1, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - }, - ], - }, - } - ) - - bd.Database("foreground").write( - { - ("foreground", "E"): { - "name": "E", - "location": "somewhere", - "reference product": "e", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "E"), - }, - { - "amount": 11, - "type": "technosphere", - "input": ("background_2024", "C"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [10, 5], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([0.3, 0.7]), - ), - }, - { - "amount": 8, - "type": "technosphere", - "input": ("foreground", "B"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [-4, -2], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([0.4, 0.6]), - ), - }, - { - "amount": 0.1, - "type": "technosphere", - "input": ("foreground", "A"), - # 'temporal_distribution': # e.g. because some hydrogen was stored in the meantime - # TemporalDistribution( - # date=np.array([-3,-1], dtype='timedelta64[Y]'), # `M` is months - # amount=np.array([0.2,0.8]) - # ), - }, - ], - }, - ("foreground", "D"): { - "name": "D", - "location": "somewhere", - "reference product": "d", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "D"), - }, - { - "amount": 5, - "type": "technosphere", - "input": ("foreground", "B"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [ - -1, - ], - dtype="timedelta64[Y]", - ), # `M` is months - amount=np.array([1]), - ), - }, - { - "amount": 2, - "type": "technosphere", - "input": ("foreground", "E"), - }, - ], - }, - ("foreground", "B"): { - "name": "B", - "location": "somewhere", - "reference product": "b", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "B"), - }, - { - "amount": 13, - "type": "technosphere", - "input": ("background_2024", "C"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [-5], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([1]), - ), - }, - ], - }, - ("foreground", "A"): { - "name": "A", - "location": "somewhere", - "reference product": "a", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "A"), - }, - { - "amount": 17, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - }, - { - "amount": 4, - "type": "technosphere", - "input": ("foreground", "B"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [-20, 15], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([0.9, 0.1]), - ), - }, - { - "amount": 0.5, - "type": "technosphere", - "input": ("foreground", "D"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [-2, -1], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([0.7, 0.3]), - ), - }, - ], - }, - } - ) - - bd.Method(("GWP", "example")).write( - [ - (("temporalis-bio", "CO2"), 1), - ] - ) - - -def db_abc_loopA_with_biosphere_tds_CO2_and_CH4(): - project_name = "db_abc_loopA_with_biosphere_tds_CO2_and_CH4" - if project_name in bd.projects: - bd.projects.delete_project(project_name) - # bd.projects.purge_deleted_directories() - - bd.projects.set_current(project_name) - - bd.Database("temporalis-bio").write( - { - ("temporalis-bio", "CO2"): { - "type": "emission", - "name": "carbon dioxide", - "temporalis code": "co2", - }, - ("temporalis-bio", "CH4"): { - "type": "emission", - "name": "methane", - "temporalis code": "ch4", - }, - } - ) - - bd.Database("background_2024").write( - { - ("background_2024", "C"): { - "name": "C", - "location": "somewhere", - "reference product": "c", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2024", "C"), - }, - { - "amount": 1, - "type": "technosphere", - "input": ("background_2024", "electricity_wind"), - }, - ], - }, - ("background_2024", "electricity_wind"): { - "name": "Electricity production, wind", - "location": "somewhere", - "reference product": "electricity, wind", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2024", "electricity_wind"), - }, - { - "amount": 1, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - }, - ], - }, - } - ) - - bd.Database("background_2008").write( - { - ("background_2008", "C"): { - "name": "C", - "location": "somewhere", - "reference product": "c", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2008", "C"), - }, - { - "amount": 1, - "type": "technosphere", - "input": ("background_2008", "electricity_wind"), - }, - ], - }, - ("background_2008", "electricity_wind"): { - "name": "Electricity production, wind", - "location": "somewhere", - "reference product": "electricity, wind", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2008", "electricity_wind"), - }, - { - "amount": 1, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - }, - ], - }, - } - ) - - bd.Database("foreground").write( - { - ("foreground", "E"): { - "name": "E", - "location": "somewhere", - "reference product": "e", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "E"), - }, - { - "amount": 11, - "type": "technosphere", - "input": ("background_2024", "C"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [10, 5], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([0.3, 0.7]), - ), - }, - { - "amount": 8, - "type": "technosphere", - "input": ("foreground", "B"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [-4, -2], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([0.4, 0.6]), - ), - }, - { - "amount": 0.1, - "type": "technosphere", - "input": ("foreground", "A"), - # 'temporal_distribution': # e.g. because some hydrogen was stored in the meantime - # TemporalDistribution( - # date=np.array([-3,-1], dtype='timedelta64[Y]'), # `M` is months - # amount=np.array([0.2,0.8]) - # ), - }, - ], - }, - ("foreground", "D"): { - "name": "D", - "location": "somewhere", - "reference product": "d", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "D"), - }, - { - "amount": 5, - "type": "technosphere", - "input": ("foreground", "B"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [ - -1, - ], - dtype="timedelta64[Y]", - ), # `M` is months - amount=np.array([1]), - ), - }, - { - "amount": 2, - "type": "technosphere", - "input": ("foreground", "E"), - }, - ], - }, - ("foreground", "B"): { - "name": "B", - "location": "somewhere", - "reference product": "b", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "B"), - }, - { - "amount": 13, - "type": "technosphere", - "input": ("background_2024", "C"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [-5], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([1]), - ), - }, - { - "amount": 6, - "type": "biosphere", - "input": ("temporalis-bio", "CH4"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [-2, 4, 6], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([0.2, 0.7, 0.1]), - ), - }, - ], - }, - ("foreground", "A"): { - "name": "A", - "location": "somewhere", - "reference product": "a", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "A"), - }, - { - "amount": 17, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [0, 3], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([0.3, 0.7]), - ), - }, - { - "amount": 4, - "type": "technosphere", - "input": ("foreground", "B"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [-20, 15], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([0.9, 0.1]), - ), - }, - { - "amount": 0.5, - "type": "technosphere", - "input": ("foreground", "D"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [-2, -1], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([0.7, 0.3]), - ), - }, - ], - }, - } - ) - - bd.Method(("GWP", "example")).write( - [ - (("temporalis-bio", "CO2"), 1), - (("temporalis-bio", "CH4"), 25), - ] - ) - - -def db_abcd_CO2_foreground_and_in_deep_background(): - project_name = "db_abcd_CO2_foreground_and_in_deep_background" - if project_name in bd.projects: - bd.projects.delete_project(project_name) - bd.projects.purge_deleted_directories() - - bd.projects.set_current(project_name) - - bd.Database("temporalis-bio").write( - { - ("temporalis-bio", "CO2"): { - "type": "emission", - "name": "carbon dioxide", - "temporalis code": "co2", - }, - ("temporalis-bio", "CH4"): { - "type": "emission", - "name": "methane", - "temporalis code": "ch4", - }, - } - ) - - bd.Database("background_2024").write( - { - ("background_2024", "C"): { - "name": "C", - "location": "somewhere", - "reference product": "c", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2024", "C"), - }, - { - "amount": 1, - "type": "technosphere", - "input": ("background_2024", "electricity_wind"), - }, - # no biosphere in intersecting node between background and foreground - ], - }, - # ('background_2024', 'D'): { - # 'name': 'D', - # 'location': 'somewhere', - # 'reference product': 'd', - # 'exchanges': [ - # { - # 'amount': 1, - # 'type': 'production', - # 'input': ('background_2024', 'D'), - # }, - # { - # 'amount': 3, - # 'type': 'technosphere', - # 'input': ('background_2024', 'electricity_wind'), - # }, - # ] - # }, - ("background_2024", "electricity_wind"): { - "name": "Electricity production, wind", - "location": "somewhere", - "reference product": "electricity, wind", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2024", "electricity_wind"), - }, - { - "amount": 1, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - }, - ], - }, - } - ) - - bd.Database("background_2008").write( - { - ("background_2008", "C"): { - "name": "C", - "location": "somewhere", - "reference product": "c", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2008", "C"), - }, - { - "amount": 1, - "type": "technosphere", - "input": ("background_2008", "electricity_wind"), - }, - # no biosphere in intersecting node between background and foreground - ], - }, - ("background_2008", "electricity_wind"): { - "name": "Electricity production, wind", - "location": "somewhere", - "reference product": "electricity, wind", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2008", "electricity_wind"), - }, - { - "amount": 1, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - }, - ], - }, - # ('background_2008', 'D'): { - # 'name': 'D', - # 'location': 'somewhere', - # 'reference product': 'd', - # 'exchanges': [ - # { - # 'amount': 1, - # 'type': 'production', - # 'input': ('background_2008', 'D'), - # }, - # { - # 'amount': 3, - # 'type': 'technosphere', - # 'input': ('background_2008', 'electricity_wind'), - # }, - # ] - # }, - } - ) - - bd.Database("foreground").write( - { - ("foreground", "B"): { - "name": "B", - "location": "somewhere", - "reference product": "b", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "B"), - }, - { - "amount": 3, - "type": "technosphere", - "input": ("background_2024", "C"), - "temporal_distribution": TemporalDistribution( - date=np.array([-1], dtype="timedelta64[Y]"), - amount=np.array([1]), - ), - }, - { - "amount": 6, - "type": "biosphere", - "input": ("temporalis-bio", "CH4"), - # 'temporal_distribution': - # TemporalDistribution( - # date=np.array([-2, 4, 6], dtype='timedelta64[Y]'), - # amount=np.array([0.2, 0.7, 0.1]) - # ), - }, - ], - }, - ("foreground", "A"): { - "name": "A", - "location": "somewhere", - "reference product": "a", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "A"), - }, - { - "amount": 3, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - # 'temporal_distribution': - # TemporalDistribution( - # date=np.array([0, 1], dtype='timedelta64[Y]'), - # amount=np.array([0.3, 0.7]) - # ), - }, - { - "amount": 0.3, - "type": "technosphere", - "input": ("foreground", "B"), - # 'temporal_distribution': - # TemporalDistribution( - # date=np.array([-20, 15], dtype='timedelta64[Y]'), - # amount=np.array([0.9, 0.1]) - # ), - }, - ], - }, - } - ) - - bd.Method(("GWP", "example")).write( - [ - (("temporalis-bio", "CO2"), 1), - (("temporalis-bio", "CH4"), 25), - ] - ) - - -def db_abcd_CO2_only_in_deep_background(): - project_name = "db_abcd_CO2_only_in_deep_background" - if project_name in bd.projects: - bd.projects.delete_project(project_name) - bd.projects.purge_deleted_directories() - - bd.projects.set_current(project_name) - - bd.Database("temporalis-bio").write( - { - ("temporalis-bio", "CO2"): { - "type": "emission", - "name": "carbon dioxide", - "temporalis code": "co2", - }, - ("temporalis-bio", "CH4"): { - "type": "emission", - "name": "methane", - "temporalis code": "ch4", - }, - } - ) - - bd.Database("background_2024").write( - { - ("background_2024", "C"): { - "name": "C", - "location": "somewhere", - "reference product": "c", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2024", "C"), - }, - { - "amount": 1, - "type": "technosphere", - "input": ("background_2024", "electricity_wind"), - }, - # no biosphere in intersecting node between background and foreground - ], - }, - ("background_2024", "electricity_wind"): { - "name": "Electricity production, wind", - "location": "somewhere", - "reference product": "electricity, wind", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2024", "electricity_wind"), - }, - { - "amount": 1, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - }, - ], - }, - } - ) - - bd.Database("background_2008").write( - { - ("background_2008", "C"): { - "name": "C", - "location": "somewhere", - "reference product": "c", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2008", "C"), - }, - { - "amount": 1, - "type": "technosphere", - "input": ("background_2008", "electricity_wind"), - }, - # no biosphere in intersecting node between background and foreground - ], - }, - ("background_2008", "electricity_wind"): { - "name": "Electricity production, wind", - "location": "somewhere", - "reference product": "electricity, wind", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2008", "electricity_wind"), - }, - { - "amount": 1, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - }, - ], - }, - } - ) - - bd.Database("foreground").write( - { - ("foreground", "B"): { - "name": "B", - "location": "somewhere", - "reference product": "b", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "B"), - }, - { - "amount": 3, - "type": "technosphere", - "input": ("background_2024", "C"), - "temporal_distribution": TemporalDistribution( - date=np.array([-1], dtype="timedelta64[Y]"), - amount=np.array([1]), - ), - }, - # no biosphere in foreground - # { - # 'amount': 6, - # 'type': 'biosphere', - # 'input': ('temporalis-bio', 'CH4'), - # # 'temporal_distribution': - # # TemporalDistribution( - # # date=np.array([-2, 4, 6], dtype='timedelta64[Y]'), - # # amount=np.array([0.2, 0.7, 0.1]) - # # ), - # }, - ], - }, - ("foreground", "A"): { - "name": "A", - "location": "somewhere", - "reference product": "a", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "A"), - }, - # no biosphere in foreground - # { - # 'amount': 3, - # 'type': 'biosphere', - # 'input': ('temporalis-bio', 'CO2'), - # # 'temporal_distribution': - # # TemporalDistribution( - # # date=np.array([0, 1], dtype='timedelta64[Y]'), - # # amount=np.array([0.3, 0.7]) - # # ), - # }, - { - "amount": 0.3, - "type": "technosphere", - "input": ("foreground", "B"), - # 'temporal_distribution': - # TemporalDistribution( - # date=np.array([-20, 15], dtype='timedelta64[Y]'), - # amount=np.array([0.9, 0.1]) - # ), - }, - ], - }, - } - ) - - bd.Method(("GWP", "example")).write( - [ - (("temporalis-bio", "CO2"), 1), - (("temporalis-bio", "CH4"), 25), - ] - ) - - -def db_abcd_CO2_foreground_deep_background_and_two_markets(): - project_name = "db_abcd_CO2_foreground_deep_background_and_two_markets" - if project_name in bd.projects: - bd.projects.delete_project(project_name) - bd.projects.purge_deleted_directories() - - bd.projects.set_current(project_name) - - bd.Database("temporalis-bio").write( - { - ("temporalis-bio", "CO2"): { - "type": "emission", - "name": "carbon dioxide", - "temporalis code": "co2", - }, - ("temporalis-bio", "CH4"): { - "type": "emission", - "name": "methane", - "temporalis code": "ch4", - }, - } - ) - - bd.Database("background_2024").write( - { - ("background_2024", "C"): { - "name": "C", - "location": "somewhere", - "reference product": "c", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2024", "C"), - }, - { - "amount": 1, - "type": "technosphere", - "input": ("background_2024", "electricity_wind"), - }, - # biosphere in intersecting process (market) - { - "amount": 5, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - }, - ], - }, - ("background_2024", "D"): { - "name": "D", - "location": "somewhere", - "reference product": "d", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2024", "D"), - }, - { - "amount": 3, - "type": "technosphere", - "input": ("background_2024", "electricity_wind"), - }, - ], - }, - ("background_2024", "electricity_wind"): { - "name": "Electricity production, wind", - "location": "somewhere", - "reference product": "electricity, wind", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2024", "electricity_wind"), - }, - { - "amount": 1.5, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - }, - ], - }, - } - ) - - bd.Database("background_2008").write( - { - ("background_2008", "C"): { - "name": "C", - "location": "somewhere", - "reference product": "c", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2008", "C"), - }, - { - "amount": 1, - "type": "technosphere", - "input": ("background_2008", "electricity_wind"), - }, - # biosphere in intersecting process (market) - { - "amount": 5, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - }, - ], - }, - ("background_2008", "D"): { - "name": "D", - "location": "somewhere", - "reference product": "d", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2008", "D"), - }, - { - "amount": 3, - "type": "technosphere", - "input": ("background_2008", "electricity_wind"), - }, - ], - }, - ("background_2008", "electricity_wind"): { - "name": "Electricity production, wind", - "location": "somewhere", - "reference product": "electricity, wind", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2008", "electricity_wind"), - }, - { - "amount": 1.5, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - }, - ], - }, - } - ) - - bd.Database("foreground").write( - { - ("foreground", "B"): { - "name": "B", - "location": "somewhere", - "reference product": "b", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "B"), - }, - { - "amount": 1, - "type": "technosphere", - "input": ("background_2024", "C"), - "temporal_distribution": TemporalDistribution( - date=np.array([-1], dtype="timedelta64[Y]"), - amount=np.array([1]), - ), - }, - { - "amount": 6, - "type": "technosphere", - "input": ("background_2024", "D"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [-6], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([1]), - ), - }, - ], - }, - ("foreground", "A"): { - "name": "A", - "location": "somewhere", - "reference product": "a", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "A"), - }, - { - "amount": 0, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - # 'temporal_distribution': - # TemporalDistribution( - # date=np.array([0, 1], dtype='timedelta64[Y]'), - # amount=np.array([0.3, 0.7]) - # ), - }, - { - "amount": 1, - "type": "technosphere", - "input": ("foreground", "B"), - # 'temporal_distribution': - # TemporalDistribution( - # date=np.array([-20, 15], dtype='timedelta64[Y]'), - # amount=np.array([0.9, 0.1]) - # ), - }, - ], - }, - } - ) - - bd.Method(("GWP", "example")).write( - [ - (("temporalis-bio", "CO2"), 1), - (("temporalis-bio", "CH4"), 25), - ] - ) - - -def db_abc_loopA_with_biosphere_advanced(): - - project_name = "___abc_loopA_with_biosphere_advanced__" - if project_name in bd.projects: - bd.projects.delete_project(project_name) - # bd.projects.purge_deleted_directories() - - bd.projects.set_current(project_name) - - bd.Database("temporalis-bio").write( - { - ("temporalis-bio", "CO2"): { - "type": "emission", - "name": "carbon dioxide", - "temporalis code": "co2", - }, - } - ) - - bd.Database("background_2024").write( - { - ("background_2024", "C"): { - "name": "C", - "location": "somewhere", - "reference product": "c", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2024", "C"), - }, - { - "amount": 1, - "type": "technosphere", - "input": ("background_2024", "electricity_wind"), - }, - ], - }, - ("background_2024", "electricity_wind"): { - "name": "Electricity production, wind", - "location": "somewhere", - "reference product": "electricity, wind", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2024", "electricity_wind"), - }, - { - "amount": 1, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - "temporal_distribution": TemporalDistribution( - date=np.array([-2, 1, 2], dtype="timedelta64[Y]"), - amount=np.array([0.2, 0.7, 0.1]), - ), - }, - ], - }, - } - ) - - bd.Database("background_2008").write( - { - ("background_2008", "C"): { - "name": "C", - "location": "somewhere", - "reference product": "c", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2008", "C"), - }, - { - "amount": 1, - "type": "technosphere", - "input": ("background_2008", "electricity_wind"), - }, - ], - }, - ("background_2008", "electricity_wind"): { - "name": "Electricity production, wind", - "location": "somewhere", - "reference product": "electricity, wind", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2008", "electricity_wind"), - }, - { - "amount": 1, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - "temporal_distribution": TemporalDistribution( - date=np.array([-2, 1, 2], dtype="timedelta64[Y]"), - amount=np.array([0.2, 0.7, 0.1]), - ), - }, - ], - }, - } - ) - - bd.Database("foreground").write( - { - ("foreground", "E"): { - "name": "E", - "location": "somewhere", - "reference product": "e", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "E"), - }, - { - "amount": 11, - "type": "technosphere", - "input": ("background_2024", "C"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [10, 5], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([0.3, 0.7]), - ), - }, - { - "amount": 8, - "type": "technosphere", - "input": ("foreground", "B"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [-4, -2], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([0.4, 0.6]), - ), - }, - { - "amount": 0.1, - "type": "technosphere", - "input": ("foreground", "A"), - # 'temporal_distribution': # e.g. because some hydrogen was stored in the meantime - # TemporalDistribution( - # date=np.array([-3,-1], dtype='timedelta64[Y]'), # `M` is months - # amount=np.array([0.2,0.8]) - # ), - }, - ], - }, - ("foreground", "D"): { - "name": "D", - "location": "somewhere", - "reference product": "d", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "D"), - }, - { - "amount": 5, - "type": "technosphere", - "input": ("foreground", "B"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [ - -1, - ], - dtype="timedelta64[Y]", - ), # `M` is months - amount=np.array([1]), - ), - }, - { - "amount": 2, - "type": "technosphere", - "input": ("foreground", "E"), - }, - ], - }, - ("foreground", "B"): { - "name": "B", - "location": "somewhere", - "reference product": "b", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "B"), - }, - { - "amount": 13, - "type": "technosphere", - "input": ("background_2024", "C"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [-5], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([1]), - ), - }, - ], - }, - ("foreground", "A"): { - "name": "A", - "location": "somewhere", - "reference product": "a", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "A"), - }, - { - "amount": 17, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - }, - { - "amount": 4, - "type": "technosphere", - "input": ("foreground", "B"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [-20, 15], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([0.9, 0.1]), - ), - }, - { - "amount": 0.5, - "type": "technosphere", - "input": ("foreground", "D"), - "temporal_distribution": TemporalDistribution( # e.g. because some hydrogen was stored in the meantime - date=np.array( - [-2, -1], dtype="timedelta64[Y]" - ), # `M` is months - amount=np.array([0.7, 0.3]), - ), - }, - ], - }, - } - ) - - bd.Method(("GWP", "example")).write( - [ - (("temporalis-bio", "CO2"), 1), - ] - ) - - -def db_abc_loopA_with_biosphere_advanced_simple(): - - project_name = "___abc_loopA_with_biosphere_advanced_simple__" - if project_name in bd.projects: - bd.projects.delete_project(project_name) - # bd.projects.purge_deleted_directories() - - bd.projects.set_current(project_name) - - bd.Database("temporalis-bio").write( - { - ("temporalis-bio", "CO2"): { - "type": "emission", - "name": "carbon dioxide", - "temporalis code": "co2", - }, - ("temporalis-bio", "CH4"): { - "type": "emission", - "name": "methane", - "temporalis code": "ch4", - }, - } - ) - - bd.Database("background_2024").write( - { - ("background_2024", "C"): { - "name": "C", - "location": "somewhere", - "reference product": "c", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2024", "C"), - }, - { - "amount": 1, - "type": "technosphere", - "input": ("background_2024", "electricity_wind"), - }, - ], - }, - ("background_2024", "electricity_wind"): { - "name": "Electricity production, wind", - "location": "somewhere", - "reference product": "electricity, wind", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2024", "electricity_wind"), - }, - { - "amount": 1, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - "temporal_distribution": TemporalDistribution( - date=np.array([-2, 1, 2], dtype="timedelta64[Y]"), - amount=np.array([0.2, 0.7, 0.1]), - ), - }, - ], - }, - } - ) - - bd.Database("background_2008").write( - { - ("background_2008", "C"): { - "name": "C", - "location": "somewhere", - "reference product": "c", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2008", "C"), - }, - { - "amount": 1, - "type": "technosphere", - "input": ("background_2008", "electricity_wind"), - }, - ], - }, - ("background_2008", "electricity_wind"): { - "name": "Electricity production, wind", - "location": "somewhere", - "reference product": "electricity, wind", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("background_2008", "electricity_wind"), - }, - { - "amount": 1, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - "temporal_distribution": TemporalDistribution( - date=np.array([-2, 1, 2], dtype="timedelta64[Y]"), - amount=np.array([0.2, 0.7, 0.1]), - ), - }, - ], - }, - } - ) - - bd.Database("foreground").write( - { - ("foreground", "E"): { - "name": "E", - "location": "somewhere", - "reference product": "e", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "E"), - }, - { - "amount": 11, - "type": "technosphere", - "input": ("background_2024", "C"), - }, - { - "amount": 8, - "type": "technosphere", - "input": ("foreground", "B"), - }, - { - "amount": 0.1, - "type": "technosphere", - "input": ("foreground", "A"), - # 'temporal_distribution': # e.g. because some hydrogen was stored in the meantime - # TemporalDistribution( - # date=np.array([-3,-1], dtype='timedelta64[Y]'), # `M` is months - # amount=np.array([0.2,0.8]) - # ), - }, - ], - }, - ("foreground", "D"): { - "name": "D", - "location": "somewhere", - "reference product": "d", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "D"), - }, - { - "amount": 5, - "type": "technosphere", - "input": ("foreground", "B"), - }, - { - "amount": 2, - "type": "technosphere", - "input": ("foreground", "E"), - }, - ], - }, - ("foreground", "B"): { - "name": "B", - "location": "somewhere", - "reference product": "b", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "B"), - }, - { - "amount": 13, - "type": "technosphere", - "input": ("background_2024", "C"), - }, - { - "amount": 1, - "type": "biosphere", - "input": ("temporalis-bio", "CH4"), - "temporal_distribution": TemporalDistribution( - date=np.array( - [ - -2, - ], - dtype="timedelta64[Y]", - ), - amount=np.array([1]), - ), - }, - ], - }, - ("foreground", "A"): { - "name": "A", - "location": "somewhere", - "reference product": "a", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("foreground", "A"), - }, - { - "amount": 17, - "type": "biosphere", - "input": ("temporalis-bio", "CO2"), - }, - { - "amount": 4, - "type": "technosphere", - "input": ("foreground", "B"), - }, - { - "amount": 0.5, - "type": "technosphere", - "input": ("foreground", "D"), - }, - ], - }, - } - ) - - bd.Method(("GWP", "example")).write( - [ - (("temporalis-bio", "CO2"), 1), - ] - ) - - -def db_dynamic_cf_test(): - - project_name = "___db_dynamic_cf_test_ch4_onenodetest__" - if project_name in bd.projects: - bd.projects.delete_project(project_name) - bd.projects.purge_deleted_directories() - - bd.projects.set_current(project_name) - - bd.Database("temporalis-bio").write( - { - ("temporalis-bio", "CO2"): { - "type": "emission", - "name": "carbon dioxide", - "temporalis code": "co2", - }, - ("temporalis-bio", "CH4"): { - "type": "emission", - "name": "methane", - "temporalis code": "ch4", - }, - ("temporalis-bio", "N2O"): { - "type": "emission", - "name": "nitrous oxide", - "temporalis code": "n2o", - }, - } - ) - - bd.Database("test").write( - { - ("test", "A"): { - "name": "A", - "location": "somewhere", - "reference product": "a", - "exchanges": [ - { - "amount": 1, - "type": "production", - "input": ("test", "A"), - }, - { - "amount": 1, - "type": "biosphere", - "input": ("temporalis-bio", "CH4"), - }, - ], - }, - } - ) - - bd.Method(("GWP", "example")).write( - [ - (("temporalis-bio", "CO2"), 1), - (("temporalis-bio", "CH4"), 28.41), # from Levasseur integrals - (("temporalis-bio", "N2O"), 263.97), # from Levasseur integrals - ] - ) diff --git a/tests/fixtures/test_databases.py b/tests/fixtures/vehicle_db_fixture.py similarity index 71% rename from tests/fixtures/test_databases.py rename to tests/fixtures/vehicle_db_fixture.py index 8d99ba7..d01d5d6 100644 --- a/tests/fixtures/test_databases.py +++ b/tests/fixtures/vehicle_db_fixture.py @@ -1,26 +1,21 @@ - +import pytest import bw2data as bd import numpy as np -from bw_temporalis import TemporalDistribution - -def create_electric_vehicle_dbs(): - project_name = "__test_EV1__" - if project_name in bd.projects: - bd.projects.delete_project(project_name) - #bd.projects.purge_deleted_directories() +from bw2data.tests import bw2test +from bw_temporalis import TemporalDistribution - bd.projects.set_current(project_name) +@pytest.fixture +@bw2test +def vehicle_db(): bd.Database("bio").write( { ("bio", "CO2"): { "type": "emission", "name": "carbon dioxide", - }, - }, - + }, ) bd.Database("db_2020").write( @@ -36,14 +31,12 @@ def create_electric_vehicle_dbs(): "input": ("db_2020", "glider"), }, { - "amount": 6.29, #aggregated LCI of CO2-eq + "amount": 6.29, # aggregated LCI of CO2-eq "type": "biosphere", "input": ("bio", "CO2"), }, ], }, - - ("db_2020", "powertrain"): { "name": "market for powertrain, for electric passenger car", "location": "somewhere", @@ -55,14 +48,12 @@ def create_electric_vehicle_dbs(): "input": ("db_2020", "powertrain"), }, { - "amount": 17.89, #aggregated LCI of CO2-eq + "amount": 17.89, # aggregated LCI of CO2-eq "type": "biosphere", "input": ("bio", "CO2"), }, ], }, - - ("db_2020", "battery"): { "name": "battery production, Li-ion, LiMn2O4, rechargeable, prismatic", "location": "somewhere", @@ -74,14 +65,12 @@ def create_electric_vehicle_dbs(): "input": ("db_2020", "battery"), }, { - "amount": 8.23, #aggregated LCI of CO2-eq + "amount": 8.23, # aggregated LCI of CO2-eq "type": "biosphere", "input": ("bio", "CO2"), }, ], }, - - ("db_2020", "electricity"): { "name": "market group for electricity, low voltage", "location": "somewhere", @@ -93,13 +82,12 @@ def create_electric_vehicle_dbs(): "input": ("db_2020", "electricity"), }, { - "amount": 0.73, #aggregated LCI of CO2-eq + "amount": 0.73, # aggregated LCI of CO2-eq "type": "biosphere", "input": ("bio", "CO2"), }, ], }, - ("db_2020", "dismantling"): { "name": "market for manual dismantling of used electric passenger car", "location": "somewhere", @@ -111,14 +99,12 @@ def create_electric_vehicle_dbs(): "input": ("db_2020", "dismantling"), }, { - "amount": 0.0091, #aggregated LCI of CO2-eq + "amount": 0.0091, # aggregated LCI of CO2-eq "type": "biosphere", "input": ("bio", "CO2"), }, ], }, - - ("db_2020", "battery_recycling"): { "name": "market for used Li-ion battery", "location": "somewhere", @@ -130,7 +116,7 @@ def create_electric_vehicle_dbs(): "input": ("db_2020", "battery_recycling"), }, { - "amount": -1.18, #aggregated LCI of CO2-eq + "amount": -1.18, # aggregated LCI of CO2-eq "type": "biosphere", "input": ("bio", "CO2"), }, @@ -152,14 +138,12 @@ def create_electric_vehicle_dbs(): "input": ("db_2030", "glider"), }, { - "amount": 4.37, #aggregated LCI of CO2-eq + "amount": 4.37, # aggregated LCI of CO2-eq "type": "biosphere", "input": ("bio", "CO2"), }, ], }, - - ("db_2030", "powertrain"): { "name": "market for powertrain, for electric passenger car", "location": "somewhere", @@ -171,14 +155,12 @@ def create_electric_vehicle_dbs(): "input": ("db_2030", "powertrain"), }, { - "amount": 11.90, #aggregated LCI of CO2-eq + "amount": 11.90, # aggregated LCI of CO2-eq "type": "biosphere", "input": ("bio", "CO2"), }, ], }, - - ("db_2030", "battery"): { "name": "battery production, Li-ion, LiMn2O4, rechargeable, prismatic", "location": "somewhere", @@ -190,14 +172,12 @@ def create_electric_vehicle_dbs(): "input": ("db_2030", "battery"), }, { - "amount": 5.26, #aggregated LCI of CO2-eq + "amount": 5.26, # aggregated LCI of CO2-eq "type": "biosphere", "input": ("bio", "CO2"), }, ], }, - - ("db_2030", "electricity"): { "name": "market group for electricity, low voltage", "location": "somewhere", @@ -209,13 +189,12 @@ def create_electric_vehicle_dbs(): "input": ("db_2030", "electricity"), }, { - "amount": 0.23, #aggregated LCI of CO2-eq + "amount": 0.23, # aggregated LCI of CO2-eq "type": "biosphere", "input": ("bio", "CO2"), }, ], }, - ("db_2030", "dismantling"): { "name": "market for manual dismantling of used electric passenger car", "location": "somewhere", @@ -227,14 +206,12 @@ def create_electric_vehicle_dbs(): "input": ("db_2030", "dismantling"), }, { - "amount": 0.008, #aggregated LCI of CO2-eq + "amount": 0.008, # aggregated LCI of CO2-eq "type": "biosphere", "input": ("bio", "CO2"), }, ], }, - - ("db_2030", "battery_recycling"): { "name": "market for used Li-ion battery", "location": "somewhere", @@ -246,7 +223,7 @@ def create_electric_vehicle_dbs(): "input": ("db_2030", "battery_recycling"), }, { - "amount": -0.60, #aggregated LCI of CO2-eq + "amount": -0.60, # aggregated LCI of CO2-eq "type": "biosphere", "input": ("bio", "CO2"), }, @@ -268,14 +245,12 @@ def create_electric_vehicle_dbs(): "input": ("db_2040", "glider"), }, { - "amount": 3.71, #aggregated LCI of CO2-eq + "amount": 3.71, # aggregated LCI of CO2-eq "type": "biosphere", "input": ("bio", "CO2"), }, ], }, - - ("db_2040", "powertrain"): { "name": "market for powertrain, for electric passenger car", "location": "somewhere", @@ -287,14 +262,12 @@ def create_electric_vehicle_dbs(): "input": ("db_2040", "powertrain"), }, { - "amount": 9.79, #aggregated LCI of CO2-eq + "amount": 9.79, # aggregated LCI of CO2-eq "type": "biosphere", "input": ("bio", "CO2"), }, ], }, - - ("db_2040", "battery"): { "name": "battery production, Li-ion, LiMn2O4, rechargeable, prismatic", "location": "somewhere", @@ -306,14 +279,12 @@ def create_electric_vehicle_dbs(): "input": ("db_2040", "battery"), }, { - "amount": 4.25, #aggregated LCI of CO2-eq + "amount": 4.25, # aggregated LCI of CO2-eq "type": "biosphere", "input": ("bio", "CO2"), }, ], }, - - ("db_2040", "electricity"): { "name": "market group for electricity, low voltage", "location": "somewhere", @@ -325,13 +296,12 @@ def create_electric_vehicle_dbs(): "input": ("db_2040", "electricity"), }, { - "amount": 0.067, #aggregated LCI of CO2-eq + "amount": 0.067, # aggregated LCI of CO2-eq "type": "biosphere", "input": ("bio", "CO2"), }, ], }, - ("db_2040", "dismantling"): { "name": "market for manual dismantling of used electric passenger car", "location": "somewhere", @@ -343,14 +313,12 @@ def create_electric_vehicle_dbs(): "input": ("db_2040", "dismantling"), }, { - "amount": 0.0077, #aggregated LCI of CO2-eq + "amount": 0.0077, # aggregated LCI of CO2-eq "type": "biosphere", "input": ("bio", "CO2"), }, ], }, - - ("db_2040", "battery_recycling"): { "name": "market for used Li-ion battery", "location": "somewhere", @@ -362,7 +330,7 @@ def create_electric_vehicle_dbs(): "input": ("db_2040", "battery_recycling"), }, { - "amount": -0.40, #aggregated LCI of CO2-eq + "amount": -0.40, # aggregated LCI of CO2-eq "type": "biosphere", "input": ("bio", "CO2"), }, @@ -371,7 +339,7 @@ def create_electric_vehicle_dbs(): } ) - #parameters for EV: + # parameters for EV: ELECTRICITY_CONSUMPTION = 0.2 # kWh/km MILEAGE = 150_000 # km LIFETIME = 16 # years @@ -382,88 +350,86 @@ def create_electric_vehicle_dbs(): MASS_BATTERY = 280 # kg bd.Database("foreground").write( - { ("foreground", "EV"): { - "name": "electric vehicle life cycle", - "location": "somewhere", - "reference product": "electric vehicle life cycle", - "exchanges": [ - - { - "amount": 1, - "type": "production", - "input": ("foreground", "EV"), - }, - - { - "amount": MASS_GLIDER, - "type": "technosphere", - "input": ("db_2020", "glider"), - "temporal_distribution": TemporalDistribution( - date=np.array([-2, -1], dtype="timedelta64[Y]"), #40% of production consumption in year -1, 60% in year -2 - amount=np.array([0.6, 0.4]) - ) - }, - - { - "amount": MASS_POWERTRAIN, - "type": "technosphere", - "input": ("db_2020", "powertrain"), - "temporal_distribution": TemporalDistribution( - date=np.array([-2, -1], dtype="timedelta64[Y]"), #40% of production consumption in year -1, 60% in year -2 - amount=np.array([0.6, 0.4]) - ) - }, - - { - "amount": MASS_BATTERY, - "type": "technosphere", - "input": ("db_2020", "battery"), - "temporal_distribution": TemporalDistribution( - date=np.array([-2, -1], dtype="timedelta64[Y]"), #40% of production consumption in year -1, 60% in year -2 - amount=np.array([0.6, 0.4]) - ) - }, - - { - "amount": ELECTRICITY_CONSUMPTION * MILEAGE, - "type": "technosphere", - "input": ("db_2020", "electricity"), - "temporal_distribution": TemporalDistribution( - date=np.array([int(LIFETIME/2)], dtype="timedelta64[Y]"), #all electricity consumption in year 8, to simplify tests - amount=np.array([1]) - ) - }, - - { - "amount": MASS_GLIDER, - "type": "technosphere", - "input": ("db_2020", "dismantling"), - "temporal_distribution": TemporalDistribution( - date=np.array([LIFETIME + 1], dtype="timedelta64[Y]"), - amount=np.array([1]) - ) - }, - - { - "amount": -MASS_BATTERY, - "type": "technosphere", - "input": ("db_2020", "battery_recycling"), - "temporal_distribution": TemporalDistribution( - date=np.array([LIFETIME + 1], dtype="timedelta64[Y]"), - amount=np.array([1]) - ) - }, - - ], - }, + "name": "electric vehicle life cycle", + "location": "somewhere", + "reference product": "electric vehicle life cycle", + "exchanges": [ + { + "amount": 1, + "type": "production", + "input": ("foreground", "EV"), + }, + { + "amount": MASS_GLIDER, + "type": "technosphere", + "input": ("db_2020", "glider"), + "temporal_distribution": TemporalDistribution( + date=np.array( + [-2, -1], dtype="timedelta64[Y]" + ), # 40% of production consumption in year -1, 60% in year -2 + amount=np.array([0.6, 0.4]), + ), + }, + { + "amount": MASS_POWERTRAIN, + "type": "technosphere", + "input": ("db_2020", "powertrain"), + "temporal_distribution": TemporalDistribution( + date=np.array( + [-2, -1], dtype="timedelta64[Y]" + ), # 40% of production consumption in year -1, 60% in year -2 + amount=np.array([0.6, 0.4]), + ), + }, + { + "amount": MASS_BATTERY, + "type": "technosphere", + "input": ("db_2020", "battery"), + "temporal_distribution": TemporalDistribution( + date=np.array( + [-2, -1], dtype="timedelta64[Y]" + ), # 40% of production consumption in year -1, 60% in year -2 + amount=np.array([0.6, 0.4]), + ), + }, + { + "amount": ELECTRICITY_CONSUMPTION * MILEAGE, + "type": "technosphere", + "input": ("db_2020", "electricity"), + "temporal_distribution": TemporalDistribution( + date=np.array( + [int(LIFETIME / 2)], dtype="timedelta64[Y]" + ), # all electricity consumption in year 8, to simplify tests + amount=np.array([1]), + ), + }, + { + "amount": MASS_GLIDER, + "type": "technosphere", + "input": ("db_2020", "dismantling"), + "temporal_distribution": TemporalDistribution( + date=np.array([LIFETIME + 1], dtype="timedelta64[Y]"), + amount=np.array([1]), + ), + }, + { + "amount": -MASS_BATTERY, + "type": "technosphere", + "input": ("db_2020", "battery_recycling"), + "temporal_distribution": TemporalDistribution( + date=np.array([LIFETIME + 1], dtype="timedelta64[Y]"), + amount=np.array([1]), + ), + }, + ], + }, } ) bd.Method(("GWP", "example")).write( [ (("bio", "CO2"), 1), - ] ) diff --git a/tests/test_electric_vehicle.py b/tests/test_electric_vehicle.py index b481702..f2d0425 100644 --- a/tests/test_electric_vehicle.py +++ b/tests/test_electric_vehicle.py @@ -9,32 +9,32 @@ from datetime import datetime -from .fixtures.test_databases import create_electric_vehicle_dbs +# make sure the test db is loaded +def test_vehicle_db_fixture(vehicle_db): + assert len(bd.databases) == 5 + # for now, one test class, but could be set up more modularly +@pytest.mark.usefixtures("vehicle_db") class TestClass_EV: - - create_electric_vehicle_dbs() #moved database creation to fixtures to avoid cluttered tests, used aggregated LCIs for all excahnges in CO2-eq - bd.projects.set_current("__test_EV__") + @pytest.fixture(autouse=True) + def setup_method(self, vehicle_db): + self.electric_vehicle = bd.get_node(database="foreground", code="EV") - foreground = bd.Database("foreground") - electric_vehicle = bd.get_activity(("foreground", "EV")) - - - database_date_dict = { - "db_2020": datetime.strptime("2020", "%Y"), - "db_2030": datetime.strptime("2030", "%Y"), - "db_2040": datetime.strptime("2040", "%Y"), - "foreground": "dynamic", - } + + database_date_dict = { + "db_2020": datetime.strptime("2020", "%Y"), + "db_2030": datetime.strptime("2030", "%Y"), + "db_2040": datetime.strptime("2040", "%Y"), + "foreground": "dynamic", + } - tlca = TimexLCA(demand={electric_vehicle.key: 1}, method=("GWP", "example"), database_date_dict = database_date_dict) + self.tlca = TimexLCA(demand={self.electric_vehicle.key: 1}, method=("GWP", "example"), database_date_dict = database_date_dict) - tlca.build_timeline() - tlca.lci() - tlca.static_lcia() - tlca.static_score + self.tlca.build_timeline() + self.tlca.lci() + self.tlca.static_lcia() def test_static_lca_score(self): @@ -42,7 +42,7 @@ def test_static_lca_score(self): slca.lci() slca.lcia() expected_static_score = slca.score - + assert self.tlca.static_lca.score == expected_static_score