{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### This script shows how to use the existing code in opengrid to create a baseload electricity consumption benchmark. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import os\n",
    "import sys\n",
    "import inspect\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from matplotlib.dates import HourLocator, DateFormatter, AutoDateLocator\n",
    "import datetime as dt\n",
    "import pytz\n",
    "import pandas as pd\n",
    "import pdb\n",
    "import tmpo\n",
    "\n",
    "from opengrid import config\n",
    "from opengrid.library import houseprint\n",
    "\n",
    "c = config.Config()\n",
    "\n",
    "try:\n",
    "    if os.path.exists(c.get('tmpo', 'data')):\n",
    "        path_to_tmpo_data = c.get('tmpo', 'data')\n",
    "except:\n",
    "    path_to_tmpo_data = None\n",
    "\n",
    "\n",
    "%matplotlib inline\n",
    "plt.rcParams['figure.figsize']=14,8"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### We create one big dataframe, the columns are the sensors of type *gas*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "hp = houseprint.load_houseprint_from_file('new_houseprint.pkl')\n",
    "hp.init_tmpo(path_to_tmpo_data=path_to_tmpo_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "df = hp.get_data(sensortype='gas')\n",
    "df = df.diff()\n",
    "df = df[df>0]\n",
    "df = df*10*60/1000 #from L/min to kW: 10 Wh/L, 60 min/h, 1 kW/1000W"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false,
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "# plot timeseries and load duration for each retained sensor\n",
    "for sensor in df.columns:\n",
    "    plt.figure()\n",
    "    ax1=plt.subplot(121)\n",
    "    plt.plot_date(df.index, df[sensor], '-', label=sensor)\n",
    "    plt.ylabel('kW')\n",
    "    plt.legend()\n",
    "    \n",
    "    ax2=plt.subplot(122)\n",
    "    plt.plot(np.sort(df[sensor])[::-1], label=sensor)\n",
    "    plt.ylabel('kW')\n",
    "    plt.legend()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
