Skip to content

Instantly share code, notes, and snippets.

View cmutel's full-sized avatar

Chris Mutel cmutel

View GitHub Profile
import csv
import bw2data as bd
bio_db_name = 'ecoinvent-3.10-biosphere'
new_method = ("Something", "Something", "Danger zone")
# Writing
with open(f'{bio_db_name}.csv', 'w', encoding='utf-8') as csvfile:
fieldnames = ['id', 'name', 'categories', 'unit', 'cf']
@cmutel
cmutel / fix_minor_version_ecospold.py
Created October 19, 2023 12:41
Fix the `minorRelease` in ecospold files
import os
import sys
from pathlib import Path
from typing import Union
from lxml import etree, objectify
def fix_version(
filepath: Union[str, Path],
@cmutel
cmutel / bw3_schema.py
Last active November 1, 2023 21:09
In-progress schema for Brightway 3 basic database
from typing import List, Optional
from enum import IntEnum
from datetime import datetime
from pydantic import BaseModel, Json, HttpUrl, Field
class BrightwayBase(BaseModel):
id: int
name: str
import bw2data as bd
import bw2calc as bc
bd.projects.set_current("ghg-scores")
db = bd.Database("eg")
db.register()
a = db.new_node(code="a", name="a")
a.save()

The aim of bw_projects is relatively simple - we want to store data in a SQLite file and in a few subdirectories, and we want to be able to do switch this SQLite file and associated subdirectories whenever we want.

To do this we use peewee as an ORM to SQLite, and its ability to bind ORM tables to a database object after initial import:

    def _create_database(self):
        db = SqliteDatabase(self._filepath)
        for model in self._tables:
            model.bind(db, bind_refs=False, bind_backrefs=False)
 db.connect()
#!/usr/bin/env python
from collections import defaultdict
from pathlib import Path
import bw2data as bd
import bw2io as bi
import functools
import pandas as pd
import requests
import tempfile
# Reset min/max
for ds in bd.Database("swiss consumption 1.0"):
for exc in ds.technosphere():
if exc.get('uncertainty type') == 0 or exc.get('uncertainty_type') == 0:
exc['minimum'] = exc['maximum'] = np.NaN
exc.save()
# Get functional unit
ave_hh = bd.get_node(name='ch hh average consumption disaggregated, years 151617')
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