Skip to main content

background

Background LCI implementation including Tarjan Ordering.

This is kept as a separate repo because it is the only place numpy/scipy is required. The idea is to enable people to run LCI/A computations without having the background data on their machine or having to perform matrix construction and inversion (i.e. only using foreground computations, like GaBi does).

Partial Ordering

The default implementation performs an ordering of the LCI database using Tarjan's algorithm for detecting strongly-connected components (see Partial Ordering of Life Cycle Inventory Databases)

It performs the ordering, and then builds and stores a static LCI database (A and B matrices).
This code is a bit convoluted, but it works.

(Muttered question from the audience)

No, it isn't tested. Tests have been performed (and passed).

(indistinct grumbling)

I know. I'm sorry.

Installing

Installation should be straightforward-- lxml is required here to access a local copy of ecoinvent.

user@host$ pip install antelope_background lxml

Setting up a catalog with ecoinvent data

>>> from antelope_core import LcCatalog
>>> from antelope_core.data_sources.ecoinvent import EcoinventConfig
>>> cat = LcCatalog('/home/user/my_catalog')
Loading JSON data from /home/b/my_catalog/reference-quantities.json:
local.qdb: /home/b/my_catalog/reference-quantities.json
local.qdb: /data/GitHub/lca-tools/lcatools/qdb/data/elcd_reference_quantities.json
25 new quantity entities added (25 total)
6 new flow entities added (6 total)
 
>>> ec = EcoinventConfig('/path/to/ecoinvent')
>>> for res in ec.make_resources('local.ecoinvent.3.7.1.cutoff'):
        cat.add_resource(res)
 
>>> cat.show_interfaces()
local.ecoinvent.3.7.1.cutoff [basic, exchange]
local.qdb [basic, index, quantity]
 
>>>

When the background is installed, new interface methods are available for catalog queries. In order to access them, the background matrix must be constructed, which is done through traversal of the LCI network using Tarjan's algorithm. This is triggered automatically any time you request a background interface method. But it can also be triggered explicitly:

>>> q = cat.query('local.ecoinvent.3.7.1.cutoff')
>>> q.check_bg()
... # several minutes pass 
 Loaded 17400 processes (t=158.06 s)
 Loaded 17495 processes (t=158.69 s)
20 new quantity entities added (20 total)
5333 new flow entities added (5333 total)
17495 new process entities added (17495 total)
...
Creating flat background
...
 True
 
>>> cat.show_interfaces()
local.ecoinvent.3.7.1.cutoff [basic, exchange]
local.ecoinvent.3.7.1.cutoff.index.20210205 [background, basic, index]
local.qdb [basic, index, quantity]
 
>>>

The check_bg() route is slow because it requires indexing the database and traversing all exchanges, both of which require loading all XML files. Fortunately, if the two steps are done during the same python session, then the inventory remains in memory and each file only has to be loaded once.

Once the background matrix and index are created, the XML files do not need to be individually loaded except to access details about a specific process.

Now that the background interface exists, background queries can be conducted.

Contributing

Please do!

Metadata

Release files for antelope-background 0.3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for antelope-background 0.3.3
File Size Uploaded Provenance Actions
antelope_background-0.3.3.tar.gz 36.4 kB Without provenance Details for antelope_background-0.3.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for antelope-background 0.3.3
File Interpreter ABI Platform Actions
antelope_background-0.3.3-py3-none-any.whl Python 3 none any Details for antelope_background-0.3.3-py3-none-any.whl

Total release size: 83.7 kB

Release files / antelope_background-0.3.3.tar.gz

Download URL antelope_background-0.3.3.tar.gz
Size 36.4 kB
Tags Source
SHA-256 checksum
How to use checksums
510bbf7bfe13144493a8bdc25661060e5000bede0e8e2d8dbbce5907adcfcb1d
BLAKE2b-256 checksum
How to use checksums
99ebe3f8d8c80ebe3ffd1326a5585d6acd686706b3ffb30fd2b720b59d19cc0a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.12

Release files / antelope_background-0.3.3-py3-none-any.whl

Download URL antelope_background-0.3.3-py3-none-any.whl
Size 47.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5bded0d26c8fa37a0650b2accfa49fd1b8d3d65187ff6feb4dffb3756a1ff40f
BLAKE2b-256 checksum
How to use checksums
0c1aa31d2772027b1d2d43c207f7d83e645470654120b839c331734a7bad6750
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.12

Security for antelope-background 0.3.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page