Skip to content

Commit 1dee23f

Browse files
authored
Merge pull request #1532 from mrvisscher/major-ecoinvent-import
Quick-fix for already extracted ecoinvent releases
2 parents e75db0d + 0aa1e7e commit 1dee23f

6 files changed

Lines changed: 44 additions & 14 deletions

File tree

.github/ISSUE_TEMPLATE/bug_report.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Bug report
22
description: File a bug report for AB.
3-
labels: ["bug"]
3+
type: Bug
44
body:
55
- type: markdown
66
attributes:
@@ -35,9 +35,10 @@ body:
3535
options:
3636
- Windows 10
3737
- Windows 11
38-
- MacOS
38+
- MacOS (Apple Silicon)
39+
- MacOS (Intel)
3940
- Linux/Other (please specify above)
40-
default: 0
41+
default: 1
4142
- type: textarea
4243
id: conda-env
4344
attributes:

.github/ISSUE_TEMPLATE/feature_request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Feature request
22
description: File a feature request for AB.
3-
labels: ["feature"]
3+
type: Feature
44
body:
55
- type: markdown
66
attributes:

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99

1010
# Activity Browser
1111

12+
13+
> [!TIP]
14+
> **Activity Browser** now has an open beta for Version 3🚀.
15+
>
16+
> The beta supports many new features such as Multi-functionality and uses Brightway 2.5 under the hood.
17+
> Help us by making Activity Browser even better by using and providing feedback on Activity Browser.
18+
>
19+
> Learn more about the beta
20+
> [here](https://lca-activitybrowser.github.io/activity-browser/beta.html).
21+
1222
<img src="https://user-images.githubusercontent.com/33026150/54299977-47a9f680-45bc-11e9-81c6-b99462f84d0b.png" width=100%/>
1323

1424
The **Activity Browser (AB) is an open source software for Life Cycle Assessment (LCA)** that builds on [Brightway2](https://brightway.dev).

activity_browser/actions/database/database_import_from_ecoinvent.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import re
2+
import os
23
from logging import getLogger
34
from copy import deepcopy
45

@@ -223,7 +224,7 @@ def run_safely(self, release: ei.release, version: str, model: str):
223224
fix_version=False
224225
)
225226
path = str(path)
226-
if not path.endswith(".7z"):
227+
if not path.endswith(".7z") and os.path.exists(path + ".7z"):
227228
path = path + ".7z"
228229
self.download_ready.emit(path)
229230

activity_browser/bwutils/io/ecoinvent_importer.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,21 @@ class Ecoinvent7zImporter:
4242

4343
def __init__(self, archive_path: str) -> None:
4444
self.archive_path = archive_path
45+
self.is_compressed = archive_path.endswith('.7z')
4546

4647
def install_biosphere(self, biosphere_name: str = "biosphere3") -> None:
4748
"""
4849
Installs the biosphere that is bundled in the ecoinvent .7z. Simple extraction and installing through the
4950
standard bw2io importer is quick enough because we're talking about a single file.
5051
"""
51-
# extract the elementary exchanges to a temporary location
52-
with py7zr.SevenZipFile(self.archive_path, mode='r') as archive:
53-
temp = tempfile.gettempdir()
54-
archive.extract(temp, ["MasterData/ElementaryExchanges.xml"])
55-
bio_file = os.path.join(temp, "MasterData/ElementaryExchanges.xml")
52+
if self.is_compressed:
53+
# extract the elementary exchanges to a temporary location
54+
with py7zr.SevenZipFile(self.archive_path, mode='r') as archive:
55+
temp = tempfile.gettempdir()
56+
archive.extract(temp, ["MasterData/ElementaryExchanges.xml"])
57+
bio_file = os.path.join(temp, "MasterData", "ElementaryExchanges.xml")
58+
else:
59+
bio_file = os.path.join(self.archive_path, "MasterData", "ElementaryExchanges.xml")
5660

5761
# initiate the importer with the elementary exchanges file
5862
importer = Ecospold2BiosphereImporter(biosphere_name, None, bio_file)
@@ -71,11 +75,16 @@ def install_ecoinvent(self, db_name, biosphere_name: str = "biosphere3"):
7175
log.warning(f"Database already exists, overwriting {db_name}")
7276
bd.Database(db_name).delete(warn=False)
7377

74-
# load the spold files into memory
75-
spold_bytes = self.read_archive_to_bytes()
78+
if self.is_compressed:
79+
# load the spold files into memory
80+
spold_bytes = self.read_archive_to_bytes()
81+
82+
# process the in-memory data to a dict format and applying strategies
83+
db_data = self.process_bytes(spold_bytes, db_name)
84+
else:
85+
# if the archive is not compressed, we can use the standard importer
86+
db_data = Ecospold2DataExtractor.extract(os.path.join(self.archive_path, "datasets"), db_name)
7687

77-
# process the in-memory data to a dict format and applying strategies
78-
db_data = self.process_bytes(spold_bytes, db_name)
7988
db_data = self.apply_strategies(db_data, biosphere_name)
8089

8190
# rewrite into an ingestible format

activity_browser/docs/wiki/_Footer.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,12 @@ Activity Browser is a __community project__, we rely on __you__ for it to be awe
22

33
| <picture><img alt="Activity Browser logo" src="./assets/activitybrowser.png" width="25"></picture> | ❓ Need help?<br/>[💬 Ask the community](https://github.com/LCA-ActivityBrowser/activity-browser/discussions?discussions_q=) | 💡 Ideas to improve?<br/>[💭 Request a feature](https://github.com/LCA-ActivityBrowser/activity-browser/issues/new?assignees=&labels=feature&projects=&template=feature_request.yml) | 🔥 Something Broken?<br/>[🪲 Start a bug report](https://github.com/LCA-ActivityBrowser/activity-browser/issues/new?assignees=&labels=bug&projects=&template=bug_report.yml) | ⚙️ Want to help out? <br/>[🛠️ Learn how to contribute](https://github.com/LCA-ActivityBrowser/activity-browser/blob/main/CONTRIBUTING.md) |
44
|----------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------|
5+
6+
> [!TIP]
7+
> **Activity Browser** now has an open beta for Version 3🚀.
8+
>
9+
> The beta supports many new features such as Multi-functionality and uses Brightway 2.5 under the hood.
10+
> Help us by making Activity Browser even better by using and providing feedback on Activity Browser.
11+
>
12+
> Learn more about the beta
13+
> [here](https://lca-activitybrowser.github.io/activity-browser/beta.html).

0 commit comments

Comments
 (0)