In [1]:
import sys
import os
import json
import re

sys.path.append('../..')

import lcatools
from lcatools.foreground.manager import ForegroundManager
from lcatools.interact import *

In [2]:
F = ForegroundManager('.')


ForegroundArchive archive added in position 0
IlcdLcia archive added in position 1
JSON archive added in position 2
JSON archive added in position 3
JSON archive added in position 4
JSON archive added in position 5
JSON archive added in position 6
JSON archive added in position 7
JSON archive added in position 8
JSON archive added in position 9
JSON archive added in position 10
Generating flow-quantity database...
Loading LCIA data... (0.80 s)
Loading JSON data from /data/GitHub/lca-tools-datafiles/catalogs/elcd_lcia.json.gz:
Found Extension: zip
54 new quantity entities added (54 total)
1256 new flow entities added (1256 total)
0 new process entities added (0 total)
0 unmatched flows found from source LCIA... 

finished LCIA... (1.69 s)
Loading JSON data from /data/GitHub/lca-tools-datafiles/catalogs/ei_lcia.json.gz:
**Upstream reference encountered: /data/LCI/Ecoinvent/3.2/undefined

710 new quantity entities added (710 total)
3255 new flow entities added (3255 total)
0 new process entities added (0 total)
92 unmatched flows found from source EI-LCIA... 

finished EI-LCIA... (8.01 s)
Loading JSON data from /data/GitHub/lca-tools-datafiles/catalogs/ecoinvent_3.2_apos_xlsx.json.gz:
Loading FG from /data/LCI/Ecoinvent/3.2/current_Version_3.2_apos_ecoSpold02.zip
Found Extension: zip
Loading BG from /data/LCI/Ecoinvent/3.2/current_Version_3.2_apos_lcia_ecoSpold02.zip
Found Extension: zip
**Upstream reference encountered: /home/b/Dropbox/data/Ecoinvent/3.2/activity_overview_for_users_3.2_undefined.xlsx

