In [1]:
from brightway2 import *

In [2]:
projects.set_current('Olive oil')

In [0]:
sp = SimaProCSVImporter('/home/oney/documents/eaternity/data/zhaw_simapro_olivenöl.csv', 'Olive-oil')
sp.statistics()


Out[0]:
(9, 127, 127)
Extracted 9 unallocated datasets in 0.04 seconds
9 datasets
127 exchanges
127 unlinked exchanges
  Type biosphere: 30 unique unlinked exchanges
  Type production: 11 unique unlinked exchanges
  Type technosphere: 40 unique unlinked exchanges

In [5]:
bw2setup()


Wrote 718 LCIA methods with 178008 characterization factors
Creating core data migrations

Applied 4 strategies in 2.47 seconds
Applying strategy: normalize_units
Applying strategy: set_biosphere_type
Applying strategy: drop_unspecified_subcategories
Applying strategy: link_iterable_by_fields
Created database: biosphere3
Creating default LCIA methods

Title: Writing activities to SQLite3 database:
  Started: 03/02/2017 11:29:09
  Finished: 03/02/2017 11:29:11
  Total time elapsed: 00:00:01
  CPU %: 89.20
  Memory %: 1.87
Total time elapsed: 00:00:01
[####                          ] | ETA: 00:00:00 | ETA: 00:00:00 | ETA: 00:00:00[############################  ] | ETA: 00:00:00 | ETA: 00:00:00 | ETA: 00:00:00 | ETA: 00:00:00 | ETA: 00:00:00 | ETA: 00:00:00 | ETA: 00:00:00 | ETA: 00:00:00 | ETA: 00:00:00 | ETA: 00:00:00 | ETA: 00:00:00 | ETA: 00:00:00 | ETA: 00:00:00 | ETA: 00:00:00 | ETA: 00:00:00 | ETA: 00:00:00 | ETA: 00:00:00 | ETA: 00:00:01 | ETA: 00:00:01 | ETA: 00:00:01 | ETA: 00:00:01 | ETA: 00:00:01 | ETA: 00:00:01
Applying strategy: normalize_units
Applying strategy: drop_unspecified_subcategories
Applied 2 strategies in 0.02 seconds
[#                             ] | ETA: 00:00:01 | ETA: 00:00:01[                              ]0%                          100%
Writing activities to SQLite3 database:
Creating default biosphere


In [6]:
sp.migrate('simapro-ecoinvent-3.3')


Applying strategy: migrate_exchanges
Applying strategy: migrate_datasets

In [7]:
sp.migrate('default-units')


Applying strategy: migrate_datasets
Applying strategy: migrate_exchanges

In [33]:
sp.match_database('ecoinvent 3.3', ignore_categories=True)


Applying strategy: link_iterable_by_fields

In [34]:
sp2.match_database('ecoinvent 3.3', ignore_categories=True)


Applying strategy: link_iterable_by_fields
Couldn't apply strategy link_iterable_by_fields:
	Object in source database can't be uniquely linked to target database.
Problematic dataset is:
{'filename': '(missing)',
 'location': 'MY',
 'name': 'palm oil mill operation',
 'unit': 'kilogram'}
Possible targets include (at least one not shown):
[{'filename': '3c5fe132-406b-484d-82c3-2d5b13961154_6e4b5116-b180-45f9-ad9b-d750dadffb0e.spold',
  'location': 'MY',
  'name': 'palm oil mill operation',
  'unit': 'kilogram'},
 {'filename': '3c5fe132-406b-484d-82c3-2d5b13961154_17e163ef-4e16-4368-83f3-9d6faaf6ae3b.spold',
  'location': 'MY',
  'name': 'palm oil mill operation',
  'unit': 'kilogram'}]

In [35]:
db = Database('ecoinvent 3.3')

In [36]:
import functools
from bw2io.strategies import link_iterable_by_fields

sp.apply_strategy(functools.partial(
        link_iterable_by_fields, 
        other=Database('ecoinvent 3.2 cutoff'),
        kind='technosphere',
        fields=['reference product', 'name', 'unit', 'location']
))
sp.statistics()


Applying strategy: link_iterable_by_fields
4 datasets
33 exchanges
29 unlinked exchanges
  Type technosphere: 16 unique unlinked exchanges
Out[36]:
(4, 33, 29)

In [37]:
sp2.apply_strategy(functools.partial(
        link_iterable_by_fields, 
        other=Database('ecoinvent 3.2 cutoff'),
        kind='technosphere',
        fields=['reference product', 'name', 'unit', 'location']
))
sp2.statistics()


Applying strategy: link_iterable_by_fields
1 datasets
22 exchanges
20 unlinked exchanges
  Type technosphere: 15 unique unlinked exchanges
Out[37]:
(1, 22, 20)

In [38]:
for i, e in enumerate(sp.unlinked):
    print(e['name'], e['unit'], e['categories'])
    if i > 20:
        break


Potato starch {DE}| production | Alloc Rec, U kilogram ('Materials/fuels',)
Steam, in chemical industry {RER}| production | Alloc Rec, U kilogram ('Materials/fuels',)
Transport, freight train {Europe without Switzerland}| market for | Alloc Rec, U ton kilometer ('Materials/fuels',)
Transport, freight, lorry, unspecified {GLO}| market for | Alloc Rec, U ton kilometer ('Materials/fuels',)
Electricity, low voltage {ENTSO-E}| market group for | Alloc Rec, U kilowatt hour ('Electricity/heat',)
Biowaste {GLO}| treatment of biowaste, municipal incineration | Alloc Rec, U kilogram ('Waste to treatment',)
Molasses, from sugar beet {CH}| beet sugar production | Alloc Rec, U kilogram ('Materials/fuels',)
Sodium chloride, powder {RER}| production | Alloc Rec, U kilogram ('Materials/fuels',)
Electricity, low voltage {ENTSO-E}| market group for | Alloc Rec, U kilowatt hour ('Materials/fuels',)
Carrot {GLO}| market for | Alloc Rec, U kilogram ('Materials/fuels',)
Cabbage white {GLO}| market for | Alloc Rec, U kilogram ('Materials/fuels',)
Onion {GLO}| market for | Alloc Rec, U kilogram ('Materials/fuels',)
Blast furnace slag {RoW}| treatment of, to inert waste | Alloc Rec, U kilogram ('Waste to treatment',)
Fodder yeast {CH}| ethanol production from whey | Alloc Rec, U kilogram ('Materials/fuels',)
Transport, freight train {Europe without Switzerland}| market for | Alloc Rec, U ton kilometer ('Electricity/heat',)
Transport, freight, lorry, unspecified {GLO}| market for | Alloc Rec, U ton kilometer ('Electricity/heat',)

In [39]:
db.search('ENTSO')


Out[39]:
['market group for electricity, medium voltage' (kilowatt hour, ENTSO-E, None),
 'market group for electricity, low voltage' (kilowatt hour, ENTSO-E, None),
 'electricity, high voltage, production mix' (kilowatt hour, ENTSO-E, None),
 'market group for electricity, high voltage' (kilowatt hour, ENTSO-E, None),
 'market group for electricity, high voltage' (kilowatt hour, UCTE, None),
 'market group for electricity, low voltage' (kilowatt hour, UCTE, None),
 'market group for electricity, medium voltage' (kilowatt hour, UCTE, None),
 'heat and power co-generation, hard coal' (kilowatt hour, NL, None),
 'heat and power co-generation, hard coal' (megajoule, DK, None),
 'heat and power co-generation, hard coal' (kilowatt hour, FI, None),
 'heat and power co-generation, hard coal' (megajoule, NL, None),
 'heat and power co-generation, hard coal' (megajoule, DE, None),
 'heat and power co-generation, hard coal' (kilowatt hour, CZ, None),
 'heat and power co-generation, hard coal' (kilowatt hour, DE, None),
 'heat and power co-generation, hard coal' (kilowatt hour, AT, None),
 'heat and power co-generation, hard coal' (megajoule, AT, None),
 'heat and power co-generation, hard coal' (kilowatt hour, DK, None),
 'heat and power co-generation, hard coal' (megajoule, FI, None),
 'heat and power co-generation, hard coal' (megajoule, CZ, None),
 'heat and power co-generation, hard coal' (kilowatt hour, NO, None),
 'heat and power co-generation, hard coal' (kilowatt hour, SK, None),
 'heat and power co-generation, hard coal' (megajoule, SE, None),
 'heat and power co-generation, hard coal' (kilowatt hour, SE, None),
 'heat and power co-generation, hard coal' (kilowatt hour, PL, None),
 'heat and power co-generation, hard coal' (megajoule, PL, None)]

In [40]:
migration_data = {
    'fields': ['name'],
    'data': [
        (
            # First element is input data in the order of `fields` above
            ('Electricity, low voltage {ENTSO-E}| market group for | Alloc Rec, U',),
            # Second element is new values 
            {
                'name': 'market group for electricity, low voltage',
                'reference product': 'electricity, high voltage',
                'location': 'ENTSO-E',
            }
        )
    ]
}

Migration('new-ecoinvent').write(
    migration_data, 
    description='New datasets in ecoinvent 3.2'
)

In [41]:
sp.migrate('new-ecoinvent')


Applying strategy: migrate_datasets
Applying strategy: migrate_exchanges

In [43]:
sp.match_database('ecoinvent 3.3', ignore_categories=True)


Applying strategy: link_iterable_by_fields

In [56]:
sp.statistics()


4 datasets
33 exchanges
25 unlinked exchanges
  Type technosphere: 14 unique unlinked exchanges
Out[56]:
(4, 33, 25)

In [57]:
for i, e in enumerate(sp2.unlinked):
    print(e['name'], e['unit'], e['categories'])
    if i > 20:
        break


palm oil mill operation kilogram ('Materials/fuels',)
monosodium glutamate, at plant/RER kilogram ('Materials/fuels',)
yeast extract, at plant/RER kilogram ('Materials/fuels',)
potato starch production kilogram ('Materials/fuels',)
beet sugar production kilogram ('Materials/fuels',)
maltodextrin, at plant/RER kilogram ('Materials/fuels',)
vegetable extract, at plant/RER kilogram ('Materials/fuels',)
market for chemical, organic kilogram ('Materials/fuels',)
heat production, natural gas, at industrial furnace >100kW megajoule ('Materials/fuels',)
market group for electricity, low voltage kilowatt hour ('Materials/fuels',)
market for transport, freight train ton kilometer ('Materials/fuels',)
market for carrot kilogram ('Materials/fuels',)
market for onion kilogram ('Materials/fuels',)
market for transport, freight, lorry, unspecified ton kilometer ('Materials/fuels',)
treatment of biowaste, municipal incineration kilogram ('Waste to treatment',)

In [58]:
migration_data2 = {
    'fields': ['name'],
    'data': [
        (
            # First element is input data in the order of `fields` above
            ('Electricity, low voltage {UCTE}| market group for | Alloc Rec, U',),
            # Second element is new values 
            { 
                'name': 'market group for electricity, low voltage',
                'reference product': 'electricity, low voltage',
                'location': 'UCTE',
            }
        )
    ]
}

Migration('new-ecoinvent2').write(
    migration_data2, 
    description='New datasets in ecoinvent 3.2'
)

In [59]:
sp2.migrate('new-ecoinvent2')


Applying strategy: migrate_datasets
Applying strategy: migrate_exchanges

In [60]:
sp2.match_database('ecoinvent 3.3', ignore_categories=True)


Applying strategy: link_iterable_by_fields
Couldn't apply strategy link_iterable_by_fields:
	Object in source database can't be uniquely linked to target database.
Problematic dataset is:
{'filename': '(missing)',
 'location': 'MY',
 'name': 'palm oil mill operation',
 'unit': 'kilogram'}
Possible targets include (at least one not shown):
[{'filename': '3c5fe132-406b-484d-82c3-2d5b13961154_17e163ef-4e16-4368-83f3-9d6faaf6ae3b.spold',
  'location': 'MY',
  'name': 'palm oil mill operation',
  'unit': 'kilogram'},
 {'filename': '3c5fe132-406b-484d-82c3-2d5b13961154_adad6cb6-eef9-4869-b743-8bd5be3c7c7a.spold',
  'location': 'MY',
  'name': 'palm oil mill operation',
  'unit': 'kilogram'}]

In [61]:
sp2.statistics()


1 datasets
22 exchanges
20 unlinked exchanges
  Type technosphere: 15 unique unlinked exchanges
Out[61]:
(1, 22, 20)

In [62]:
test = sp.write_database()


Writing activities to SQLite3 database:
0%  100%
[    ]
-------------------------
InvalidExchangeTraceback (most recent call last)
<ipython-input-62-d6142b2bdf88> in <module>()
----> 1 test = sp.write_database()

/d/documents/eaternity/bw2-py/envs/bw2/lib/python3.5/site-packages/bw2io/importers/simapro_csv.py in write_database(self, data, name, *args, **kwargs)
     99 
    100     def write_database(self, data=None, name=None, *args, **kwargs):
--> 101         db = super(SimaProCSVImporter, self).write_database(data, name, *args, **kwargs)
    102         database_parameters[db.name] = self.global_parameters
    103         db.metadata['simapro import'] = self.metadata

/d/documents/eaternity/bw2-py/envs/bw2/lib/python3.5/site-packages/bw2io/importers/base_lci.py in write_database(self, data, name, overwrite, backend, **kwargs)
    109                 db.register(format=self.format, **kwargs)
    110         existing.update(data)
--> 111         db.write(existing)
    112         print("Created database: {}".format(db.name))
    113         return db

/d/documents/eaternity/src/bw2data/bw2data/project.py in writable_project(wrapped, instance, args, kwargs)
    383     if projects.read_only:
    384         raise ReadOnlyProject(READ_ONLY_PROJECT)
--> 385     return wrapped(*args, **kwargs)

/d/documents/eaternity/src/bw2data/bw2data/backends/peewee/database.py in write(self, data, process)
    243         if data:
    244             try:
--> 245                 self._efficient_write_many_data(data)
    246             except:
    247                 # Purge all data from database, then reraise

/d/documents/eaternity/src/bw2data/bw2data/backends/peewee/database.py in _efficient_write_many_data(self, data, indices)
    165                 for exchange in ds.get('exchanges', []):
    166                     if 'input' not in exchange or 'amount' not in exchange:
--> 167                         raise InvalidExchange
    168                     if 'type' not in exchange:
    169                         raise UntypedExchange

InvalidExchange: 

In [0]:
sp2.statistics()


Out[0]:
(1, 22, 0)
1 datasets
22 exchanges
0 unlinked exchanges
  

In [37]:
sp2.write_database()


Out[37]:
Brightway2 SQLiteBackend: Bouillion
Title: Writing activities to SQLite3 database:
  Started: 02/01/2017 14:15:31
  Finished: 02/01/2017 14:15:31
  Total time elapsed: 00:00:00
  CPU %: 118.90
  Memory %: 10.27
Created database: Bouillion
Writing activities to SQLite3 database:
0%  100%
[#] | ETA: 00:00:00 | ETA: 00:00:00
Total time elapsed: 00:00:00

In [38]:
bouillon = Database('Bouillion')

In [0]:


In [39]:
sp2.write_excel()


Wrote matching file to:
/Users/ioconnor/Library/Application Support/Brightway3/Import-Boullion-Zutaten-2017.d090a31abfd003aac4dcee6cf4276765/output/db-matching-Bouillion.xlsx

In [40]:
sp.match_database('Bouillion',ignore_categories=True)


Applying strategy: link_iterable_by_fields

In [41]:
sp.statistics()


Out[41]:
(4, 33, 0)
4 datasets
33 exchanges
0 unlinked exchanges
  

In [0]:


In [42]:
sp.write_excel()


Wrote matching file to:
/Users/ioconnor/Library/Application Support/Brightway3/Import-Boullion-Zutaten-2017.d090a31abfd003aac4dcee6cf4276765/output/db-matching-Bouillon-Zutaten.xlsx

In [0]:


In [0]:


In [43]:
sp.write_database()


Out[43]:
Brightway2 SQLiteBackend: Bouillon-Zutaten
Title: Writing activities to SQLite3 database:
  Started: 02/01/2017 14:15:44
  Finished: 02/01/2017 14:15:44
  Total time elapsed: 00:00:00
  CPU %: 116.40
  Memory %: 9.79
Created database: Bouillon-Zutaten
Writing activities to SQLite3 database:
0%  100%
[####] | ETA: 00:00:00 | ETA: 00:00:00 | ETA: 00:00:00 | ETA: 00:00:00 | ETA: 00:00:00
Total time elapsed: 00:00:00

In [44]:
bouillon = Database('Bouillion')

In [45]:
bouillonZ = Database('Bouillon-Zutaten')

In [46]:
list(bouillon)


Out[46]:
['Gemüsebouillon Paste' (kilogram, None, None)]

In [47]:
list(databases)


Out[47]:
['Bouillon-Zutaten', 'biosphere3', 'ecoinvent 3.2 cutoff', 'Bouillion']

calculate LCIA

try first sth from ecoinvent


In [51]:
act = Database("ecoinvent 3.2 cutoff").search("pineapple")
act


Out[51]:
['pineapple production' (kilogram, GLO, None),
 'market for pineapple' (kilogram, GLO, None)]

In [52]:
act = Database("ecoinvent 3.2 cutoff").search("pineapple")[1]
act


Out[52]:
'market for pineapple' (kilogram, GLO, None)

In [53]:
lca = LCA(
    {act.key: 1}, 
    method=('IPCC 2013', 'climate change', 'GWP 100a'),
)
lca.lci()
lca.lcia()
lca.score


Out[53]:
0.199092072939385

try now for bouillon


In [63]:
bou = Database("bouillon").search("Paste")
bou


Out[63]:
[]

In [68]:
lca = LCA(
    demand={bouillon.random(): 1}, 
    method=('IPCC 2013', 'climate change', 'GWP 100a'),
)
lca.lci()
lca.lcia()
lca.score


Out[68]:
2.261934855435636

In [69]:
lca = LCA(
    demand={bouillonZ.random(): 1}, 
    method=('IPCC 2013', 'climate change', 'GWP 100a'),
)
lca.lci()
lca.lcia()
lca.score


Out[69]:
6.202014863956596

FRAGEN

  • stimmt das, dass bouillon z in bouillon einfliesst?
  • wie weiss ich sicher, dass ich gem[sebouillon ausgewaehlt habe?

In [0]:


In [0]:


In [0]:


In [0]:


In [0]:


In [0]:


In [0]:


In [0]:


In [0]:


In [0]:


In [0]:


In [0]:


In [0]:


In [0]:


In [0]:


In [0]:


In [0]:


In [0]:


In [0]:


In [0]:


In [0]:


In [0]:


In [0]: