Skip to content

Instantly share code, notes, and snippets.

@cmutel cmutel/
Created Mar 16, 2017

What would you like to do?
Send LCI/A data as CSVs to minimal bw2calc server
import csv
import requests
This script will create a very simple life cycle inventory, and send it to the bw2calc server.
Example standalone bw2calc server here:
The CSV schema for the inventory exchanges is:
producer (int), consumer (int), type (int), amount (float)
Note that biosphere exchanges are included here, and the biosphere flow is the producer; the emitting activity is the consumer.
Types are:
0: production (must be included for each activity)
1: technosphere input (positive number for consumption)
2: biosphere flow emission or consumption
The CSV schema for the impact assessment method is:
flow (int), amount (float)
ELEC = 1
COAL = 2
CO2 = 3
LCI = [
(ELEC, ELEC, 0, 1), # Production
(COAL, COAL, 0, 1), # Production
(COAL, ELEC, 1, 0.1),
(CO2, COAL, 2, 2)
LCIA = [(CO2, 1)]
URL = ''
def export_lci():
with open("lci.csv", "w") as f:
writer = csv.writer(f)
for row in LCI:
with open("lcia.csv", "w") as f:
writer = csv.writer(f)
for row in LCIA:
def make_request():
data = {'activity': ELEC, 'amount': 1}
files = {
'lci': open('lci.csv', 'rb'),
'lcia': open('lcia.csv', 'rb')
return, data=data, files=files)
def main():
resp = make_request()
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.