Skip to content

Commit

Permalink
Ingredients (#497)
Browse files Browse the repository at this point in the history
Co-authored-by: Ingredient editor <[email protected]>
Co-authored-by: Christophe Combelles <[email protected]>
  • Loading branch information
3 people authored Mar 7, 2024
1 parent 27248fe commit ec574d6
Show file tree
Hide file tree
Showing 18 changed files with 12,615 additions and 6,375 deletions.
5 changes: 1 addition & 4 deletions data/common/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ def load_json(filename):


def progress_bar(index, total):
print(
"(" + (index) * "•" + (total - index) * " " + f") {str(index)}/{total}",
end="\r",
)
print(f"Export in progress: {str(index)}/{total}", end="\r")


def with_subimpacts(process):
Expand Down
22 changes: 19 additions & 3 deletions data/common/import_.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ def import_simapro_csv(
biosphere=BIOSPHERE,
migrations=[],
excluded_strategies=[],
other_strategies=[],
source=None,
):
"""
Import file at path `datapath` into database named `dbname`, and apply provided brightway `migrations`.
Expand All @@ -199,6 +201,9 @@ def import_simapro_csv(
database = bw2io.importers.simapro_csv.SimaProCSVImporter(
unzipped, dbname, normalize_biosphere=True
)
if source:
for ds in database:
ds["source"] = source
os.unlink(unzipped)

print("### Applying migrations...")
Expand All @@ -218,11 +223,13 @@ def import_simapro_csv(
s
for s in database.strategies
if not any([e in repr(s) for e in excluded_strategies])
]
] + 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"))
)
database.apply_strategy(
functools.partial(
link_technosphere_by_activity_hash, fields=("name", "location")
Expand All @@ -231,7 +238,7 @@ def import_simapro_csv(
database.statistics()

print("### Adding unlinked flows and activities...")
# comment to enable stopping on unlinked activities
# comment to enable stopping on unlinked activities and creating an excel file
database.add_unlinked_flows_to_biosphere_database(biosphere)
database.add_unlinked_activities()

Expand Down Expand Up @@ -362,3 +369,12 @@ def add_missing_substances(project, biosphere):
for code, activity in substances.items():
if not [flow for flow in bio if flow["code"] == code]:
bio.new_activity(code, **activity)


def sync_datapackages():
print("Syncing datapackages...")
for method in bw2data.methods:
bw2data.Method(method).process()

for database in bw2data.databases:
bw2data.Database(database).process()
2 changes: 1 addition & 1 deletion data/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,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-2 bw2-io.json
ADD https://api.github.com/repos/ccomb/brightway2-io/git/refs/tags/ccomb-3 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.DEV33 bw2-data.json
ADD https://api.github.com/repos/brightway-lca/brightway2-calc/git/refs/tags/2.0.DEV16 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 @@ -10,7 +10,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-2
git+https://github.com/ccomb/brightway2-io@ccomb-3
ipywidgets>=8.1, <8.2
jupyter-collaboration
matplotlib>=3.7, <3.8
Expand Down
Loading

0 comments on commit ec574d6

Please sign in to comment.