diff --git a/.ipynb_checkpoints/BW2_tutorial-checkpoint.ipynb b/.ipynb_checkpoints/BW2_tutorial-checkpoint.ipynb
new file mode 100644
index 0000000..b9bf7f7
--- /dev/null
+++ b/.ipynb_checkpoints/BW2_tutorial-checkpoint.ipynb
@@ -0,0 +1,5434 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Introductory note\n",
+ " \n",
+ "This is a [Jupyter Notebook](https://jupyter-notebook-beginner-guide.readthedocs.io/en/latest/what_is_jupyter.html) with the purpose of making you familiar with the basic Python-based [Brightway2 LCA framework](https://brightwaylca.org/) and its various functionalities, all developed by [Chris Mutel and colleagues](https://2.docs.brightwaylca.org/credits.html#authors).\n",
+ "\n",
+ "This notebook is designed to get you started with creating your own project, setting up your database(s) (used as background systems) and simple foreground systems, performing your first impact assessments, analysing your results, and running Monte Carlo simulations in calculation setups.\n",
+ "\n",
+ "Since Brightway2 builds on Python, a widely used programming language for scientific analysis, and can be installed easiest through the package and environment mangement system [*conda*](https://docs.conda.io/projects/conda/en/latest/), we need to get either [Anaconda](https://www.anaconda.com/), an open source distribution for multiple languages including Python and R, or at least [Miniconda](https://docs.conda.io/en/latest/miniconda.html), the bootstrap version of Anaconda. The full Anaconda installation contains, among others, a terminal and an IDE (integrated development environment). And, good for us, it natively installs the setup for Jupyter Notebooks, through which we can work most effectively with Brightway2. Both Jupyter and Brightway can also be installed through [*pip*](https://jupyter.readthedocs.io/en/latest/install.html#new-to-python-and-jupyter), but it may be a tad trickier.\n",
+ "\n",
+ "For clarification: *conda* is, just like *pip*, a package and environment management system; the difference, however, is that \"*pip* installs python packages within any environment; *conda* installs any package within conda environments.\" (quote from [here](https://jakevdp.github.io/blog/2016/08/25/conda-myths-and-misconceptions/))\n",
+ "\n",
+ " \n",
+ "\n",
+ "**Update 08/03/2021 - Elin Barrett**\n",
+ "Changes to this notebook have been made to fix broken links and certificates.\n",
+ "\n",
+ " Notes by Elin are in this colour throughout.\n",
+ " \n",
+ "\n",
+ "---\n",
+ "\n",
+ "**Recommended prerequisites are:**\n",
+ "* having installed [Brightway2](https://2.docs.brightwaylca.org/installation.html) + all relevant packages (make sure to do so in the correct virtual environment) and possibly even having had a first quick look at its [documentation](https://2.docs.brightway.dev/index.html). *Credits where credits are due:* much of the present notebook is based both directly and indirectly on this documentation (and the [example notebooks](https://2.docs.brightway.dev/notebooks.html))\n",
+ "* knowledge of the foundations of life cycle assessment. If you don't have this knowledge (or simply need a refresher), have a look at the [online teaching resources](http://www.teaching.industrialecology.uni-freiburg.de/) provided by the Industrial Ecology Freiburg Group, led by Stefan Pauliuk\n",
+ "* familiarity with any programming language - no Python-specific requirements, as most methods are quite intuitive and will be explained anyway. In case you are a bloody beginner, check [this](https://github.com/PoutineAndRosti/Brightway-Seminar-2017/blob/master/Day%201%20AM/1%20-%20Python%20and%20notebook%20basics.ipynb) out :)\n",
+ "\n",
+ " \n",
+ "\n",
+ "---\n",
+ "\n",
+ "**For Jupyter newbies**\n",
+ "\n",
+ "In a [Jupyter notebook](https://jupyter-notebook.readthedocs.io/en/stable/index.html) everything is live and interactive. And, perhaps more interesting, markdown elements and actual code are mixed - and you can even include images, videos, and other formats. There are [many](https://github.com/jupyter/jupyter/wiki/A-gallery-of-interesting-Jupyter-Notebooks), [many](https://rise.readthedocs.io/en/maint-5.5/index.html) things that you can do with such notebooks, and there are also many [cool](https://blog.dominodatalab.com/lesser-known-ways-of-using-notebooks/) [tricks](https://www.dataquest.io/blog/jupyter-notebook-tips-tricks-shortcuts/) as well as some [extensions](https://github.com/ipython-contrib/jupyter_contrib_nbextensions).\n",
+ "\n",
+ "To get you started, you might want to press the `h`-key, which gives you an overview of keyboard shortcuts. Then, you have markdown (richt text containing) cells and code cells: if you hover over and select any cell by clicking on it (notice the blue bar on the left of the cell; turns green when you are in edit mode, i.e. having clicked into the cell box) you can turn it into either a markdown one by pressing `m` or into a code cell by pressing `y`; there are other types, too, but they are not relevant for what we want to do. Click on a cell to select it or simply use the arrow keys to navigate. If you want to run a cell, simply press `shift+enter`. And if you want to insert an empty cell above or below the current one, simply press `a` or `b`. For changing the contents of a cell, either doubleclick a markdown cell or click a code cell; pressing `enter` works, too. You can exit a cell using `Esc` and can copy, cut, and paste cells when pressing the keys `c`, `x`, and `v` when having selected a cell. As for the output of a command, note that clicking on it once makes it scroll-able, clicking on it twice results in hiding it.\n",
+ "\n",
+ "You will notice further below that there are sometimes commands starting with `import`. These ones are needed to \"import\" the code of the respective package into the present code. For instance, by importing the Brightway2 package you enable the present notebook to use the Brightway2 functionalities. To have access to these packages, you need to download them first; otherwise you will receive an error message. You can download such packages in two ways: either in the notebook or in the terminal (make sure to be in the right virtual environment). To find out more about that I would advise you to use the search engine of your choice ;)\n",
+ "\n",
+ "These are the absolute basics, but they are already more than what you need here. Because you basically just need to run the presented cells.\n",
+ "\n",
+ " \n",
+ "\n",
+ "---\n",
+ "\n",
+ "**Recap on LCA**\n",
+ "\n",
+ "To make sure we are on the same page, let's recapitulate the basics of LCA, expressed in a single formula (the notation may differ to the one that you are familiar with):\n",
+ "\n",
+ "$$h = CBA^{-1}f$$\n",
+ "\n",
+ "where:\n",
+ "- $A$... transaction matrix (dimensions *p x q*)\n",
+ "- $B$... environmental interventions matrix (dimensions *r x q*)\n",
+ "- $C$... characterisation matrix (dimensions *p x q*)\n",
+ "- $f$... final demand vector (dimensions *p x 1*)\n",
+ "- $h$... characterised inventory matrix (dimensions *1 x 1*)\n",
+ "\n",
+ "with the dimensions being:\n",
+ "- *p*... number of products\n",
+ "- *q*... number of activities/processes\n",
+ "- *r*... number of elementary flows\n",
+ "\n",
+ "Specific parts of the above formula have distinct names. Since these names are also used in the Brightway2-framework, we will note them down here:\n",
+ "- $f$... demand array\n",
+ "- $A{^-1}f$... supply array\n",
+ "- $BA{^-1}f$... inventory\n",
+ "- $CBA{^-1}f$... characterised inventory\n",
+ "\n",
+ "To not only get a single score per impact category, we can diagonalise the supply array (how this can be realised in the Brightway2-framework is not shown in this notebook) so that we can see the environmental impacts per process:\n",
+ "\n",
+ "$$h_{process} = CB~diag(A^{-1}f)$$\n",
+ "\n",
+ "You can do the same for breaking down the total environmental impact to the stressors:\n",
+ "\n",
+ "$$h_{stressor} = C~diag(BA^{-1}f)$$\n",
+ "\n",
+ "Another way of representing your results is to show the environmental stressors per activity for a specific impact category:\n",
+ "\n",
+ "$$h_{category} = diag(C)~B~diag(A^{-1}f)$$\n",
+ "\n",
+ " \n",
+ "\n",
+ "---\n",
+ "\n",
+ "**The notebook is structured as follows:**\n",
+ "1. [Setup of a project](#section1): *How to set up a project to work in*\n",
+ "2. [Database import/setup](#section2): *How to import a database and get it ready for use* \n",
+ " 2.1 [Importing ecoinvent and Forwast](#section21) \n",
+ " 2.2 [Database selection and a first look at activities](#section22) \n",
+ " 2.3 [Importing a dataset from Excel](#section23) \n",
+ "3. [Manual database creation](#section3): *How to manually create a database*\n",
+ "4. [LCIA](#section4): *Basics of the LCIA calculations*\n",
+ "5. [Foreground system](#section5): *How to set up a very simple product system and ways to explore BW2's functionalities* \n",
+ " 5.1 [Simple product system](#section51) \n",
+ " 5.2 [Bottle production](#section52) \n",
+ "6. [Manipulating an exchange](#section6): *How to manipulate an activity in multiple ways* \n",
+ " 6.1 [Copying and deleting an activity](#section61) \n",
+ " 6.2 [First attempts at manipulating an exchange's keys/values](#section62) \n",
+ " 6.3 [Substituting an exchange](#section63) \n",
+ " 6.4 [Successfully manipulating an exchange](#section64) \n",
+ "7. [Basic contribution analysis](#section7): *How to examine the LCA results* \n",
+ " 7.1 [Recalculation of the inventory](#section71) \n",
+ " 7.2 [Basic contribution analysis](#section72) \n",
+ " 7.3 [Top emissions and processes by name](#section73) \n",
+ "8. [Multi-LCA](#section8): *How to compare multiple alternatives across multiple impact categories simultaneously* \n",
+ " 8.1 [Manually comparing products](#section81) \n",
+ " 8.2 [Calculation setups](#section82) \n",
+ " 8.3 [MLCA](#section83) \n",
+ "9. [Monte Carlo simulation](#section9): *How to quantify uncertainties of the LCA result* \n",
+ "\n",
+ " \n",
+ "\n",
+ "---\n",
+ "\n",
+ "**Outcomes - what are we going to learn?**\n",
+ "\n",
+ "By completing this notebook (run it locally on your machine and don't just read the code), we will:\n",
+ "- have understood the basics of the Brightway2 LCA framework\n",
+ "- know how to import/generate/handle datasets in Brightway2\n",
+ "- be able to run simple LCAs (both linearly and in parallel)\n",
+ "- be able to analyse a product system and the results of an LCA\n",
+ "- be able to visualise data in form of tables and figures\n",
+ "- be rewarded with a dabbing 🦄\n",
+ "\n",
+ " \n",
+ "\n",
+ "---\n",
+ "Just for clarification, abbreviations used in the markdown cells of this notebook are:\n",
+ "\n",
+ "| Abbreviation(s) | Written out |\n",
+ "| --- | --- |\n",
+ "| bw, BW2 | Brightway2 |\n",
+ "| FU | Functional unit |\n",
+ "| LCA | Life cycle assessment |\n",
+ "| LCI | Life cycle inventory |\n",
+ "| LCIA | Life cycle impact assessment |\n",
+ "\n",
+ "---\n",
+ "\n",
+ "So, that would be it what we're up to do. But if you're super keen then you might also be interested in checking out the **[Activity browser](https://github.com/LCA-ActivityBrowser/activity-browser)** and **[LCOPT](https://lcopt.readthedocs.io/en/latest/)**, both of which are essentially graphical user interfaces for BW2. The latter one can be used particularly for parametrised inventories (you'll learn more about the basics of this later).\n",
+ "\n",
+ " \n",
+ "\n",
+ "---"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ " \n",
+ "# 1. Setup of a project\n",
+ "\n",
+ "A project gets instantiated and relevant libraries/modules imported."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import os\n",
+ "import matplotlib.pyplot as plt\n",
+ "import numpy as np\n",
+ "import pandas as pd\n",
+ "import brightway2 as bw\n",
+ "from brightway2 import *\n",
+ "from bw2data.parameters import ActivityParameter, DatabaseParameter, ProjectParameter, Group"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Let's list the available projects. There are two ways for doing so:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "[Project: default, Project: StepByStep]"
+ ]
+ },
+ "execution_count": 2,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "list(bw.projects)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "Brightway2 projects manager with 2 objects:\n",
+ "\tStepByStep\n",
+ "\tdefault\n",
+ "Use `projects.report()` to get a report on all projects."
+ ]
+ },
+ "execution_count": 3,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "#same as above\n",
+ "bw.projects"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "We can get more information (installed databases and file sizes) on the individual projects with the following command:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "[('StepByStep', 2, 0.026502669), ('default', 0, 8.2127e-05)]"
+ ]
+ },
+ "execution_count": 4,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "bw.projects.report()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "... and also see where they are stored:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'C:\\\\Users\\\\elin.barrett\\\\AppData\\\\Local\\\\pylca\\\\Brightway3\\\\default.c21f969b5f03d33d43e04f8f136e7682'"
+ ]
+ },
+ "execution_count": 5,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "bw.projects.dir"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "We can also create sub-directories for e.g. to-be-generated data:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'C:\\\\Users\\\\elin.barrett\\\\AppData\\\\Local\\\\pylca\\\\Brightway3\\\\default.c21f969b5f03d33d43e04f8f136e7682\\\\my-new-directory'"
+ ]
+ },
+ "execution_count": 6,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "projects.request_directory(\"my-new-directory\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "But we won't need this here, so let's delete it again:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import shutil\n",
+ "os.rmdir(os.path.join(bw.projects.dir, 'my-new-directory'))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "To create a new project or to access an existing one, we type in:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Biosphere database already present!!! No setup is needed\n"
+ ]
+ }
+ ],
+ "source": [
+ "bw.projects.set_current(\"StepByStep\") #Creating/accessing the project\n",
+ "bw.bw2setup() #Importing elementary flows, LCIA methods and some other data"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "Brightway2 projects manager with 2 objects:\n",
+ "\tStepByStep\n",
+ "\tdefault\n",
+ "Use `projects.report()` to get a report on all projects."
+ ]
+ },
+ "execution_count": 9,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "#now we see that we have created our first project\n",
+ "bw.projects"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "To see where your current project is stored, type:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'C:\\\\Users\\\\elin.barrett\\\\AppData\\\\Local\\\\pylca\\\\Brightway3\\\\StepByStep.68d8c641ebe12c46d077d8ff720c3bbd'"
+ ]
+ },
+ "execution_count": 10,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "bw.projects.dir"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "**Troubleshooting**\n",
+ "\n",
+ "Sometimes not everything goes as intended (depending on many different factors) and there may be some problems occurring when executing Brightway specific commands. Then it helps to examine the system paths for all respective modules, see where the binary Python interpreter is located, and list which kernels are available and where they are located."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import sys"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 12,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'C:\\\\Users\\\\elin.barrett\\\\AppData\\\\Local\\\\Continuum\\\\anaconda3\\\\envs\\\\brightway-env\\\\python.exe'"
+ ]
+ },
+ "execution_count": 12,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "sys.executable"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "['',\n",
+ " 'C:\\\\Users\\\\elin.barrett\\\\AppData\\\\Local\\\\Continuum\\\\anaconda3\\\\envs\\\\my-rdkit-env\\\\Lib\\\\site-packages',\n",
+ " 'C:\\\\Users\\\\elin.barrett\\\\AppData\\\\Local\\\\Continuum\\\\anaconda3\\\\envs\\\\brightway-env\\\\python36.zip',\n",
+ " 'C:\\\\Users\\\\elin.barrett\\\\AppData\\\\Local\\\\Continuum\\\\anaconda3\\\\envs\\\\brightway-env\\\\DLLs',\n",
+ " 'C:\\\\Users\\\\elin.barrett\\\\AppData\\\\Local\\\\Continuum\\\\anaconda3\\\\envs\\\\brightway-env\\\\lib',\n",
+ " 'C:\\\\Users\\\\elin.barrett\\\\AppData\\\\Local\\\\Continuum\\\\anaconda3\\\\envs\\\\brightway-env',\n",
+ " 'C:\\\\Users\\\\elin.barrett\\\\AppData\\\\Local\\\\Continuum\\\\anaconda3\\\\envs\\\\brightway-env\\\\lib\\\\site-packages',\n",
+ " 'C:\\\\Users\\\\elin.barrett\\\\AppData\\\\Local\\\\Continuum\\\\anaconda3\\\\envs\\\\brightway-env\\\\lib\\\\site-packages\\\\pypardiso-0.2.2-py3.6.egg',\n",
+ " 'C:\\\\Users\\\\elin.barrett\\\\AppData\\\\Local\\\\Continuum\\\\anaconda3\\\\envs\\\\brightway-env\\\\lib\\\\site-packages\\\\win32',\n",
+ " 'C:\\\\Users\\\\elin.barrett\\\\AppData\\\\Local\\\\Continuum\\\\anaconda3\\\\envs\\\\brightway-env\\\\lib\\\\site-packages\\\\win32\\\\lib',\n",
+ " 'C:\\\\Users\\\\elin.barrett\\\\AppData\\\\Local\\\\Continuum\\\\anaconda3\\\\envs\\\\brightway-env\\\\lib\\\\site-packages\\\\Pythonwin',\n",
+ " 'C:\\\\Users\\\\elin.barrett\\\\AppData\\\\Local\\\\Continuum\\\\anaconda3\\\\envs\\\\brightway-env\\\\lib\\\\site-packages\\\\IPython\\\\extensions',\n",
+ " 'C:\\\\Users\\\\elin.barrett\\\\.ipython']"
+ ]
+ },
+ "execution_count": 13,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "sys.path"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Available kernels:\n",
+ " python3 C:\\Users\\elin.barrett\\AppData\\Local\\Continuum\\anaconda3\\envs\\brightway-env\\share\\jupyter\\kernels\\python3\n"
+ ]
+ }
+ ],
+ "source": [
+ "!jupyter kernelspec list"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "**Magic commands**"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "For unexperienced python users it may be interesting to check out some *magic commands* that can be quite helpful, for example when timing the execution of a command. A list of available *magic commands* can be found below."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 15,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "application/json": {
+ "cell": {
+ "!": "OSMagics",
+ "HTML": "Other",
+ "SVG": "Other",
+ "bash": "Other",
+ "capture": "ExecutionMagics",
+ "cmd": "Other",
+ "debug": "ExecutionMagics",
+ "file": "Other",
+ "html": "DisplayMagics",
+ "javascript": "DisplayMagics",
+ "js": "DisplayMagics",
+ "latex": "DisplayMagics",
+ "perl": "Other",
+ "prun": "ExecutionMagics",
+ "pypy": "Other",
+ "python": "Other",
+ "python2": "Other",
+ "python3": "Other",
+ "ruby": "Other",
+ "script": "ScriptMagics",
+ "sh": "Other",
+ "svg": "DisplayMagics",
+ "sx": "OSMagics",
+ "system": "OSMagics",
+ "time": "ExecutionMagics",
+ "timeit": "ExecutionMagics",
+ "writefile": "OSMagics"
+ },
+ "line": {
+ "alias": "OSMagics",
+ "alias_magic": "BasicMagics",
+ "autocall": "AutoMagics",
+ "automagic": "AutoMagics",
+ "autosave": "KernelMagics",
+ "bookmark": "OSMagics",
+ "cd": "OSMagics",
+ "clear": "KernelMagics",
+ "cls": "KernelMagics",
+ "colors": "BasicMagics",
+ "config": "ConfigMagics",
+ "connect_info": "KernelMagics",
+ "copy": "Other",
+ "ddir": "Other",
+ "debug": "ExecutionMagics",
+ "dhist": "OSMagics",
+ "dirs": "OSMagics",
+ "doctest_mode": "BasicMagics",
+ "echo": "Other",
+ "ed": "Other",
+ "edit": "KernelMagics",
+ "env": "OSMagics",
+ "gui": "BasicMagics",
+ "hist": "Other",
+ "history": "HistoryMagics",
+ "killbgscripts": "ScriptMagics",
+ "ldir": "Other",
+ "less": "KernelMagics",
+ "load": "CodeMagics",
+ "load_ext": "ExtensionMagics",
+ "loadpy": "CodeMagics",
+ "logoff": "LoggingMagics",
+ "logon": "LoggingMagics",
+ "logstart": "LoggingMagics",
+ "logstate": "LoggingMagics",
+ "logstop": "LoggingMagics",
+ "ls": "Other",
+ "lsmagic": "BasicMagics",
+ "macro": "ExecutionMagics",
+ "magic": "BasicMagics",
+ "matplotlib": "PylabMagics",
+ "mkdir": "Other",
+ "more": "KernelMagics",
+ "notebook": "BasicMagics",
+ "page": "BasicMagics",
+ "pastebin": "CodeMagics",
+ "pdb": "ExecutionMagics",
+ "pdef": "NamespaceMagics",
+ "pdoc": "NamespaceMagics",
+ "pfile": "NamespaceMagics",
+ "pinfo": "NamespaceMagics",
+ "pinfo2": "NamespaceMagics",
+ "popd": "OSMagics",
+ "pprint": "BasicMagics",
+ "precision": "BasicMagics",
+ "profile": "BasicMagics",
+ "prun": "ExecutionMagics",
+ "psearch": "NamespaceMagics",
+ "psource": "NamespaceMagics",
+ "pushd": "OSMagics",
+ "pwd": "OSMagics",
+ "pycat": "OSMagics",
+ "pylab": "PylabMagics",
+ "qtconsole": "KernelMagics",
+ "quickref": "BasicMagics",
+ "recall": "HistoryMagics",
+ "rehashx": "OSMagics",
+ "reload_ext": "ExtensionMagics",
+ "ren": "Other",
+ "rep": "Other",
+ "rerun": "HistoryMagics",
+ "reset": "NamespaceMagics",
+ "reset_selective": "NamespaceMagics",
+ "rmdir": "Other",
+ "run": "ExecutionMagics",
+ "save": "CodeMagics",
+ "sc": "OSMagics",
+ "set_env": "OSMagics",
+ "store": "StoreMagics",
+ "sx": "OSMagics",
+ "system": "OSMagics",
+ "tb": "ExecutionMagics",
+ "time": "ExecutionMagics",
+ "timeit": "ExecutionMagics",
+ "unalias": "OSMagics",
+ "unload_ext": "ExtensionMagics",
+ "who": "NamespaceMagics",
+ "who_ls": "NamespaceMagics",
+ "whos": "NamespaceMagics",
+ "xdel": "NamespaceMagics",
+ "xmode": "BasicMagics"
+ }
+ },
+ "text/plain": [
+ "Available line magics:\n",
+ "%alias %alias_magic %autocall %automagic %autosave %bookmark %cd %clear %cls %colors %config %connect_info %copy %ddir %debug %dhist %dirs %doctest_mode %echo %ed %edit %env %gui %hist %history %killbgscripts %ldir %less %load %load_ext %loadpy %logoff %logon %logstart %logstate %logstop %ls %lsmagic %macro %magic %matplotlib %mkdir %more %notebook %page %pastebin %pdb %pdef %pdoc %pfile %pinfo %pinfo2 %popd %pprint %precision %profile %prun %psearch %psource %pushd %pwd %pycat %pylab %qtconsole %quickref %recall %rehashx %reload_ext %ren %rep %rerun %reset %reset_selective %rmdir %run %save %sc %set_env %store %sx %system %tb %time %timeit %unalias %unload_ext %who %who_ls %whos %xdel %xmode\n",
+ "\n",
+ "Available cell magics:\n",
+ "%%! %%HTML %%SVG %%bash %%capture %%cmd %%debug %%file %%html %%javascript %%js %%latex %%perl %%prun %%pypy %%python %%python2 %%python3 %%ruby %%script %%sh %%svg %%sx %%system %%time %%timeit %%writefile\n",
+ "\n",
+ "Automagic is ON, % prefix IS NOT needed for line magics."
+ ]
+ },
+ "execution_count": 15,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "lsmagic"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Just two examples:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 16,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'C:\\\\Users\\\\elin.barrett\\\\OneDrive - Unilever\\\\Sustainability\\\\Brightwayintro'"
+ ]
+ },
+ "execution_count": 16,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "%pwd\n",
+ "#returns the path to the current folder\n",
+ "#same output as:\n",
+ "#os.getcwd()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 17,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The slowest run took 9.16 times longer than the fastest. This could mean that an intermediate result is being cached.\n",
+ "1000000 loops, best of 3: 338 ns per loop\n",
+ "Wall time: 0 ns\n"
+ ]
+ },
+ {
+ "data": {
+ "text/plain": [
+ "6.48074069840786"
+ ]
+ },
+ "execution_count": 17,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "import math\n",
+ "%timeit math.sqrt(42)\n",
+ "\n",
+ "#compare this with the time needed for the simple command:\n",
+ "%time math.sqrt(42)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Btw, if you don't know how a method works, just add a \"?\" behind, e.g. for this magic command:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 20,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "alias?"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "... or \"??\" to see the actual code of this method."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 21,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "alias??"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "**Continue, or back to [table of contents](#section0)?**\n",
+ "***"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ " \n",
+ "# 2. Database import/setup"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ " \n",
+ "## 2.1 Importing ecoinvent and Forwast\n",
+ "\n",
+ "LCA draws on a lot of background data. Those can be found in numerous databases, for instance ecoinvent. We can check which databases are available in the current project with the following command:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 18,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "Databases dictionary with 2 object(s):\n",
+ "\tbiosphere3\n",
+ "\tforwast"
+ ]
+ },
+ "execution_count": 18,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "#list the available databases\n",
+ "bw.databases"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "If the list does not yet include the database we want, we can import it. As an example, we first import FORWAST and then the 3.5 ecoinvent cut-off database and check on some of the import's statistics:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 31,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "Writing activities to SQLite3 database:\n",
+ "0% [##############################] 100% | ETA: 00:00:00\n",
+ "Total time elapsed: 00:00:11\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Title: Writing activities to SQLite3 database:\n",
+ " Started: 03/08/2021 13:51:31\n",
+ " Finished: 03/08/2021 13:51:42\n",
+ " Total time elapsed: 00:00:11\n",
+ " CPU %: 56.40\n",
+ " Memory %: 3.00\n"
+ ]
+ }
+ ],
+ "source": [
+ "#FORWAST\n",
+ "import zipfile\n",
+ "from bw2data.utils import download_file\n",
+ "\n",
+ "if 'forwast' in bw.databases:\n",
+ " print(\"Database has already been imported.\")\n",
+ "else:\n",
+ " dirpath = \"C:\\\\Users\\elin.barrett\\\\OneDrive - Unilever\\\\Sustainability\\\\forwast.bw2package\"\n",
+ " BW2Package.import_file(os.path.join(dirpath, \"forwast.bw2package\"))\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "The automatic download of the forwast database gets an SSLError, so go to [this link](https://lca-net.com/wp-content/uploads/forwast.bw2package.zip) to download the zip file then point the notebook at it.\n",
+ "\n",
+ "Because ecoinvent is licensed and I don't know how the licenses work, I have skipped the rest of this section and the rest of the notebook uses forwast only.\n",
+ " "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 33,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#ecoinvent\n",
+ "#if 'ecoinvent 3.5_cutoff_ecoSpold02' in bw.databases:\n",
+ "# print(\"Database has already been imported.\")\n",
+ "#else:\n",
+ " # mind that the ecoinvent file must be unzipped; then: path to the datasets subfolder\n",
+ "# fpei35cut = r\"C:\\Users\\Maximilian Koslowski\\Forschung\\Ecoinvent\\3.5\\ecoinvent 3.5_cutoff_ecoSpold02\\datasets\"\n",
+ " # the \"r\" makes sure that the path is read as a string - especially useful when you have spaces in your string\n",
+ "# ei35cut = bw.SingleOutputEcospold2Importer(fpei35cut, 'ecoinvent 3.5_cutoff_ecoSpold02')\n",
+ "# ei35cut\n",
+ "# ei35cut.apply_strategies()\n",
+ "# ei35cut.statistics()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "If unlinked exchanges are present: If that happens (it might for other versions of ecoinvent!) and we want to understand the details of it, we first check the proper exchange linkages in the logfile of the import:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#open the logfile and check the deleted exchanges\n",
+ "fp = r\"C:\\Users\\Maximilian Koslowski\\AppData\\Local\\pylca\\Brightway3\\Logs\\3Dprinting-LCA.674d125927554cffbf495553d43372bd\\Ecospold2-import-error.FyZMwV.log\"\n",
+ "\n",
+ "with open(fp) as f:\n",
+ " lines = [x.strip() for x in f]\n",
+ "\n",
+ "for line in lines[:26]:\n",
+ " print(line)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "And then we check what the actual flows of the respective activities are:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#mind that the identifiers looked for below were used when linking the consequential ecoinvent 3.5 database, hence \"fpei35con\"\n",
+ "for filename in os.listdir(fpei35con):\n",
+ " if \"874057b2-e4e0-446c-be44-ff2881801e9f\" in filename:\n",
+ " print(filename)\n",
+ " if \"7757e24e-897e-4b07-8ca9-87bb8dbe3016\" in filename:\n",
+ " print(filename)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "As of now, no better way of handling this issue exists than simply deleting such exchanges (as was done automatically). The import of other databases works a bit smoother. How that is done can be found in some example notebooks [here](https://docs.brightwaylca.org/notebooks.html#example-notebooks)."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Before we can actually make use of the newly imported database, we need to save it!"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#write database to disk --> actually saves it\n",
+ "ei35cut.write_database()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 32,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "Databases dictionary with 2 object(s):\n",
+ "\tbiosphere3\n",
+ "\tforwast"
+ ]
+ },
+ "execution_count": 32,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "#list the available databases - again\n",
+ "bw.databases"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "**IMPORTANT NOTE** \n",
+ "\n",
+ ">In the following, we will mainly use data from ecoinvent. In case you do not have access to it, do not worry - you can complete almost the whole notebook with the free FORWAST database, too. You would only have to change the database selection in each respective cell from `eidb.` to `fw.` (abbreviations taken from below). Mind that you would also have to undertake manual changes in the Excel spreadsheet for making the respective import work (chapter 2.3). Also, mind that the FORWAST data differs to the one of ecoinvent; this, however, affects only few of your commands further below (e.g. finding activities by name etc.). If you want to work with data from other sources, e.g. Agribalyse, please see the respective [strategies](https://2.docs.brightwaylca.org/notebooks.html#example-notebooks) for their data import."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ " \n",
+ "## 2.2 Database selection and a first look at activities\n",
+ "\n",
+ "If our database of choice is already included, then we just make use of it directly. For convenience, we need to assign a variable to it so that the database can be worked with more easily."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 19,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#eidb = bw.Database('ecoinvent 3.5_cutoff_ecoSpold02')\n",
+ "fw = bw.Database('forwast')"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "We can also check up on the type and length of our imported database."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 20,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The imported forwast database is of type and has a length of 277.\n"
+ ]
+ }
+ ],
+ "source": [
+ "print(\"The imported forwast database is of type {} and has a length of {}.\".format(type(fw), len(fw)))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "And we can even visualise our technospheres:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 21,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "image/png": "iVBORw0KGgoAAAANSUhEUgAAACIAAAAiCAYAAAA6RwvCAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAAEs0lEQVR4nO2We0yVdRjHP+/7ngPncBWTNC6hEiJmlHhLdKuluDGswUamTJ2aqCiVsyw2N5elzZkNK2dZM1NXMDVziW3RLKd5mUg4VC6hEtcjoJ4Dcu7nvL/+OCdIFkc71uIPvv+97/u7fJ7v8zzv7ycJIRgIkv9vgD81CNJXgyB9NWBANL4+xuwpEAAx5pt8Ur6fIOHiy/Bi3JIOJAmgdWvhnOgVRXGJQA0IcuSbjJbsjbFz3XH/BOS+HGnWD6UiPBYBZHa+SqirBYQAl3MYwMZ38+uyD6Rtl4SgS0hscUfVGw4pMw2HlNOGQ0rQvwaCLLMhIZ0KggmnneTuj8DeRcqdHZJ3xJoAh3aNQKZEHYbLJU9XBaVCkArsfGAQxdIFbrfnISiYdVMWcx1IpJZl1kWkcAIAEzyTWD+a8afjwQYjL0WrqvCsfdvFSw8McrhsFwHG5l4YfRDLJ66kBnAD3d5x+56NHyqA7J/T2bgtnyUlWdJ77kcodwXysYjSPjBICPDNlQMMv3EVVNX7MpT8yXnsHvI4mTPWAuAKUCicHkctoAI2kFShUEIkQpWl/tb/qyRfh17h4tfELHbgBhYmZGIcEe/pFql37Q/K9yNZxnAhbC2YzUyuMlA5/lE6kwqwRzqIaA7DGNsFEmLX/IZ+A/fpiCEijWPkogB7644Q3VINQr1rzLjuNp5UTxJiKQOtQtnkx5CsTgo+W87bm1ezam9OT9C+9vIJor3dze2wdI7wOlrg0+vfo7vZ1JsmID0ll2pgrmMzMyxvgdOMTSdxFRBInBtVDk7gHrcNnyDLypoIbDNxJzSVElahAMXVB4m8Ud9bwKHh5E/K4woyCTQw0bwNNDIl0+OokWBG/VRmHZwKXb5BfNaIYdxWYQeKxg7BGDMcXdevZLMJN7A6/gUaoxJA9sZiMbO5bD9TuUMlE7igfxNcgqwzjcQJT8Qjqtb1mx6fjhSnlaDBTU6NidAbHdjCUij1OrPz2neMbqnxOCMEBAWzftICqlBIpoJU6zuglfl2WgwGydNNfjuyoihOaGwKUW2R5BTNIdCpY/vssQDEOs4x27KFHx9OYm9cKgZ9RE83FZ/dSaTDjARUBmZyXr8YgK3bn/fPEXDi0jmwdprBKXAioP0WqCpNAU+zO/xr0tqr2XL5MPMazvbMmjdtFfOmLEcFRtpP3cOL+wBZL7XxEDY6kk0UZu9DxkXexXaUViOoKsGdv+AAhlqNNLllcNp75nZo9XwVMpJQbjHFVADWW/6DaBTIxYgeE/YkO4VZXyDjYEVVOyENbZjD0zhOFhpgQ/MpUjqueVpbCNAEsGfiizQAT1DDXPvL/oOUXVYEbsQrWNFgFObxdvH57ANCYGNRnYmg6wZawxZylJW4gU11xwgwd3l+et7aWzohlyt4jgtf8lms/emHjKXW5PqxOoDCmWNAUQB4rnMjo0QFq5+aT01YtHcHT31OMDZwdG2Rv8X69zq84DilKSexYCHv+G8EtHoK+KfgN1CB9y8WkfR75V1/4IoI3xc2f++sOWcyLrEv/SgyDpZcbiextgVEoDhPBhLwYWMpGbUnPCm6D9f9Ss1/oQFzix8E6atBkL4aMCB/AL6g3xzgDZpaAAAAAElFTkSuQmCC\n",
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {
+ "needs_background": "light"
+ },
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "fw.graph_technosphere()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "I don't know how to make this not tiny, although because it's a figure you could download it as an image then look at it full-size that way if necessary I suppose.\n",
+ " \n",
+ "\n",
+ "Nice graphic! But it doesn't really tell us much... Let's have a bit of a closer look at what our database contains. We can, for instance, examine a random process of the imported ecoinvent database by doing the following:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 22,
+ "metadata": {
+ "scrolled": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "{'products': [{'location': 'GLO',\n",
+ " 'unit': 'EUR2003',\n",
+ " 'output': ('forwast', 'a090983fe0b9aa8877e2b4e72421ed58'),\n",
+ " 'amount': 1.0,\n",
+ " 'input': ('forwast', 'a090983fe0b9aa8877e2b4e72421ed58'),\n",
+ " 'categories': (),\n",
+ " 'loc': 1.0,\n",
+ " 'type': 'production',\n",
+ " 'name': '_84 Hotels and restaurants, EU27',\n",
+ " 'uncertainty type': 0}],\n",
+ " 'categories': ['Input Output', 'EU27 2003'],\n",
+ " 'filename': '/Users/marie/Downloads/FORWAST-ecospold1/FORWAST-ecospold100167.XML',\n",
+ " 'type': 'process',\n",
+ " 'comment': 'Location: Unspecified\\nTechnology: Unspecified\\nTime period: Unspecified',\n",
+ " 'location': 'GLO',\n",
+ " 'unit': 'EUR2003',\n",
+ " 'code': 'a090983fe0b9aa8877e2b4e72421ed58',\n",
+ " 'production amount': 1.0,\n",
+ " 'name': '_84 Hotels and restaurants, EU27',\n",
+ " 'database': 'forwast'}"
+ ]
+ },
+ "execution_count": 22,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "random_act = fw.random()\n",
+ "random_act.as_dict()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "To get an overview of all exchanges of the selected process, type:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 23,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Exchange: 1.0 EUR2003 '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000712307951627944 kilogram '__1 Bovine meat and milk, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000107332010096907 kilogram '__2 Pigs, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000226060301576555 kilogram '__3 Poultry and animals n.e.c., EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00579471935322287 kilogram '__4 Grain crops, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00635371819452267 kilogram '__5 Crops n.e.c., EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000886804639545545 EUR2003 '__6 Agricultural services n.e.c., EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000505289821522072 kilogram '__7 Forest products, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000432516875634936 kilogram '__9 Fish, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00179827091992188 kilogram '_10 Coal, lignite, peat, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 6.94377887373604e-06 kilogram '_12 Iron ores from mine, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 6.46610730758635e-09 kilogram '_13 Bauxite from mine, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 2.98059398221944e-08 kilogram '_14 Copper from mine, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 2.01184555188974e-05 kilogram '_15 Metals from mine n.e.c., EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.0228879433274352 kilogram '_16 Sand, gravel and stone from quarry, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00207904847206591 kilogram '_17 Clay and soil from quarry, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00060530984899484 kilogram '_18 Minerals from mine n.e.c., EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00361537418724339 kilogram '_19 Meat and fish products, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00340399991753731 kilogram '_20 Dairy products, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00334408647468961 kilogram '_21 Fruits and vegetables, processed, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00309233023450662 kilogram '_22 Vegetable and animal oils and fats, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.0217361611582999 kilogram '_23 Flour, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.0065182368026394 kilogram '_24 Sugar, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.0221204289840347 kilogram '_25 Animal feeds, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00515674079061915 kilogram '_26 Food preparations n.e.c., EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00310685087703497 kilogram '_27 Beverages, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000112017614607695 kilogram '_28 Tobacco products, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000489265065008809 kilogram '_29 Textiles, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000101866955232465 kilogram '_30 Wearing apparel and furs, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 1.10116042216625e-05 kilogram '_31 Leather products, footwear, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00207807345614748 kilogram '_32 Wood products, except furniture, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000925316151703102 kilogram '_33 Pulp, virgin, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.0025327900718264 kilogram '_34 Recycling of waste paper, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00171606212024567 kilogram '_35 Paper and paper products, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000643233545764989 kilogram '_36 Printed matter and recorded media, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00356121240071821 kilogram '_37 Refined petroleum products and fuels, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000688785857709917 kilogram '_39 Fertiliser, N, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000116890382998694 kilogram '_40 Fertiliser, other than N, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000143260739026398 kilogram '_41 Plastics basic, virgin, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000133946352666078 kilogram '_42 Recycling of plastics basic, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000943546371154792 kilogram '_43 Chemicals n.e.c., EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000476257235252233 kilogram '_44 Rubber and plastic products, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 6.46610730758635e-11 kilogram '_45 Glass, mineral wool and ceramic goods, virgin, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 1.6498300386153e-11 kilogram '_46 Recycling of glass, mineral wool and ceramic goods, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00363187690298339 kilogram '_47 Cement, virgin, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000519797479132006 kilogram '_48 Recycling of slags and ashes, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.011044567678326 kilogram '_49 Concrete, asphalt and other mineral products, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00304616911750754 kilogram '_50 Recycling of concrete, asphalt and other mineral products, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000773018401722375 kilogram '_51 Bricks, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 6.85215558755166e-05 kilogram '_53 Iron basic, virgin, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00353383749533586 kilogram '_54 Recycling of iron basic, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 2.79563214366334e-06 kilogram '_55 Aluminium basic, virgin, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000359856236112306 kilogram '_56 Recycling of aluminium basic, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 6.51009776790054e-07 kilogram '_57 Copper basic, virgin, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 5.66634893582582e-05 kilogram '_58 Recycling of copper basic, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 6.46610730758635e-11 kilogram '_59 Metals basic, n.e.c., virgin, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 1.12102564557464e-05 kilogram '_60 Recycling of metals basic, n.e.c., EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 1.80719648835974e-05 kilogram '_61 Iron, after first processing, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 6.46610730758635e-11 kilogram '_62 Aluminium, after first processing, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 1.04610215485697e-06 kilogram '_63 Copper, after first processing, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Exchange: 1.99352312248e-07 kilogram '_64 Metals n.e.c., after first processing, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000878156255959713 kilogram '_65 Fabricated metal products, except machinery, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.0025422744797404 kilogram '_66 Machinery and equipment n.e.c., EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 7.92566268323164e-05 kilogram '_67 Office machinery and computers, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000506766319522157 kilogram '_68 Electrical machinery n.e.c., EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000249617033192053 kilogram '_69 Radio, television and communication equipment, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 1.38102895469478e-05 kilogram '_70 Instruments, medical, precision, optical, clocks, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00072134591633804 EUR2003 '_71 Motor vehicles and trailers, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000257756091959064 EUR2003 '_72 Transport equipment n.e.c., EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00184203302244005 kilogram '_73 Furniture and other manufactured goods n.e.c., EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 1.56284935957275e-06 EUR2003 '_74 Recycling services, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.209575826298948 kilowatt hour '_75 Electricity, steam and hot water, EU27' (kilowatt hour, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.0104236812264823 kilogram '_76 Gas, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00193907254937114 EUR2003 '_77 Water, fresh, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.0116961592696434 EUR2003 '_78 Buildings, residential, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.009118595840312 EUR2003 '_79 Buildings, non-residential, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00117689585188079 EUR2003 '_80 Infrastructure, excluding buildings, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00712901034666923 EUR2003 '_81 Trade and repair of motor vehicles and service stations, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.0434489806545475 EUR2003 '_82 Wholesale trade, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.0167476433030551 EUR2003 '_83 Retail trade and repair services, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.0185913240533225 EUR2003 '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00701361332786307 EUR2003 '_85 Land transport and transport via pipelines, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000280563078089906 EUR2003 '_86 Transport by ship, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00158426396755363 EUR2003 '_87 Air transport, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00779528601869543 EUR2003 '_88 Cargo handling, harbours and travel agencies, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.0100071413532763 EUR2003 '_89 Post and telecommunication, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.015821513144067 EUR2003 '_90 Financial intermediation, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.0028197881566139 EUR2003 '_91 Insurance and pension funding, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00231953609489354 EUR2003 '_92 Services auxiliary to financial intermediation, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.0228848381389854 EUR2003 '_93 Real estate services, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00205276350396463 EUR2003 '_94 Renting of machinery and equipment etc., EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00592771812939773 EUR2003 '_95 Computer and related services, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000162310399158519 EUR2003 '_96 Research and development, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.0429646227909624 EUR2003 '_97 Business services n.e.c., EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000887725212489733 EUR2003 '_98 Public service and security, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00116254885581418 EUR2003 '_99 Education services, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00121678886118897 EUR2003 '100 Health and social work, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00214913367350769 kilogram '101 Waste treatment, Incineration of waste, Food, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000365690343038318 kilogram '102 Waste treatment, Incineration of waste, Paper, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000137051211015417 kilogram '103 Waste treatment, Incineration of waste, Plastic, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 5.78103005890188e-05 kilogram '104 Waste treatment, Incineration of waste, Metals, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000142251931714475 kilogram '105 Waste treatment, Incineration of waste, Glass' (kilogram, inert, EU27, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000222006304504917 kilogram '106 Waste treatment, Incineration of waste, Textiles, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00015498356140918 kilogram '107 Waste treatment, Incineration of waste, Wood, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 3.02129453942371e-06 kilogram '108 Waste treatment, Incineration of waste, Oil' (kilogram, Hazardous waste, EU27, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000397898298572675 kilogram '109 Waste treatment, Biogasification of food waste, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000279375401125495 kilogram '112 Waste treatment, Composting of food waste, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000330449799516185 kilogram '113 Waste treatment, Composting of paper and wood, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00226326319467684 kilogram '114 Waste treatment, Waste water treatment, food, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00218172330041619 kilogram '116 Waste treatment, Landfill of waste, Food, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000365690343038318 kilogram '117 Waste treatment, Landfill of waste, Paper, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000605508057906123 kilogram '118 Waste treatment, Landfill of waste, Plastic, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000435855848251955 kilogram '119 Waste treatment, Landfill of waste, Iron, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Exchange: 4.48088002762443e-05 kilogram '120 Waste treatment, Landfill of waste, Alu, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 3.55198728883054e-05 kilogram '121 Waste treatment, Landfill of waste, Copper, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000154546646701235 kilogram '122 Waste treatment, Landfill of waste, Metals nec, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000433116094487355 kilogram '123 Waste treatment, Landfill of waste, Glass' (kilogram, inert, EU27, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 2.70985064397632e-05 kilogram '124 Waste treatment, Landfill of waste, Mine waste, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000222006304504917 kilogram '125 Waste treatment, Landfill of waste, Textiles, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000838970322784815 kilogram '126 Waste treatment, Landfill of waste, Wood, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 3.02129453942371e-06 kilogram '127 Waste treatment, Landfill of waste, Oil' (kilogram, Hazardous waste, EU27, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000104160761217423 kilogram '128 Waste treatment, Landfill of waste, Slag' (kilogram, ash, EU27, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00128166139805254 EUR2003 '130 Membership organisations, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00156014631849529 EUR2003 '131 Recreational and cultural services, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00414240061169097 EUR2003 '132 Services n.e.c., EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 1.02180131386455e-07 kilogram 'Ammonia' (kilogram, None, ('air',)) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.0319991201529406 kilogram 'Carbon dioxide, non-fossil' (kilogram, None, ('air',)) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.0416796913395681 kilogram 'Carbon dioxide, fossil' (kilogram, None, ('air',)) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 2.75923076798768e-05 kilogram 'Carbon monoxide, fossil' (kilogram, None, ('air',)) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 1.15558590986795e-06 kilogram 'Dinitrogen monoxide' (kilogram, None, ('air',)) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 1.27970729243991e-05 kilogram 'Methane, fossil' (kilogram, None, ('air',)) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 4.57286570371075e-05 kilogram 'Nitrogen oxides' (kilogram, None, ('air',)) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 1.6792409109883e-05 kilogram 'NMVOC, non-methane volatile organic compounds, unspecified origin' (kilogram, None, ('air',)) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 1.98736950745042e-05 kilogram 'Sulfur dioxide' (kilogram, None, ('air',)) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n"
+ ]
+ }
+ ],
+ "source": [
+ "for exc in random_act.exchanges():\n",
+ " print(exc)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "And if you want to get more information on one specific exchange of the chosen process, do:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 24,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "{'location': 'GLO',\n",
+ " 'unit': 'kilogram',\n",
+ " 'output': ('forwast', 'a090983fe0b9aa8877e2b4e72421ed58'),\n",
+ " 'amount': 0.000505289821522072,\n",
+ " 'input': ('forwast', '19a956028320b38ff43d08f4afffaed9'),\n",
+ " 'categories': (),\n",
+ " 'loc': 0.000505289821522072,\n",
+ " 'type': 'technosphere',\n",
+ " 'name': '__7 Forest products, EU27',\n",
+ " 'uncertainty type': 0}"
+ ]
+ },
+ "execution_count": 24,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "#change the numeral to check out the other exchanges (as from the list above)\n",
+ "[exc for exc in random_act.exchanges()][7].as_dict()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Sometimes it can also be helpful to have some activity characteristics at hand, for instance if you want to search a database using an activity's code or want to get an activity's name when only having its key..."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 25,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'a090983fe0b9aa8877e2b4e72421ed58'"
+ ]
+ },
+ "execution_count": 25,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "#getting an activity's code\n",
+ "random_act['code']"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 26,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])"
+ ]
+ },
+ "execution_count": 26,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "#getting an activity's name through its code\n",
+ "fw.get(random_act['code'])"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 27,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "('forwast', 'a090983fe0b9aa8877e2b4e72421ed58')"
+ ]
+ },
+ "execution_count": 27,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "#getting an activity's key\n",
+ "random_act.key"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 28,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])"
+ ]
+ },
+ "execution_count": 28,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "#getting an activity's name using its key\n",
+ "bw.get_activity(random_act.key)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ " \n",
+ "## 2.3 Importing a dataset from Excel\n",
+ "\n",
+ "In addition to the import of a standard background database and the manual database creation (see below), we can also import data from various file types, one of them being Excel. This works relatively smoothly, provided the Excel workbook is created correctly. In the following, we import a flawless dataset. However, if you are interested in tiny, tricky challenges regarding the Excel import, have a look [here](https://github.com/PoutineAndRosti/Brightway-Seminar-2017/blob/master/Day%201%20PM/Data%20IO.ipynb). The here used Excel file was adapted from this source, so that it works with our imported ecoinvent 3.5 database. Another way for importing an, now unknown, Excel file can be found [here](https://nbviewer.jupyter.org/urls/bitbucket.org/cmutel/brightway2/raw/default/notebooks/IO%20-%20importing%20an%20Excel%20file.ipynb). But here we'll stick to the first approach:"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "\n",
+ " Even though every example I can find online uses a .xlsx file, the sourcecode for ExcelImporter explicitly checks for a .xls filetype, so that needs to be used, but then you get a lot of other errors - currently trying to unpick this, but until then, skip the rest of this section.\n",
+ " "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 29,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "path = \"C:\\\\Users\\elin.barrett\\\\OneDrive - Unilever\\\\Sustainability\\\\Brightwayintro\\\\\""
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 31,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "ename": "XLRDError",
+ "evalue": "Excel xlsx file; not supported",
+ "output_type": "error",
+ "traceback": [
+ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
+ "\u001b[1;31mXLRDError\u001b[0m Traceback (most recent call last)",
+ "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mimp\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mbw\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mExcelImporter\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mpath\u001b[0m\u001b[1;33m+\u001b[0m\u001b[1;34m\"excel_importer_example.xlsx\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2\u001b[0m \u001b[0mimp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mapply_strategies\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[0mimp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmatch_database\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfields\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'name'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'unit'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'location'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[1;31m#imp.match_database(\"ecoinvent 3.5_cutoff_ecoSpold02\", fields=('name', 'unit', 'location'))\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[0mimp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstatistics\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
+ "\u001b[1;32mC:\\Users\\elin.barrett\\AppData\\Local\\Continuum\\anaconda3\\envs\\brightway-env\\lib\\site-packages\\bw2io\\importers\\excel.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, filepath)\u001b[0m\n\u001b[0;32m 105\u001b[0m ]\n\u001b[0;32m 106\u001b[0m \u001b[0mstart\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtime\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 107\u001b[1;33m \u001b[0mdata\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mextractor\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mextract\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfilepath\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 108\u001b[0m \u001b[0mdata\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0my\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0my\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mdata\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mvalid_first_cell\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0my\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 109\u001b[0m print(\"Extracted {} worksheets in {:.2f} seconds\".format(\n",
+ "\u001b[1;32mC:\\Users\\elin.barrett\\AppData\\Local\\Continuum\\anaconda3\\envs\\brightway-env\\lib\\site-packages\\bw2io\\extractors\\excel.py\u001b[0m in \u001b[0;36mextract\u001b[1;34m(cls, filepath)\u001b[0m\n\u001b[0;32m 11\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mextract\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcls\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfilepath\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 12\u001b[0m \u001b[1;32massert\u001b[0m \u001b[0mos\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpath\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mexists\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfilepath\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Can't file file at path {}\"\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfilepath\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 13\u001b[1;33m \u001b[0mwb\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mxlrd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mopen_workbook\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfilepath\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 14\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mname\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcls\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mextract_sheet\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mwb\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mname\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mwb\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msheet_names\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 15\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
+ "\u001b[1;32mC:\\Users\\elin.barrett\\AppData\\Local\\Continuum\\anaconda3\\envs\\brightway-env\\lib\\site-packages\\xlrd\\__init__.py\u001b[0m in \u001b[0;36mopen_workbook\u001b[1;34m(filename, logfile, verbosity, use_mmap, file_contents, encoding_override, formatting_info, on_demand, ragged_rows, ignore_workbook_corruption)\u001b[0m\n\u001b[0;32m 168\u001b[0m \u001b[1;31m# files that xlrd can parse don't start with the expected signature.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 169\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mfile_format\u001b[0m \u001b[1;32mand\u001b[0m \u001b[0mfile_format\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[1;34m'xls'\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 170\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mXLRDError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mFILE_FORMAT_DESCRIPTIONS\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mfile_format\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m+\u001b[0m\u001b[1;34m'; not supported'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 171\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 172\u001b[0m bk = open_workbook_xls(\n",
+ "\u001b[1;31mXLRDError\u001b[0m: Excel xlsx file; not supported"
+ ]
+ }
+ ],
+ "source": [
+ "imp = bw.ExcelImporter(path+\"excel_importer_example.xlsx\")\n",
+ "imp.apply_strategies()\n",
+ "imp.match_database(fields=('name', 'unit', 'location'))\n",
+ "#imp.match_database(\"ecoinvent 3.5_cutoff_ecoSpold02\", fields=('name', 'unit', 'location'))\n",
+ "imp.statistics()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "You can check whether the import went as expected by having a look at an Excel sheet, that includes our process data. The location of this file is given as output of the following command:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "imp.write_excel()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Seems like everything went fine :)\n",
+ "\n",
+ "If an exchange cannot be linked using the above applied strategies, because the respective input is listed multiple times in the database, you would have to link it manually. An example for such a case is `treatment of aluminium scrap, post-consumer, prepared for recycling, at refiner`, for which two ecoinvent (3.5 cutoff) entries exist."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Having imported the data, we also need to write it to a database to save it:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "imp.write_database()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "bw.databases"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "wbi = bw.Database(\"BW2 Excel water bottle import\")\n",
+ "for act in wbi:\n",
+ " print(act)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "wbp = [act for act in wbi][0]\n",
+ "for exc in wbp.exchanges():\n",
+ " print(exc)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "See whether the details of our biosphere exchange are correct:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "ex = [act for act in wbi if 'water bottle production' in act['name']][0]\n",
+ "[exc for exc in ex.exchanges() if 'Carbon dioxide' in str(exc)][0].as_dict()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Final check whether really everything worked - these commands will be explained later in detail:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "lca = bw.LCA(\n",
+ " {(\"BW2 Excel water bottle import\", \"WriteSomeCode_UUID_isFineButNotNecessary\"): 1}, \n",
+ " ('IPCC 2013', 'climate change', 'GWP 100a')\n",
+ ")\n",
+ "lca.lci()\n",
+ "lca.lcia()\n",
+ "lca.score"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Ok, enough with that. Let's delete this database (not the Excel file!) and the associated variables now:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "del databases[wbi.name]\n",
+ "#or:\n",
+ "#wbi.delete()\n",
+ "del wbi, wbp"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Alternatively, we can also deregister the database, which removes all metadata:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "bw.Database('BW2 Excel water bottle import').deregister()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "bw.databases"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "**Continue, or back to [table of contents](#section0)?**\n",
+ "***"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ " \n",
+ "# 3. Manual database creation\n",
+ "In addition, let's add a new database manually. There are two very similar ways of doing so, shown below. Mind that this database needs to be saved as well so that we can work with it."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 32,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "Writing activities to SQLite3 database:\n",
+ "0% [#] 100% | ETA: 00:00:00\n",
+ "Total time elapsed: 00:00:00\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Title: Writing activities to SQLite3 database:\n",
+ " Started: 03/09/2021 17:36:23\n",
+ " Finished: 03/09/2021 17:36:23\n",
+ " Total time elapsed: 00:00:00\n",
+ " CPU %: 100.80\n",
+ " Memory %: 0.55\n"
+ ]
+ },
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "Writing activities to SQLite3 database:\n",
+ "0% [##] 100% | ETA: 00:00:00\n",
+ "Total time elapsed: 00:00:00\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Title: Writing activities to SQLite3 database:\n",
+ " Started: 03/09/2021 17:36:24\n",
+ " Finished: 03/09/2021 17:36:24\n",
+ " Total time elapsed: 00:00:00\n",
+ " CPU %: 0.00\n",
+ " Memory %: 0.66\n"
+ ]
+ }
+ ],
+ "source": [
+ "#One way of manually creating a database:\n",
+ "db1 = bw.Database('3D')\n",
+ "db1.register()\n",
+ "db1.write({('3D', 'Printer'):{\n",
+ " 'name': 'Printer',\n",
+ " 'exchanges': [],\n",
+ " 'unit': 'unit',\n",
+ " 'location': 'somewhere',\n",
+ " 'categories': ('in the', 'universe')\n",
+ "}})\n",
+ "\n",
+ "\n",
+ "\n",
+ "#Another way of manually creating a database is to have the data in a separate dictionary and then write it into an instantiated database:\n",
+ "db2 = Database(\"example\")\n",
+ "example_data = {\n",
+ " (\"example\", \"A\"): {\n",
+ " \"name\": \"A\",\n",
+ " \"exchanges\": [{\n",
+ " \"amount\": 1.0,\n",
+ " \"input\": (\"example\", \"B\"),\n",
+ " \"type\": \"technosphere\"\n",
+ " }],\n",
+ " 'unit': 'kilogram',\n",
+ " 'location': 'here',\n",
+ " 'categories': (\"very\", \"interesting\")\n",
+ " },\n",
+ " (\"example\", \"B\"): {\n",
+ " \"name\": \"B\",\n",
+ " \"exchanges\": [],\n",
+ " 'unit': 'microgram',\n",
+ " 'location': 'there',\n",
+ " 'categories': ('quite', 'boring')\n",
+ " }\n",
+ " }\n",
+ "\n",
+ "db2.write(example_data)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Let's see if our databases actually exist:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 33,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "Databases dictionary with 4 object(s):\n",
+ "\t3D\n",
+ "\tbiosphere3\n",
+ "\texample\n",
+ "\tforwast"
+ ]
+ },
+ "execution_count": 33,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "bw.databases"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Well, seems like it. Now, let's have a look at a random activity in our second database:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 34,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'B' (microgram, there, ('quite', 'boring'))"
+ ]
+ },
+ "execution_count": 34,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "db2.random()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "If we want to get some information on the number of exchanges in each activity contained in the database, we type in:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 35,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "[('B' (microgram, there, ('quite', 'boring')), 0),\n",
+ " ('A' (kilogram, here, ('very', 'interesting')), 1)]"
+ ]
+ },
+ "execution_count": 35,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "num_exchanges = [(activity, len(activity.exchanges())) for activity in db2]\n",
+ "num_exchanges"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "We can also look for our activities, in this case all of them, by typing:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 36,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "['Printer' (unit, somewhere, ('in the', 'universe'))]"
+ ]
+ },
+ "execution_count": 36,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "db1.search(\"*\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "However, we don't want to use these databases in the following. Therefore, we simply delete them, just like we deleted the dataset imported from an Excel file above:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 37,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "del databases[db1.name]\n",
+ "del databases[db2.name]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 38,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "Databases dictionary with 2 object(s):\n",
+ "\tbiosphere3\n",
+ "\tforwast"
+ ]
+ },
+ "execution_count": 38,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "#make sure that the databases got deleted\n",
+ "bw.databases"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Okay, now that we have our background data (be it manually created or imported from an existing database), it's time to model our foreground system!"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "**Continue, or back to [table of contents](#section0)?**\n",
+ "***\n",
+ "\n",
+ "\n",
+ "I've worked through this up to here\n",
+ " "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ " \n",
+ "# 4. LCIA\n",
+ "\n",
+ "Before continuing with a simple product system example, the basics of the inventory caluclation shall be introduced. First, let's have a look at which LCIA methods we can access:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 39,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "[]"
+ ]
+ },
+ "execution_count": 39,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "list(bw.methods)\n",
+ "\n",
+ "#or use the built-in method\n",
+ "#bw.methods.list\n",
+ "\n",
+ "#or the following\n",
+ "#bw.methods.items()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Ok, we see that there are quite a few methods that we could use for our LCA. Can we get more details on them? Sure we can! Those details are stored as values (`bw.methods.values()`), with the method names being the keys (`bw.methods.keys()`):"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "for key in bw.methods:\n",
+ " print(key, ':', bw.methods[key])"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "To access the description of only one method, type:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "bw.methods.get(('CML 2001', 'acidification potential', 'average European'))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "As you can see, this is a nested dictionary. You can also access values within the nested one, for example:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "bw.methods.get(('ILCD 1.0.8 2016 midpoint', 'ecosystem quality', 'marine eutrophication')).get('unit')"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Now, let's select a set of LCIA methods to be applied in an inventory calculation, in this case the IPCC 2013 GWP100a (no LT)."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "CC_method = [m for m in bw.methods if 'IPCC 2013' in str(m) and 'climate change' in str(m) and 'GWP 100a' in str(m) and not 'no LT' in str(m)][0]\n",
+ "CC_method"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Let's define the functional unit/ reference flow; for now, this is only a random one, picked from our ecoinvent database:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# select a process to be defined as functional unit\n",
+ "process = eidb.random()\n",
+ "process"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "functional_unit = {process:1}"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Now we can calculate the inventory!"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "lca = LCA(functional_unit,CC_method)\n",
+ "\n",
+ "# alternatively, you can enter both functional unit and LCIA method directly into the LCA-command:\n",
+ "# myFirstLCA_quick = bw.LCA({process:1}, ('IPCC 2013', 'climate change', 'GWP 100a'))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "And here we perform the actual impact calculation! Mind that this does not yield an output."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "lca.lci()\n",
+ "lca.lcia()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "To see the actual impact as mid- or endpoint indicator (according to the impact assessment method used), we type in:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "lca.score"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "This result is given in the unit specified by the impact assessment method."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "You can also check which LCIA method was applied for a given result:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "lca.method"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "To see what else you can do with the lca-object, press tab in the next cell:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "lca."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "**Change the method**"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Now let's change the impact assessment method and experiment with two other methods, `redo_lci` and `redo_lcia`:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "agri_land_occ = [m for m in bw.methods if 'ReCiPe Midpoint (H)' in str(m) and 'agricultural land occupation' in str(m) and not 'w/o LT' in str(m) ][0]\n",
+ "lca.switch_method(agri_land_occ)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "We can recalculate our LCI, including a changed demand, i.e. a new functional unit:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "demand = {process:2}\n",
+ "lca.redo_lci(demand)\n",
+ "lca.score"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "The above command, however, has neither adopted the changed impact assessment method, nor has it recalculated the impacts. What's more, we don't see the change of the inventory reflected in our score - simply because it wasn't recalculated. Only the inventory as well as the demand and supply arrays got changed. To recalculate our inventory with our newly chosen impact assessment method (and, if you like, an adjusted demand), we need to type the following:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "demand2 = {process:3}\n",
+ "lca.redo_lcia(demand2)\n",
+ "lca.score"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "**Additional stuff**"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Ok, enough with adjustments and recalculations. Let's check out some matrices now:\n",
+ "\n",
+ "- the technosphere matrix:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "lca.technosphere_matrix"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "print(lca.technosphere_matrix)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "- the biosphere matrix:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "lca.biosphere_matrix"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "print(lca.biosphere_matrix)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "- the characterisation matrix:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "lca.characterization_matrix"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "print(lca.characterization_matrix)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "- the inventory:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "lca.inventory"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "print(lca.inventory)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "- the characterised inventory:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "lca.characterized_inventory"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "print(lca.characterized_inventory)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "+ and the demand as well as supply arrays:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "lca.demand_array #contains what we entered as final demand. Check that it only contains this demand by summing up the whole array"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "lca.demand_array.sum()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "lca.supply_array #equals the multiplication of our inverted transaction matrix by the final demand, i.e. (Ae-1)*y"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "**Continue, or back to [table of contents](#section0)?**\n",
+ "***"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ " \n",
+ "# 5. Foreground system\n",
+ "\n",
+ "For modeling a foreground system, a new database is created that is linked to ecoinvent via exchanges. Some steps need to be considered, exemplified below for two simple product systems."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ " \n",
+ "## 5.1 How to create a simple product system?"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Now we want to create the product system for a fictitious aluminium waste handling process, consisting of inputs from the treatment of aluminium scrap as well as markets for transports and compressed air. For creating a product system, we need to create foreground processes that we link to background processes. For the latter, we can search in the background database. When we don't know the exact name of an activity, we can first search for the parts of the name that we are sure about, e.g. low-voltage electricity:"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "**Setup of technosphere**"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#this search does not yield the complete list as we will see later\n",
+ "eidb.search('electricity, low voltage')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#this search, however, does yield the complete list\n",
+ "for act in [act for act in eidb if 'electricity, low voltage' in act['name']]:\n",
+ " print(act)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "From this list, we can select the target activity through a more narrow description including indexing."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "process = [act for act in eidb if 'electricity, low voltage' in act['name'] and 'CA-ON' in act['location']][0]\n",
+ "process"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Have a closer look at the description of the target activity."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "process.as_dict()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Side note: You can also find the name of an activity by its code:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "eidb.get('cfd25c57d2a355b94813229866ae9f5d')"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Now, let's create and save a new activity for which we design the product system."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "waste_handling = eidb.new_activity(code = 'test1', name = \"Waste handling\", unit = \"unit\")\n",
+ "waste_handling.save()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "**Include parameters**"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Adding some parameters on the project level works like the following. Mind that there are also parameters on the activity and database level. The commands for handling and saving those are quite similar; for more details, look [here](https://docs.brightwaylca.org/technical/bw2data.html#parameters)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "project_data = [{\n",
+ " 'name': 'M',\n",
+ " 'amount': 0.06,\n",
+ "}, {\n",
+ " 'name': 'D',\n",
+ " 'amount': 200\n",
+ "}]\n",
+ "\n",
+ "parameters.new_project_parameters(project_data)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# have a look at existing project parameters\n",
+ "for param in ProjectParameter.select():\n",
+ " print(param, param.amount)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Let's make use of the entered parameters by parametrising the input amounts!"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "aluminium = [act for act in eidb if act['name']=='treatment of aluminium scrap, post-consumer, prepared for recycling, at refiner' and 'RER' in act['location']][0]\n",
+ "waste_handling.new_exchange(input=aluminium.key,amount=0,unit=\"kilogram\",type='technosphere', formula='M').save()\n",
+ "waste_handling.save()\n",
+ "\n",
+ "transport = [act for act in eidb if act['name']=='market for transport, freight, lorry 3.5-7.5 metric ton, EURO5' and 'RoW' in act['location']][0]\n",
+ "waste_handling.new_exchange(input=transport.key,amount=0,unit=\"ton kilometer\",type='technosphere', formula='D*M/1000').save()\n",
+ "waste_handling.save()\n",
+ "\n",
+ "air = [act for act in eidb if act['name']=='market for compressed air, 600 kPa gauge' and 'GLO' in act['location']][0]\n",
+ "waste_handling.new_exchange(input=air.key,amount=0,unit=\"cubic meter\",type='technosphere', formula='D*M/1000').save()\n",
+ "waste_handling.save()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Before the parameters become valid, we also need to save them by adding them to a group. Then we need to recalculate the exchanges based on the parameters."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "parameters.add_exchanges_to_group(\"again another group\", waste_handling)\n",
+ "ActivityParameter.recalculate_exchanges(\"again another group\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Now we can have a look at the inputs to our waste handling activity. There are two ways:\n",
+ "\n",
+ "- one that quantifies the input:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#Have a look at all exchanges of the selected activity\n",
+ "for exc in waste_handling.exchanges():\n",
+ " print(exc)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "- and one that does not:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "for act in waste_handling.technosphere():\n",
+ " print(act.input)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Moreover, we can check on some details of our new activity:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#get general information on the new activity\n",
+ "act = eidb.get('test1')\n",
+ "act"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#or like that\n",
+ "eidb.search('waste handling')"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "**Delete parameters and activities**"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#delete a set of parameters; does not delete the parameter from the project parameters list?!?\n",
+ "name = ['M']\n",
+ "for name in ProjectParameter.select():\n",
+ " name.delete()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#should delete the parameters but doesn't?!?\n",
+ "ProjectParameter.delete()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#remove the respective exchanges from the group; does not yet change anything about the exchanges?!?\n",
+ "parameters.remove_exchanges_from_group(\"again another group\", waste_handling)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#should remove parameters, but does not really work\n",
+ "parameters.remove_from_group(\"again another group\", waste_handling)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#Delete the list of project data (or any other dictionary); does not affect the parametrised exchanges until they get recalculated\n",
+ "project_data.clear() #.remove would only clear the content but leave empty instances\n",
+ "#quick check to see that it got deleted\n",
+ "for data in project_data:\n",
+ " print(data)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#delete the table of existing project parameters, i.e. actually deletes the project parameters\n",
+ "ProjectParameter.drop_table(safe=True, drop_sequences=True)\n",
+ "#create a new empty table of project parameters\n",
+ "ProjectParameter.create_table()\n",
+ "\n",
+ "for name in ProjectParameter.select():\n",
+ " name.print()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#delete all waste handling activities that were accidentally created\n",
+ "for activity in [act for act in eidb if act['name']=='Waste handling' and 'GLO' in act['location']]:\n",
+ " activity.delete()\n",
+ "#delete individual bottle production activity\n",
+ "#waste_handling.delete"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "scrolled": false
+ },
+ "outputs": [],
+ "source": [
+ "#check that the activity actually got deleted\n",
+ "eidb.search('waste handling')"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Seems like it..."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ " \n",
+ "## 5.2 Bottle production\n",
+ "Okay, now that we know the basics for creating (and deleting) a simple product system, we will create another one, explore it, and perform an LCA on it. So, here's a first short example on a simplified plastic bottle production. This process only has three inputs: electricity, transport, and polyethylene."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "**Setup of the product system**"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "As mentioned earlier, the 'eidb.search' function does not give all the items that actually match the search criteria. We see this by comparing the following command with the one thereafter:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "scrolled": false
+ },
+ "outputs": [],
+ "source": [
+ "#incomplete search results\n",
+ "eidb.search('electricity production, photovoltaic, 3kWp slanted-roof installation,')#, filter={'location': 'CA-ON'})"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#complete search results\n",
+ "for act in [act for act in eidb if 'electricity production, photovoltaic, 3kWp slanted-roof installation,' in act['name']]:# and 'CA-ON' in act['location']]:\n",
+ " print(act)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#we can also sort our search results\n",
+ "list_to_be_sorted = [act for act in eidb if 'electricity production, photovoltaic, 3kWp slanted-roof installation,' in act['name']] # and 'CA-ON' in act['location']]:\n",
+ "newlist = sorted(list_to_be_sorted, key=lambda k: k['name'])\n",
+ "\n",
+ "#for multiple keys, its works like this:\n",
+ "#newlist = sorted(list_to_be_sorted, key = itemgetter('name','categories'))\n",
+ "#or\n",
+ "#newlist = sorted(list_to_be_sorted, key=lambda k: (k['name'],k['categories']))\n",
+ "\n",
+ "newlist"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#now let's refine the search and pick one activity\n",
+ "[act for act in eidb if 'electricity production, photovoltaic, 3kWp slanted-roof installation,' in act['name'] and 'CA-ON' in act['location']][0]"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "mind:\n",
+ " Activities do not have very many required fields; aside from database and code, the only other required field is name, but most activities will have a location and unit as well. If no type is specified for an activity, then the activity is assumed to be a process. Other types include product and biosphere for biosphere flows. Activity type is used to determine whether an activity should be placed in the biosphere or technosphere matrices during LCA calculations.\n",
+ "\n",
+ "\n",
+ "Let's now create our [parameterised product system](https://docs.brightwaylca.org/intro.html#parameterized-datasets):"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [],
+ "source": [
+ "#The following for-loop is only to guarantee that we can create a new bottle production process\n",
+ "for activity in [act for act in eidb if 'Bottle production' in act['name'] and 'GLO' in act['location']]:\n",
+ " activity.delete()\n",
+ "\n",
+ "# activities and exchanges for simple bottle production model\n",
+ "bottle_production = eidb.new_activity(code = 'test1', name = \"Bottle production\", unit = \"unit\")\n",
+ "#bottle_production.save()\n",
+ "\n",
+ "project_data = [{\n",
+ " 'name': 'M',\n",
+ " 'amount': 0.06,\n",
+ "}, {\n",
+ " 'name': 'D',\n",
+ " 'amount': 200\n",
+ "}]\n",
+ "\n",
+ "parameters.new_project_parameters(project_data)\n",
+ "\n",
+ "for param in ProjectParameter.select():\n",
+ " print(param, param.amount)\n",
+ "\n",
+ "electricity = [act for act in eidb if act['name']=='electricity production, photovoltaic, 3kWp slanted-roof installation, multi-Si, panel, mounted, label-certified' and 'CH' in act['location']][0]\n",
+ "bottle_production.new_exchange(input=electricity.key,amount=0,unit=\"kilowatt hour\",type='technosphere', formula='20*M/3.6').save()\n",
+ "bottle_production.save()\n",
+ "\n",
+ "#mind how the following activity is treated differently! The reason for this will be shown later\n",
+ "polyethylene = [act for act in eidb if act['name']=='market for polyethylene, high density, granulate' and 'GLO' in act['location']][0]\n",
+ "pe = bottle_production.new_exchange(input=polyethylene.key,amount=0,unit=\"kilogram\",type='technosphere', formula='M')\n",
+ "pe.save()\n",
+ "bottle_production.save()\n",
+ "\n",
+ "transport = [act for act in eidb if act['name']=='market for transport, freight, lorry 3.5-7.5 metric ton, EURO5' and 'RER' in act['location']][0]\n",
+ "bottle_production.new_exchange(input=transport.key,amount=0,unit=\"ton kilometer\",type='technosphere', formula='D*M/1000').save()\n",
+ "bottle_production.save()\n",
+ "\n",
+ "parameters.add_exchanges_to_group(\"again another group\", bottle_production)\n",
+ "ActivityParameter.recalculate_exchanges(\"again another group\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "**Cross-check the exchanges**"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Let's check whether everything went ok when creating our exchanges:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [],
+ "source": [
+ "for exc in bottle_production.exchanges():\n",
+ " print(exc)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [],
+ "source": [
+ "bottle_production.as_dict()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#also this works:\n",
+ "for key in bottle_production:\n",
+ " print(key, ':', bottle_production[key])"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Ok, seems like everything is fine with the bottle production activity. But what about the inputs - can we check how they are actually linked? Sure! To see the **inputs** of, for instance, our polyethylene input, we type:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "for exc in polyethylene.exchanges():\n",
+ " print(exc)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "And to see the **outputs** of this activity, i.e. the upstream exchanges across the whole database, we type:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [],
+ "source": [
+ "for exc in polyethylene.upstream():\n",
+ " print(exc)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "... and yes, here it is. We can find our newly created exchange at the very bottom of the window!"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Alternatively, we can also look straight for the **output of a new exchange** (and some other methods of the exchange). For doing so, it is important to have given a name to the exchange that you now want to examine further (as done when creating the product system)."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "pe.input, pe.output, pe.amount, pe.unit, pe.uncertainty_type"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Mind that the **amount equals to zero** here. This might possibly be due to the fact that this amount is parametrised but was set to zero initially (or because of the parameter level, i.e. project in this case)."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "**Troubleshooting**\n",
+ "\n",
+ "In case something went wrong during the setup of the product system, make sure to remove all parameters and the saved activities (as shown below) and rerun the window for creating the product system."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#Delete the list of project data (or any other dictionary); does not affect the parametrised exchanges until they get recalculated\n",
+ "project_data.clear() #.remove would only clear the content but leave empty instances\n",
+ "#quick check to see that it got deleted\n",
+ "for data in project_data:\n",
+ " print(data)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#delete the table of existing project parameters, i.e. actually deletes the project parameters\n",
+ "ProjectParameter.drop_table(safe=True, drop_sequences=True)\n",
+ "#create a new empty table of project parameters\n",
+ "ProjectParameter.create_table()\n",
+ "\n",
+ "for name in ProjectParameter.select():\n",
+ " name.print()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#delete all bottle production activities that were accidentally created\n",
+ "for activity in [act for act in eidb if act['name']=='Bottle production' and 'GLO' in act['location']]:\n",
+ " activity.delete()\n",
+ "#delete individual bottle production activity\n",
+ "#waste_handling.delete"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Now let's see whether really everthing got deleted:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [],
+ "source": [
+ "for exc in bottle_production.exchanges():\n",
+ " print(exc)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "**Definition of LCIA methods and functional unit**"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "method_key = [m for m in bw.methods if 'ReCiPe' in str(m) and 'Midpoint (H)' in str(m) and 'climate change' in str(m)][0]\n",
+ "\n",
+ "functional_unit = {bottle_production:1}"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "**LCA calculation**"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "lca = bw.LCA(functional_unit,method_key)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "lca.lci()\n",
+ "lca.lcia()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "lca.demand"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "lca.method"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "lca.score"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "**Elementary and product flows**\n",
+ "\n",
+ "There are a few ways to examine the elementary flows of our product system which are explained below. The same goes for product flows."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "eidb.filepath_processed()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "your_structured_array = np.load(eidb.filepath_processed())\n",
+ "pd.DataFrame(your_structured_array).head()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "pd.Series(bw.mapping).head()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "pd.DataFrame(lca.bio_params).head(6) "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "lca.activity_dict"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Getting the key from the \"demand\" attribute:\n",
+ "act_key = list(lca.demand)[0].key\n",
+ "# Getting the column number from the activity_dict:\n",
+ "col_index = lca.activity_dict[act_key]\n",
+ "print(\"The column index for activity {} is {}\".format(act_key, col_index))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#have the numbering, i.e. the value, in the beginning\n",
+ "myFirstLCA_rev_activity_dict = {value:key for key, value in lca.activity_dict.items()}\n",
+ "myFirstLCA_rev_activity_dict"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "lca_rev_act_dict, lca_rev_product_dict, lca_rev_bio_dict = lca.reverse_dict()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "As done earlier for another product system, let's check out the technosphere:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "lca.technosphere_matrix"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "print(lca.technosphere_matrix)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from bw2analyzer.matrix_grapher import SparseMatrixGrapher"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "SparseMatrixGrapher(lca.biosphere_matrix).graph()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "lca.technosphere_matrix"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "SparseMatrixGrapher(lca.technosphere_matrix).ordered_graph()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "If you're now wondering that this looks very similar to the result of the command `eidb.graph_technosphere()`, then you're right. The only difference is that our foreground system is now included."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Before being able to get deeper insights, we need to prepare a few variables, all based on the column index, which we get like that:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "print(\"As a reminder, the column index for {} is {}\".format(act_key, col_index))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "The column is given in *compressed sparse row* format. We can see that by doing as follows:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "myColumn = lca.technosphere_matrix[:, col_index]\n",
+ "myColumn"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "print(myColumn)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Now let's switch from the *compressed sparse row* format to the *coordinate* format. With that we can examine our columns a bit further :) And, interestingly, the print-outs of our columns look exactly the same."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "myColumnCOO = myColumn.tocoo()\n",
+ "myColumnCOO"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "The output is unchanged for that:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "print(myColumnCOO)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "myColumnCOO.row"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Let's have a look again at the identifiers of our foreground activities:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "[lca_rev_product_dict[i] for i in myColumnCOO.row]"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Through these identifiers we can also get the names of our activities:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "names_of_my_inputs = [bw.get_activity(lca_rev_product_dict[i])['name'] for i in myColumnCOO.row]\n",
+ "names_of_my_inputs"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "And those names can of course be linked to the actual amounts (which then looks much nicer in a table than above, only with the keys)."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# First create a dict with the information I want:\n",
+ "myColumnAsDict = dict(zip(names_of_my_inputs,myColumnCOO.data))\n",
+ "# Create Pandas Series from dict\n",
+ "pd.Series(myColumnAsDict, name=\"A series with information on exchanges in my foreground process\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "An alternative way to generate such a table is as follows, not depending on all the column-preparation..."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "pd.Series({bw.get_activity(exc.input)['name']:exc.amount for exc in bottle_production.technosphere()}, \n",
+ " name=\"alternative way to generate exchanges\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Which, to be honest, does not give more information than the command we already used a couple of times (the data is simply presented in a different way):"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "scrolled": false
+ },
+ "outputs": [],
+ "source": [
+ "for exc in bottle_production.exchanges():\n",
+ " print(exc)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "**Continue, or back to [table of contents](#section0)?**\n",
+ "***"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ " \n",
+ "# 6. Manipulating an exchange"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "In the following, we want to manipulate the electricity exchange. This we want to do by not only changing the amount, but by manipulating the underlying formula."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ " \n",
+ "## 6.1 Copying and deleting activities\n",
+ "\n",
+ "First, let's copy our bottle production product system!"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "bottle_production_copy = bottle_production.copy()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "To see whether it really got copied, let's have a look at the exchanges:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "for exc in bottle_production_copy.exchanges():\n",
+ " print(exc)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "bottle_production_copy.save()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Ok, seems like it worked."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "You can delete the entire technosphere of an activity like this:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "bottle_production_copy.technosphere().delete()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "If you even want to delete the activity itself, you can do it this way:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "bottle_production_copy.delete()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Check whether the activity is still in the database:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "bottle_production_copy in eidb"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "But now let's get our copy back and start working with it:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "bottle_production_copy = bottle_production.copy()\n",
+ "bottle_production_copy.save()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "bottle_production_copy.as_dict()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ " \n",
+ "## 6.2 First attempts at manipulating an exchange's keys/values\n",
+ "\n",
+ "First a short reminder what an exchange of our activity looks like. Let's for example take the first exchange, which is electricity. There are different ways of getting (almost) the same information:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "[exc for exc in bottle_production_copy.exchanges()][0]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "print([exc for exc in bottle_production_copy.exchanges()][0].items)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [],
+ "source": [
+ "[exc for exc in bottle_production_copy.exchanges()][0].as_dict()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "And quite obviously the output of this exchange is our bottle production..."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "[exc for exc in bottle_production_copy.exchanges()][0].output"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Let's have a look at the formula of our exchange of interest - there's again two ways of doing so:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "[exc for exc in bottle_production_copy.exchanges()][0]['formula']"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "print([exc for exc in bottle_production_copy.exchanges()][0].get('formula'))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Let's see if we can manipulate this formula or the exchange in general:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#add another key with value\n",
+ "[exc for exc in bottle_production_copy.exchanges()][0]['key']='value'"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "del [exc for exc in bottle_production_copy.exchanges()][0]['key']"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#change the formula and by that the amount of our exchange\n",
+ "#[exc for exc in bottle_production_copy.exchanges()][0].update({'formula': '40*M/3.6'})\n",
+ "list(exc for exc in bottle_production_copy.exchanges())[0].update({'formula': '40*M/3.6'})\n",
+ "[exc for exc in bottle_production_copy.exchanges()][0].save()\n",
+ "bottle_production_copy.save()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "[exc for exc in bottle_production_copy.exchanges()][0]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "list(exc for exc in bottle_production_copy.exchanges())[0]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "example = [exc for exc in bottle_production_copy.exchanges()][0]\n",
+ "print(example.update({'formula': '40*M/3.6'}))\n",
+ "example"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "example.update? #no the update command is used differently."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "bottle_production_copy.substitution? #no, the substitution command is used for something else."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "[exc for exc in bottle_production_copy.exchanges()][0].update"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#change the formula and by that the amount of our exchange\n",
+ "[exc for exc in bottle_production_copy.exchanges()][0]['formula']='40*M/3.6'"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#see if the formula in the respective exchange changed\n",
+ "[exc for exc in bottle_production_copy.exchanges()][0].as_dict()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Ok, so we see that nothing of this really works. Maybe we'll still find a solution for doing so. Actually we are super close, jsut a tiny part needs to be changed. But for now, let's try to substitute an exchange first."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ " \n",
+ "## 6.3 Substituting an exchange\n",
+ "\n",
+ "So, let's first delete our activity and then recreate it:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#delete individual bottle production activity\n",
+ "bottle_production_copy.delete()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#delete all bottle production activities that were accidentally created\n",
+ "for activity in [act for act in eidb if act['name']=='Bottle production copy' and 'GLO' in act['location']]:\n",
+ " activity.delete()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "bottle_production_copy = bottle_production.copy(code='test2', name=\"Bottle production copy\")\n",
+ "bottle_production_copy.save()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Check whether the copy was actually created and saved:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "eidb.search('Bottle production')#, filter={'code': 'test2'})"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Let's have a look at the exchanges of our production system:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [],
+ "source": [
+ "[exc for exc in bottle_production_copy.exchanges()]"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Once again, let's see the details of our exchange of interest, i.e. electricity:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [],
+ "source": [
+ "[exc for exc in bottle_production_copy.exchanges()][0].as_dict()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Reminder: We can also see all upstream exchanges of our activity of interest, i.e. electricity production:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "[exc for exc in electricity.upstream()]\n",
+ "\n",
+ "#same as:\n",
+ "#for exc in electricity.upstream():\n",
+ "# print(exc)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Now let's delete an exchange either from the upstream or the downstream perspective:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#downstream\n",
+ "[exc for exc in bottle_production_copy.exchanges()][0].delete()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#upstream\n",
+ "[exc for exc in electricity.upstream()][2].delete()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Now we add a new exchange as replacement for our deleted one. This action has to be validated by adding the exchange to the group so that the amount (calculated through a formula) is correct."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#this is our replacement for the original electricity input\n",
+ "el_subst = [act for act in eidb if act['name']=='electricity production, photovoltaic, 3kWp slanted-roof installation, multi-Si, panel, mounted, label-certified' and 'CH' in act['location']][0]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "bottle_production_copy.new_exchange(input=el_subst.key,amount=0,unit=\"kilowatt hour\",type='technosphere', formula='40*M/3.6').save()\n",
+ "bottle_production_copy.save()\n",
+ "\n",
+ "parameters.add_exchanges_to_group(\"again another group\", bottle_production_copy)\n",
+ "ActivityParameter.recalculate_exchanges(\"again another group\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Let's check our exchanges and whether we got what we wanted!"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "[exc for exc in bottle_production_copy.exchanges()]"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Yesss!!! Now, a more in-detail look at our exchange of interest (especially regarding the formula and the amount):"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [],
+ "source": [
+ "[exc for exc in bottle_production_copy.exchanges()][2].as_dict()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ " \n",
+ "## 6.4 Successfully manipulating an exchange"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Now let's finally manipulate a key,value pair of an exchange. There are two ways for doing so, depending on whether you want to assign a name to your exchange. **Alternative A** is the long version, **alternative B** the short one."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "+ **Alternative A**\n",
+ "\n",
+ "Here, we want to first add another exchange to our production system, assign a variable to it, and then change its amount through an adjustment of its formula."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#add another electricity source to our bottle production system\n",
+ "el_extra = [act for act in eidb if act['name']=='electricity production, photovoltaic, 3kWp slanted-roof installation, single-Si, panel, mounted, label-certified' and 'CH' in act['location']][0]\n",
+ "\n",
+ "el_ext = bottle_production_copy.new_exchange(input=el_extra.key,amount=0,unit=\"kilowatt hour\",type='technosphere', formula='10*M/3.6')\n",
+ "el_ext.save()\n",
+ "bottle_production.save()\n",
+ "\n",
+ "parameters.add_exchanges_to_group(\"again another group\", bottle_production_copy)\n",
+ "ActivityParameter.recalculate_exchanges(\"again another group\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#check our exchanges\n",
+ "[exc for exc in bottle_production_copy.exchanges()]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#have a look at the created exchange\n",
+ "el_ext.as_dict()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#let's change the amount of this exchange through an adjustment of the formula\n",
+ "\n",
+ "#btw: for getting a subset of the exchange-dictionary, you can type (to get the formula):\n",
+ "#wanted_key = ['formula']\n",
+ "#formula = dict((k, el_ext[k]) for k in wanted_key if k in el_ext)\n",
+ "\n",
+ "el_ext['formula']='20*M/3.6'\n",
+ "\n",
+ "el_ext.save()\n",
+ "bottle_production.save()\n",
+ "\n",
+ "parameters.add_exchanges_to_group(\"again another group\", bottle_production_copy)\n",
+ "ActivityParameter.recalculate_exchanges(\"again another group\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#check whether it worked and got adopted in the product system\n",
+ "[exc for exc in bottle_production_copy.exchanges()]"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Great! It worked."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "+ **Alternative B**\n",
+ "\n",
+ "A quicker way for changing the formula of an exchange is to do the following. This also allows to manipulate exchanges that have no name (as compared to `el_ext` in the above example); you just need to give an intermediate name to the respective exchange."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "el_exc=[exc for exc in bottle_production_copy.exchanges()][3]\n",
+ "el_exc['formula']='30*M/3.6'\n",
+ "el_exc\n",
+ "\n",
+ "el_exc.save()\n",
+ "bottle_production.save()\n",
+ "\n",
+ "parameters.add_exchanges_to_group(\"again another group\", bottle_production_copy)\n",
+ "ActivityParameter.recalculate_exchanges(\"again another group\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#let's see whether our change got adopted in the exchange-dictionary\n",
+ "[exc for exc in bottle_production_copy.exchanges()][3].as_dict()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#check whether it is also included in the product system\n",
+ "[exc for exc in bottle_production_copy.exchanges()]"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Yeah, awesome! Now we know how to do that."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "**Troubleshooting**\n",
+ "\n",
+ "If anything went wrong when copying or manipulating an activity, you can do the following things and restart - but if there's no error message anywhere, don't execute these following commands, because we will use our bottle production systems later again:"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "* Only delete a selected exchange (via two ways) - be sure to index correctly, otherwise you may have to reinstantiate your database:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "[exc for exc in bottle_production_copy.exchanges()][0].delete()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "[exc for exc in electricity.upstream()][2].delete()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "- Delete all exchanges that you copied accidentally:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "for act in [act for act in eidb if 'Bottle production copy' in act['name'] and 'GLO' in act['location']]:\n",
+ " act.delete()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "**Continue, or back to [table of contents](#section0)?**\n",
+ "***"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ " \n",
+ "# 7. Basic contribution analysis\n",
+ "\n",
+ "Based on the bottle production product system: Let's have a bit of a closer look at the inventory and the contributions of individual exchanges/activities!"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "But before that, we recalculate our inventory:"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ " \n",
+ "## 7.1 Recalculation of the inventory"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#these are our method and functional unit, same as above in section 5.\n",
+ "method_key = [m for m in bw.methods if 'ReCiPe' in str(m) and 'Midpoint (H)' in str(m) and 'climate change' in str(m)][0]\n",
+ "\n",
+ "functional_unit = {bottle_production:1}"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "lca = bw.LCA(functional_unit, method_key)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "lca.lci()\n",
+ "lca.lcia()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "lca.demand"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "lca.method"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "print(\"The {} process accounts for {:f} {}.\".format(\n",
+ " list(functional_unit.keys())[0]['name'],\n",
+ " lca.score,\n",
+ " bw.methods.get(method_key).get('unit')\n",
+ " ))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "And now over to the contribution analysis. Let's find the most damaging activities and biosphere flows."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ " \n",
+ "## 7.2 Basic contribution analysis"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import bw2analyzer as bwa"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "ca = bwa.ContributionAnalysis()\n",
+ "ca.annotated_top_processes(lca, limit=5) #returns a list of tuples: (lca score, supply amount, activity name)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "We can also set a limit below one, which will filter by fraction of impact instead of number of activities; we can also return activity keys instead of names."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#change \"False\" to \"True\" and this command will give a similar result as the following one, only that we set a limit here\n",
+ "ca.annotated_top_processes(lca, names=False, limit=0.001, limit_type='percent')"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Another way of listing the most contributing activities is this:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [],
+ "source": [
+ "lca.top_activities() #this command essentially relies on the annotated_top_process command from above. Hence, the output is given as (lca score, supply amount, activity name)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "And of course we can do the same for elementary flows:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "ca.annotated_top_emissions(lca, limit=0.02, limit_type='percent')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [],
+ "source": [
+ "#or like that\n",
+ "lca.top_emissions()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Notice that you can use the bw2analyzer.ContributionAnalysis method for analysing your results further, for instance through a Hinton matrix - see for yourself:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "ca.hinton_matrix(lca, rows=10, cols=10)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ " \n",
+ "## 7.3 Top emissions and processes by name"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "In addition to the basic contribution analysis, we can also look at individual activities (columns) or flows (rows).\n",
+ "\n",
+ "What if we want to group names together, i.e. to get the total impact for all \"phosphates\"? There isn't a built-in function for this, but it is relatively easy to do. Let's start with creating different lists:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from collections import defaultdict\n",
+ "\n",
+ "#get the keys for each biosphere flow of the same name\n",
+ "all_unique_names_and_their_keys = defaultdict(list)\n",
+ "\n",
+ "for flow in bw.Database(\"biosphere3\"):\n",
+ " if flow.key in lca.biosphere_dict:\n",
+ " all_unique_names_and_their_keys[flow['name']].append(flow.key)\n",
+ " \n",
+ "all_unique_names_and_their_keys"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#get the rows for all biosphere flows of the same name\n",
+ "all_unique_names_and_their_rows = {\n",
+ " name: [lca.biosphere_dict[key] for key in keys] \n",
+ " for name, keys in all_unique_names_and_their_keys.items()\n",
+ "}\n",
+ "\n",
+ "all_unique_names_and_their_rows"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#get the scores for all biosphere flows of the same name\n",
+ "all_unique_names_and_their_scores = {\n",
+ " name: [lca.characterized_inventory[row, :].sum() for row in rows]\n",
+ " for name, rows in all_unique_names_and_their_rows.items()\n",
+ "}\n",
+ "\n",
+ "all_unique_names_and_their_scores"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Now, let's sort this list by the score and only display the first 10 results."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#get the first 10 scores of the most contributing biosphere flows\n",
+ "sorted_scores = sorted(\n",
+ " [(sum(scores), name) for name, scores in all_unique_names_and_their_scores.items()], \n",
+ " reverse=True\n",
+ ")\n",
+ "\n",
+ "sorted_scores[:10]"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "We can also encapsulate all this functionality in a single function."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from collections import defaultdict\n",
+ "\n",
+ "def top_emissions_by_name(lca, biosphere_database='biosphere3'):\n",
+ " names = defaultdict(list)\n",
+ "\n",
+ " for flow in bw.Database(\"biosphere3\"):\n",
+ " if flow.key in lca.biosphere_dict:\n",
+ " names[flow['name']].append(\n",
+ " lca.characterized_inventory[lca.biosphere_dict[flow.key], :].sum()\n",
+ " )\n",
+ " \n",
+ " return sorted(\n",
+ " [(sum(scores), name) for name, scores in names.items()], \n",
+ " reverse=True\n",
+ " )"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "top_emissions_by_name(lca)[:5]"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "We can see that this function also groups emissions according to their type, e.g. all fossil carbon dioxide emissions are summed to \"Carbon dioxide, fossil\", as compared to the command in the top `ca.annotated_top_emissions`."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Possibly we can do the same for the technosphere flows with only slight adaptations to the above function:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from collections import defaultdict\n",
+ "\n",
+ "def top_processes_by_name(lca, technosphere_database='ecoinvent 3.5_cutoff_ecoSpold02'):\n",
+ " names = defaultdict(list)\n",
+ "\n",
+ " for flow in eidb:\n",
+ " if flow.key in lca.activity_dict:\n",
+ " names[flow['name']].append(\n",
+ " lca.characterized_inventory[:, lca.activity_dict[flow.key]].sum()\n",
+ " )\n",
+ " \n",
+ " return sorted(\n",
+ " [(sum(scores), name) for name, scores in names.items()], \n",
+ " reverse=True\n",
+ " )"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "top_processes_by_name(lca)[:5]"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Let's check whether both the top_processes_by_name and the top_emissions_by_name equal our lca.score:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "l = [t[0] for t in top_processes_by_name(lca)]\n",
+ "sum(l)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "l = [t[0] for t in top_emissions_by_name(lca)]\n",
+ "sum(l)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "lca.score"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Well, I guess we can say that is close enough, as these tiny deviations may be due to some rounding errors."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "**Continue, or back to [table of contents](#section0)?**\n",
+ "***"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ " \n",
+ "# 8. Multi-LCA\n",
+ "\n",
+ "To speed up comparative LCA, i.e. to compare multiple product alternatives (possibly across multiple impact categories), we can use the M-LCA functionality."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ " \n",
+ "## 8.1 Manually comparing products"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "The original code for such a comparative static LCA can be found [here](https://nbviewer.jupyter.org/github/PascalLesage/Shared-BW2-notebooks/blob/master/Comparative%20static%20LCA%20in%20Brightway2.ipynb). Here, we want to look at **bananas instead of dairy**. So let's see which activities we have in ecoinvent:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "bananas_unsorted = [act for act in eidb if 'banana' in act['name']]\n",
+ "bananas = sorted(bananas_unsorted, key=lambda k: k['name'])\n",
+ "bananas"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Of these activities, we now select the banana production processes for Colombia, Costa Rica, and India, and we select three impact methods on climate change, land use, and water stress."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "banana_CO = [act for act in eidb if 'banana' in act['name'] and 'CO' in act['location']][0]\n",
+ "banana_CR = [act for act in eidb if 'banana' in act['name'] and 'CR' in act['location']][0]\n",
+ "banana_IN = [act for act in eidb if 'banana' in act['name'] and 'IN' in act['location']][0]\n",
+ "\n",
+ "inventory = [banana_CO, banana_CR, banana_IN]\n",
+ "\n",
+ "methods = [[m for m in bw.methods if 'ReCiPe Midpoint (H)' in str(m) and 'climate change' in str(m)][0],\n",
+ " [m for m in bw.methods if 'ReCiPe Midpoint (H)' in str(m) and 'agricultural land occupation' in str(m) and not 'w/o LT' in str(m) ][0],\n",
+ " [m for m in bw.methods if 'ReCiPe Midpoint (H)' in str(m) and 'water depletion' in str(m) and not 'w/o LT' in str(m) and not 'V1.13' in str(m)][0]]\n",
+ "\n",
+ "print(\"Let's compare\\n{},\\n{}, and\\n{}\".format(banana_CO, banana_CR, banana_IN))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "results = []\n",
+ "\n",
+ "for banana in inventory:\n",
+ " lca = bw.LCA({banana:1})\n",
+ " lca.lci()\n",
+ " for method in methods:\n",
+ " lca.switch_method(method)\n",
+ " lca.lcia()\n",
+ " results.append((banana[\"name\"], banana[\"location\"], method[1].title(), lca.score, bw.methods.get(method).get('unit')))\n",
+ "results"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "We should probably present these results in a nicer form. Let's use `pandas` for that:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "results_df = pd.DataFrame(results, columns=[\"Name\", \"Location\", \"Method\", \"Score\", \"Unit\"])\n",
+ "results_df = pd.pivot_table(results_df, index = [\"Name\", \"Location\"], columns = [\"Method\", \"Unit\"], values = \"Score\")\n",
+ "results_df"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "df = pd.DataFrame.from_dict(results).T\n",
+ "df"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "We can also normalise these results, which may help to get a better overview:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "NormResults_df = results_df / results_df.max()\n",
+ "NormResults_df"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Sidenote: We can certainly run this kind of comparative LCA with our own product systems, e.g. the bottle production from above. We would just have to select the respective reference flow..."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ " \n",
+ "## 8.2 Calculation setups"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "A faster way of running comparative LCAs is through calculation setups. So, let's get familiar with them! This can be done best by just employing random activities as funcitonal units and selecting the LCIA methods which can be applied to the present biosphere flows (only a subset of these ones). Due to computation time, we decide to use the FORWAST database instead of ecoinvent - although this certainly works, too."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# define the functional units and LCIA methods; taken from example notebook\n",
+ "functional_units = [{fw.random(): 1} for _ in range(20)]\n",
+ "\n",
+ "import random\n",
+ "\n",
+ "all_forwast_flows = {exc.input for ds in fw for exc in ds.biosphere()}\n",
+ "suitable_methods = [method \n",
+ " for method in bw.methods \n",
+ " if {cf[0] for cf in Method(method).load()}.intersection(all_forwast_flows)]\n",
+ "\n",
+ "print(\"Can use {} of {} LCIA methods\".format(len(suitable_methods), len(bw.methods)))\n",
+ "chosen_methods = random.sample(suitable_methods, 8)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "functional_units"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "chosen_methods"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Now we come to the actual calculation setup which gets defined through our functional units and the chosen LCIA methods:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "my_calculation_setup = {'inv': functional_units, 'ia': chosen_methods}"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "calculation_setups['set of calculation setups'] = my_calculation_setup"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "mlca = MultiLCA('set of calculation setups')\n",
+ "mlca.results"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Hm, does not seem to be so difficult. Therefore, let's try it on a better chosen example."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ " \n",
+ "## 8.3 MLCA"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Let's decide on our LCIA method selection:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "[m for m in bw.methods if 'ReCiPe' in str(m) and 'Midpoint (H)' in str(m) and 'land' in str(m)][:3]"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Now a different way fo setting up our list of selected LCIA methods:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "land_methods = [m for m in bw.methods if 'ReCiPe' in str(m) and 'Midpoint (H)' in str(m) and 'land' in str(m)][:3]\n",
+ "methods = land_methods + [[m for m in bw.methods if 'ReCiPe' in str(m) and 'Midpoint (H)' in str(m) and 'climate change' in str(m)][0],\n",
+ " [m for m in bw.methods if 'ReCiPe' in str(m) and 'Midpoint (H)' in str(m) and 'water depletion' in str(m)][0]]\n",
+ "print(methods)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "And now we calculate the results for one functional unit (our banana production from above) and multiple LCIA methods:"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "**One functional unit, multiple impact categories**"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "all_scores = {}\n",
+ "banana_lca = bw.LCA({banana_CO:1}, methods[0])\n",
+ "banana_lca.lci()\n",
+ "banana_lca.lcia()\n",
+ "for category in methods:\n",
+ " banana_lca.switch_method(category)\n",
+ " banana_lca.lcia()\n",
+ " all_scores[category] = {}\n",
+ " all_scores[category]['score'] = banana_lca.score\n",
+ " all_scores[category]['unit'] = bw.Method(category).metadata['unit']\n",
+ " print(\"The score is {:f} {} for impact category {}\".format(banana_lca.score, \n",
+ " bw.Method(category).metadata['unit'],\n",
+ " bw.Method(category).name)\n",
+ " )"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "We can certainly present these results also in a nice table:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "df = pd.DataFrame.from_dict(all_scores).T\n",
+ "df"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "And now let's visualise the results only for the scores that have the same unit, i.e. in this example agricultural and urban land occupation."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "%matplotlib inline\n",
+ "import matplotlib.pyplot as plt"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "df_m2 = df[df['unit']=='square meter-year']\n",
+ "df_m2"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "df_m2.plot(kind='barh')"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "And of course we can find the relative contributions for our selected functional unit, too:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "banana_lca_unitProcessContribution = banana_lca.characterized_inventory.sum(axis=0).A1\n",
+ "banana_lca_unitProcessRelativeContribution = banana_lca_unitProcessContribution/banana_lca.score\n",
+ "banana_lca_unitProcessRelativeContribution"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "And now we calculate the results for multiple functional units and multiple LCIA methods:"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "**Multiple functional units, multiple impact categories**"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#Set up the production system\n",
+ "prod_sys = [{banana_CO.key:1}, {banana_CR.key:1}, {banana_IN.key:1}]\n",
+ "prod_sys"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "bw.calculation_setups['multiLCA'] = {'inv': prod_sys, 'ia': methods}\n",
+ "bw.calculation_setups['multiLCA']\n",
+ "myMultiLCA = bw.MultiLCA('multiLCA')\n",
+ "myMultiLCA.results\n",
+ "\n",
+ "df_impact = pd.DataFrame(data = myMultiLCA.results, columns = methods)\n",
+ "df_impact"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Just in case we cannot remember for some reason our functional units, we can easily find their definition again:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "myMultiLCA.func_units"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "The same certainly goes for our chosen LCIA methods:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "myMultiLCA.methods"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "**Continue, or back to [table of contents](#section0)?**\n",
+ "***"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ " \n",
+ "# 9. Monte Carlo simulation\n",
+ "\n",
+ "According to British statistician George Cox \"all models are wrong but some are useful\" - in that light, quantifying uncertainty makes LCA results more reliable/robust. One of the easiest/ most common ways to do so is to perform a [Monte Carlo simulation](https://en.wikipedia.org/wiki/Monte_Carlo_method), a random sampling technique. Before elaborating on that, we need to understand how uncertainty information is stored in Brightway:"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Uncertainty information in Brightway"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Uncertainty is stored at the level of the exchanges - remember this! So, let's have a look at a random ecoinvent exchange:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "[exc for exc in eidb.random().exchanges()][0].as_dict()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "The *necessary* uncertainty information of an exchange is described in the following fields: \n",
+ " - **'uncertainty type'** : type of probability distribution function that the exchange follows. For example, the uncertainty type = 2 indicates a `lognormal` distribution. \n",
+ " - **'loc', 'scale', 'shape', 'minimum', 'maximum'**: parameters of the distribution function, which are respectively the location (mean $\\mu$, mode, offset, or median), scale (e.g. standard deviation $\\sigma$), and shape as well as minimum and maximum of the underlying distribution. Mind that different distribution functions require different parameters - not all parameters have to be defined for each distribution.\n",
+ "\n",
+ "Some *additional* uncertainty related information ('scale without pedigree', 'pedigree') are also there, but are not directly used in the calculation of the uncertainty. They are also specific to ecoinvent.\n",
+ "\n",
+ "Uncertainty in Brightway is dealt with using a Python package called `stats_arrays` (see [here](http://stats-arrays.readthedocs.io/en/latest/)), developed by Chris Mutel in the context of the development of Brightway but applicable to any stochastic model in Python. Have a look at it to see which probability distribution functions are available. And then, let's import this package!"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import stats_arrays"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Just to give a brief example of how the uncertainty information \"works\", let's have a look at the lognormal distribution. As a reminder: \n",
+ " - a random variable $X$ is a lognormal if its natural logarithm $ln(X)$ is normally distributed \n",
+ " - the natural logarithm of the *median* of the lognormal distribution is equal to the median (=mean) of the underlying distribution \n",
+ "\n",
+ "Taking the deterministic amount `amount` to be the median, we should have `loc` = `ln('amount')`. Let's do this for the first exchange of a random ecoinvent activity that has a lognormal distribution:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#run this cell again if the output is empty\n",
+ "e = [exc for exc in eidb.random().exchanges() if exc['uncertainty type'] == 2][0]\n",
+ "e.as_dict()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "e['loc'] == np.log(e['amount'])"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Basic Monte Carlo simulation"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "**One functional unit, one impact category**"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#MC simulation with 10 iterations for our banana production and the IPCC GWP100a method\n",
+ "mc = bw.MonteCarloLCA({banana_CO:1}, ('IPCC 2013', 'climate change', 'GWP 100a'))\n",
+ "scores = [next(mc) for _ in range(10)]\n",
+ "scores\n",
+ "\n",
+ "#or this way:\n",
+ "#for _ in range(10):\n",
+ "# print(next(mc))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Let's print the results of our MC:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import matplotlib.pyplot as plt"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "scrolled": false
+ },
+ "outputs": [],
+ "source": [
+ "plt.hist(scores,bins=40)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Well, this doesn't really look like anything yet. We should increase the number of iterations - which yields more robust results. Around 10,000 iterations is a good starting point. However, this takes a while, so we will just give it a try with 1000 now. See for yourself how long it would take for a higher number of iterations."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#define the number of iterations\n",
+ "n_runs = 1000"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "%%time\n",
+ "values = [next(mc) for _ in range(n_runs)]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "plt.hist(values, bins=40)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "We can also **run the MCs in parallel** which speeds up the computation time - see the following and compare the calculation times!"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# We can also create parallel Monte Carlo that will run simultations on multiple workers simultaneoulsy\n",
+ "bw.ParallelMonteCarlo?"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "pmc = bw.ParallelMonteCarlo(mc.demand, mc.method, iterations=n_runs)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "%%time\n",
+ "values = pmc.calculate()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "plt.hist(values, bins=40)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "**One functional unit, multiple impact categories**"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# define the function for MC simulation\n",
+ "def multiImpactMonteCarloLCA(functional_unit, list_methods, iterations):\n",
+ " # Step 1\n",
+ " MC_lca = bw.MonteCarloLCA(functional_unit)\n",
+ " MC_lca.lci()\n",
+ " # Step 2\n",
+ " C_matrices = {}\n",
+ " # Step 3\n",
+ " for method in list_methods:\n",
+ " MC_lca.switch_method(method)\n",
+ " C_matrices[method] = MC_lca.characterization_matrix\n",
+ " # Step 4\n",
+ " results = np.empty((len(list_methods), iterations))\n",
+ " # Step 5\n",
+ " for iteration in range(iterations):\n",
+ " next(MC_lca)\n",
+ " for method_index, method in enumerate(list_methods):\n",
+ " results[method_index, iteration] = (C_matrices[method]*MC_lca.inventory).sum()\n",
+ " return results\n",
+ "\n",
+ "# define the LCIA methods, functional unit, and the number of iterations\n",
+ "ILCD = [method for method in bw.methods if \"ILCD\" in str(method) and \"no LT\" not in str(method)]\n",
+ "fu = {banana_CO:1}\n",
+ "iterations = 100\n",
+ "\n",
+ "# let it run!\n",
+ "test_results = multiImpactMonteCarloLCA(fu, ILCD, iterations)\n",
+ "test_results"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "ILCD"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#we can get the plots for all 34 ILCD methods (--> type: len(ILCD)) by changing the index in the brackets\n",
+ "plt.hist(test_results[33], bins=40)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "If you are interested in applying a **sensitivity analysis**, check out this [notebook](https://github.com/PoutineAndRosti/Brightway-Seminar-2017/blob/master/Day%202%20PM/Sensitivity%20analysis%20-%20example%20with%20PAWN%20indices.ipynb)."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "---\n",
+ "\n",
+ "At this point, it's worth pointing again at the **[Activity browser](https://github.com/LCA-ActivityBrowser/activity-browser)** and **[LCOPT](https://lcopt.readthedocs.io/en/latest/)**. These two Brightway2-extensions serve different purposes and require different settings, so check them out if you're curious.\n",
+ "\n",
+ "---"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "And now, last but not least, here's our reward for finishing this notebook :)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from IPython.display import Image\n",
+ "Image(url=\"https://cdn.shopify.com/s/files/1/1869/0319/products/ART-dabbing-unicorn_color-powder-blue_1024x1024.jpg?v=1523903512\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "**Back to [table of contents](#section0)?**\n",
+ "***"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.6.12"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git a/BW2_tutorial.ipynb b/BW2_tutorial.ipynb
index b91a036..b9bf7f7 100644
--- a/BW2_tutorial.ipynb
+++ b/BW2_tutorial.ipynb
@@ -16,10 +16,16 @@
"\n",
" \n",
"\n",
+ "**Update 08/03/2021 - Elin Barrett**\n",
+ "Changes to this notebook have been made to fix broken links and certificates.\n",
+ "\n",
+ " Notes by Elin are in this colour throughout.\n",
+ " \n",
+ "\n",
"---\n",
"\n",
"**Recommended prerequisites are:**\n",
- "* having installed [Brightway2](https://2.docs.brightwaylca.org/installation.html) + all relevant packages (make sure to do so in the correct virtual environment) and possibly even having had a first quick look at its [documentation](https://docs.brightwaylca.org/index.html). *Credits where credits are due:* much of the present notebook is based both directly and indirectly on this documentation (and the [example notebooks](https://docs.brightwaylca.org/notebooks.html#example-notebooks))\n",
+ "* having installed [Brightway2](https://2.docs.brightwaylca.org/installation.html) + all relevant packages (make sure to do so in the correct virtual environment) and possibly even having had a first quick look at its [documentation](https://2.docs.brightway.dev/index.html). *Credits where credits are due:* much of the present notebook is based both directly and indirectly on this documentation (and the [example notebooks](https://2.docs.brightway.dev/notebooks.html))\n",
"* knowledge of the foundations of life cycle assessment. If you don't have this knowledge (or simply need a refresher), have a look at the [online teaching resources](http://www.teaching.industrialecology.uni-freiburg.de/) provided by the Industrial Ecology Freiburg Group, led by Stefan Pauliuk\n",
"* familiarity with any programming language - no Python-specific requirements, as most methods are quite intuitive and will be explained anyway. In case you are a bloody beginner, check [this](https://github.com/PoutineAndRosti/Brightway-Seminar-2017/blob/master/Day%201%20AM/1%20-%20Python%20and%20notebook%20basics.ipynb) out :)\n",
"\n",
@@ -155,7 +161,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
@@ -177,18 +183,43 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 2,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "[Project: default, Project: StepByStep]"
+ ]
+ },
+ "execution_count": 2,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"list(bw.projects)"
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 3,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "Brightway2 projects manager with 2 objects:\n",
+ "\tStepByStep\n",
+ "\tdefault\n",
+ "Use `projects.report()` to get a report on all projects."
+ ]
+ },
+ "execution_count": 3,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"#same as above\n",
"bw.projects"
@@ -203,9 +234,20 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 4,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "[('StepByStep', 2, 0.026502669), ('default', 0, 8.2127e-05)]"
+ ]
+ },
+ "execution_count": 4,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"bw.projects.report()"
]
@@ -219,9 +261,20 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 5,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'C:\\\\Users\\\\elin.barrett\\\\AppData\\\\Local\\\\pylca\\\\Brightway3\\\\default.c21f969b5f03d33d43e04f8f136e7682'"
+ ]
+ },
+ "execution_count": 5,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"bw.projects.dir"
]
@@ -235,9 +288,20 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 6,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'C:\\\\Users\\\\elin.barrett\\\\AppData\\\\Local\\\\pylca\\\\Brightway3\\\\default.c21f969b5f03d33d43e04f8f136e7682\\\\my-new-directory'"
+ ]
+ },
+ "execution_count": 6,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"projects.request_directory(\"my-new-directory\")"
]
@@ -251,7 +315,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
@@ -268,9 +332,17 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 8,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Biosphere database already present!!! No setup is needed\n"
+ ]
+ }
+ ],
"source": [
"bw.projects.set_current(\"StepByStep\") #Creating/accessing the project\n",
"bw.bw2setup() #Importing elementary flows, LCIA methods and some other data"
@@ -278,9 +350,23 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 9,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "Brightway2 projects manager with 2 objects:\n",
+ "\tStepByStep\n",
+ "\tdefault\n",
+ "Use `projects.report()` to get a report on all projects."
+ ]
+ },
+ "execution_count": 9,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"#now we see that we have created our first project\n",
"bw.projects"
@@ -295,9 +381,20 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 10,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'C:\\\\Users\\\\elin.barrett\\\\AppData\\\\Local\\\\pylca\\\\Brightway3\\\\StepByStep.68d8c641ebe12c46d077d8ff720c3bbd'"
+ ]
+ },
+ "execution_count": 10,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"bw.projects.dir"
]
@@ -313,7 +410,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
@@ -322,27 +419,70 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 12,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'C:\\\\Users\\\\elin.barrett\\\\AppData\\\\Local\\\\Continuum\\\\anaconda3\\\\envs\\\\brightway-env\\\\python.exe'"
+ ]
+ },
+ "execution_count": 12,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"sys.executable"
]
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
+ "execution_count": 13,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "['',\n",
+ " 'C:\\\\Users\\\\elin.barrett\\\\AppData\\\\Local\\\\Continuum\\\\anaconda3\\\\envs\\\\my-rdkit-env\\\\Lib\\\\site-packages',\n",
+ " 'C:\\\\Users\\\\elin.barrett\\\\AppData\\\\Local\\\\Continuum\\\\anaconda3\\\\envs\\\\brightway-env\\\\python36.zip',\n",
+ " 'C:\\\\Users\\\\elin.barrett\\\\AppData\\\\Local\\\\Continuum\\\\anaconda3\\\\envs\\\\brightway-env\\\\DLLs',\n",
+ " 'C:\\\\Users\\\\elin.barrett\\\\AppData\\\\Local\\\\Continuum\\\\anaconda3\\\\envs\\\\brightway-env\\\\lib',\n",
+ " 'C:\\\\Users\\\\elin.barrett\\\\AppData\\\\Local\\\\Continuum\\\\anaconda3\\\\envs\\\\brightway-env',\n",
+ " 'C:\\\\Users\\\\elin.barrett\\\\AppData\\\\Local\\\\Continuum\\\\anaconda3\\\\envs\\\\brightway-env\\\\lib\\\\site-packages',\n",
+ " 'C:\\\\Users\\\\elin.barrett\\\\AppData\\\\Local\\\\Continuum\\\\anaconda3\\\\envs\\\\brightway-env\\\\lib\\\\site-packages\\\\pypardiso-0.2.2-py3.6.egg',\n",
+ " 'C:\\\\Users\\\\elin.barrett\\\\AppData\\\\Local\\\\Continuum\\\\anaconda3\\\\envs\\\\brightway-env\\\\lib\\\\site-packages\\\\win32',\n",
+ " 'C:\\\\Users\\\\elin.barrett\\\\AppData\\\\Local\\\\Continuum\\\\anaconda3\\\\envs\\\\brightway-env\\\\lib\\\\site-packages\\\\win32\\\\lib',\n",
+ " 'C:\\\\Users\\\\elin.barrett\\\\AppData\\\\Local\\\\Continuum\\\\anaconda3\\\\envs\\\\brightway-env\\\\lib\\\\site-packages\\\\Pythonwin',\n",
+ " 'C:\\\\Users\\\\elin.barrett\\\\AppData\\\\Local\\\\Continuum\\\\anaconda3\\\\envs\\\\brightway-env\\\\lib\\\\site-packages\\\\IPython\\\\extensions',\n",
+ " 'C:\\\\Users\\\\elin.barrett\\\\.ipython']"
+ ]
+ },
+ "execution_count": 13,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"sys.path"
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 14,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Available kernels:\n",
+ " python3 C:\\Users\\elin.barrett\\AppData\\Local\\Continuum\\anaconda3\\envs\\brightway-env\\share\\jupyter\\kernels\\python3\n"
+ ]
+ }
+ ],
"source": [
"!jupyter kernelspec list"
]
@@ -363,9 +503,150 @@
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
+ "execution_count": 15,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "application/json": {
+ "cell": {
+ "!": "OSMagics",
+ "HTML": "Other",
+ "SVG": "Other",
+ "bash": "Other",
+ "capture": "ExecutionMagics",
+ "cmd": "Other",
+ "debug": "ExecutionMagics",
+ "file": "Other",
+ "html": "DisplayMagics",
+ "javascript": "DisplayMagics",
+ "js": "DisplayMagics",
+ "latex": "DisplayMagics",
+ "perl": "Other",
+ "prun": "ExecutionMagics",
+ "pypy": "Other",
+ "python": "Other",
+ "python2": "Other",
+ "python3": "Other",
+ "ruby": "Other",
+ "script": "ScriptMagics",
+ "sh": "Other",
+ "svg": "DisplayMagics",
+ "sx": "OSMagics",
+ "system": "OSMagics",
+ "time": "ExecutionMagics",
+ "timeit": "ExecutionMagics",
+ "writefile": "OSMagics"
+ },
+ "line": {
+ "alias": "OSMagics",
+ "alias_magic": "BasicMagics",
+ "autocall": "AutoMagics",
+ "automagic": "AutoMagics",
+ "autosave": "KernelMagics",
+ "bookmark": "OSMagics",
+ "cd": "OSMagics",
+ "clear": "KernelMagics",
+ "cls": "KernelMagics",
+ "colors": "BasicMagics",
+ "config": "ConfigMagics",
+ "connect_info": "KernelMagics",
+ "copy": "Other",
+ "ddir": "Other",
+ "debug": "ExecutionMagics",
+ "dhist": "OSMagics",
+ "dirs": "OSMagics",
+ "doctest_mode": "BasicMagics",
+ "echo": "Other",
+ "ed": "Other",
+ "edit": "KernelMagics",
+ "env": "OSMagics",
+ "gui": "BasicMagics",
+ "hist": "Other",
+ "history": "HistoryMagics",
+ "killbgscripts": "ScriptMagics",
+ "ldir": "Other",
+ "less": "KernelMagics",
+ "load": "CodeMagics",
+ "load_ext": "ExtensionMagics",
+ "loadpy": "CodeMagics",
+ "logoff": "LoggingMagics",
+ "logon": "LoggingMagics",
+ "logstart": "LoggingMagics",
+ "logstate": "LoggingMagics",
+ "logstop": "LoggingMagics",
+ "ls": "Other",
+ "lsmagic": "BasicMagics",
+ "macro": "ExecutionMagics",
+ "magic": "BasicMagics",
+ "matplotlib": "PylabMagics",
+ "mkdir": "Other",
+ "more": "KernelMagics",
+ "notebook": "BasicMagics",
+ "page": "BasicMagics",
+ "pastebin": "CodeMagics",
+ "pdb": "ExecutionMagics",
+ "pdef": "NamespaceMagics",
+ "pdoc": "NamespaceMagics",
+ "pfile": "NamespaceMagics",
+ "pinfo": "NamespaceMagics",
+ "pinfo2": "NamespaceMagics",
+ "popd": "OSMagics",
+ "pprint": "BasicMagics",
+ "precision": "BasicMagics",
+ "profile": "BasicMagics",
+ "prun": "ExecutionMagics",
+ "psearch": "NamespaceMagics",
+ "psource": "NamespaceMagics",
+ "pushd": "OSMagics",
+ "pwd": "OSMagics",
+ "pycat": "OSMagics",
+ "pylab": "PylabMagics",
+ "qtconsole": "KernelMagics",
+ "quickref": "BasicMagics",
+ "recall": "HistoryMagics",
+ "rehashx": "OSMagics",
+ "reload_ext": "ExtensionMagics",
+ "ren": "Other",
+ "rep": "Other",
+ "rerun": "HistoryMagics",
+ "reset": "NamespaceMagics",
+ "reset_selective": "NamespaceMagics",
+ "rmdir": "Other",
+ "run": "ExecutionMagics",
+ "save": "CodeMagics",
+ "sc": "OSMagics",
+ "set_env": "OSMagics",
+ "store": "StoreMagics",
+ "sx": "OSMagics",
+ "system": "OSMagics",
+ "tb": "ExecutionMagics",
+ "time": "ExecutionMagics",
+ "timeit": "ExecutionMagics",
+ "unalias": "OSMagics",
+ "unload_ext": "ExtensionMagics",
+ "who": "NamespaceMagics",
+ "who_ls": "NamespaceMagics",
+ "whos": "NamespaceMagics",
+ "xdel": "NamespaceMagics",
+ "xmode": "BasicMagics"
+ }
+ },
+ "text/plain": [
+ "Available line magics:\n",
+ "%alias %alias_magic %autocall %automagic %autosave %bookmark %cd %clear %cls %colors %config %connect_info %copy %ddir %debug %dhist %dirs %doctest_mode %echo %ed %edit %env %gui %hist %history %killbgscripts %ldir %less %load %load_ext %loadpy %logoff %logon %logstart %logstate %logstop %ls %lsmagic %macro %magic %matplotlib %mkdir %more %notebook %page %pastebin %pdb %pdef %pdoc %pfile %pinfo %pinfo2 %popd %pprint %precision %profile %prun %psearch %psource %pushd %pwd %pycat %pylab %qtconsole %quickref %recall %rehashx %reload_ext %ren %rep %rerun %reset %reset_selective %rmdir %run %save %sc %set_env %store %sx %system %tb %time %timeit %unalias %unload_ext %who %who_ls %whos %xdel %xmode\n",
+ "\n",
+ "Available cell magics:\n",
+ "%%! %%HTML %%SVG %%bash %%capture %%cmd %%debug %%file %%html %%javascript %%js %%latex %%perl %%prun %%pypy %%python %%python2 %%python3 %%ruby %%script %%sh %%svg %%sx %%system %%time %%timeit %%writefile\n",
+ "\n",
+ "Automagic is ON, % prefix IS NOT needed for line magics."
+ ]
+ },
+ "execution_count": 15,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"lsmagic"
]
@@ -379,9 +660,20 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 16,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'C:\\\\Users\\\\elin.barrett\\\\OneDrive - Unilever\\\\Sustainability\\\\Brightwayintro'"
+ ]
+ },
+ "execution_count": 16,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"%pwd\n",
"#returns the path to the current folder\n",
@@ -391,15 +683,35 @@
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
+ "execution_count": 17,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The slowest run took 9.16 times longer than the fastest. This could mean that an intermediate result is being cached.\n",
+ "1000000 loops, best of 3: 338 ns per loop\n",
+ "Wall time: 0 ns\n"
+ ]
+ },
+ {
+ "data": {
+ "text/plain": [
+ "6.48074069840786"
+ ]
+ },
+ "execution_count": 17,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"import math\n",
"%timeit math.sqrt(42)\n",
"\n",
"#compare this with the time needed for the simple command:\n",
- "#%time math.sqrt(42)"
+ "%time math.sqrt(42)"
]
},
{
@@ -411,7 +723,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
@@ -427,7 +739,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
@@ -462,9 +774,22 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 18,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "Databases dictionary with 2 object(s):\n",
+ "\tbiosphere3\n",
+ "\tforwast"
+ ]
+ },
+ "execution_count": 18,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"#list the available databases\n",
"bw.databases"
@@ -479,9 +804,31 @@
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
+ "execution_count": 31,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "Writing activities to SQLite3 database:\n",
+ "0% [##############################] 100% | ETA: 00:00:00\n",
+ "Total time elapsed: 00:00:11\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Title: Writing activities to SQLite3 database:\n",
+ " Started: 03/08/2021 13:51:31\n",
+ " Finished: 03/08/2021 13:51:42\n",
+ " Total time elapsed: 00:00:11\n",
+ " CPU %: 56.40\n",
+ " Memory %: 3.00\n"
+ ]
+ }
+ ],
"source": [
"#FORWAST\n",
"import zipfile\n",
@@ -490,29 +837,37 @@
"if 'forwast' in bw.databases:\n",
" print(\"Database has already been imported.\")\n",
"else:\n",
- " filepath = download_file(\"forwast.bw2package.zip\", url=\"http://lca-net.com/wp-content/uploads/\")\n",
- " dirpath = os.path.dirname(filepath)\n",
- " zipfile.ZipFile(filepath).extractall(dirpath)\n",
- " BW2Package.import_file(os.path.join(dirpath, \"forwast.bw2package\"))"
+ " dirpath = \"C:\\\\Users\\elin.barrett\\\\OneDrive - Unilever\\\\Sustainability\\\\forwast.bw2package\"\n",
+ " BW2Package.import_file(os.path.join(dirpath, \"forwast.bw2package\"))\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "The automatic download of the forwast database gets an SSLError, so go to [this link](https://lca-net.com/wp-content/uploads/forwast.bw2package.zip) to download the zip file then point the notebook at it.\n",
+ "\n",
+ "Because ecoinvent is licensed and I don't know how the licenses work, I have skipped the rest of this section and the rest of the notebook uses forwast only.\n",
+ " "
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 33,
"metadata": {},
"outputs": [],
"source": [
"#ecoinvent\n",
- "if 'ecoinvent 3.5_cutoff_ecoSpold02' in bw.databases:\n",
- " print(\"Database has already been imported.\")\n",
- "else:\n",
+ "#if 'ecoinvent 3.5_cutoff_ecoSpold02' in bw.databases:\n",
+ "# print(\"Database has already been imported.\")\n",
+ "#else:\n",
" # mind that the ecoinvent file must be unzipped; then: path to the datasets subfolder\n",
- " fpei35cut = r\"C:\\Users\\Maximilian Koslowski\\Forschung\\Ecoinvent\\3.5\\ecoinvent 3.5_cutoff_ecoSpold02\\datasets\"\n",
+ "# fpei35cut = r\"C:\\Users\\Maximilian Koslowski\\Forschung\\Ecoinvent\\3.5\\ecoinvent 3.5_cutoff_ecoSpold02\\datasets\"\n",
" # the \"r\" makes sure that the path is read as a string - especially useful when you have spaces in your string\n",
- " ei35cut = bw.SingleOutputEcospold2Importer(fpei35cut, 'ecoinvent 3.5_cutoff_ecoSpold02')\n",
- " ei35cut\n",
- " ei35cut.apply_strategies()\n",
- " ei35cut.statistics()"
+ "# ei35cut = bw.SingleOutputEcospold2Importer(fpei35cut, 'ecoinvent 3.5_cutoff_ecoSpold02')\n",
+ "# ei35cut\n",
+ "# ei35cut.apply_strategies()\n",
+ "# ei35cut.statistics()"
]
},
{
@@ -585,9 +940,22 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 32,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "Databases dictionary with 2 object(s):\n",
+ "\tbiosphere3\n",
+ "\tforwast"
+ ]
+ },
+ "execution_count": 32,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"#list the available databases - again\n",
"bw.databases"
@@ -614,11 +982,11 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
- "eidb = bw.Database('ecoinvent 3.5_cutoff_ecoSpold02')\n",
+ "#eidb = bw.Database('ecoinvent 3.5_cutoff_ecoSpold02')\n",
"fw = bw.Database('forwast')"
]
},
@@ -631,11 +999,19 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 20,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The imported forwast database is of type and has a length of 277.\n"
+ ]
+ }
+ ],
"source": [
- "print(\"The imported ecoinvent database is of type {} and has a length of {}.\".format(type(eidb), len(eidb)))"
+ "print(\"The imported forwast database is of type {} and has a length of {}.\".format(type(fw), len(fw)))"
]
},
{
@@ -647,42 +1023,77 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 21,
"metadata": {
"scrolled": true
},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "image/png": "iVBORw0KGgoAAAANSUhEUgAAACIAAAAiCAYAAAA6RwvCAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAAEs0lEQVR4nO2We0yVdRjHP+/7ngPncBWTNC6hEiJmlHhLdKuluDGswUamTJ2aqCiVsyw2N5elzZkNK2dZM1NXMDVziW3RLKd5mUg4VC6hEtcjoJ4Dcu7nvL/+OCdIFkc71uIPvv+97/u7fJ7v8zzv7ycJIRgIkv9vgD81CNJXgyB9NWBANL4+xuwpEAAx5pt8Ur6fIOHiy/Bi3JIOJAmgdWvhnOgVRXGJQA0IcuSbjJbsjbFz3XH/BOS+HGnWD6UiPBYBZHa+SqirBYQAl3MYwMZ38+uyD6Rtl4SgS0hscUfVGw4pMw2HlNOGQ0rQvwaCLLMhIZ0KggmnneTuj8DeRcqdHZJ3xJoAh3aNQKZEHYbLJU9XBaVCkArsfGAQxdIFbrfnISiYdVMWcx1IpJZl1kWkcAIAEzyTWD+a8afjwQYjL0WrqvCsfdvFSw8McrhsFwHG5l4YfRDLJ66kBnAD3d5x+56NHyqA7J/T2bgtnyUlWdJ77kcodwXysYjSPjBICPDNlQMMv3EVVNX7MpT8yXnsHvI4mTPWAuAKUCicHkctoAI2kFShUEIkQpWl/tb/qyRfh17h4tfELHbgBhYmZGIcEe/pFql37Q/K9yNZxnAhbC2YzUyuMlA5/lE6kwqwRzqIaA7DGNsFEmLX/IZ+A/fpiCEijWPkogB7644Q3VINQr1rzLjuNp5UTxJiKQOtQtnkx5CsTgo+W87bm1ezam9OT9C+9vIJor3dze2wdI7wOlrg0+vfo7vZ1JsmID0ll2pgrmMzMyxvgdOMTSdxFRBInBtVDk7gHrcNnyDLypoIbDNxJzSVElahAMXVB4m8Ud9bwKHh5E/K4woyCTQw0bwNNDIl0+OokWBG/VRmHZwKXb5BfNaIYdxWYQeKxg7BGDMcXdevZLMJN7A6/gUaoxJA9sZiMbO5bD9TuUMlE7igfxNcgqwzjcQJT8Qjqtb1mx6fjhSnlaDBTU6NidAbHdjCUij1OrPz2neMbqnxOCMEBAWzftICqlBIpoJU6zuglfl2WgwGydNNfjuyoihOaGwKUW2R5BTNIdCpY/vssQDEOs4x27KFHx9OYm9cKgZ9RE83FZ/dSaTDjARUBmZyXr8YgK3bn/fPEXDi0jmwdprBKXAioP0WqCpNAU+zO/xr0tqr2XL5MPMazvbMmjdtFfOmLEcFRtpP3cOL+wBZL7XxEDY6kk0UZu9DxkXexXaUViOoKsGdv+AAhlqNNLllcNp75nZo9XwVMpJQbjHFVADWW/6DaBTIxYgeE/YkO4VZXyDjYEVVOyENbZjD0zhOFhpgQ/MpUjqueVpbCNAEsGfiizQAT1DDXPvL/oOUXVYEbsQrWNFgFObxdvH57ANCYGNRnYmg6wZawxZylJW4gU11xwgwd3l+et7aWzohlyt4jgtf8lms/emHjKXW5PqxOoDCmWNAUQB4rnMjo0QFq5+aT01YtHcHT31OMDZwdG2Rv8X69zq84DilKSexYCHv+G8EtHoK+KfgN1CB9y8WkfR75V1/4IoI3xc2f++sOWcyLrEv/SgyDpZcbiextgVEoDhPBhLwYWMpGbUnPCm6D9f9Ss1/oQFzix8E6atBkL4aMCB/AL6g3xzgDZpaAAAAAElFTkSuQmCC\n",
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {
+ "needs_background": "light"
+ },
+ "output_type": "display_data"
+ }
+ ],
"source": [
"fw.graph_technosphere()"
]
},
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {
- "scrolled": true
- },
- "outputs": [],
- "source": [
- "eidb.graph_technosphere()"
- ]
- },
{
"cell_type": "markdown",
"metadata": {},
"source": [
+ "I don't know how to make this not tiny, although because it's a figure you could download it as an image then look at it full-size that way if necessary I suppose.\n",
+ " \n",
+ "\n",
"Nice graphic! But it doesn't really tell us much... Let's have a bit of a closer look at what our database contains. We can, for instance, examine a random process of the imported ecoinvent database by doing the following:"
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 22,
"metadata": {
"scrolled": false
},
- "outputs": [],
- "source": [
- "random_act = eidb.random()\n",
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "{'products': [{'location': 'GLO',\n",
+ " 'unit': 'EUR2003',\n",
+ " 'output': ('forwast', 'a090983fe0b9aa8877e2b4e72421ed58'),\n",
+ " 'amount': 1.0,\n",
+ " 'input': ('forwast', 'a090983fe0b9aa8877e2b4e72421ed58'),\n",
+ " 'categories': (),\n",
+ " 'loc': 1.0,\n",
+ " 'type': 'production',\n",
+ " 'name': '_84 Hotels and restaurants, EU27',\n",
+ " 'uncertainty type': 0}],\n",
+ " 'categories': ['Input Output', 'EU27 2003'],\n",
+ " 'filename': '/Users/marie/Downloads/FORWAST-ecospold1/FORWAST-ecospold100167.XML',\n",
+ " 'type': 'process',\n",
+ " 'comment': 'Location: Unspecified\\nTechnology: Unspecified\\nTime period: Unspecified',\n",
+ " 'location': 'GLO',\n",
+ " 'unit': 'EUR2003',\n",
+ " 'code': 'a090983fe0b9aa8877e2b4e72421ed58',\n",
+ " 'production amount': 1.0,\n",
+ " 'name': '_84 Hotels and restaurants, EU27',\n",
+ " 'database': 'forwast'}"
+ ]
+ },
+ "execution_count": 22,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "random_act = fw.random()\n",
"random_act.as_dict()"
]
},
@@ -695,9 +1106,162 @@
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
+ "execution_count": 23,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Exchange: 1.0 EUR2003 '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000712307951627944 kilogram '__1 Bovine meat and milk, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000107332010096907 kilogram '__2 Pigs, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000226060301576555 kilogram '__3 Poultry and animals n.e.c., EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00579471935322287 kilogram '__4 Grain crops, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00635371819452267 kilogram '__5 Crops n.e.c., EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000886804639545545 EUR2003 '__6 Agricultural services n.e.c., EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000505289821522072 kilogram '__7 Forest products, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000432516875634936 kilogram '__9 Fish, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00179827091992188 kilogram '_10 Coal, lignite, peat, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 6.94377887373604e-06 kilogram '_12 Iron ores from mine, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 6.46610730758635e-09 kilogram '_13 Bauxite from mine, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 2.98059398221944e-08 kilogram '_14 Copper from mine, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 2.01184555188974e-05 kilogram '_15 Metals from mine n.e.c., EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.0228879433274352 kilogram '_16 Sand, gravel and stone from quarry, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00207904847206591 kilogram '_17 Clay and soil from quarry, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00060530984899484 kilogram '_18 Minerals from mine n.e.c., EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00361537418724339 kilogram '_19 Meat and fish products, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00340399991753731 kilogram '_20 Dairy products, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00334408647468961 kilogram '_21 Fruits and vegetables, processed, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00309233023450662 kilogram '_22 Vegetable and animal oils and fats, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.0217361611582999 kilogram '_23 Flour, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.0065182368026394 kilogram '_24 Sugar, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.0221204289840347 kilogram '_25 Animal feeds, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00515674079061915 kilogram '_26 Food preparations n.e.c., EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00310685087703497 kilogram '_27 Beverages, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000112017614607695 kilogram '_28 Tobacco products, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000489265065008809 kilogram '_29 Textiles, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000101866955232465 kilogram '_30 Wearing apparel and furs, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 1.10116042216625e-05 kilogram '_31 Leather products, footwear, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00207807345614748 kilogram '_32 Wood products, except furniture, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000925316151703102 kilogram '_33 Pulp, virgin, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.0025327900718264 kilogram '_34 Recycling of waste paper, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00171606212024567 kilogram '_35 Paper and paper products, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000643233545764989 kilogram '_36 Printed matter and recorded media, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00356121240071821 kilogram '_37 Refined petroleum products and fuels, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000688785857709917 kilogram '_39 Fertiliser, N, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000116890382998694 kilogram '_40 Fertiliser, other than N, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000143260739026398 kilogram '_41 Plastics basic, virgin, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000133946352666078 kilogram '_42 Recycling of plastics basic, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000943546371154792 kilogram '_43 Chemicals n.e.c., EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000476257235252233 kilogram '_44 Rubber and plastic products, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 6.46610730758635e-11 kilogram '_45 Glass, mineral wool and ceramic goods, virgin, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 1.6498300386153e-11 kilogram '_46 Recycling of glass, mineral wool and ceramic goods, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00363187690298339 kilogram '_47 Cement, virgin, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000519797479132006 kilogram '_48 Recycling of slags and ashes, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.011044567678326 kilogram '_49 Concrete, asphalt and other mineral products, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00304616911750754 kilogram '_50 Recycling of concrete, asphalt and other mineral products, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000773018401722375 kilogram '_51 Bricks, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 6.85215558755166e-05 kilogram '_53 Iron basic, virgin, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00353383749533586 kilogram '_54 Recycling of iron basic, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 2.79563214366334e-06 kilogram '_55 Aluminium basic, virgin, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000359856236112306 kilogram '_56 Recycling of aluminium basic, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 6.51009776790054e-07 kilogram '_57 Copper basic, virgin, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 5.66634893582582e-05 kilogram '_58 Recycling of copper basic, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 6.46610730758635e-11 kilogram '_59 Metals basic, n.e.c., virgin, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 1.12102564557464e-05 kilogram '_60 Recycling of metals basic, n.e.c., EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 1.80719648835974e-05 kilogram '_61 Iron, after first processing, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 6.46610730758635e-11 kilogram '_62 Aluminium, after first processing, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 1.04610215485697e-06 kilogram '_63 Copper, after first processing, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Exchange: 1.99352312248e-07 kilogram '_64 Metals n.e.c., after first processing, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000878156255959713 kilogram '_65 Fabricated metal products, except machinery, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.0025422744797404 kilogram '_66 Machinery and equipment n.e.c., EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 7.92566268323164e-05 kilogram '_67 Office machinery and computers, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000506766319522157 kilogram '_68 Electrical machinery n.e.c., EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000249617033192053 kilogram '_69 Radio, television and communication equipment, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 1.38102895469478e-05 kilogram '_70 Instruments, medical, precision, optical, clocks, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00072134591633804 EUR2003 '_71 Motor vehicles and trailers, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000257756091959064 EUR2003 '_72 Transport equipment n.e.c., EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00184203302244005 kilogram '_73 Furniture and other manufactured goods n.e.c., EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 1.56284935957275e-06 EUR2003 '_74 Recycling services, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.209575826298948 kilowatt hour '_75 Electricity, steam and hot water, EU27' (kilowatt hour, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.0104236812264823 kilogram '_76 Gas, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00193907254937114 EUR2003 '_77 Water, fresh, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.0116961592696434 EUR2003 '_78 Buildings, residential, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.009118595840312 EUR2003 '_79 Buildings, non-residential, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00117689585188079 EUR2003 '_80 Infrastructure, excluding buildings, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00712901034666923 EUR2003 '_81 Trade and repair of motor vehicles and service stations, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.0434489806545475 EUR2003 '_82 Wholesale trade, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.0167476433030551 EUR2003 '_83 Retail trade and repair services, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.0185913240533225 EUR2003 '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00701361332786307 EUR2003 '_85 Land transport and transport via pipelines, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000280563078089906 EUR2003 '_86 Transport by ship, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00158426396755363 EUR2003 '_87 Air transport, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00779528601869543 EUR2003 '_88 Cargo handling, harbours and travel agencies, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.0100071413532763 EUR2003 '_89 Post and telecommunication, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.015821513144067 EUR2003 '_90 Financial intermediation, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.0028197881566139 EUR2003 '_91 Insurance and pension funding, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00231953609489354 EUR2003 '_92 Services auxiliary to financial intermediation, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.0228848381389854 EUR2003 '_93 Real estate services, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00205276350396463 EUR2003 '_94 Renting of machinery and equipment etc., EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00592771812939773 EUR2003 '_95 Computer and related services, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000162310399158519 EUR2003 '_96 Research and development, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.0429646227909624 EUR2003 '_97 Business services n.e.c., EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000887725212489733 EUR2003 '_98 Public service and security, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00116254885581418 EUR2003 '_99 Education services, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00121678886118897 EUR2003 '100 Health and social work, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00214913367350769 kilogram '101 Waste treatment, Incineration of waste, Food, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000365690343038318 kilogram '102 Waste treatment, Incineration of waste, Paper, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000137051211015417 kilogram '103 Waste treatment, Incineration of waste, Plastic, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 5.78103005890188e-05 kilogram '104 Waste treatment, Incineration of waste, Metals, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000142251931714475 kilogram '105 Waste treatment, Incineration of waste, Glass' (kilogram, inert, EU27, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000222006304504917 kilogram '106 Waste treatment, Incineration of waste, Textiles, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00015498356140918 kilogram '107 Waste treatment, Incineration of waste, Wood, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 3.02129453942371e-06 kilogram '108 Waste treatment, Incineration of waste, Oil' (kilogram, Hazardous waste, EU27, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000397898298572675 kilogram '109 Waste treatment, Biogasification of food waste, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000279375401125495 kilogram '112 Waste treatment, Composting of food waste, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000330449799516185 kilogram '113 Waste treatment, Composting of paper and wood, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00226326319467684 kilogram '114 Waste treatment, Waste water treatment, food, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00218172330041619 kilogram '116 Waste treatment, Landfill of waste, Food, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000365690343038318 kilogram '117 Waste treatment, Landfill of waste, Paper, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000605508057906123 kilogram '118 Waste treatment, Landfill of waste, Plastic, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000435855848251955 kilogram '119 Waste treatment, Landfill of waste, Iron, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Exchange: 4.48088002762443e-05 kilogram '120 Waste treatment, Landfill of waste, Alu, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 3.55198728883054e-05 kilogram '121 Waste treatment, Landfill of waste, Copper, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000154546646701235 kilogram '122 Waste treatment, Landfill of waste, Metals nec, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000433116094487355 kilogram '123 Waste treatment, Landfill of waste, Glass' (kilogram, inert, EU27, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 2.70985064397632e-05 kilogram '124 Waste treatment, Landfill of waste, Mine waste, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000222006304504917 kilogram '125 Waste treatment, Landfill of waste, Textiles, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000838970322784815 kilogram '126 Waste treatment, Landfill of waste, Wood, EU27' (kilogram, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 3.02129453942371e-06 kilogram '127 Waste treatment, Landfill of waste, Oil' (kilogram, Hazardous waste, EU27, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.000104160761217423 kilogram '128 Waste treatment, Landfill of waste, Slag' (kilogram, ash, EU27, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00128166139805254 EUR2003 '130 Membership organisations, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00156014631849529 EUR2003 '131 Recreational and cultural services, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.00414240061169097 EUR2003 '132 Services n.e.c., EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003']) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 1.02180131386455e-07 kilogram 'Ammonia' (kilogram, None, ('air',)) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.0319991201529406 kilogram 'Carbon dioxide, non-fossil' (kilogram, None, ('air',)) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 0.0416796913395681 kilogram 'Carbon dioxide, fossil' (kilogram, None, ('air',)) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 2.75923076798768e-05 kilogram 'Carbon monoxide, fossil' (kilogram, None, ('air',)) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 1.15558590986795e-06 kilogram 'Dinitrogen monoxide' (kilogram, None, ('air',)) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 1.27970729243991e-05 kilogram 'Methane, fossil' (kilogram, None, ('air',)) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 4.57286570371075e-05 kilogram 'Nitrogen oxides' (kilogram, None, ('air',)) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 1.6792409109883e-05 kilogram 'NMVOC, non-methane volatile organic compounds, unspecified origin' (kilogram, None, ('air',)) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n",
+ "Exchange: 1.98736950745042e-05 kilogram 'Sulfur dioxide' (kilogram, None, ('air',)) to '_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])>\n"
+ ]
+ }
+ ],
"source": [
"for exc in random_act.exchanges():\n",
" print(exc)"
@@ -712,12 +1276,32 @@
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
+ "execution_count": 24,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "{'location': 'GLO',\n",
+ " 'unit': 'kilogram',\n",
+ " 'output': ('forwast', 'a090983fe0b9aa8877e2b4e72421ed58'),\n",
+ " 'amount': 0.000505289821522072,\n",
+ " 'input': ('forwast', '19a956028320b38ff43d08f4afffaed9'),\n",
+ " 'categories': (),\n",
+ " 'loc': 0.000505289821522072,\n",
+ " 'type': 'technosphere',\n",
+ " 'name': '__7 Forest products, EU27',\n",
+ " 'uncertainty type': 0}"
+ ]
+ },
+ "execution_count": 24,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"#change the numeral to check out the other exchanges (as from the list above)\n",
- "[exc for exc in random_act.exchanges()][0].as_dict()"
+ "[exc for exc in random_act.exchanges()][7].as_dict()"
]
},
{
@@ -729,9 +1313,20 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 25,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'a090983fe0b9aa8877e2b4e72421ed58'"
+ ]
+ },
+ "execution_count": 25,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"#getting an activity's code\n",
"random_act['code']"
@@ -739,19 +1334,41 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 26,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])"
+ ]
+ },
+ "execution_count": 26,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"#getting an activity's name through its code\n",
- "eidb.get(random_act['code'])"
+ "fw.get(random_act['code'])"
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 27,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "('forwast', 'a090983fe0b9aa8877e2b4e72421ed58')"
+ ]
+ },
+ "execution_count": 27,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"#getting an activity's key\n",
"random_act.key"
@@ -759,9 +1376,20 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 28,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'_84 Hotels and restaurants, EU27' (EUR2003, GLO, ['Input Output', 'EU27 2003'])"
+ ]
+ },
+ "execution_count": 28,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"#getting an activity's name using its key\n",
"bw.get_activity(random_act.key)"
@@ -777,18 +1405,51 @@
"In addition to the import of a standard background database and the manual database creation (see below), we can also import data from various file types, one of them being Excel. This works relatively smoothly, provided the Excel workbook is created correctly. In the following, we import a flawless dataset. However, if you are interested in tiny, tricky challenges regarding the Excel import, have a look [here](https://github.com/PoutineAndRosti/Brightway-Seminar-2017/blob/master/Day%201%20PM/Data%20IO.ipynb). The here used Excel file was adapted from this source, so that it works with our imported ecoinvent 3.5 database. Another way for importing an, now unknown, Excel file can be found [here](https://nbviewer.jupyter.org/urls/bitbucket.org/cmutel/brightway2/raw/default/notebooks/IO%20-%20importing%20an%20Excel%20file.ipynb). But here we'll stick to the first approach:"
]
},
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "\n",
+ " Even though every example I can find online uses a .xlsx file, the sourcecode for ExcelImporter explicitly checks for a .xls filetype, so that needs to be used, but then you get a lot of other errors - currently trying to unpick this, but until then, skip the rest of this section.\n",
+ " "
+ ]
+ },
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 29,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "path = \"C:\\\\Users\\elin.barrett\\\\OneDrive - Unilever\\\\Sustainability\\\\Brightwayintro\\\\\""
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 31,
"metadata": {
"scrolled": true
},
- "outputs": [],
- "source": [
- "imp = bw.ExcelImporter(os.path.join(\"excel_importer_example.xlsx\"))\n",
+ "outputs": [
+ {
+ "ename": "XLRDError",
+ "evalue": "Excel xlsx file; not supported",
+ "output_type": "error",
+ "traceback": [
+ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
+ "\u001b[1;31mXLRDError\u001b[0m Traceback (most recent call last)",
+ "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mimp\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mbw\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mExcelImporter\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mpath\u001b[0m\u001b[1;33m+\u001b[0m\u001b[1;34m\"excel_importer_example.xlsx\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2\u001b[0m \u001b[0mimp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mapply_strategies\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[0mimp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmatch_database\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfields\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'name'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'unit'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'location'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[1;31m#imp.match_database(\"ecoinvent 3.5_cutoff_ecoSpold02\", fields=('name', 'unit', 'location'))\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[0mimp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstatistics\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
+ "\u001b[1;32mC:\\Users\\elin.barrett\\AppData\\Local\\Continuum\\anaconda3\\envs\\brightway-env\\lib\\site-packages\\bw2io\\importers\\excel.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, filepath)\u001b[0m\n\u001b[0;32m 105\u001b[0m ]\n\u001b[0;32m 106\u001b[0m \u001b[0mstart\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtime\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 107\u001b[1;33m \u001b[0mdata\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mextractor\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mextract\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfilepath\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 108\u001b[0m \u001b[0mdata\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0my\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0my\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mdata\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mvalid_first_cell\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0my\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 109\u001b[0m print(\"Extracted {} worksheets in {:.2f} seconds\".format(\n",
+ "\u001b[1;32mC:\\Users\\elin.barrett\\AppData\\Local\\Continuum\\anaconda3\\envs\\brightway-env\\lib\\site-packages\\bw2io\\extractors\\excel.py\u001b[0m in \u001b[0;36mextract\u001b[1;34m(cls, filepath)\u001b[0m\n\u001b[0;32m 11\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mextract\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcls\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfilepath\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 12\u001b[0m \u001b[1;32massert\u001b[0m \u001b[0mos\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpath\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mexists\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfilepath\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Can't file file at path {}\"\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfilepath\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 13\u001b[1;33m \u001b[0mwb\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mxlrd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mopen_workbook\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfilepath\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 14\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mname\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcls\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mextract_sheet\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mwb\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mname\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mwb\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msheet_names\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 15\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
+ "\u001b[1;32mC:\\Users\\elin.barrett\\AppData\\Local\\Continuum\\anaconda3\\envs\\brightway-env\\lib\\site-packages\\xlrd\\__init__.py\u001b[0m in \u001b[0;36mopen_workbook\u001b[1;34m(filename, logfile, verbosity, use_mmap, file_contents, encoding_override, formatting_info, on_demand, ragged_rows, ignore_workbook_corruption)\u001b[0m\n\u001b[0;32m 168\u001b[0m \u001b[1;31m# files that xlrd can parse don't start with the expected signature.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 169\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mfile_format\u001b[0m \u001b[1;32mand\u001b[0m \u001b[0mfile_format\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[1;34m'xls'\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 170\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mXLRDError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mFILE_FORMAT_DESCRIPTIONS\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mfile_format\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m+\u001b[0m\u001b[1;34m'; not supported'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 171\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 172\u001b[0m bk = open_workbook_xls(\n",
+ "\u001b[1;31mXLRDError\u001b[0m: Excel xlsx file; not supported"
+ ]
+ }
+ ],
+ "source": [
+ "imp = bw.ExcelImporter(path+\"excel_importer_example.xlsx\")\n",
"imp.apply_strategies()\n",
"imp.match_database(fields=('name', 'unit', 'location'))\n",
- "imp.match_database(\"ecoinvent 3.5_cutoff_ecoSpold02\", fields=('name', 'unit', 'location'))\n",
+ "#imp.match_database(\"ecoinvent 3.5_cutoff_ecoSpold02\", fields=('name', 'unit', 'location'))\n",
"imp.statistics()"
]
},
@@ -966,9 +1627,52 @@
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
+ "execution_count": 32,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "Writing activities to SQLite3 database:\n",
+ "0% [#] 100% | ETA: 00:00:00\n",
+ "Total time elapsed: 00:00:00\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Title: Writing activities to SQLite3 database:\n",
+ " Started: 03/09/2021 17:36:23\n",
+ " Finished: 03/09/2021 17:36:23\n",
+ " Total time elapsed: 00:00:00\n",
+ " CPU %: 100.80\n",
+ " Memory %: 0.55\n"
+ ]
+ },
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "Writing activities to SQLite3 database:\n",
+ "0% [##] 100% | ETA: 00:00:00\n",
+ "Total time elapsed: 00:00:00\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Title: Writing activities to SQLite3 database:\n",
+ " Started: 03/09/2021 17:36:24\n",
+ " Finished: 03/09/2021 17:36:24\n",
+ " Total time elapsed: 00:00:00\n",
+ " CPU %: 0.00\n",
+ " Memory %: 0.66\n"
+ ]
+ }
+ ],
"source": [
"#One way of manually creating a database:\n",
"db1 = bw.Database('3D')\n",
@@ -1018,9 +1722,24 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 33,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "Databases dictionary with 4 object(s):\n",
+ "\t3D\n",
+ "\tbiosphere3\n",
+ "\texample\n",
+ "\tforwast"
+ ]
+ },
+ "execution_count": 33,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"bw.databases"
]
@@ -1034,9 +1753,20 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 34,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'B' (microgram, there, ('quite', 'boring'))"
+ ]
+ },
+ "execution_count": 34,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"db2.random()"
]
@@ -1050,9 +1780,21 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 35,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "[('B' (microgram, there, ('quite', 'boring')), 0),\n",
+ " ('A' (kilogram, here, ('very', 'interesting')), 1)]"
+ ]
+ },
+ "execution_count": 35,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"num_exchanges = [(activity, len(activity.exchanges())) for activity in db2]\n",
"num_exchanges"
@@ -1067,9 +1809,20 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 36,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "['Printer' (unit, somewhere, ('in the', 'universe'))]"
+ ]
+ },
+ "execution_count": 36,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"db1.search(\"*\")"
]
@@ -1083,7 +1836,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 37,
"metadata": {},
"outputs": [],
"source": [
@@ -1093,9 +1846,22 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 38,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "Databases dictionary with 2 object(s):\n",
+ "\tbiosphere3\n",
+ "\tforwast"
+ ]
+ },
+ "execution_count": 38,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"#make sure that the databases got deleted\n",
"bw.databases"
@@ -1113,7 +1879,11 @@
"metadata": {},
"source": [
"**Continue, or back to [table of contents](#section0)?**\n",
- "***"
+ "***\n",
+ "\n",
+ "\n",
+ "I've worked through this up to here\n",
+ " "
]
},
{
@@ -1128,9 +1898,20 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 39,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "[]"
+ ]
+ },
+ "execution_count": 39,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"list(bw.methods)\n",
"\n",
@@ -4645,7 +5426,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.6.8"
+ "version": "3.6.12"
}
},
"nbformat": 4,
diff --git a/excel_importer_example.xls b/excel_importer_example.xls
new file mode 100644
index 0000000..835ad60
Binary files /dev/null and b/excel_importer_example.xls differ
diff --git a/excel_importer_example_problems.xlsx b/excel_importer_example_problems.xlsx
new file mode 100644
index 0000000..a835c77
Binary files /dev/null and b/excel_importer_example_problems.xlsx differ