Skip to content

Instantly share code, notes, and snippets.

View cmutel's full-sized avatar

Chris Mutel cmutel

View GitHub Profile
from pathlib import Path
import appdirs
import hashlib
import re
import unicodedata
re_slugify = re.compile(r"[^\w\s-]", re.UNICODE)
MULTI_RE = re.compile(r"_{2,}")
Process: python3.7 [25261]
Path: /Users/USER/*/python3.7
Identifier: python3.7
Version: 0
Code Type: X86-64 (Native)
Parent Process: bash [25037]
Responsible: python3.7 [25261]
User ID: 501
Date/Time: 2020-10-12 09:51:38.892 +0200
activity-browser-~ bsteubing/noarch::activity-browser-dev-2020.10.06-pypy_0
appdirs conda-forge/noarch::appdirs-1.4.3-py_1
arrow conda-forge/osx-64::arrow-0.17.0-py37hc8dfbb8_0
asteval conda-forge/noarch::asteval-0.9.16-pyh5ca1d4c_0
astunparse conda-forge/noarch::astunparse-1.6.2-py_0
beautifulsoup4 conda-forge/noarch::beautifulsoup4-4.9.3-pyhb0f4dca_0
brightway2 cmutel/noarch::brightway2-2.3-py_2
brotlipy conda-forge/osx-64::brotlipy-0.7.0-py37h60d8a13_1000
bw2analyzer cmutel/noarch::bw2analyzer-0.9.4-py_1
bw2calc cmutel/noarch::bw2calc-1.8.0-py_0
@cmutel
cmutel / description.md
Last active November 13, 2020 11:27
Multi-outputs in Brightway

Implementing multi-functionality in bw2data

Multi-functionality support will be added as a new library in Brightway, compatible with bw2data version 4 or later (still in development). The code name for this library is "nife", as it is like a Swiss army knife, just a bit less complicated. The actual library name can be decided later :)

Allocation and substitution functions

The idea of supporting multi-output processes is to allow different approaches to handling these outputs to be executed and compared. Allocation is kind of approach, though there are others. In this text, I will use the phrase "resolution functions" as a generic term for these approaches.

Resolution functions must be implemented in Python, and will be stored in a mapping dictionary:

@cmutel
cmutel / import_stuff.py
Created March 13, 2020 14:18
Importing ecoinvent
from brightway2 import *
projects.set_current("2020 class EI import")
bw2setup()
dp = "/Users/cmutel/Documents/LCA/Ecoinvent/3.6/cutoff/datasets" # Or whatever
ei = SingleOutputEcospold2Importer(dp, "ecoinvent")
ei.apply_strategies()
ei.statistics()
ei.write_database()
databases
act = Database("ecoinvent").random()
@cmutel
cmutel / pq_test.py
Created April 17, 2019 11:21
Trying parquet for Brightway LCA result vectors
import brightway2 as bw
from time import time
import numpy as np
import pyarrow as pa
import pyarrow.parquet as pq
def fu_iterator(name="ecoinvent 3.5 cutoff", cutoff=500):
for i, x in enumerate(bw.Database(name)):
if i >= cutoff:
@cmutel
cmutel / ontology_voting.py
Last active April 9, 2019 07:24
BONSAI voting on nomenclature for "flow object" possible replacement
orig_data = """BDACFE
DCAFBE
AFDCEB
ADCFBE
CAEBDF
DCABFGHE
AFCED
DCAFBEGH
BGEACDH""".split("\n")
@cmutel
cmutel / gist:83c7a8f05a7b141f8bcc2e6d43146231
Created October 5, 2018 11:35
Uncertainty statistics from ecoinvent 3.5 (cutoff)
from brightway2 import *
from bw2data.backends.peewee.schema import ExchangeDataset as ED
qs = ED.select().filter(ED.output_database == "ecoinvent cutoff 3.5")
uncertain = 0
empty_pedigree = 0
NO_PEDIGREE = {
'reliability': 1,
('ILCD 2.0 2018 midpoint no LT', 'climate change', 'climate change biogenic')
('ILCD 2.0 2018 midpoint no LT', 'climate change', 'climate change fossil')
('ILCD 2.0 2018 midpoint no LT', 'climate change', 'climate change land use and land use change')
('ILCD 2.0 2018 midpoint no LT', 'climate change', 'climate change total')
('ILCD 2.0 2018 midpoint no LT', 'ecosystem quality', 'freshwater and terrestrial acidification')
('ILCD 2.0 2018 midpoint no LT', 'ecosystem quality', 'freshwater ecotoxicity')
('ILCD 2.0 2018 midpoint no LT', 'ecosystem quality', 'freshwater eutrophication')
('ILCD 2.0 2018 midpoint no LT', 'ecosystem quality', 'marine eutrophication')
('ILCD 2.0 2018 midpoint no LT', 'ecosystem quality', 'terrestrial eutrophication')
('ILCD 2.0 2018 midpoint no LT', 'human health', 'carcinogenic effects')
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.