718 new quantity entities added (718 total)
6767 new flow entities added (6767 total)
11420 new process entities added (11420 total)
Loading LCIA results from 52cfdcee-514c-4366-a7e8-b2a23212e995_759b89bd-3aa6-42ad-b767-5bb9ef5d331d.spold
Loading LCIA results from 6158d46e-b32c-42b9-aa95-1eeb4e593ec2_73b452c8-3ac4-4993-86e4-fe0653467988.spold
Loading LCIA results from 6268f498-c703-49d1-b646-3ee9d15c0200_7a7db01b-126b-42fa-b3cc-e2ed48081eca.spold
Loading LCIA results from 6c46fcb8-bd3f-41f0-b9d0-dfbde74ecfec_26448127-c1ac-4f48-818a-5e8fd9cb1645.spold
Loading LCIA results from 598c89fe-6d31-48a3-89ae-3687734e4208_c5adb1fb-872e-4446-a3bb-c4b61aa4bd45.spold
Loading LCIA results from aee5bcfc-9314-4598-82e1-e82c400e4364_cfbce515-3f54-4411-ad9d-3d26b7faa15a.spold
Loading LCIA results from 57697b27-e4f7-4afc-847f-e0b189a7b900_560e69eb-413e-49db-8796-3dd103ae8888.spold
Loading LCIA results from e47aac85-2f09-426b-82f8-4627b31bbcb9_af729e94-ad8b-4c25-859c-e2f6aba1de16.spold
market for sugar beet [GLO]
Loading LCIA results from 86bceccc-2692-4218-b3ca-25157a6dde91_a498d9fb-9402-4374-b2e2-3f85f5d98f43.spold
Loading LCIA results from 6e00445b-5435-4aa8-9b3d-82bf908647d3_75168394-3da2-467a-90a1-285836ccd00d.spold
Loading LCIA results from b27d6a13-dc49-493e-8ada-8677b999a2a2_bab7524a-43df-40ff-ab5b-2a318758273d.spold
Loading LCIA results from b203c4a7-fc43-4434-89b4-490061e32a93_7349f706-8f4e-4061-9e68-a66c269b4030.spold
Loading LCIA results from 62c92136-dc40-41fd-8286-e024c3097209_a00b7e35-1bc7-4b73-9df8-05f3dd07ffdb.spold
Loading LCIA results from 1ae5f888-6823-4250-a3b5-b6de66a0d9cb_c5adb1fb-872e-4446-a3bb-c4b61aa4bd45.spold
ethanol production from sugar beet molasses [RoW]
Loading LCIA results from 7424a131-694d-48a5-b188-de7adf16dd99_1125e767-7b5d-442e-81d6-9b0d3e1919ac.spold
Loading LCIA results from 86c6f7e6-a0ea-4897-a7f6-ef757bb46a2c_e98c4987-0c27-4ad8-aa06-568bea573460.spold
Loading LCIA results from f461b3a8-fff5-45d8-90fb-563e157624ad_9e6f12d8-b727-4aef-94e3-c8278e3661d7.spold
sugar beet production [RoW]
Loading LCIA results from 32364fde-3444-4cef-b6f3-385185db172e_6dc5955e-e2a6-4fd5-845d-63df2e29ecaa.spold
Loading LCIA results from af714d54-d182-4204-a338-411913942ac5_f9c6e4e7-e45c-423e-b48e-f7e140efb38e.spold
Loading LCIA results from 102e64cf-8548-47f4-a69a-836facb18e55_5321a299-0c03-4bfc-9dda-d020456f6b2e.spold
Loading LCIA results from 05f6e302-35c7-496e-ae61-7ad592dc3dca_d006454e-161f-4b7f-ad8a-8892ee176041.spold
Loading LCIA results from 71019788-1cb7-4fd2-924a-e1b278cd2a9a_1fa64d0c-afd7-46ab-b95c-3a54e0902dd0.spold
Loading LCIA results from ae5135f7-64dc-4a5c-8879-27f2edee898f_a2193d6a-1c79-42de-aa16-355543601b4e.spold
Loading LCIA results from 7d3fa0a4-1fb2-459a-ba7c-a6dd32e15ba1_6c365ae3-f8cb-4aff-8709-afea7fbf0a40.spold
Loading LCIA results from bb6cc7c3-a81e-4b6e-ba86-de97ec13cb7d_2be73167-58e8-4706-a68f-167c80df9f72.spold
Loading LCIA results from 31147725-f08f-4e3d-8196-29744fad76d8_9d63da75-8289-4b96-a900-67ec3bd40a16.spold
Loading LCIA results from 1030f31c-3c48-4952-a097-e84fa182cba2_fb76d2b4-16bb-4373-bcdf-03545f362b83.spold
Loading LCIA results from e075b3df-0fa5-477f-9430-9c2c2a39fd57_db8488c0-a49f-4550-8bae-f2356ce1de64.spold
Loading LCIA results from 40d9dc2f-e712-4d8b-8fa3-ed9f2dbfcdf1_93ee89ba-ff0b-4c4b-a333-af78bda8a9c4.spold
Loading LCIA results from d3e789cb-ecca-4bb2-884e-2f218039a94d_9e0c9c28-7d8f-4f18-a769-bff3a4c8c1e5.spold
Loading LCIA results from 0f1c7ebe-c324-42ce-893f-0aaed23ee973_8d53f85d-4fd8-4861-9f64-5799ac3906a6.spold
Loading LCIA results from ad026e7f-b646-4e4f-9689-6e06868e2538_759b89bd-3aa6-42ad-b767-5bb9ef5d331d.spold
Loading LCIA results from ddc30d35-2aa9-4520-965a-dfa558dbbabc_318df8f5-f490-436c-8f93-23ccfa15e60a.spold
Loading LCIA results from 1bd6b86a-5ff6-4fc2-9935-81297d2658f1_3fdcbdaa-e8d2-46fc-8632-268b89a29ba0.spold
Loading LCIA results from fe830632-b16e-4014-9ddd-f4f0712e63bd_f4470cb4-f0f6-43d0-9e03-52bec610169f.spold
Loading LCIA results from 268b4507-3a49-49d9-8ee6-765059909ac3_f5707bdf-f7e2-479b-b3ea-99c04de8a927.spold
Loading LCIA results from 90dfdb8d-22e6-4a3f-a29b-33412dba667e_aeb1ebef-7095-4956-91da-8c4017df556d.spold
Loading LCIA results from 61e38d92-d558-4759-b9a8-dea9954cf16f_ba4b7781-39f2-465b-8d98-0bc1c4c82e61.spold
Loading LCIA results from 75aaa5d0-e5df-4977-a8fb-b79dad545a2d_6f4bede8-f885-499c-8ac9-6832e35d9d16.spold
Loading LCIA results from 181ab724-e1c9-4ce0-9b60-1c73a6b58738_92b3c2d6-e5bf-4b2e-b2ac-1352d6640b58.spold
Loading LCIA results from 82552aab-ecf2-4d0b-9e76-e7ec4ce47178_f33b4dc5-f3af-4ca8-aeff-3deeb7159ec1.spold
Loading LCIA results from 44eaa1cc-dc5d-4830-90ca-dc83c2834adb_50306184-2a7e-4825-8e5d-fe8e674d1274.spold
Loading LCIA results from a82a19b3-c85c-4ba7-a7b8-aaef88010bb7_1a444fb4-f931-4369-8683-2844944ebdba.spold
Loading LCIA results from 1cbeda02-4edf-45b4-b787-02d6783807e2_725cbdbd-cdb2-484b-9363-2c6facb2ab4b.spold
Loading LCIA results from d7b1820b-e83a-4aec-95d0-a5aff9e45891_4cc48a86-dc1d-4c85-815c-8f1988326e97.spold
Loading LCIA results from 5ed130c8-104f-486d-baf6-e5c7124a2b15_1be4f7e4-5244-4f9d-b80d-7fbf1e337e2b.spold
Loading LCIA results from 05ed83fe-5ddd-4da8-9e9b-e997a9e68c81_7225e2a6-7fd6-40e2-b341-f097b027d119.spold
Loading LCIA results from a6b03ed3-532c-43c8-abd6-c8242eb18d05_1125e767-7b5d-442e-81d6-9b0d3e1919ac.spold
Loading LCIA results from 921b7b9e-7dc0-4efe-8d1c-26de6f65c595_560e69eb-413e-49db-8796-3dd103ae8888.spold
finished... (14.84 s)

