Skip to content

Commit

Permalink
Merge branch 'master' of github.com:MTES-MCT/ecobalyse into switch_to…
Browse files Browse the repository at this point in the history
…_brightway
  • Loading branch information
ccomb committed Nov 25, 2024
2 parents 8996060 + 1939b77 commit 31b6e4c
Show file tree
Hide file tree
Showing 30 changed files with 7,878 additions and 2,364 deletions.
51 changes: 51 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,57 @@
# Changelog


## [2.6.0](https://github.com/MTES-MCT/ecobalyse/compare/v2.5.0..v2.6.0) (2024-11-20)



### 🚀 Features

- Add API FAQ page. ([#829](https://github.com/MTES-MCT/ecobalyse/issues/829))
- Intégration Laine woolmark ([#831](https://github.com/MTES-MCT/ecobalyse/issues/831))

### ⚙️ Miscellaneous Tasks

- Upgrade dependencies, Nov. 2024. ([#830](https://github.com/MTES-MCT/ecobalyse/issues/830))
- *(data)* Fixed typo paysane→paysanne ([#836](https://github.com/MTES-MCT/ecobalyse/issues/836))


## [2.5.0](https://github.com/MTES-MCT/ecobalyse/compare/v2.4.0..v2.5.0) (2024-11-07)



### 🚀 Features

- Add bookmarks for objects ([#781](https://github.com/MTES-MCT/ecobalyse/issues/781))
- Add object explorer pages. ([#803](https://github.com/MTES-MCT/ecobalyse/issues/803))
- Distinguish Objects from Veli. ([#813](https://github.com/MTES-MCT/ecobalyse/issues/813))
- Display score without durability ([#815](https://github.com/MTES-MCT/ecobalyse/issues/815))
- Textile export ([#808](https://github.com/MTES-MCT/ecobalyse/issues/808))
- Object export ([#812](https://github.com/MTES-MCT/ecobalyse/issues/812))

### 🪲 Bug Fixes

- Create object encrypted file for versions ([#800](https://github.com/MTES-MCT/ecobalyse/issues/800))
- Improve object simulator. ([#799](https://github.com/MTES-MCT/ecobalyse/issues/799))
- Fix encoded display name field. ([#820](https://github.com/MTES-MCT/ecobalyse/issues/820))

### 🚜 Refactor

- Aggregate in python ([#794](https://github.com/MTES-MCT/ecobalyse/issues/794))
- Turn food process category into a list ([#795](https://github.com/MTES-MCT/ecobalyse/issues/795))
- Aggregate in python ([#807](https://github.com/MTES-MCT/ecobalyse/issues/807))

### ⚙️ Miscellaneous Tasks

- Upgrade dependencies to their latest version, Oct. 2024. ([#801](https://github.com/MTES-MCT/ecobalyse/issues/801))
- Add tolerance to tests comparison ([#810](https://github.com/MTES-MCT/ecobalyse/issues/810))
- *(data)* New export ([#819](https://github.com/MTES-MCT/ecobalyse/issues/819))

### ◀️ Revert

- "refactor: aggregate in python" ([#806](https://github.com/MTES-MCT/ecobalyse/issues/806))


## [2.4.0](https://github.com/MTES-MCT/ecobalyse/compare/v2.3.0..v2.4.0) (2024-10-10)


Expand Down
4 changes: 3 additions & 1 deletion data/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def normalization_factors(impact_defs):


def spproject(activity):
"""return the current simapro project for an activity"""
"""return the current simapro project for an activity source database"""
match activity.get("database"):
case "Ginko":
return "Ginko w/o azadirachtin"
Expand All @@ -26,6 +26,8 @@ def spproject(activity):
return "EcobalyseIsNotASimaProProject"
case "Ecoinvent 3.9.1":
return "ADEME UPR"
case "Woolmark":
return "Woolmark"
case _:
return "AGB3.1.1 2023-03-06"

Expand Down
19 changes: 14 additions & 5 deletions data/common/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,22 @@ def progress_bar(index, total):
print(f"Export in progress: {str(index)}/{total}", end="\r")


def search(dbname, name, excluded_term=None):
results = bw2data.Database(dbname).search(name)
def search(dbname, search_terms, excluded_term=None):
results = bw2data.Database(dbname).search(search_terms)
if excluded_term:
results = [res for res in results if excluded_term not in res["name"]]
if not results:
print(f"Not found in brightway : '{name}'")
print(f"Not found in brightway : '{search_terms}'")
return None
if len(results) > 1:
# if the search gives more than one results, find the one with exact name
exact_results = [a for a in results if a["name"] == search_terms]
if len(exact_results) == 1:
return exact_results[0]
else:
raise ValueError(
f"This 'search' field returns more than one result in database {dbname}: {search_terms}"
)
return results[0]


Expand Down Expand Up @@ -374,8 +383,8 @@ def load_json(filename):


@functools.cache
def cached_search(dbname, name, excluded_term=None):
return search(dbname, name, excluded_term)
def cached_search(dbname, search_terms, excluded_term=None):
return search(dbname, search_terms, excluded_term)


def find_id(dbname, activity):
Expand Down
61 changes: 33 additions & 28 deletions data/common/import_.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import functools
import json
import os
import re
import sys
from os.path import dirname
import tempfile
from os.path import basename, join, splitext
from subprocess import call
from zipfile import ZipFile

Expand Down Expand Up @@ -173,6 +173,7 @@ def add_variant_activity(activity_data, dbname):
def import_simapro_csv(
datapath,
dbname,
external_db=None,
biosphere="biosphere3",
migrations=[],
first_strategies=[],
Expand All @@ -185,29 +186,29 @@ def import_simapro_csv(
"""
print(f"### Importing {datapath}...")
# unzip
with ZipFile(datapath) as zf:
print("### Extracting the zip file...")
zf.extractall(path=dirname(datapath))
unzipped = datapath[0:-4]

if "AGB" in datapath:
print("### Patching Agribalyse...")
# `yield` is used as a variable in some Simapro parameters. bw2parameters cannot handle it:
# (sed is faster than Python)
call("sed -i 's/yield/Yield_/g' " + unzipped, shell=True)
# Fix some errors in Agribalyse:
call("sed -i 's/01\\/03\\/2005/1\\/3\\/5/g' " + unzipped, shell=True)
call("sed -i 's/\"0;001172\"/0,001172/' " + unzipped, shell=True)

print(f"### Importing into {dbname}...")
# Do the import
database = bw2io.importers.simapro_csv.SimaProCSVImporter(
unzipped, dbname, normalize_biosphere=True
)
if source:
for ds in database:
ds["source"] = source
os.unlink(unzipped)
with tempfile.TemporaryDirectory() as tempdir:
with ZipFile(datapath) as zf:
print(f"### Extracting the zip file in {tempdir}...")
zf.extractall(path=tempdir)
unzipped, _ = splitext(join(tempdir, basename(datapath)))

if "AGB" in datapath:
print("### Patching Agribalyse...")
# `yield` is used as a variable in some Simapro parameters. bw2parameters cannot handle it:
# (sed is faster than Python)
call("sed -i 's/yield/Yield_/g' " + unzipped, shell=True)
# Fix some errors in Agribalyse:
call("sed -i 's/01\\/03\\/2005/1\\/3\\/5/g' " + unzipped, shell=True)
call("sed -i 's/\"0;001172\"/0,001172/' " + unzipped, shell=True)

print(f"### Importing into {dbname}...")
# Do the import
database = bw2io.importers.simapro_csv.SimaProCSVImporter(
unzipped, dbname, normalize_biosphere=True
)
if source:
for ds in database:
ds["source"] = source

print("### Applying migrations...")
# Apply provided migrations
Expand All @@ -223,20 +224,24 @@ def import_simapro_csv(
print("### Applying strategies...")
# exclude strategies/migrations
database.strategies = (
first_strategies
list(first_strategies)
+ [
s
for s in database.strategies
if not any([e in repr(s) for e in excluded_strategies])
]
+ other_strategies
+ list(other_strategies)
)

database.apply_strategies()
database.statistics()
# try to link remaining unlinked technosphere activities
database.apply_strategy(
functools.partial(link_technosphere_by_activity_hash, fields=("name", "unit"))
functools.partial(
link_technosphere_by_activity_hash,
external_db_name=external_db,
fields=("name", "unit"),
)
)
database.apply_strategy(
functools.partial(
Expand Down
2 changes: 1 addition & 1 deletion data/create_activities.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
del bw2data.databases["Ecobalyse"]

if (db := "Ecobalyse") not in bw2data.databases:
for vertical in ("object", "food", "textile"):
for vertical in ("food", "textile", "object"):
file = f"{vertical}/activities_to_create.json"
if os.path.exists(file):
add_created_activities(db, file)
Expand Down
2 changes: 1 addition & 1 deletion data/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ RUN mkdir -p /home/$NB_USER/data \

# keep in sync with requirements.txt
# allow to update the image if the source repo is updated
ADD https://api.github.com/repos/ccomb/brightway2-io/git/refs/tags/ccomb-5 bw2-io.json
ADD https://api.github.com/repos/ccomb/brightway2-io/git/refs/tags/ccomb-6 bw2-io.json
ADD https://api.github.com/repos/brightway-lca/brightway2-parameters/git/refs/tags/1.1.0 bw2-parameters.json
ADD https://api.github.com/repos/brightway-lca/brightway2-data/git/refs/tags/4.0.dev42 bw2-data.json
ADD https://api.github.com/repos/brightway-lca/brightway2-calc/git/refs/tags/2.0.dev17 bw2-calc.json
Expand Down
2 changes: 1 addition & 1 deletion data/docker/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ git+https://github.com/brightway-lca/[email protected]
git+https://github.com/brightway-lca/[email protected]
git+https://github.com/brightway-lca/[email protected]
git+https://github.com/brightway-lca/[email protected]
git+https://github.com/ccomb/brightway2-io@ccomb-5
git+https://github.com/ccomb/brightway2-io@ccomb-6
ipywidgets>=8.1, <8.2
jupyter-collaboration>=2.0, <2.1
matplotlib>=3.7, <3.8
Expand Down
Loading

0 comments on commit 31b6e4c

Please sign in to comment.