Skip to content

Commit

Permalink
0.9.dev25
Browse files Browse the repository at this point in the history
  • Loading branch information
cmutel committed Nov 10, 2023
1 parent d11ff60 commit 9810c48
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 81 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
@@ -1,5 +1,10 @@
# `bw2io` Changelog

### 0.9.DEV25 (2023-11-10)

* Fix missing import from dev24
* Some documentation improvements

### 0.9.DEV24 (2023-11-09)

* [#227 Add `import_ecoinvent_release` utility](https://github.com/brightway-lca/brightway2-io/pull/227)
Expand Down
67 changes: 3 additions & 64 deletions README.rst
Expand Up @@ -17,77 +17,16 @@ Brightway2 input and output
:target: https://coveralls.io/bitbucket/cmutel/brightway2-io?branch=default
:alt: Test coverage report

This package provides tools for the import, export, and management of inventory databases and impact assessment methods. It is part of the `Brightway2 LCA framework <https://brightway.dev/>`_. `Online documentation <https://2.docs.brightway.dev/>`_ is available, and the source code is hosted on `Github <https://github.com/brightway-lca/brightway2-io>`_.

Compatibility with Brightway2X
------------------------------
*Until there is a solution to using seamlessly bw2io to use any flow list (to create the biosphere) regardless of the bw2io and brightway2X package version, specific versions of bw2io must be used for compatibility with specific ecoinvent versions.*

This code in this repository is used to release packages for both `Brightway25 <https://github.com/brightway-lca/brightway25>`_ (the current default branch of this repository `"master" <https://github.com/brightway-lca/brightway2-io/tree/master>`_) and `Brightway2 <https://github.com/brightway-lca/brightway2>`_ (the `"legacy" <https://github.com/brightway-lca/brightway2-io/tree/legacy>`_ branch in this repository).

- For the *Brightway2 compatible* version, use a ``0.8.X`` version.
- use version ``0.8.7`` to have a Brightway2 installation compatible with Ecoinvent 3.8

If you have a working environment with brightway2 ::

conda install -c conda-forge -c cmutel bw2io=0.8.7

If you have are starting a new environment ::
conda install -c conda-forge -c cmutel brightway2 bw2io=0.8.7
- use version ``0.8.8`` to have a Brightway2 installation compatible with Ecoinvent 3.9 ::
conda install -c conda-forge bw2io=0.8.8 # If you have a working environment with brightway2
conda install -c conda-forge brightway2 bw2io=0.8.8 # If you are starting a new environment
- For the *Brightway25 compatible* version, use a ``0.9.X`` version.
- use version ``0.9.dev11`` to have a Brightway2 installation compatible with Ecoinvent 3.8.

*This version is only available through pypi.*

If you already have a brightway25 environment, do ::
pip install bw2io==0.9.dev11
- use version ``0.9.dev10`` to have a Brightway2 installation compatible with Ecoinvent 3.9 ::
conda install -c conda-forge -c cmutel bw2io=0.9.dev10 # If you have a working environment with brightway25
conda install -c conda-forge -c cmutel brightway25 bw2io=0.9.dev10 # If you are starting a new environment
TL;DR
^^^^^

Summing up, you need a specific version of bw2io for specific versions of ecoinvent 3.8 and 3.9.::

+------------------|-------------------|------------------+
|Ecoinvent version | Brightway Version | bw2io Version |
+==================|===================|==================+
|ecoinvent 3.8 | bw2 | bw2io 0.8.7 |
+------------------|-------------------|------------------+
|ecoinvent 3.9 | bw2 | bw2io 0.8.8 |
+------------------|-------------------|------------------+
|ecoinvent 3.8 | bw25 | bw2io 0.9.dev11 |
+------------------|-------------------|------------------+
|ecoinvent 3.9 | bw25 | bw2io 0.9.dev10 |
+------------------|-------------------|------------------+


This package provides tools for the import, export, and management of inventory databases and impact assessment methods. It is part of the `Brightway LCA framework <https://brightway.dev/>`_. `Online documentation <https://2.docs.brightway.dev/>`_ is available, and the source code is hosted on `Github <https://github.com/brightway-lca/brightway2-io>`_.

Bw2io approach
---------------

In contrast with previous IO functionality in Brightway2, brightway2-io uses an iterative approach to importing and linking data. First, data is *extracted* into a common format. Next, a series of *strategies* is employed to uniquely identify each dataset and link datasets internally and to the biosphere. Following internal linking, linking to other background datasets can be performed. Finally, database data is written to disk.
brightway2-io is an ETL library. First, data is *extracted* into a common format. Next, a series of *strategies* is employed to uniquely identify each dataset and link datasets internally and to the biosphere. Following internal linking, linking to other background datasets can be performed. Finally, database data is written to disk.

This approach offers a number of benefits that help mitigate some of the serious problems in existing inventory data formats: the number of unlinked exchanges can be easily seen, linking strategies can be iteratively applied, and intermediate results can be saved.

Here is a typical usage:

Here is a typical usage. Note that we also have shortcuts for popular LCA databases such as ecoinvent:

.. code-block:: python
Expand Down
38 changes: 22 additions & 16 deletions bw2io/ecoinvent.py
Expand Up @@ -68,11 +68,16 @@ def import_ecoinvent_release(
"""
Import an ecoinvent LCI and/or LCIA release.
Uses [ecoinvent_interface](https://github.com/brightway-lca/ecoinvent_interface). Auth credentials are optional as they can be set externally (see the `ecoinvent_interface` documentation), and such permanent storage is highly recommended.
Uses [ecoinvent_interface](https://github.com/brightway-lca/ecoinvent_interface).
Auth credentials are optional as they can be set externally (see the
`ecoinvent_interface` documentation), and such permanent storage is highly
recommended.
**DO NOT** run `bw2setup` before using this function - it isn't needed and will cause broken results.
**DO NOT** run `bw2setup` before using this function - it isn't needed and
will cause broken results.
System model strings follow the ecoinvent unofficial API. They are given in a short or long form. The short forms:
System model strings follow the ecoinvent unofficial API. They can be given
in a short or long form. The short forms:
* cutoff
* consequential
Expand All @@ -91,17 +96,20 @@ def import_ecoinvent_release(
version
The ecoinvent release version as a string, e.g. '3.9.1'
system_model
The system model as a string in short or long form, e.g. 'apos' or 'Allocation cut-off by classification'
The system model as a string in short or long form, e.g. 'apos' or
'Allocation cut-off by classification'
username
ecoinvent username
password
ecoinvent password
lci
Flag on whether to import the inventory database
lcia
Flag on whether to import the LCIA impact categories
Flag on whether to import the LCIA impact categories. The biosphere
database must exist if `lci` is `False`
biosphere_name
Name of database to store biosphere flows. They will be stored in the main LCI database if not specified.
Name of database to store biosphere flows. They will be stored in the
main LCI database if not specified.
use_existing_biosphere
Flag on whether to create a new biosphere database or use an existing one
importer_signal
Expand All @@ -112,17 +120,14 @@ def import_ecoinvent_release(
Get ecoinvent 3.9.1 cutoff in a new project (**without** running `bw2setup` first):
>>> my_ecoinvent_username = "XXX"
>>> my_ecoinvent_password = "XXX"
>>> import ecoinvent_interface as ei
>>> import bw2data as bd
>>> import bw2io as bi
>>> bd.projects.set_current("some new project")
>>> bi.import_ecoinvent_release(
... version="3.9.1",
... system_model="cutoff",
... username=my_ecoinvent_username,
... password=my_ecoinvent_password,
... username="XXX",
... password="XXX"",
... )
>>> bd.databases
Databases dictionary with 2 object(s):
Expand All @@ -136,8 +141,8 @@ def import_ecoinvent_release(
>>> bi.import_ecoinvent_release(
... version="3.9.1",
... system_model="apos",
... username=my_ecoinvent_username,
... password=my_ecoinvent_password,
... username="XXX",
... password="XXX"",
... use_existing_biosphere=True
... )
>>> bd.databases
Expand All @@ -146,14 +151,15 @@ def import_ecoinvent_release(
ecoinvent-3.9.1-biosphere
ecoinvent-3.9.1-cutoff
Create a new database but use `biosphere3` for the biosphere database name don't add LCIA methods
Create a new database but use `biosphere3` for the biosphere database name
and don't add LCIA methods:
>>> bd.projects.set_current("some other project")
>>> bi.import_ecoinvent_release(
... version="3.9.1",
... system_model="cutoff",
... username=my_ecoinvent_username,
... password=my_ecoinvent_password,
... username="XXX",
... password="XXX",
... biosphere_name="biosphere3",
... lcia=False
... )
Expand Down
2 changes: 1 addition & 1 deletion bw2io/version.py
@@ -1 +1 @@
version = (0, 9, "DEV24")
version = (0, 9, "DEV25")

0 comments on commit 9810c48

Please sign in to comment.