In [3]:
frag = next(f for f in F[0].fragments(background=False))

In [4]:
F.draw_fragment(frag)


-<--*   4a37702 (      1) ethanol production from sugar beet molasses [RoW]
    | -<--B   bce6ce5 (      0) ammonium sulfate, as N
    | -<--B   0740a66 (      0) ethanol fermentation plant
    | =>=---: 2968b7b (      0) molasses, from sugar beet
    | -<--B   76a37f5 (   0.11) lime
    | -<--*   36ef048 (    3.8) sugar beet
    |  | -<--*   1799103 (      1) sugar beet
    |  |  | -<--B   8e1cb31 (5.1e-05) fertilising, by broadcaster
    |  |  | -<--B   3ba3c84 (5.7e-05) application of plant protection product, by field sprayer
    |  |  | -<--B   95ded38 (4.2e-05) potassium sulfate, as K2O
    |  |  | -<--B   cf3497a (0.00028) ammonium nitrate, as N
    |  |  | -<--B   e6d8b98 (2.6e-05) hoeing
    |  |  | -<--B   47c0ca2 (2.6e-05) triazine-compound, unspecified
    |  |  | -<--B   c330e5a (0.00017) liquid manure spreading, by vacuum tanker
    |  |  | -<--B   8070ae7 (2.7e-05) sugar beet seed, for sowing
    |  |  | -<--B   a925df0 (2.6e-05) fodder loading, by self-loading trailer
    |  |  | -<--B   39fa0ac (  0.001) transport, tractor and trailer, agricultural
    |  |  | -<--B   0c9d875 (0.00064) potassium chloride, as K2O
    |  |  | -<--B   753c14c (8.1e-05) phosphate fertiliser, as P2O5
    |  |  | -<--B   13ec51a (9.7e-05) urea, as N
    |  |  | -<--B   6817cce (0.00015) nitrogen fertiliser, as N
    |  |  | -<--B   ddc4c2d (1.3e-05) green manure, Swiss integrated production, until February
    |  |  | -<--B   e365c1c (1.3e-05) harvesting, by complete harvester, beets
    |  |  | -<--B   7d46431 (7.7e-06) benzimidazole-compound
    |  |  | -<--B   df4dca5 (-0.0033) biowaste
    |  |  | -<--B   ee05d46 (2.6e-05) phosphate rock, as P2O5, beneficiated, dry
    |  |  | -<--B   5532522 (1.9e-06) cyclic N-compound
    |  |  | -<--B   83d0764 (1.3e-05) sowing
    |  |  | -<--B   5be8746 (   0.12) solid manure loading and spreading, by hydraulic loader and spreader
    |  |  | -<--B   c761b09 (2.6e-05) tillage, harrowing, by spring tine harrow
    |  |  | -<--B   9215e7b (4.8e-06) [thio]carbamate-compound
    |  |  | -<--B   f9a2cc3 (3.9e-06) pesticide, unspecified
    |  |  | -<--B   2e9483b (2.1e-05) ammonium sulfate, as N
    |  |  | -<--B   ff4b760 (1.3e-05) tillage, ploughing
    |  | 
    |  | -<--B   efc4504 (   0.02) transport, freight, lorry, unspecified
    | 
    | -<--B   2ae168c (      0) nitrogen fertiliser, as N
    | -<--B   9438c00 (0.00051) chemical, inorganic
    | -<--B   8b59e50 (  0.038) transport, tractor and trailer, agricultural
    | -<--B   be50d7c (  -0.77) sugar beet pulp
    | -<--B   035b944 (5.9e-11) sugar refinery
    | -<--B   d30b1cb (   0.56) heat, district or industrial, natural gas
    | -<--B   e4046e1 (   0.56) heat, district or industrial, natural gas
    | -<--B   785f445 (    2.1) tap water
    | -<--B   73c362f ( 0.0095) coke
    | -<--B   c74262b (0.00024) sulfuric acid
    | -<--B   9548702 ( 0.0013) soda ash, light, crystalline, heptahydrate
    | -<--B   509b6ae (  0.063) electricity, medium voltage
    | -<--B   e42c9b5 (  -0.14) limestone residue
    | -<--B   d193a54 (    2.1) tap water
    | -<--B   8ae6663 (      0) vinasse, from fermentation of sugar beet molasses
    | -<--B   8a21dee (-0.0066) wastewater, from residence
    | -<--B   571b6a4 (0.00035) chemical, organic
    | -<--B   3189ffd (  0.063) electricity, medium voltage
    | -<--B   e1352ca (  -0.14) molasses, from sugar beet
   

