{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# What is this notebook\n",
    "\n",
    "TODO"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from brightway2 import *"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Basic setup\n",
    "\n",
    "Start a new project, and install base data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "projects.set_current(\"student-project-SimaPro-import\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Creating default biosphere\n",
      "\n",
      "Applying strategy: drop_unspecified_subcategories"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Writing activities to SQLite3 database:\n",
      "0%                          100%\n",
      "[##############################] | ETA[sec]: 0.000 \n",
      "Total time elapsed: 1.329 sec\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Title: Writing activities to SQLite3 database:\n",
      "  Started: 05/22/2015 11:08:36\n",
      "  Finished: 05/22/2015 11:08:38\n",
      "  Total time elapsed: 1.329 sec\n",
      "  CPU %: 49.500000\n",
      "  Memory %: 0.259149\n",
      "Created database: biosphere3\n",
      "Creating default LCIA methods\n",
      "\n",
      "Applying strategy: set_biosphere_type\n",
      "Applying strategy: drop_unspecified_subcategories\n",
      "Applying strategy: link_iterable_by_fields\n",
      "Wrote 692 LCIA methods with 170915 characterization factors\n",
      "Creating core data migrations\n",
      "\n"
     ]
    }
   ],
   "source": [
    "bw2setup()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Also want ecoinvent database"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Extracting ecospold2 files:\n",
      "0%                          100%\n",
      "[##############################] | ETA[sec]: 0.000 | Item ID: fff527b1-0fe4-4\n",
      "Total time elapsed: 102.789 sec\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Title: Extracting ecospold2 files:\n",
      "  Started: 05/22/2015 11:09:41\n",
      "  Finished: 05/22/2015 11:11:24\n",
      "  Total time elapsed: 102.789 sec\n",
      "  CPU %: 85.200000\n",
      "  Memory %: 2.959931\n",
      "Extracted 11301 datasets in 103.76 seconds\n",
      "Applying strategy: remove_zero_amount_coproducts\n",
      "Applying strategy: remove_zero_amount_inputs_with_no_activity\n",
      "Applying strategy: es2_assign_only_product_with_amount_as_reference_product\n",
      "Applying strategy: assign_single_product_as_activity\n",
      "Applying strategy: create_composite_code\n",
      "Applying strategy: drop_unspecified_subcategories\n",
      "Applying strategy: link_biosphere_by_flow_uuid\n",
      "Applying strategy: link_internal_technosphere_by_composite_code\n",
      "Applying strategy: delete_exchanges_missing_activity\n",
      "Applying strategy: delete_ghost_exchanges"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Writing activities to SQLite3 database:\n",
      "0%                          100%\n",
      "[##############################] | ETA[sec]: 0.000 \n",
      "Total time elapsed: 86.280 sec\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Title: Writing activities to SQLite3 database:\n",
      "  Started: 05/22/2015 11:11:29\n",
      "  Finished: 05/22/2015 11:12:56\n",
      "  Total time elapsed: 86.280 sec\n",
      "  CPU %: 79.200000\n",
      "  Memory %: 3.224015\n",
      "Created database: ecoinvent 3.1 cutoff\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "Brightway2 SQLiteBackend: ecoinvent 3.1 cutoff"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ei = SingleOutputEcospold2Importer(\n",
    "    \"/Users/cmutel/Documents/LCA Documents/Ecoinvent/3.1/cutoff/datasets\", \n",
    "    \"ecoinvent 3.1 cutoff\"\n",
    ")\n",
    "ei.apply_strategies()\n",
    "ei.write_database()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## First attempt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "NameError\n",
      "   AirMass\n",
      "name 'AirMass' is not defined\n"
     ]
    },
    {
     "ename": "DuplicateName",
     "evalue": "Parameter name pi is a built-in symbol",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mDuplicateName\u001b[0m                             Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-7-abd31e09665d>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0mfp\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m\"data/caes.CSV\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0msp\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mSimaProCSVImporter\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfp\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"CAES\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      3\u001b[0m \u001b[0msp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstatistics\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/Users/cmutel/local34/bw3dev/lib/python3.4/site-packages/bw2io/importers/simapro_csv.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, filepath, name, delimiter, encoding, normalize_biosphere, biosphere_db)\u001b[0m\n\u001b[1;32m     37\u001b[0m                 \u001b[0mdelimiter\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdelimiter\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     38\u001b[0m                 \u001b[0mname\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 39\u001b[0;31m                 \u001b[0mencoding\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mencoding\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     40\u001b[0m             )\n\u001b[1;32m     41\u001b[0m         print(u\"Extracted {} unallocated datasets in {:.2f} seconds\".format(\n",
      "\u001b[0;32m/Users/cmutel/local34/bw3dev/lib/python3.4/site-packages/bw2io/extractors/simapro_csv.py\u001b[0m in \u001b[0;36mextract\u001b[0;34m(cls, filepath, delimiter, name, encoding)\u001b[0m\n\u001b[1;32m    102\u001b[0m                     \u001b[0mfilepath\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    103\u001b[0m                     \u001b[0mglobal_parameters\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 104\u001b[0;31m                     \u001b[0mproject_metadata\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    105\u001b[0m                 )\n\u001b[1;32m    106\u001b[0m                 \u001b[0mdatasets\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mds\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/Users/cmutel/local34/bw3dev/lib/python3.4/site-packages/bw2io/extractors/simapro_csv.py\u001b[0m in \u001b[0;36mread_data_set\u001b[0;34m(cls, data, index, db_name, filepath, gp, pm)\u001b[0m\n\u001b[1;32m    512\u001b[0m         ps = ParameterSet(\n\u001b[1;32m    513\u001b[0m             \u001b[0mds\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'parameters'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 514\u001b[0;31m             \u001b[0;34m{\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mvalue\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'amount'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mkey\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvalue\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mgp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    515\u001b[0m         )\n\u001b[1;32m    516\u001b[0m         \u001b[0;31m# Changes in-place\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/Users/cmutel/local34/bw3dev/lib/python3.4/site-packages/bw2parameters/parameter_set.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, params, global_params)\u001b[0m\n\u001b[1;32m     13\u001b[0m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mparams\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mparams\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     14\u001b[0m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mglobal_params\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mglobal_params\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 15\u001b[0;31m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbasic_validation\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     16\u001b[0m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreferences\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_references\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     17\u001b[0m         \u001b[0;32mfor\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mreferences\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreferences\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/Users/cmutel/local34/bw3dev/lib/python3.4/site-packages/bw2parameters/parameter_set.py\u001b[0m in \u001b[0;36mbasic_validation\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m     86\u001b[0m             \u001b[0;32melif\u001b[0m \u001b[0mkey\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mEXISTING_SYMBOLS\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     87\u001b[0m                 raise DuplicateName(\n\u001b[0;32m---> 88\u001b[0;31m                     \u001b[0;34mu\"Parameter name {} is a built-in symbol\"\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     89\u001b[0m                 )\n\u001b[1;32m     90\u001b[0m         \u001b[0;32mfor\u001b[0m \u001b[0mkey\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvalue\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mglobal_params\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mDuplicateName\u001b[0m: Parameter name pi is a built-in symbol"
     ]
    }
   ],
   "source": [
    "fp = \"data/caes.CSV\"\n",
    "sp = SimaProCSVImporter(fp, name=\"CAES\")\n",
    "sp.statistics()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The formula parser throws an error - it has a certain number of symbols already defined, and when one of those symbol names is used as a variable it raises an error. In this case, we already have $\\pi$ defined, so we can manually delete it from the CSV file."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Extracted 4 unallocated datasets in 0.03 seconds\n",
      "4 datasets\n",
      "1312 exchanges\n",
      "1312 unlinked exchanges\n",
      "  Type biosphere: 1294 unique unlinked exchanges\n",
      "  Type production: 4 unique unlinked exchanges\n",
      "  Type technosphere: 12 unique unlinked exchanges\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(4, 1312, 1312)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fp = \"data/caes-no-pi.CSV\"\n",
    "sp = SimaProCSVImporter(fp, name=\"CAES\")\n",
    "sp.statistics()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Apply default strategies"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Applying strategy: assign_only_product_as_production\n",
      "Applying strategy: drop_unspecified_subcategories\n",
      "Applying strategy: sp_allocate_products\n",
      "Applying strategy: split_simapro_name_geo\n",
      "Applying strategy: strip_biosphere_exc_locations\n",
      "Applying strategy: link_technosphere_based_on_name_unit_location\n",
      "Applying strategy: normalize_biosphere_categories\n",
      "Applying strategy: normalize_simapro_biosphere_categories\n",
      "Applying strategy: normalize_biosphere_names\n",
      "Applying strategy: normalize_simapro_biosphere_names\n",
      "Applying strategy: link_iterable_by_fields\n",
      "4 datasets\n",
      "1312 exchanges\n",
      "12 unlinked exchanges\n",
      "  Type biosphere: 2 unique unlinked exchanges\n",
      "  Type technosphere: 10 unique unlinked exchanges\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(4, 1312, 12)"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sp.apply_strategies()\n",
    "sp.statistics()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Look at each undefined exchange"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false,
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Air compressor, screw-type compressor, 300kW {GLO}| market for | Alloc Def, U\n",
      "Electricity, medium voltage {CH}| market for | Alloc Def, U\n",
      "Gas turbine, 10MW electrical {GLO}| market for | Alloc Def, U\n",
      "Concrete block {GLO}| market for | Alloc Def, U\n",
      "Reinforcing steel {GLO}| market for | Alloc Def, U\n",
      "Clay\n",
      "Water, unspecified natural origin/m3\n",
      "Steel, chromium steel 18/8 {GLO}| market for | Alloc Def, U\n",
      "Aluminium, cast alloy {GLO}| market for | Alloc Def, U\n",
      "Silicon, metallurgical grade {GLO}| market for | Alloc Def, U\n",
      "Casting, brass {CH}| processing | Alloc Def, U\n",
      "Selective coat, aluminium sheet, nickel pigmented aluminium oxide {GLO}| market for | Alloc Def, U\n"
     ]
    }
   ],
   "source": [
    "for exc in sp.unlinked:\n",
    "    print(exc['name'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Fix links to ecoinvent 3.1\n",
    "\n",
    "This is a two-step process. First, we have to change the names to ones that ecoinvent uses (no, there is not ecoinvent process `Steel, chromium steel 18/8 {GLO}| market for | Alloc Def, U`!).\n",
    "\n",
    "Then we can try to link against the Ecoinvent 3.1 database."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Applying strategy: migrate_datasets\n",
      "Applying strategy: migrate_exchanges\n"
     ]
    }
   ],
   "source": [
    "sp.migrate(\"simapro-ecoinvent-3\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Because we are importin from SimaPro, the categories are screwed up (i.e. ecoinvent categories aren't cleanly imported). Tell the matching algorithm to ignore categories and only use product, reference product, unit, and location."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Applying strategy: link_iterable_by_fields\n",
      "4 datasets\n",
      "1312 exchanges\n",
      "2 unlinked exchanges\n",
      "  Type biosphere: 2 unique unlinked exchanges\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(4, 1312, 2)"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import functools\n",
    "from bw2io.strategies import link_iterable_by_fields\n",
    "\n",
    "sp.apply_strategy(functools.partial(\n",
    "        link_iterable_by_fields, \n",
    "        other=Database(\"ecoinvent 3.1 cutoff\"),\n",
    "        kind=\"technosphere\",\n",
    "        fields=[\"reference product\", \"name\", \"unit\", \"location\"]\n",
    "))\n",
    "sp.statistics()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## What is left?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false,
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'amount': 0.0001942, 'type': 'biosphere', 'name': 'Clay', 'categories': ('natural resource', 'in ground'), 'comment': '', 'loc': 0.0001942, 'uncertainty type': 0, 'unit': 'kilogram'}\n",
      "{'amount': 3.6721e-05, 'type': 'biosphere', 'name': 'Water, unspecified natural origin/m3', 'categories': ('natural resource', 'in water'), 'comment': '', 'loc': 3.6721e-05, 'uncertainty type': 0, 'unit': 'cubic meter'}\n"
     ]
    }
   ],
   "source": [
    "for exc in sp.unlinked:\n",
    "    print(exc)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## What to do when the matching is \"good enough\"\n",
    "\n",
    "In this case, we are going to ignore these missing exchanges. We do this (naturally) through another strategy, thoough this one has a shortcut:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Warning: This is the nuclear weapon of linking, and should only be used in extreme cases. Must be called with the keyword argument ``i_am_reckless=True``!\n"
     ]
    }
   ],
   "source": [
    "sp.drop_unlinked()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Oops, we got a complaint. But we proceed anyway:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Applying strategy: drop_unlinked\n"
     ]
    }
   ],
   "source": [
    "sp.drop_unlinked(i_am_reckless=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Write an excel sheet with all exchanges\n",
    "\n",
    "Just to get a better view on what was imported"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Wrote matching file to:\n",
      "/Users/cmutel/Library/Application Support/Brightway3/student-project-SimaPro-import.679e4acaf664ea565578a3224feee904/export/db-matching-CAES.xlsx\n"
     ]
    }
   ],
   "source": [
    "sp.write_excel()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Write the database"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "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: 0.206 sec\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Title: Writing activities to SQLite3 database:\n",
      "  Started: 05/22/2015 11:33:00\n",
      "  Finished: 05/22/2015 11:33:00\n",
      "  Total time elapsed: 0.206 sec\n",
      "  CPU %: 88.700000\n",
      "  Memory %: 3.946972\n",
      "Created database: CAES\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "Brightway2 SQLiteBackend: CAES"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sp.write_database()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "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.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
