Skip to content

Instantly share code, notes, and snippets.

View cmutel's full-sized avatar

Chris Mutel cmutel

View GitHub Profile
import pyecospold
dirpath = "path to 3.9.1 files"
datasets = pyecospold.parse_directory_v2(dirpath)
for filepath, ecospold in datasets:
try:
ds = ecospold.childActivityDataset
assert ds
except (AttributeError, AssertionError):
ds = ecospold.activityDataset
#!/bin/bash
xsltproc --output docs/v1-schema/EcoInventCategories.html xs3p-master/xs3p.xsl pyecospold/schemas/v1/EcoInventCategories.xsd
xsltproc --output docs/v1-schema/EcoInventCompanyCodes.html xs3p-master/xs3p.xsl pyecospold/schemas/v1/EcoInventCompanyCodes.xsd
xsltproc --output docs/v1-schema/EcoInventRegionalCodes.html xs3p-master/xs3p.xsl pyecospold/schemas/v1/EcoInventRegionalCodes.xsd
xsltproc --output docs/v1-schema/EcoInventUnits.html xs3p-master/xs3p.xsl pyecospold/schemas/v1/EcoInventUnits.xsd
xsltproc --output docs/v1-schema/EcoSpold01DataTypes.html xs3p-master/xs3p.xsl pyecospold/schemas/v1/EcoSpold01DataTypes.xsd
xsltproc --output docs/v1-schema/EcoSpold01Dataset.html xs3p-master/xs3p.xsl pyecospold/schemas/v1/EcoSpold01Dataset.xsd
xsltproc --output docs/v1-schema/EcoSpold01ElementaryDataset.html xs3p-master/xs3p.xsl pyecospold/schemas/v1/EcoSpold01ElementaryDataset.xsd
xsltproc --output docs/v1-schema/EcoSpold01FlowData.html xs3p-master/xs3p.xsl pyecospold/schemas/v1/EcoSpold01FlowData.xsd
xs

Contest on visualization of sustainability assessment data

Now more than ever we need high-quality sustainability assessment to avoid the climate and other environmental crises. However, this research community is hindered by a lack of expertise in information visualization. You are cordially invited to participate in an open contest on the visualization of sustainability assessment data. With a prize fund of €2000, this could be your chance to help people make better decisions through information visualization, while also earning a nice reward! The contest Github repo is https://github.com/Depart-de-Sentier/visualization-contest-2022, and this includes the example input and results data, the contest rules, and the submission procedure. Please note the following:

  • The submission deadline is January 16, 2023, at 12:00 UTC.
  • The contest prize fund is sponsored by the ecoinvent association (https://ecoinvent.org/)
  • Contest entries must include working open source code such that your ideas can be used in sus

Brightway ❤️ SimaPro

SimaPro CSV is a standard format for data interchange, but is currently difficult to import into Brightway due to the following:

  • The list of elementary flows in SimaPro differs from that used in ecoinvent (which is the base data in Brightway). While there are matching lists from GLAD, these lists do not include SimaPro. Note that there are two difficulties here: a) SimaPro fixes some naming weirdness in ecoinvent, which results in different names; b) SimaPro includes additional flows which don't have direct matches in ecoinvent.
  • The formula language in SimaPro is mostly Python compatible (i.e. can be eval-ed). However, there are some functions which need to be rewritten, and I don't have the SimaPro formula language specification.
  • SimaPro adapts some modelling concepts from ecoinvent; the most prominent is to change the system modelling of waste treatment to make the numerical signs more reasonable. These values n
@cmutel
cmutel / foo.py
Created July 15, 2021 08:26
Exchange problem solver
print(my_activity, my_activity.key)
for exc in my_activity.exchanges():
print(exc)
print("\t", exc.input.key)
@cmutel
cmutel / split_exchanges.py
Created July 12, 2021 21:11
Split exchanges when importing data to Brightway2
from copy import deepcopy
def split_exchanges(data, filter_params, changed_attributes, allocation_factors=None):
"""Split unlinked exchanges in ``data`` which satisfy ``filter_params`` into new exchanges with changed attributes.
``changed_attributes`` is a list of dictionaries with the attributes that should be changed.
``allocation_factors`` is an optional list of floats to allocate the original exchange amount to the respective copies definedd in ``changed_attributes``. They don't have to sum to one. If ``allocation_factors`` are not defined, then exchanges are split equally.
@cmutel
cmutel / exchanges.py
Created May 27, 2021 10:06
Exchanges in Brightway2
In [1]: import bw2data as bd
...: bd.projects.set_current("ecoinvent 3.7.1 bw2")
...: ei = bd.Database("ecoinvent 3.7.1")
...: act = ei.random()
...: act
...:
Out[1]: 'plastic flake production, consumer electronics, for recycling, by grinding/shredding, formal sector' (kilogram, IN, None)
In [2]: for exc in act.exchanges():
...: print(type(exc))
import bw2io as bi
import bw2data as bd
bd.projects.set_current("REPLACE ME")
bio_37 = [
{
"categories": [
"social",
"unspecified"
@cmutel
cmutel / Brightway TAG site.md
Created February 8, 2021 10:05
Draft text for PSI LEA TAG website
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,}")