In [5]:
ffs = F.traverse(frag)

In [6]:
lcia_methods = (q for q in F[0].lcia_methods())

In [11]:
quantity = next(lcia_methods)
str(quantity)


Out[11]:
'ReCiPe Midpoint (I), agricultural land occupation, ALOP [LCIA]'

In [12]:
total = 0.0
print('%s' % quantity)
skips = []
for i in ffs:
    mag = i.node_weight
    scr = i.term.score_cache(quantity)
    if scr is None:
        print('skipping this one: %s' % i.fragment['Name'])
        skips.append(i)
        continue
    cont = mag * scr.total()
    #if i.fragment.direction == i.term.direction:
    #    cont *= -1
    print('%10.3g x %10.3g = %10.3g %s' % (mag, scr.total(), cont, i.fragment['Name']))
    total += cont
print('Total: %10.6g' % total)


ReCiPe Midpoint (I), agricultural land occupation, ALOP [LCIA]
         1 x          0 =          0 ethanol production from sugar beet molasses [RoW]
         0 x      0.193 =          0 market for ammonium sulfate, as N [GLO]
         0 x   2.03e+05 =          0 market for ethanol fermentation plant [GLO]
skipping this one: molasses, from sugar beet
      0.11 x    0.00188 =   0.000207 market for lime [GLO]
      3.79 x          0 =          0 sugar beet
      3.79 x     0.0757 =      0.287 sugar beet
  0.000195 x       1.24 =   0.000241 market for fertilising, by broadcaster [GLO]
  0.000214 x       1.23 =   0.000263 market for application of plant protection product, by field sprayer [GLO]
  0.000159 x      0.324 =   5.16e-05 market for potassium sulfate, as K2O [GLO]
   0.00105 x       0.12 =   0.000126 market for ammonium nitrate, as N [GLO]
  9.74e-05 x       3.59 =    0.00035 market for hoeing [GLO]
  9.83e-05 x      0.443 =   4.35e-05 market for triazine-compound, unspecified [GLO]
   0.00064 x      0.115 =   7.38e-05 market for liquid manure spreading, by vacuum tanker [GLO]
  0.000102 x       4.31 =    0.00044 market for sugar beet seed, for sowing [GLO]
  9.88e-05 x      0.059 =   5.83e-06 market for fodder loading, by self-loading trailer [GLO]
   0.00378 x     0.0452 =   0.000171 market for transport, tractor and trailer, agricultural [GLO]
   0.00243 x      0.035 =   8.51e-05 market for potassium chloride, as K2O [GLO]
  0.000306 x      0.191 =   5.85e-05 market for phosphate fertiliser, as P2O5 [GLO]
  0.000369 x     0.0789 =   2.91e-05 market for urea, as N [GLO]
  0.000572 x      0.536 =   0.000307 market for nitrogen fertiliser, as N [GLO]
  4.87e-05 x   5.57e+03 =      0.271 market for green manure, Swiss integrated production, until February [GLO]
  4.87e-05 x       14.8 =    0.00072 market for harvesting, by complete harvester, beets [GLO]
  2.92e-05 x      0.456 =   1.33e-05 market for benzimidazole-compound [GLO]
    0.0126 x     0.0136 =   0.000171 market for biowaste [RoW]
  9.69e-05 x     0.0177 =   1.72e-06 market for phosphate rock, as P2O5, beneficiated, dry [GLO]
   7.3e-06 x      0.999 =    7.3e-06 market for cyclic N-compound [GLO]
  4.87e-05 x        3.1 =   0.000151 market for sowing [GLO]
     0.438 x   0.000286 =   0.000125 market for solid manure loading and spreading, by hydraulic loader and spreader [GLO]
  9.74e-05 x       3.24 =   0.000316 market for tillage, harrowing, by spring tine harrow [GLO]
   1.8e-05 x      0.628 =   1.13e-05 market for [thio]carbamate-compound [GLO]
  1.48e-05 x      0.626 =   9.24e-06 market for pesticide, unspecified [GLO]
  7.96e-05 x      0.193 =   1.54e-05 market for ammonium sulfate, as N [GLO]
  4.87e-05 x       5.33 =    0.00026 market for tillage, ploughing [GLO]
    0.0758 x    0.00205 =   0.000155 market for transport, freight, lorry, unspecified [GLO]
         0 x      0.536 =          0 market for nitrogen fertiliser, as N [GLO]
  0.000507 x       0.14 =   7.07e-05 market for chemicals, inorganic [GLO]
    0.0379 x     0.0452 =    0.00171 market for transport, tractor and trailer, agricultural [GLO]
     0.773 x          0 =          0 market for sugar beet pulp [GLO]
  5.95e-11 x   2.47e+05 =   1.47e-05 market for sugar refinery [GLO]
     0.564 x   0.000104 =   5.84e-05 market for heat, district or industrial, natural gas [CH]
     0.564 x   5.98e-05 =   3.37e-05 market group for heat, district or industrial, natural gas [GLO]
      2.08 x   3.35e-05 =   6.98e-05 market group for tap water [GLO]
   0.00952 x   0.000843 =   8.02e-06 market for coke [GLO]
  0.000239 x     0.0157 =   3.76e-06 market for sulfuric acid [GLO]
   0.00131 x     0.0916 =    0.00012 market for soda ash, light, crystalline, heptahydrate [GLO]
     0.063 x     0.0353 =    0.00222 market group for electricity, medium voltage [GLO]
     0.139 x   0.000674 =   9.35e-05 market for limestone residue [GLO]
      2.08 x   1.41e-05 =   2.93e-05 market for tap water [CH]
        -0 x   1.03e-05 =         -0 market for vinasse, from fermentation of sugar beet molasses [GLO]
    0.0066 x     0.0179 =   0.000118 market for wastewater, from residence [GLO]
  0.000352 x     0.0392 =   1.38e-05 market for chemical, organic [GLO]
     0.063 x     0.0189 =    0.00119 market for electricity, medium voltage [CH]
     0.136 x   0.000652 =   8.87e-05 market for molasses, from sugar beet [GLO]
Total:   0.568269

In [13]:
F.bg_lcia(frag.term.term_node, [quantity], ref_flow=frag.term.term_flow, )[quantity.get_uuid()].show_details()


Loading LCIA results from f01eb904-d7e7-4633-b1a7-be54f33daa96_ffcb8cbb-77ab-4f87-8a94-87ca5b8ea79e.spold
ReCiPe Midpoint (I), agricultural land occupation, ALOP [LCIA] m2a
------------------------------------------------------------
         1 x      0.568 =      0.568 [RoW] ethanol, without water, in 95% solution state, from fermentation (CAS 000064-17-5) [By-product classification: allocatable product]
============================================================
             Total score: 0.568269 
     0.568 ReCiPe Midpoint (I), agricultural land occupation, ALOP [LCIA]