{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2017-10-06T19:44:45.387902Z", "start_time": "2017-10-06T19:44:43.358391Z" }, "collapsed": true }, "outputs": [], "source": [ "%matplotlib inline\n", "import matplotlib.pyplot as plt\n", "import seaborn as sns\n", "import pandas as pd\n", "import numpy as np\n", "import os\n", "from os.path import join\n", "import sys\n", "import json" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2017-10-06T19:45:01.337538Z", "start_time": "2017-10-06T19:45:01.266594Z" }, "collapsed": true }, "outputs": [], "source": [ "# Load the \"autoreload\" extension\n", "%load_ext autoreload\n", "\n", "# always reload modules marked with \"%aimport\"\n", "%autoreload 1" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2017-10-06T19:46:04.101537Z", "start_time": "2017-10-06T19:46:04.097009Z" }, "collapsed": true }, "outputs": [], "source": [ "# add the 'src' directory as one where we can import modules\n", "cwd = os.getcwd()\n", "src_dir = join(cwd, os.pardir, 'src')\n", "sys.path.append(src_dir)" ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "ExecuteTime": { "end_time": "2017-10-06T20:02:59.353425Z", "start_time": "2017-10-06T20:02:59.347122Z" }, "collapsed": true }, "outputs": [], "source": [ "from util.utils import rename_cols" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Load data" ] }, { "cell_type": "code", "execution_count": 31, "metadata": { "ExecuteTime": { "end_time": "2017-10-06T20:04:40.401619Z", "start_time": "2017-10-06T20:04:39.800061Z" } }, "outputs": [], "source": [ "#EPA CEMS data\n", "path = join(cwd, '..', 'Data storage', 'Derived data',\n", " 'Monthly EPA emissions 2017-08-31.csv')\n", "epa = pd.read_csv(path)\n", "rename_cols(epa)\n", "epa = epa.groupby(['year', 'month', 'plant id']).sum()" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "ExecuteTime": { "end_time": "2017-10-06T19:46:56.181114Z", "start_time": "2017-10-06T19:46:48.458776Z" }, "collapsed": true }, "outputs": [], "source": [ "#EIA facility data\n", "path = join(cwd, '..', 'Data storage',\n", " 'Facility gen fuels and CO2 2017-08-31.zip')\n", "eia_fac = pd.read_csv(path)\n", "rename_cols(eia_fac)\n", "eia_fac = eia_fac.groupby(['year', 'month', 'plant id', 'fuel']).sum()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Find a facility with biomass and CHP" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "ExecuteTime": { "end_time": "2017-10-06T19:53:28.304368Z", "start_time": "2017-10-06T19:53:28.300718Z" }, "collapsed": true }, "outputs": [], "source": [ "idx = pd.IndexSlice" ] }, { "cell_type": "code", "execution_count": 37, "metadata": { "ExecuteTime": { "end_time": "2017-10-06T20:18:00.871851Z", "start_time": "2017-10-06T20:18:00.767560Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
total fuel (mmbtu)generation (mwh)elec fuel (mmbtu)latlonquarterall fuel fossil co2 (kg)elec fuel fossil co2 (kg)all fuel total co2 (kg)elec fuel total co2 (kg)
yearmonthplant idfuel
201661897NG909.03.54756.046.735331-92.151711248240.632971.9248240.632971.92
SUB19577.076.3871199.046.735331-92.15171121902884.40116542.801902884.40116542.80
WDS218373.0852.06613372.046.735331-92.15171120.000.0020483387.401254293.60
\n", "
" ], "text/plain": [ " total fuel (mmbtu) generation (mwh) \\\n", "year month plant id fuel \n", "2016 6 1897 NG 909.0 3.547 \n", " SUB 19577.0 76.387 \n", " WDS 218373.0 852.066 \n", "\n", " elec fuel (mmbtu) lat lon quarter \\\n", "year month plant id fuel \n", "2016 6 1897 NG 56.0 46.735331 -92.151711 2 \n", " SUB 1199.0 46.735331 -92.151711 2 \n", " WDS 13372.0 46.735331 -92.151711 2 \n", "\n", " all fuel fossil co2 (kg) elec fuel fossil co2 (kg) \\\n", "year month plant id fuel \n", "2016 6 1897 NG 48240.63 2971.92 \n", " SUB 1902884.40 116542.80 \n", " WDS 0.00 0.00 \n", "\n", " all fuel total co2 (kg) elec fuel total co2 (kg) \n", "year month plant id fuel \n", "2016 6 1897 NG 48240.63 2971.92 \n", " SUB 1902884.40 116542.80 \n", " WDS 20483387.40 1254293.60 " ] }, "execution_count": 37, "metadata": {}, "output_type": "execute_result" } ], "source": [ "example_eia = eia_fac.loc[idx[2016, 6, 1897, :], :]\n", "example_eia" ] }, { "cell_type": "code", "execution_count": 38, "metadata": { "ExecuteTime": { "end_time": "2017-10-06T20:18:05.518361Z", "start_time": "2017-10-06T20:18:05.510851Z" } }, "outputs": [ { "data": { "text/plain": [ "total fuel (mmbtu) 2.388590e+05\n", "generation (mwh) 9.320000e+02\n", "elec fuel (mmbtu) 1.462700e+04\n", "lat 1.402060e+02\n", "lon -2.764551e+02\n", "quarter 6.000000e+00\n", "all fuel fossil co2 (kg) 1.951125e+06\n", "elec fuel fossil co2 (kg) 1.195147e+05\n", "all fuel total co2 (kg) 2.243451e+07\n", "elec fuel total co2 (kg) 1.373808e+06\n", "dtype: float64" ] }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ "example_eia.sum()" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "ExecuteTime": { "end_time": "2017-10-06T19:58:28.301848Z", "start_time": "2017-10-06T19:58:28.207554Z" } }, "outputs": [], "source": [ "example_eia.to_clipboard()" ] }, { "cell_type": "code", "execution_count": 35, "metadata": { "ExecuteTime": { "end_time": "2017-10-06T20:06:04.523041Z", "start_time": "2017-10-06T20:06:04.514967Z" } }, "outputs": [ { "data": { "text/plain": [ "co2_mass (kg) 2.311098e+07\n", "gload (mw) NaN\n", "heat_input (mmbtu) 2.445270e+05\n", "op_time 7.909800e+02\n", "sload (1000lb/hr) 1.278900e+05\n", "Name: (2016, 6, 1897), dtype: float64" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "example_epa = epa.loc[idx[2016, 6, 1897], :]\n", "example_epa" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Adjust CO₂ emissions" ] }, { "cell_type": "code", "execution_count": 39, "metadata": { "ExecuteTime": { "end_time": "2017-10-06T20:18:41.672411Z", "start_time": "2017-10-06T20:18:41.665147Z" } }, "outputs": [ { "data": { "text/plain": [ "0.0053272706671432662" ] }, "execution_count": 39, "metadata": {}, "output_type": "execute_result" } ], "source": [ "co2_factor = (example_eia.sum()['elec fuel fossil co2 (kg)']\n", " / example_eia.sum()['all fuel total co2 (kg)'])\n", "co2_factor" ] }, { "cell_type": "code", "execution_count": 40, "metadata": { "ExecuteTime": { "end_time": "2017-10-06T20:19:22.321911Z", "start_time": "2017-10-06T20:19:22.315817Z" } }, "outputs": [ { "data": { "text/plain": [ "123118.46621921226" ] }, "execution_count": 40, "metadata": {}, "output_type": "execute_result" } ], "source": [ "co2_factor * example_epa['co2_mass (kg)']" ] } ], "metadata": { "kernelspec": { "display_name": "py36", "language": "python", "name": "py36" }, "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.2" }, "varInspector": { "cols": { "lenName": 16, "lenType": 16, "lenVar": 40 }, "kernels_config": { "python": { "delete_cmd_postfix": "", "delete_cmd_prefix": "del ", "library": "var_list.py", "varRefreshCmd": "print(var_dic_list())" }, "r": { "delete_cmd_postfix": ") ", "delete_cmd_prefix": "rm(", "library": "var_list.r", "varRefreshCmd": "cat(var_dic_list()) " } }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "window_display": false } }, "nbformat": 4, "nbformat_minor": 2 }