brightway


Connecting exchange names and codes to LCA inventory results


I'm getting into Brightway2 for some energy system modeling and I'm still getting used to the all of the concepts.
I've created a small custom demo database, and run lca.lci() and lca.lcia(). lca.inventory and lca.characterized_inventory both return sparse matrices of the results. My question, which may be very simple, is how can you connect the values in the matrix to the exchange names and keys. I.e., if I wanted to print the results to a file, how would I match the exchanges to the inventory values?
Thanks.
To really understand what is going on, it is useful to understand the difference between "intermediate" data (stored as structured text files) and "processed" data (stored as numpy structured arrays). These concepts are described both here and here.
However, to answer your question directly: what each row and column stand for in the different matrices and arrays (e.g. lca.inventory matrix, lca.supply_array, lca.characterized_inventory) are contained in a set of dictionaries that are associated with your LCA object. These are:
activity_dict: Columns in the technosphere matrix
product_dict : Rows in the technosphere matrix
biosphere_dict: Rows in the biosphere matrix
For example, lca.product_dict yields, in the case of an LCA I just did:
{('ei32_CU_U', '671c1ae85db847083176b9492f000a9d'): 8397,
('ei32_CU_U', '53398faeaf96420408204e309262b8c5'): 536,
('ei32_CU_U', 'fb8599da19dabad6929af8c3a3c3bad6'): 7774,
('ei32_CU_U', '28b3475e12e4ed0ec511cbef4dc97412'): 3051, ...}
with the key in the dictionary being the actual product in my inventory database and the value is the row in the demand_array or the supply_array.
More useful may be the reverse of these dictionaries. Let's say you want to know what a value in e.g. your supply_array refers to, you can create a reverse dictionary using a dict comprehension :
inv_product_dict = {v: k for k, v in lca.product_dict.items()}
and then simply use it directly to obtain the information you are after. Say you want to know what is in the 10th row of the supply_array, you can simply do inv_product_dict[10], which in my case yields ('ei32_CU_U', '4110733917e1fcdc7c55af3b3f068c72')
The same types of logic applies with biosphere (or elementary) flows, found in the lca.biosphere_dict (in LCA parlance, rows in the B matrix), and activities, found in the lca.activity_dict (columns of the A or B matrices).
Note that you can generate the reverse of the activity_dict/product_dict/biosphere_dict simultaneously using lca.reverse_dict(). The syntax then is:
rev_act_dict, rev_product_dict, rev_bio_dict = lca.reverse_dict()

Related Links

copy projects between different computers
importing ecoinvent 3.2 with brightway
Brightway2: Modifying/deleting exchanges from activity without using activity as dict
Backups in Brightway: how to use them
Saving multiple activities to database in a loop in Brightway
Obtaining distribution of results from LCIA
Simapro dataset to ecoinvent migration fails in brightway2
What is the best practice when importing 2 simapro datasets in brightway2 to merge them together
How to manually link in Brightway2 an imported exchange, given I have found the correct one in ecoinvent
Can't write copy of activity in newly created databases
Are eco-indicator endpoints reported in points or millipoints
Multi and Parallel Monte Carlo fail with key error (on database name)
sparse matrix solver runs out of memory in parallaleized dynamic LCA
Accessing exchange data in Brightway2 database object
Ecospold Identifiers for ecoinvent 3.2
Importing LCI database - dealing with unlinked exchanges

Categories

HOME
ckan
gsm
locale
crm
where
lithium
country-codes
clip-path
rethinkdb
doctrine2
ephesoft
select2
ldap-query
console-application
cucumberjs
orange
git-branch
connectiq
ng-tags-input
struts
apdu
sasl
smart-device
sphinx4
blockly
node-soap
webclient
matlab-compiler
mootools
minitest
cocoa-scripting
motherboard
maven-2
device-driver
scip
anypoint-studio
usernotifications
server-side-swift
bzip2
irr
automapper-4
blackberry
ios-keyboard-extension
msiexec
virtualenvwrapper
xcode7.1
cosign-api
nsoperationqueue
system-integration
boost-bind
boost-propertytree
usps
jmh
pebble-js
innertext
std
web-performance
jts
tess4j
tooltwist
p4python
litedb
pdcurses
eula
sony-xperia
fiware-health
information-hiding
mind-manager
breeze-sharp
twitter-finagle
connections
infor-eam
kernel-density
mysql-error-1146
xml-validation
grunt-contrib-imagemin
oc4j
extensibility
removeall
windows-scheduler
nx
expresso-store
blackberry-eclipse-plugin
event-propagation
dancer
cherokee
subdirectories
oaw
atmega16
onresize

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App