-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
317e15b
commit 55eba6e
Showing
48 changed files
with
886 additions
and
610 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,15 @@ As it now evolves towards a more IAM-neutral approach, a change of name was cons | |
|
||
Scientific publication available here: [Sacchi et al, 2022](https://doi.org/10.1016/j.rser.2022.112311). | ||
|
||
What's new in 1.8.0? | ||
==================== | ||
|
||
- Added support for brightway 2.5 | ||
- Added support for Python 3.11 | ||
- Uses bw2io 0.8.10 | ||
- Adds electricity storage in electricity markets -- see [docs](https://premise.readthedocs.io/en/latest/transform.html#storage) | ||
- Adds [scenario explorer dashboard](https://premisedash-6f5a0259c487.herokuapp.com/) | ||
|
||
What's new in 1.5.0? | ||
==================== | ||
|
||
|
@@ -52,7 +61,7 @@ ecoinvent 3 to reflect projected energy policy trajectories. | |
|
||
Requirements | ||
------------ | ||
* **Python 3.9** | ||
* **Python 3.9, 3.10 or 3.11** | ||
* License for [ecoinvent 3][1] | ||
* Some IAM output files come with the library and are located by default in the subdirectory "/data/iam_output_files". **If you wish to use | ||
those files, you need to request (by [email](mailto:[email protected])) an encryption key from the developers**. | ||
|
@@ -67,11 +76,8 @@ Two options: | |
A development version with the latest advancements (but with the risks of unseen bugs), | ||
is available from Anaconda Cloud: | ||
|
||
|
||
conda config --append conda-forge | ||
conda config --append cmutel | ||
conda config --append romainsacchi | ||
conda install premise | ||
|
||
conda install -c romainsacchi premise | ||
|
||
|
||
For a more stable and proven version, from Pypi: | ||
|
@@ -88,17 +94,22 @@ The best way is to follow [the examples from the Jupyter Notebook](https://githu | |
|
||
# Support | ||
|
||
Do not hesitate to contact the development team at [[email protected]](mailto:[email protected]) | ||
or [[email protected]](mailto:[email protected]). | ||
Do not hesitate to contact [[email protected]](mailto:[email protected]). | ||
|
||
## Maintainers | ||
## Contributors | ||
|
||
* [Romain Sacchi](https://github.com/romainsacchi) | ||
* [Alois Dirnaichner](https://github.com/Loisel) | ||
* [Tom Mike Terlouw](https://github.com/tomterlouw) | ||
* [Laurent Vandepaer](https://github.com/lvandepaer) | ||
* [Chris Mutel](https://github.com/cmutel/) | ||
|
||
|
||
## Maintainers | ||
|
||
* [Romain Sacchi](https://github.com/romainsacchi) | ||
* [Chris Mutel](https://github.com/cmutel/) | ||
|
||
## Contributing | ||
|
||
See [contributing](https://github.com/polca/premise/blob/master/CONTRIBUTING.md). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,6 @@ | ||
__all__ = ("NewDatabase", "clear_cache", "get_regions_definition") | ||
__version__ = (1, 7, 2) | ||
__version__ = (1, 8, 1) | ||
|
||
from pathlib import Path | ||
|
||
DATA_DIR = Path(__file__).resolve().parent / "data" | ||
INVENTORY_DIR = Path(__file__).resolve().parent / "data" / "additional_inventories" | ||
VARIABLES_DIR = Path(__file__).resolve().parent / "iam_variables_mapping" | ||
|
||
from .ecoinvent_modification import NewDatabase | ||
from .utils import clear_cache, get_regions_definition |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from bw2data import databases | ||
from bw2io.importers.base_lci import LCIImporter | ||
from wurst.linking import change_db_name, check_internal_linking, link_internal | ||
|
||
from .utils import reset_all_codes | ||
|
||
|
||
class BW2Importer(LCIImporter): | ||
def __init__(self, db_name, data): | ||
self.db_name = db_name | ||
self.data = data | ||
for act in self.data: | ||
act["database"] = self.db_name | ||
|
||
# we override `write_database` | ||
# to allow existing databases | ||
# to be overwritten | ||
def write_database(self): | ||
if self.db_name in databases: | ||
print(f"Database {self.db_name} already exists: it will be overwritten.") | ||
super().write_database() | ||
|
||
|
||
def write_brightway_database(data, name): | ||
# Restore parameters to Brightway2 format | ||
# which allows for uncertainty and comments | ||
change_db_name(data, name) | ||
link_internal(data) | ||
check_internal_linking(data) | ||
BW2Importer(name, data).write_database() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import itertools | ||
from copy import copy | ||
|
||
from bw2data import Database, databases | ||
from bw2io.importers.base_lci import LCIImporter | ||
from wurst.linking import change_db_name, check_internal_linking, link_internal | ||
|
||
|
||
class BW25Importer(LCIImporter): | ||
def __init__(self, db_name, data): | ||
self.db_name = db_name | ||
self.data = data | ||
for act in self.data: | ||
act["database"] = self.db_name | ||
|
||
# we override `write_database` | ||
# to allow existing databases | ||
# to be overwritten | ||
def write_database(self): | ||
def no_exchange_generator(data): | ||
for ds in data: | ||
cp = copy(ds) | ||
cp["exchanges"] = [] | ||
yield cp | ||
|
||
if self.db_name in databases: | ||
print(f"Database {self.db_name} already exists: " "it will be overwritten.") | ||
super().write_database( | ||
list(no_exchange_generator(self.data)), backend="iotable" | ||
) | ||
|
||
dependents = {exc["input"][0] for ds in self.data for exc in ds["exchanges"]} | ||
lookup = { | ||
obj.key: obj.id | ||
for obj in itertools.chain(*[Database(label) for label in dependents]) | ||
} | ||
|
||
def technosphere_generator(data, lookup): | ||
for ds in data: | ||
target = lookup[(ds["database"], ds["code"])] | ||
for exc in ds["exchanges"]: | ||
if exc["type"] in ( | ||
"substitution", | ||
"production", | ||
"generic production", | ||
): | ||
yield { | ||
"row": lookup[exc["input"]], | ||
"col": target, | ||
"amount": exc["amount"], | ||
"flip": False, | ||
} | ||
elif exc["type"] == "technosphere": | ||
yield { | ||
"row": lookup[exc["input"]], | ||
"col": target, | ||
"amount": exc["amount"], | ||
"flip": True, | ||
} | ||
|
||
def biosphere_generator(data, lookup): | ||
for ds in data: | ||
target = lookup[(ds["database"], ds["code"])] | ||
for exc in ds["exchanges"]: | ||
if exc["type"] == "biosphere": | ||
yield { | ||
"row": lookup[exc["input"]], | ||
"col": target, | ||
"amount": exc["amount"], | ||
"flip": False, | ||
} | ||
|
||
Database(self.db_name).write_exchanges( | ||
technosphere_generator(self.data, lookup), | ||
biosphere_generator(self.data, lookup), | ||
list(dependents), | ||
) | ||
|
||
|
||
def write_brightway_database(data, name): | ||
# Restore parameters to Brightway2 format | ||
# which allows for uncertainty and comments | ||
change_db_name(data, name) | ||
link_internal(data) | ||
check_internal_linking(data) | ||
BW25Importer(name, data).write_database() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.