{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "# Class 4 - Hybrid LCA\n",
    "\n",
    "In this class, we will learn about supply use tables, and input output tables. We will also do a toy hybrid LCA.\n",
    "\n",
    "Before getting started, make sure you have upgrade the Brightway2 packages. You should have at least the following:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "BW2 data: (2, 0, 'dev5')\n",
      "BW2 calc: (1, 1, 'dev2')\n",
      "BW2 io: (0, 2, 'dev5')\n"
     ]
    }
   ],
   "source": [
    "import bw2data, bw2calc, bw2io\n",
    "print(\"BW2 data:\", bw2data.__version__)\n",
    "print(\"BW2 calc:\", bw2calc.__version__)\n",
    "print(\"BW2 io:\", bw2io.__version__)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now import the necessary libraries:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from brightway2 import *\n",
    "from bw2io.importers.exiobase import Exiobase22Importer\n",
    "import numpy as np\n",
    "import os\n",
    "import pyprind"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Create a new project for this class:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "if 'Class 4' not in projects:\n",
    "    projects.current = \"Class 1\"\n",
    "    projects.copy_project(\"Class 4\")\n",
    "\n",
    "projects.current = \"Class 4\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We will need the latest version of the data migrations to match EXIOBASE biosphere flows to ecoinvent biosphere flows:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "create_core_migrations()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "ERROR_MSG = \"\"\"Missing a data migration needed for this class. \n",
    "\n",
    "Please make sure you hvae the latest Brightway2 libraries, and reset the notebook.\"\"\"\n",
    "assert 'exiobase-biosphere' in migrations, ERROR_MSG"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Import EXIOBASE 2.2\n",
    "\n",
    "Now we need to download the industry by industry table from version 2.2 of exiobase. You can get it from the following link. Note that you will have to register an account if this is the first time you use this database: http://www.exiobase.eu/index.php/data-download/exiobase2-year-2007-full-data-set/78-mriot-ixi-fpa-coefficient-version2-2-2/file\n",
    "\n",
    "Extract the downloaded file, and adjust the following. Windows users might need something like:\n",
    "\n",
    "    fp = \"C:\\\\Users\\\\<your name>\\\\Downloads\\\\mrIOT_IxI_fpa_coefficient_version2.2.2\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "fp = \"/Users/cmutel/Downloads/mrIOT_IxI_fpa_coefficient_version2.2.2\"\n",
    "\n",
    "assert os.path.exists(fp), \"Please adjust your filepath, the provided one doesn't work\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can now import the exiobase database. This will take a while, so go ahead and get started.\n",
    "\n",
    "Why is this so slow compared to ecoinvent, for example? The answer lies in the density of the technosphere matrix. Exiobase, and IO tables in general, use comprehensive data from surveys and national customs, so they will get data on things that normal people would never even think of. For example, how much rice from Thailand is required to produce one euro of steel in Germany?\n",
    "\n",
    "In other words, the technosphere matrix is very dense. Ecoinvent is stored as a [sparse matrix](http://docs.scipy.org/doc/scipy/reference/sparse.html), where data is only provided in about 1.5% of all possible locations - every other value is zero, and these zeros are not stored, only implied. However, the IO table has a fill rate of about 50%, meaning that we store every value in the matrix. The technosphere in ecoinvent 2.2 is about 4000 by 4000, but we only need to store about 40.000 numbers. The technosphere matrix is exiobase is about 8000 by 8000, but we store around 35.000.000 numbers.\n",
    "\n",
    "We use a special backend for IO databases, as our standard storage mechanisms simply fall apart with such large data sets. You can see this [backend here](https://bitbucket.org/cmutel/brightway2-data/src/tip/bw2data/backends/iotable/__init__.py?at=2.0&fileviewer=file-view-default)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Creating database EXIOBASE 2.2\n",
      "Extracting metadata\n",
      "Extracting emissions\n",
      "Extracting resources\n",
      "Extracting main IO table\n",
      "Extracted 163 datasets and many exchanges in 1.41 seconds\n",
      "Aggregating `substances` and `extractions`\n",
      "Processing technosphere\n",
      "Processing exchanges"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Writing activities to SQLite3 database:\n",
      "0%                          100%\n",
      "[##############################] | ETA[sec]: 0.000 \n",
      "Total time elapsed: 1.234 sec\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Title: Writing activities to SQLite3 database:\n",
      "  Started: 11/04/2015 05:42:54\n",
      "  Finished: 11/04/2015 05:42:56\n",
      "  Total time elapsed: 1.234 sec\n",
      "  CPU %: 89.000000\n",
      "  Memory %: 1.973295\n",
      "Starting IO table write\n",
      "Writing geomapping\n",
      "Creating array - this will take a while...\n",
      "On exchange number 1000000\n",
      "On exchange number 2000000\n",
      "On exchange number 3000000\n",
      "On exchange number 4000000\n",
      "On exchange number 5000000\n",
      "On exchange number 6000000\n",
      "On exchange number 7000000\n",
      "On exchange number 8000000\n",
      "On exchange number 9000000\n",
      "On exchange number 10000000\n",
      "On exchange number 11000000\n",
      "On exchange number 12000000\n",
      "On exchange number 13000000\n",
      "On exchange number 14000000\n",
      "On exchange number 15000000\n",
      "On exchange number 16000000\n",
      "On exchange number 17000000\n",
      "On exchange number 18000000\n",
      "On exchange number 19000000\n",
      "On exchange number 20000000\n",
      "On exchange number 21000000\n",
      "On exchange number 22000000\n",
      "On exchange number 23000000\n",
      "On exchange number 24000000\n",
      "On exchange number 25000000\n",
      "On exchange number 26000000\n",
      "On exchange number 27000000\n",
      "On exchange number 28000000\n",
      "On exchange number 29000000\n",
      "On exchange number 30000000\n",
      "On exchange number 31000000\n",
      "On exchange number 32000000\n",
      "On exchange number 33000000\n",
      "On exchange number 34000000\n",
      "On exchange number 35000000\n",
      "Trimming array\n",
      "Writing array\n"
     ]
    }
   ],
   "source": [
    "ex = Exiobase22Importer(fp)\n",
    "ex.apply_strategies()\n",
    "ex.write_database()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Free up some memory"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "ex = None"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# LCA calculations\n",
    "\n",
    "We can now do an LCA. We first do this the standard way:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "gwp = ('IPCC 2013', 'climate change', 'GWP 100a')\n",
    "lca = LCA({Database(\"EXIOBASE 2.2\").random(): 1}, method=gwp)\n",
    "lca.lci()\n",
    "lca.lcia()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Our technosphere matrix is sparse:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<7824x7824 sparse matrix of type '<class 'numpy.float64'>'\n",
       "\twith 35550884 stored elements in Compressed Sparse Row format>"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lca.technosphere_matrix"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "And it takes a while to solve (versus less than one second for ecoinvent 2.2):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 loops, best of 3: 13.6 s per loop\n"
     ]
    }
   ],
   "source": [
    "%timeit lca.solve_linear_system()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Free up some memory by forgetting about the `lca` object."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "lca = None"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "However, we have a special LCA class that only does [dense technosphere matrices](https://bitbucket.org/cmutel/brightway2-calc/src/tip/bw2calc/dense_lca.py?at=default&fileviewer=file-view-default). If we use it, we will get better performance, because the linear solver assumes dense instead of sparse matrices:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "dlca = DenseLCA({Database(\"EXIOBASE 2.2\").random(): 1}, method=gwp)\n",
    "dlca.lci()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The technosphere is, as you would expect, now a dense matrix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "scipy.sparse.csr.csr_matrix"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(dlca.technosphere_matrix)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The nupy dense solver of linear system is faster than the SciPy/UMFPACK sparse solver, as our matrix actually is quite dense. The performance should be much better:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 loops, best of 3: 7.58 s per loop\n"
     ]
    }
   ],
   "source": [
    "%timeit dlca.solve_linear_system()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Free up some more memory by forgetting about the `tech_params` array."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(35557095,)\n"
     ]
    }
   ],
   "source": [
    "print(dlca.tech_params.shape)\n",
    "dlca.tech_params = None"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Create aggregated processes\n",
    "\n",
    "We can now create aggregated (so-called \"system\") processes for each activity in Exiobase. These aggregated proceses can be used in our normal sparse LCAs, but are terminated, i.e. we can't understand their background supply chains.\n",
    "\n",
    "First, we create a new database."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "aggregated_db = Database(\"EXIOBASE 2.2 aggregated\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This is a normal database, not an `IOTable` database."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "bw2data.backends.peewee.database.SQLiteBackend"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(aggregated_db)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now, we invert the EXIOBASE technosphere matrix.\n",
    "\n",
    "This takes some minutes - around 4 on my laptop - so just be patient. It is helpful if there is plenty of free memory."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "inverse = np.linalg.pinv(dlca.technosphere_matrix.todense())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "With the inverse, we can calculated the aggregated inventories, and then write each aggregated process."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(36, 7824)\n"
     ]
    }
   ],
   "source": [
    "inventory = dlca.biosphere_matrix * inverse\n",
    "print(inventory.shape)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Define the activity data fields we want to keep"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "KEYS = (\n",
    "    'exiobase_code',\n",
    "    'group',\n",
    "    'group_name',\n",
    "    'location',\n",
    "    'name',\n",
    "    'synonym',\n",
    "    'type',\n",
    "    'unit'\n",
    ")\n",
    "\n",
    "data = {}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Only take each non-zero biosphere flow, and create the aggregated processes."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "0%                          100%\n",
      "[##############################] | ETA[sec]: 0.000 \n",
      "Total time elapsed: 2.755 sec\n"
     ]
    }
   ],
   "source": [
    "for ds in pyprind.prog_bar(Database(\"EXIOBASE 2.2\")):\n",
    "    col = dlca.activity_dict[ds.key]\n",
    "    \n",
    "    # Basic data\n",
    "    data[(\"EXIOBASE 2.2 aggregated\", ds['code'])] = {key: ds[key] for key in KEYS}\n",
    "    # Exchanges\n",
    "    data[(\"EXIOBASE 2.2 aggregated\", ds['code'])]['exchanges'] = [{\n",
    "        'type': 'biosphere',\n",
    "        'amount': float(inventory[row, col]),\n",
    "        'input': flow,\n",
    "        'uncertainty type': 0\n",
    "    } for flow, row in dlca.biosphere_dict.items() if inventory[row, col]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Writing activities to SQLite3 database:\n",
      "0%                          100%\n",
      "[##############################] | ETA[sec]: 0.000 \n",
      "Total time elapsed: 33.328 sec\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Title: Writing activities to SQLite3 database:\n",
      "  Started: 11/04/2015 06:13:16\n",
      "  Finished: 11/04/2015 06:13:49\n",
      "  Total time elapsed: 33.328 sec\n",
      "  CPU %: 84.800000\n",
      "  Memory %: 11.791039\n"
     ]
    }
   ],
   "source": [
    "aggregated_db.write(data)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We no longer need the dlca object, so we can forget about it to save some memory."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "dlca = None"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Sample LCA calculations\n",
    "\n",
    "We will look at two product systems selected in class. We found the dataset keys using code like:\n",
    "\n",
    "    for x in Database(\"ecoinvent 2.2\").search('fertili*'):\n",
    "        print(x, x.key)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Cement production"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "ex_cement = ('EXIOBASE 2.2 aggregated', 'Manufacture of cement, lime and plaster:CH')\n",
    "ei_cement = ('ecoinvent 2.2', 'c2ff6ffd532415eda3eaf957b17b70a1')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Check to make sure we have the correct activities"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Manufacture of cement, lime and plaster' (million €, Switzerland, None)"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "get_activity(ex_cement)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'cement, unspecified, at plant' (kilogram, CH, ['construction materials', 'binder'])"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "get_activity(ei_cement)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Exiobase: 0.6778455551516355\n",
      "Ecoinvent 0.7391718051829614\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Warning: (almost) singular matrix! (estimated cond. number: 1.97e+12)\n"
     ]
    }
   ],
   "source": [
    "lca = LCA({ex_cement: 1}, gwp)\n",
    "lca.lci()\n",
    "lca.lcia()\n",
    "print(\"Exiobase:\", lca.score / 1e6 / 10) # Assume 100 euros/ton\n",
    "\n",
    "lca = LCA({ei_cement: 1}, gwp)\n",
    "lca.lci()\n",
    "lca.lcia()\n",
    "print(\"Ecoinvent\", lca.score)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "These numbers are remarkably similar. \n",
    "\n",
    "## Nitrogenous fertilizer\n",
    "\n",
    "Let's now look at nitrogen fertilizer:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "ei_n = ('ecoinvent 2.2', '920a20d9a87340557a31ee7e8a353d3c')\n",
    "ex_n = ('EXIOBASE 2.2 aggregated', 'N-fertiliser:LU')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Check to make sure we have the correct activities"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'potassium nitrate, as N, at regional storehouse' (kilogram, RER, ['agricultural means of production', 'mineral fertiliser'])"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "get_activity(ei_n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'N-fertiliser' (million €, Luxembourg, None)"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "get_activity(ex_n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Exiobase: 0.005093872326115799\n",
      "Ecoinvent: 15.451009908674084\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Warning: (almost) singular matrix! (estimated cond. number: 1.97e+12)\n"
     ]
    }
   ],
   "source": [
    "lca = LCA({ex_n: 1}, gwp)\n",
    "lca.lci()\n",
    "lca.lcia()\n",
    "print(\"Exiobase:\", lca.score / 1e6 * 0.8)  # Assume 800 euros/ton\n",
    "\n",
    "lca = LCA({ei_n: 1}, gwp)\n",
    "lca.lci()\n",
    "lca.lcia()\n",
    "print(\"Ecoinvent:\", lca.score)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This is quite interesting - more investigation would have to be done to understand why these values are so different."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Cleaning up\n",
    "\n",
    "This project consumes a lot of hard drive space, about 2 gigabytes. We can get the exact size of this and all other projects (in gigabytes) with the following:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('3.2', 1, 0.04101514),\n",
       " ('CAES', 3, 0.689499258),\n",
       " ('Class 1', 2, 0.191735801),\n",
       " ('Class 2', 2, 0.191735801),\n",
       " ('Class 3', 3, 0.233215194),\n",
       " ('Class 4', 4, 1.956078295),\n",
       " ('US LCI', 1, 0.024052396),\n",
       " ('backcalculate', 2, 0.68859466),\n",
       " ('databases demo', 1, 2.6909e-05),\n",
       " ('default', 2, 0.390822066),\n",
       " ('econometrics', 0, 0.035075556),\n",
       " ('forwast', 2, 0.053857285),\n",
       " ('lc-impact', 2, 1.689167237),\n",
       " ('parameterized', 1, 0.022645899),\n",
       " ('temporalis', 23, 0.819151974)]"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "projects.report()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can then delete the current project.\n",
    "\n",
    "**This step is optional**, included as a convenience for those who do not want to work with Exiobase."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'default'"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "projects.delete_project(delete_dir=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The returned value is the name of the current project."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'default'"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "projects.current"
   ]
  }
 ],
 "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.4.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
