{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Documentation for the creation and usage of the heat pump library (hplib)\n",
    "\n",
    "This documentation covers the database preperation, validation and usage for simulation. If you're only interested in using hplib for simulation purpose, you should have a look into chapter [4. How to simulate](#how-to-simulate)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. [Definitions](#definitions)\n",
    "2. [Database preperation](#database-preparation)\n",
    "3. [Work with database](#work-with-database)\n",
    "    1. [Load database](#load-database)\n",
    "    2. [Load specific model](#load-specific-model)\n",
    "    3. [Load generic model](#load-generic-model)\n",
    "4. [How to simulate](#how-to-simulate)\n",
    "    1. [Simulate on time step](#simulate-one-timestep)\n",
    "    2. [Simulate a time series](#simulate-a-timeseries)\n",
    "5. [Example heat pump](#example-heat-pump)\n",
    "6. [Validation](#validation)\n",
    "    1. [Air/Water | on/off](#air-water-onoff)\n",
    "    2. [Brine/Water | on/off](#brine-water-onoff)\n",
    "    3. [Water/Water | on/off](#water-water-onoff)\n",
    "    4. [Air/Water | regulated](#air-water-regulated)\n",
    "        1. [Heating](#air-water-regulated-heating)\n",
    "        2. [Cooling](#air-water-regulated-cooling)\n",
    "    5. [Brine/Water | regulated](#brine-water-regulated)\n",
    "7. [Conclusion](#conclusion)\n",
    "8. [Additional functions](#additional-functions)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import hplib as hpl\n",
    "import hplib_database as db\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import warnings\n",
    "import numpy\n",
    "warnings.filterwarnings(\"ignore\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>\n",
       "table {float:left}\n",
       "</style>\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%%html\n",
    "<style>\n",
    "table {float:left}\n",
    "</style>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## **1. Definitions** <a class=\"anchor\" id=\"definitions\" name=\"definitions\"></a>\n",
    "\n",
    "**Abbreviations**\n",
    "\n",
    "| Abbreviation | Meaning |\n",
    "| :--- | :--- |\n",
    "| P_th | Thermal output power in W |\n",
    "| P_el | Electical input Power in W |\n",
    "| COP | Coefficient of performance |\n",
    "| EER | Energy Efficiency Ratio |\n",
    "| T_in | Input temperature in °C at primary side of the heat pump |\n",
    "| T_out | Output temperature in °C at secondary side of the heat pump |\n",
    "| T_amb | Ambient temperature in °C |\n",
    "| P_th_h_ref | Thermal heating output power in W at T_in = -7 °C and T_out = 52 °C |\n",
    "| P_el_h_ref | Elecrical input power (heating) in W at T_in = -7 °C and T_out = 52 °C |\n",
    "| COP_ref | Coefficient of performance at T_in = -7 °C and T_out = 52 °C |\n",
    "| P_th_c_ref | Thermal cooling output power in W at T_in = 35 °C and T_out = 7 °C |\n",
    "| P_el_c_ref | Elecrical input power (cooling) in W at T_in = 35 °C and T_out = 7 °C |\n",
    "| p1-p4 | Fit-Parameters for Fit-Function |\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "**Group IDs**\n",
    "\n",
    "| Group ID | Type | Subtype |\n",
    "| :--- | :--- | :--- |\n",
    "| 1 | Outdoor Air / Water | Regulated | \n",
    "| 2 | Brine / Water | Regulated | \n",
    "| 3 | Water / Water | Regulated | \n",
    "| 4 | Outdoor Air / Water | On-Off | \n",
    "| 5 | Brine / Water | On-Off | \n",
    "| 6 | Water / Water | On-Off |"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## **2. Database preparation** <a class=\"anchor\" id=\"database-preparation\" name=\"database-preparation\"></a>\n",
    "\n",
    "This section is only for documentation regarding the development of the final database. It's not neccesary to run this code again.\n",
    "\n",
    "1. we downloaded all manufacturer data from https://keymark.eu/en/products/heatpumps/certified-products .\n",
    "2. then we unzipped the files to the `input` folder and used the bash-skript `pdf2txt.sh` to convert pdf into txt.\n",
    "3. afterwards we used the following functions to create and extent the heatpump keymark database."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Import keymark data and save to csv database\n",
    "db.import_heating_data()\n",
    "# -> this creates /output/database_heating.csv\n",
    "db.import_cooling_data()\n",
    "# -> this creates /output/database_cooling.csv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Reduce to climate measurement series with average climate, delete redundant entries and save to csv sub-database\n",
    "db.reduce_heating_data('database_heating.csv','average')\n",
    "# -> this creates /output/database_heating_average.csv"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Process heating database**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Normalize electrical and thermal power from the keymark database to values from setpoint T_in = -7 °C and T_out = 52 °C\n",
    "db.normalize_heating_data('database_heating_average.csv')\n",
    "# -> this creates /output/database_heating_average_normalized.csv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Identify subtypes like on-off or regulated heat pumps and assign group id depending on its type and subtype\n",
    "db.identify_subtypes('database_heating_average_normalized.csv')\n",
    "# -> this creates /output/database_heating_average_normalized_subtypes.csv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Calculate parameters p1-p4 for P_th, P_el and COP with a least-square fit approach\n",
    "# based on  K. Schwamberger: „Modellbildung und Regelung von Gebäudeheizungsanlagen \n",
    "# mit Wärmepumpen“, VDI Verlag, Düsseldorf, Fortschrittsberichte VDI Reihe 6 Nr. 263, 1991.\n",
    "db.calculate_heating_parameters('database_heating_average_normalized_subtypes.csv')\n",
    "# -> this creates /output/hplib_database_heating.csv\n",
    "# -> this creates /src/hplib_database.csv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Many heat pump models have redundant entries because of different controller or storage configurations.\n",
    "# Reduce to unique heat pump models.\n",
    "db.reduce_to_unique()\n",
    "# -> this overwrites the /output/hplib_database_heating.csv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Calculate the relative error (RE) for each set point of every heat pump\n",
    "db.validation_relative_error_heating()\n",
    "# -> this creates /output/database_heating_average_normalized_subtypes_validation.csv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Calculate the mean absolute percentage error (MAPE) for every heat pump\n",
    "db.validation_mape_heating()\n",
    "# -> this overwrites the /output/hplib_database_heating.csv"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Process cooling database**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Overall there are not so many unique Keymark heat pumps for cooling (34 models) in comparison to heating (505 models).\n",
    "\n",
    "Out of the 34 models only 4 heat pumps had set points at different outflow temperature. \n",
    "With our fit method it is not possible to fit only over one outflow temperature. For that reason we added another\n",
    "set point at 18°C output temperature based on the heat pumps we had with this condition in Keymark. For that purpose, we identified multiplication factors for eletrical power and eer between 7°C and 18°C secondary output temperature. The mean value of that are used to calculate the electrical power and EER at 18°C for other heat pumps:\n",
    "\n",
    "```\n",
    "P_el at 18°C = P_el at 7°C * multiplication factor \n",
    "EER at 18°C = EER at 7°C * multiplication factor\n",
    "```\n",
    "\n",
    "| Outside Tempertature | Multiplication factor for P_el | Multiplication factor for EER |\n",
    "| :--- | :--- | :--- |\n",
    "| 35 | 0.85 | 1.21 |\n",
    "| 30 | 0.82 | 1.21 |\n",
    "| 25 | 0.77 | 1.20 |\n",
    "| 20 | 0.63 | 0.95 |\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Only use heatpumps which are unique and also in the heating library\n",
    "db.reduce_cooling_data()\n",
    "#this generates /output/database_cooling_reduced.csv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Normalize electrical and thermal power from the keymark database to values from setpoint T_outside = 35 °C and T_out = 7 °C\n",
    "db.normalize_and_add_cooling_data()\n",
    "#-> this creates /output/database_cooling_reduced_normalized.csv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Used the same fit method like in heating\n",
    "# except: for P_el the point 20/7 is ignored\n",
    "db.calculate_cooling_parameters()\n",
    "# -> this overwrites /src/hplib_database.csv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Calculate the relative error (RE) for each set point of every heat pump\n",
    "db.validation_relative_error_cooling()\n",
    "# this creates /output/database_cooling_reduced_normalized_subtypes_validation.csv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Calculate the mean absolute percentage error (MAPE) for every heat pump\n",
    "db.validation_mape_cooling()\n",
    "# -> this overwrites the /src/hplib_database.csv"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Create generic heat pump models**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Calculate generic heat pump models for each group id\n",
    "# for cooling: there is only a generic heat pump of type air/water | regulated available\n",
    "db.add_generic()\n",
    "# -> this overwrites the /src/hplib_database.csv"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Hint:** The csv files in the `output` folder are for documentation and validation purpose. The code `hplib.py` and database `hplib_database` files, which are meant to be used for simulations, are located in the `src` folder. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## **3. Work with database** <a class=\"anchor\" id=\"work-with-database\" name=\"work-with-database\"></a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### **3.1 Load database**  <a class=\"anchor\" id=\"load-database\" name=\"load-database\"></a>\n",
    "\n",
    "Simply execute the command without arguments and you will get a DataFrame with the complete list of manufacturers and models. Now you are able to view, filter or sort the database."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Manufacturer</th>\n",
       "      <th>Model</th>\n",
       "      <th>Date</th>\n",
       "      <th>Type</th>\n",
       "      <th>Subtype</th>\n",
       "      <th>Group</th>\n",
       "      <th>Refrigerant</th>\n",
       "      <th>Mass of Refrigerant [kg]</th>\n",
       "      <th>SPL indoor [dBA]</th>\n",
       "      <th>SPL outdoor [dBA]</th>\n",
       "      <th>...</th>\n",
       "      <th>p2_P_el_c [1/°C]</th>\n",
       "      <th>p3_P_el_c [-]</th>\n",
       "      <th>p4_P_el_c [1/°C]</th>\n",
       "      <th>p1_EER [-]</th>\n",
       "      <th>p2_EER [-]</th>\n",
       "      <th>p3_EER [-]</th>\n",
       "      <th>p4_EER [-]</th>\n",
       "      <th>MAPE_P_el_cooling</th>\n",
       "      <th>MAPE_EER</th>\n",
       "      <th>MAPE_Pdc</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Advantix</td>\n",
       "      <td>i-SHWAK V4 06</td>\n",
       "      <td>2020-05-26</td>\n",
       "      <td>Outdoor Air/Water</td>\n",
       "      <td>Regulated</td>\n",
       "      <td>1.0</td>\n",
       "      <td>R410a</td>\n",
       "      <td>2.68</td>\n",
       "      <td>35.0</td>\n",
       "      <td>64.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-0.010769</td>\n",
       "      <td>-0.763316</td>\n",
       "      <td>-70.588606</td>\n",
       "      <td>37.392760</td>\n",
       "      <td>0.046170</td>\n",
       "      <td>6.295339</td>\n",
       "      <td>-37.488343</td>\n",
       "      <td>12.221419</td>\n",
       "      <td>6.840097</td>\n",
       "      <td>9.194424</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Advantix</td>\n",
       "      <td>i-SHWAK V4 08</td>\n",
       "      <td>2020-05-26</td>\n",
       "      <td>Outdoor Air/Water</td>\n",
       "      <td>Regulated</td>\n",
       "      <td>1.0</td>\n",
       "      <td>R410a</td>\n",
       "      <td>2.20</td>\n",
       "      <td>35.0</td>\n",
       "      <td>64.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-0.010295</td>\n",
       "      <td>-1.008835</td>\n",
       "      <td>-70.584924</td>\n",
       "      <td>53.317794</td>\n",
       "      <td>0.045359</td>\n",
       "      <td>6.373991</td>\n",
       "      <td>-53.417576</td>\n",
       "      <td>8.557697</td>\n",
       "      <td>5.543797</td>\n",
       "      <td>6.180972</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Advantix</td>\n",
       "      <td>i-SHWAK V4 10</td>\n",
       "      <td>2020-05-26</td>\n",
       "      <td>Outdoor Air/Water</td>\n",
       "      <td>Regulated</td>\n",
       "      <td>1.0</td>\n",
       "      <td>R410a</td>\n",
       "      <td>3.45</td>\n",
       "      <td>39.0</td>\n",
       "      <td>64.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-0.009974</td>\n",
       "      <td>-1.070117</td>\n",
       "      <td>-71.138737</td>\n",
       "      <td>-38.305956</td>\n",
       "      <td>0.055509</td>\n",
       "      <td>10.401025</td>\n",
       "      <td>38.096062</td>\n",
       "      <td>12.129224</td>\n",
       "      <td>4.233020</td>\n",
       "      <td>12.245195</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Advantix</td>\n",
       "      <td>i-SHWAK V4 12</td>\n",
       "      <td>2020-05-26</td>\n",
       "      <td>Outdoor Air/Water</td>\n",
       "      <td>Regulated</td>\n",
       "      <td>1.0</td>\n",
       "      <td>R410a</td>\n",
       "      <td>3.45</td>\n",
       "      <td>39.0</td>\n",
       "      <td>65.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-0.009670</td>\n",
       "      <td>-1.199827</td>\n",
       "      <td>-79.730152</td>\n",
       "      <td>-106.597525</td>\n",
       "      <td>0.055461</td>\n",
       "      <td>10.417088</td>\n",
       "      <td>106.386968</td>\n",
       "      <td>10.736620</td>\n",
       "      <td>4.251786</td>\n",
       "      <td>11.085364</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Advantix</td>\n",
       "      <td>i-SHWAK V4 14T</td>\n",
       "      <td>2020-05-26</td>\n",
       "      <td>Outdoor Air/Water</td>\n",
       "      <td>Regulated</td>\n",
       "      <td>1.0</td>\n",
       "      <td>R410a</td>\n",
       "      <td>4.40</td>\n",
       "      <td>40.0</td>\n",
       "      <td>68.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-0.009060</td>\n",
       "      <td>-1.464498</td>\n",
       "      <td>-70.578508</td>\n",
       "      <td>-106.597525</td>\n",
       "      <td>0.055461</td>\n",
       "      <td>10.417088</td>\n",
       "      <td>106.386968</td>\n",
       "      <td>6.954977</td>\n",
       "      <td>4.251786</td>\n",
       "      <td>7.852487</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>506</th>\n",
       "      <td>Generic</td>\n",
       "      <td>Generic</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Brine/Water</td>\n",
       "      <td>Regulated</td>\n",
       "      <td>2.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>507</th>\n",
       "      <td>Generic</td>\n",
       "      <td>Generic</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Water/Water</td>\n",
       "      <td>Regulated</td>\n",
       "      <td>3.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>508</th>\n",
       "      <td>Generic</td>\n",
       "      <td>Generic</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Outdoor Air/Water</td>\n",
       "      <td>On-Off</td>\n",
       "      <td>4.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>509</th>\n",
       "      <td>Generic</td>\n",
       "      <td>Generic</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Brine/Water</td>\n",
       "      <td>On-Off</td>\n",
       "      <td>5.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>510</th>\n",
       "      <td>Generic</td>\n",
       "      <td>Generic</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Water/Water</td>\n",
       "      <td>On-Off</td>\n",
       "      <td>6.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>511 rows × 47 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    Manufacturer           Model        Date               Type    Subtype  \\\n",
       "0      Advantix    i-SHWAK V4 06  2020-05-26  Outdoor Air/Water  Regulated   \n",
       "1      Advantix    i-SHWAK V4 08  2020-05-26  Outdoor Air/Water  Regulated   \n",
       "2      Advantix    i-SHWAK V4 10  2020-05-26  Outdoor Air/Water  Regulated   \n",
       "3      Advantix    i-SHWAK V4 12  2020-05-26  Outdoor Air/Water  Regulated   \n",
       "4      Advantix   i-SHWAK V4 14T  2020-05-26  Outdoor Air/Water  Regulated   \n",
       "..           ...             ...         ...                ...        ...   \n",
       "506      Generic         Generic         NaN        Brine/Water  Regulated   \n",
       "507      Generic         Generic         NaN        Water/Water  Regulated   \n",
       "508      Generic         Generic         NaN  Outdoor Air/Water     On-Off   \n",
       "509      Generic         Generic         NaN        Brine/Water     On-Off   \n",
       "510      Generic         Generic         NaN        Water/Water     On-Off   \n",
       "\n",
       "     Group Refrigerant  Mass of Refrigerant [kg]  SPL indoor [dBA]  \\\n",
       "0      1.0       R410a                      2.68              35.0   \n",
       "1      1.0       R410a                      2.20              35.0   \n",
       "2      1.0       R410a                      3.45              39.0   \n",
       "3      1.0       R410a                      3.45              39.0   \n",
       "4      1.0       R410a                      4.40              40.0   \n",
       "..     ...         ...                       ...               ...   \n",
       "506    2.0         NaN                       NaN               NaN   \n",
       "507    3.0         NaN                       NaN               NaN   \n",
       "508    4.0         NaN                       NaN               NaN   \n",
       "509    5.0         NaN                       NaN               NaN   \n",
       "510    6.0         NaN                       NaN               NaN   \n",
       "\n",
       "     SPL outdoor [dBA]  ...  p2_P_el_c [1/°C] p3_P_el_c [-]  p4_P_el_c [1/°C]  \\\n",
       "0                 64.0  ...         -0.010769     -0.763316        -70.588606   \n",
       "1                 64.0  ...         -0.010295     -1.008835        -70.584924   \n",
       "2                 64.0  ...         -0.009974     -1.070117        -71.138737   \n",
       "3                 65.0  ...         -0.009670     -1.199827        -79.730152   \n",
       "4                 68.0  ...         -0.009060     -1.464498        -70.578508   \n",
       "..                 ...  ...               ...           ...               ...   \n",
       "506                NaN  ...               NaN           NaN               NaN   \n",
       "507                NaN  ...               NaN           NaN               NaN   \n",
       "508                NaN  ...               NaN           NaN               NaN   \n",
       "509                NaN  ...               NaN           NaN               NaN   \n",
       "510                NaN  ...               NaN           NaN               NaN   \n",
       "\n",
       "     p1_EER [-]  p2_EER [-]  p3_EER [-]  p4_EER [-]  MAPE_P_el_cooling  \\\n",
       "0     37.392760    0.046170    6.295339  -37.488343          12.221419   \n",
       "1     53.317794    0.045359    6.373991  -53.417576           8.557697   \n",
       "2    -38.305956    0.055509   10.401025   38.096062          12.129224   \n",
       "3   -106.597525    0.055461   10.417088  106.386968          10.736620   \n",
       "4   -106.597525    0.055461   10.417088  106.386968           6.954977   \n",
       "..          ...         ...         ...         ...                ...   \n",
       "506         NaN         NaN         NaN         NaN                NaN   \n",
       "507         NaN         NaN         NaN         NaN                NaN   \n",
       "508         NaN         NaN         NaN         NaN                NaN   \n",
       "509         NaN         NaN         NaN         NaN                NaN   \n",
       "510         NaN         NaN         NaN         NaN                NaN   \n",
       "\n",
       "     MAPE_EER   MAPE_Pdc  \n",
       "0    6.840097   9.194424  \n",
       "1    5.543797   6.180972  \n",
       "2    4.233020  12.245195  \n",
       "3    4.251786  11.085364  \n",
       "4    4.251786   7.852487  \n",
       "..        ...        ...  \n",
       "506       NaN        NaN  \n",
       "507       NaN        NaN  \n",
       "508       NaN        NaN  \n",
       "509       NaN        NaN  \n",
       "510       NaN        NaN  \n",
       "\n",
       "[511 rows x 47 columns]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "database = hpl.load_database()\n",
    "database"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### **3.2 Load specific model**  <a class=\"anchor\" id=\"load-specific-model\" name=\"load-specific-model\"></a>\n",
    "\n",
    "To get the parameters of a specific heat pump model, use the `get_parameters()` method with a specific Model name from the database.\n",
    "You will get a DataFrame with all parameters including the mean absolute percentage errors (MAPE) for this model."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Manufacturer</th>\n",
       "      <th>Model</th>\n",
       "      <th>MAPE_COP</th>\n",
       "      <th>MAPE_P_el</th>\n",
       "      <th>MAPE_P_th</th>\n",
       "      <th>P_th_h_ref [W]</th>\n",
       "      <th>P_el_h_ref [W]</th>\n",
       "      <th>COP_ref</th>\n",
       "      <th>Group</th>\n",
       "      <th>p1_P_th [1/°C]</th>\n",
       "      <th>...</th>\n",
       "      <th>p3_Pdc [-]</th>\n",
       "      <th>p4_Pdc [1/°C]</th>\n",
       "      <th>p1_P_el_c [1/°C]</th>\n",
       "      <th>p2_P_el_c [1/°C]</th>\n",
       "      <th>p3_P_el_c [-]</th>\n",
       "      <th>p4_P_el_c [1/°C]</th>\n",
       "      <th>p1_EER [-]</th>\n",
       "      <th>p2_EER [-]</th>\n",
       "      <th>p3_EER [-]</th>\n",
       "      <th>p4_EER [-]</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Advantix</td>\n",
       "      <td>i-SHWAK V4 06</td>\n",
       "      <td>9.244852</td>\n",
       "      <td>22.607658</td>\n",
       "      <td>24.897666</td>\n",
       "      <td>4500.0</td>\n",
       "      <td>2866.0</td>\n",
       "      <td>1.57</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.756924</td>\n",
       "      <td>...</td>\n",
       "      <td>0.068769</td>\n",
       "      <td>-70.599887</td>\n",
       "      <td>70.638879</td>\n",
       "      <td>-0.010769</td>\n",
       "      <td>-0.763316</td>\n",
       "      <td>-70.588606</td>\n",
       "      <td>37.39276</td>\n",
       "      <td>0.04617</td>\n",
       "      <td>6.295339</td>\n",
       "      <td>-37.488343</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1 rows × 35 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "  Manufacturer          Model  MAPE_COP  MAPE_P_el  MAPE_P_th  P_th_h_ref [W]  \\\n",
       "0    Advantix   i-SHWAK V4 06  9.244852  22.607658  24.897666          4500.0   \n",
       "\n",
       "   P_el_h_ref [W]  COP_ref  Group  p1_P_th [1/°C]  ...  p3_Pdc [-]  \\\n",
       "0          2866.0     1.57    1.0        1.756924  ...    0.068769   \n",
       "\n",
       "   p4_Pdc [1/°C]  p1_P_el_c [1/°C]  p2_P_el_c [1/°C]  p3_P_el_c [-]  \\\n",
       "0     -70.599887         70.638879         -0.010769      -0.763316   \n",
       "\n",
       "   p4_P_el_c [1/°C]  p1_EER [-]  p2_EER [-]  p3_EER [-]  p4_EER [-]  \n",
       "0        -70.588606    37.39276     0.04617    6.295339  -37.488343  \n",
       "\n",
       "[1 rows x 35 columns]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "parameters = hpl.get_parameters('i-SHWAK V4 06')\n",
    "parameters"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### **3.3 Load generic model**  <a class=\"anchor\" id=\"load-generic-model\" name=\"load-generic-model\"></a>\n",
    "\n",
    "To get the parameters of a generic heat pump model, use the `get_parameters()` method with the following keyword arguments of a free choosen set point\n",
    "\n",
    "* model='Generic'\n",
    "* group_id: 1,2,4,5,6\n",
    "* t_in: choose primary input temperature in °C\n",
    "* t_out: choose secondary output temperature in °C\n",
    "* p_th: choose thermal output power in W\n",
    "\n",
    "You will get a DataFrame with all parameters for this generic model. For every group id the parameter set is based on the average parameters of all heat pumps of its group with an MAPE of less than 25%."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Manufacturer</th>\n",
       "      <th>Model</th>\n",
       "      <th>MAPE_COP</th>\n",
       "      <th>MAPE_P_el</th>\n",
       "      <th>MAPE_P_th</th>\n",
       "      <th>P_th_h_ref [W]</th>\n",
       "      <th>P_el_h_ref [W]</th>\n",
       "      <th>COP_ref</th>\n",
       "      <th>Group</th>\n",
       "      <th>p1_P_th [1/°C]</th>\n",
       "      <th>...</th>\n",
       "      <th>p4_Pdc [1/°C]</th>\n",
       "      <th>p1_P_el_c [1/°C]</th>\n",
       "      <th>p2_P_el_c [1/°C]</th>\n",
       "      <th>p3_P_el_c [-]</th>\n",
       "      <th>p4_P_el_c [1/°C]</th>\n",
       "      <th>p1_EER [-]</th>\n",
       "      <th>p2_EER [-]</th>\n",
       "      <th>p3_EER [-]</th>\n",
       "      <th>p4_EER [-]</th>\n",
       "      <th>EER_ref</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Generic</td>\n",
       "      <td>Generic</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10168.785754</td>\n",
       "      <td>7193.433182</td>\n",
       "      <td>1.413621</td>\n",
       "      <td>1.0</td>\n",
       "      <td>69.969927</td>\n",
       "      <td>...</td>\n",
       "      <td>-71.578974</td>\n",
       "      <td>69.044359</td>\n",
       "      <td>-0.009208</td>\n",
       "      <td>-1.368639</td>\n",
       "      <td>-68.976493</td>\n",
       "      <td>-11.722768</td>\n",
       "      <td>0.06484</td>\n",
       "      <td>11.52005</td>\n",
       "      <td>11.474317</td>\n",
       "      <td>3.278166</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1 rows × 36 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "  Manufacturer    Model  MAPE_COP  MAPE_P_el  MAPE_P_th  P_th_h_ref [W]  \\\n",
       "0      Generic  Generic       NaN        NaN        NaN    10168.785754   \n",
       "\n",
       "   P_el_h_ref [W]   COP_ref  Group  p1_P_th [1/°C]  ...  p4_Pdc [1/°C]  \\\n",
       "0     7193.433182  1.413621    1.0       69.969927  ...     -71.578974   \n",
       "\n",
       "   p1_P_el_c [1/°C]  p2_P_el_c [1/°C]  p3_P_el_c [-]  p4_P_el_c [1/°C]  \\\n",
       "0         69.044359         -0.009208      -1.368639        -68.976493   \n",
       "\n",
       "   p1_EER [-]  p2_EER [-]  p3_EER [-]  p4_EER [-]   EER_ref  \n",
       "0  -11.722768     0.06484    11.52005   11.474317  3.278166  \n",
       "\n",
       "[1 rows x 36 columns]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "parameters = hpl.get_parameters(model='Generic', group_id=1, t_in=-7, t_out=52, p_th=10000)\n",
    "parameters"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## **4. How to simulate** <a class=\"anchor\" id=\"how-to-simulate\" name=\"how-to-simulate\"></a>\n",
    "\n",
    "With the Fit-Parameters p1-p4 for P_th, P_el and COP it is possible to calculate the results with the following methods:\n",
    "\n",
    "1. P_th and P_el with Fit-Functions and `COP = P_th / P_el` or\n",
    "2. P_th and COP with Fit-Functions and `P_el = P_th / COP` or\n",
    "3. P_el and COP with Fut-Functions and `P_th = P_el * COP`\n",
    "\n",
    "While the model by Schwarmberger [1] uses the first method, our validation showed, that the third method leads to better results. Therefore we decided to implement this in the `simulate` definition."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### **4.1 Simulate one timestep**  <a class=\"anchor\" id=\"simulate-one-timestep\" name=\"simulate-one-timestep\"></a>\n",
    "\n",
    "Please define a primary input temperature (t_in_primary), secondary input temperature (t_in_secondary),\n",
    "ambient / outdoor temperature (t_amb) in °C and the parameters from the previous step. The t_in_secondary\n",
    "is supposed to be heated up by 5 K which then results in output temperature.\n",
    "\n",
    "Important:\n",
    "* for air / water heat pumps t_in_primary and t_amb are supposed to be the same values.\n",
    "* for brine / water or water / water heat pumps t_in_primary and t_amb are independent values."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   T_in  T_out  T_amb       COP  EER         P_el     P_th    m_dot\n",
      "0    -7     52     -7  1.413621    0  7074.033573  10000.0  0.47619\n"
     ]
    }
   ],
   "source": [
    "# Load parameters\n",
    "parameters = hpl.get_parameters(model='Generic', group_id=1, t_in=-7, t_out=52, p_th=10000)\n",
    "# Create heat pump object with parameters\n",
    "heatpump = hpl.HeatPump(parameters)\n",
    "# Simulate with values\n",
    "# whereas mode = 1 is for heating and mode = 2 is for cooling\n",
    "results = heatpump.simulate(t_in_primary=-7, t_in_secondary=47, t_amb=-7, mode=1)\n",
    "print(pd.DataFrame([results]))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### **4.2 Simulate a timeseries**  <a class=\"anchor\" id=\"simulate-a-timeseries\" name=\"simulate-a-timeseries\"></a>\n",
    "\n",
    "The simulation approach could be to do a `for loop` around the method of simulating one timestep. But it will be faster to use the previous method with arrays as inputs. For usage you are allowed to define pandas.Series or arrays as input values. It is also possible to combine single values and pandas.Series / arrays.\n",
    "\n",
    "*The next example uses a measured timeseries for ambient / outdoor temperature and secondary \n",
    "input temperature of a real heating system to demonstrate the simulation approach. The data represents\n",
    "on year and has a temporal resolution of 1 minute*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The seasonal performance factor (SPF) for one year is = 3.9\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 8900 characters]",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Read input file with temperatures\n",
    "df = pd.read_csv('../input/TestYear.csv')\n",
    "df['T_amb'] = df['T_in_primary'] # air/water heat pump -> T_amb = T_in_primary\n",
    "# Simulate with values\n",
    "# Load parameters\n",
    "parameters = hpl.get_parameters(model='Generic', group_id=1, t_in=-7, t_out=52, p_th=10000)\n",
    "# Create heat pump object with parameters\n",
    "heatpump = hpl.HeatPump(parameters)\n",
    "# whereas mode = 1 is for heating and mode = 2 is for cooling\n",
    "results = heatpump.simulate(t_in_primary=df['T_in_primary'].values, t_in_secondary=df['T_in_secondary'].values, t_amb=df['T_amb'].values, mode=1)\n",
    "# Plot / Print some results\n",
    "# example for distribution of COPs\n",
    "results=pd.DataFrame.from_dict(results)\n",
    "results['COP'].plot.hist(bins=50, title='Distribution of COP values') \n",
    "# Calclulate seasonal performance factor (SPF)\n",
    "SPF = results['P_th'].mean() / results['P_el'].mean() \n",
    "print('The seasonal performance factor (SPF) for one year is = '+str(round(SPF,1)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## **5. Example heat pump** <a class=\"anchor\" id=\"example-heat-pump\" name=\"example-heat-pump\"></a>\n",
    "\n",
    "To get a overview over the different operation conditions, this section plots the electrical and thermal power as well as the COP for all possible primary and secondary input temperatures\n",
    " \n",
    "HEATING: **Schematic plot** of COP, P_el and P_th for an **generic air/water** heat pump: subtype = **regulated** "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<bound method Figure.show of <Figure size 432x288 with 2 Axes>>"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 31928 characters]",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 29224 characters]",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 45964 characters]",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Define Temperatures\n",
    "T_in_primary = range(-20,31)\n",
    "T_in_secondary = range(20,56)\n",
    "T_in = numpy.array([])\n",
    "T_out = numpy.array([])\n",
    "\n",
    "# Load parameters of generic air/water | regulated\n",
    "parameters = hpl.get_parameters('Generic', group_id=1, t_in=-7, t_out=52, p_th = 10000)\n",
    "heatpump=hpl.HeatPump(parameters)\n",
    "results=pd.DataFrame()\n",
    "# Create input series\n",
    "for t1 in T_in_primary:\n",
    "    for t2 in T_in_secondary:\n",
    "        T_in=numpy.append(T_in,t1)\n",
    "        T_out=numpy.append(T_out,t2)\n",
    "results=heatpump.simulate(t_in_primary=T_in, t_in_secondary=T_out, t_amb=T_in, mode=1)\n",
    "results=pd.DataFrame.from_dict(results)\n",
    "\n",
    "# Plot COP\n",
    "fig1, ax1 = plt.subplots()\n",
    "plot = plt.tricontourf(results['T_in'], results['T_out'], results['COP'])\n",
    "ax1.tricontour(results['T_in'], results['T_out'], results['COP'], colors='k')\n",
    "fig1.colorbar(plot)\n",
    "ax1.set_title('COP')\n",
    "ax1.set_xlabel('Primary input temperature [°C]')\n",
    "ax1.set_ylabel('Secondary output temperature [°C]')\n",
    "fig1.show\n",
    "\n",
    "# Plot electrical input power\n",
    "fig1, ax1 = plt.subplots()\n",
    "plot = plt.tricontourf(results['T_in'], results['T_out'], results['P_el'])\n",
    "ax1.tricontour(results['T_in'], results['T_out'], results['P_el'], colors='k')\n",
    "fig1.colorbar(plot)\n",
    "ax1.set_title('Eletrical input power [W]')\n",
    "ax1.set_xlabel('Primary input temperature [°C]')\n",
    "ax1.set_ylabel('Secondary output temperature [°C]')\n",
    "fig1.show\n",
    "\n",
    "# Plot thermal output power\n",
    "fig1, ax1 = plt.subplots()\n",
    "plot = plt.tricontourf(results['T_in'], results['T_out'], results['P_th'])\n",
    "ax1.tricontour(results['T_in'], results['T_out'], results['P_th'], colors='k')\n",
    "fig1.colorbar(plot)\n",
    "ax1.set_title('Thermal output power [W]')\n",
    "ax1.set_xlabel('Primary input temperature [°C]')\n",
    "ax1.set_ylabel('Secondary output temperature [°C]')\n",
    "fig1.show"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "COOLING: **Schematic plot** of EER, P_el and P_th for an **generic air/water** heat pump: subtype = **regulated** "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<bound method Figure.show of <Figure size 432x288 with 2 Axes>>"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 31480 characters]",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 31692 characters]",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 38724 characters]",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Define Temperatures\n",
    "T_in_primary = range(20,36)\n",
    "T_in_secondary = range(10,30)\n",
    "T_in = numpy.array([])\n",
    "T_out = numpy.array([])\n",
    "\n",
    "# Load parameters of generic air/water | regulated\n",
    "parameters = hpl.get_parameters('Generic', group_id=1, t_in=-7, t_out=52, p_th = 10000)\n",
    "heatpump=hpl.HeatPump(parameters)\n",
    "results=pd.DataFrame()\n",
    "# Create input series\n",
    "for t1 in T_in_primary:\n",
    "    for t2 in T_in_secondary:\n",
    "        T_in=numpy.append(T_in,t1)\n",
    "        T_out=numpy.append(T_out,t2)\n",
    "results=heatpump.simulate(t_in_primary=T_in, t_in_secondary=T_out, t_amb=T_in, mode=2)\n",
    "results=pd.DataFrame.from_dict(results)\n",
    "# Plot EER\n",
    "fig1, ax1 = plt.subplots()\n",
    "plot = plt.tricontourf(results['T_in'], results['T_out'], results['EER'])\n",
    "ax1.tricontour(results['T_in'], results['T_out'], results['EER'], colors='k')\n",
    "fig1.colorbar(plot)\n",
    "ax1.set_title('EER')\n",
    "ax1.set_xlabel('Primary input temperature [°C]')\n",
    "ax1.set_ylabel('Secondary output temperature [°C]')\n",
    "fig1.show\n",
    "\n",
    "# Plot electrical input power\n",
    "fig1, ax1 = plt.subplots()\n",
    "plot = plt.tricontourf(results['T_in'], results['T_out'], results['P_el'])\n",
    "ax1.tricontour(results['T_in'], results['T_out'], results['P_el'], colors='k')\n",
    "fig1.colorbar(plot)\n",
    "ax1.set_title('Eletrical input power [W]')\n",
    "ax1.set_xlabel('Primary input temperature [°C]')\n",
    "ax1.set_ylabel('Secondary output temperature [°C]')\n",
    "fig1.show\n",
    "\n",
    "# Plot thermal output power\n",
    "fig1, ax1 = plt.subplots()\n",
    "plot = plt.tricontourf(results['T_in'], results['T_out'], results['P_th'])\n",
    "ax1.tricontour(results['T_in'], results['T_out'], results['P_th'], colors='k')\n",
    "fig1.colorbar(plot)\n",
    "ax1.set_title('Thermal output power [W]')\n",
    "ax1.set_xlabel('Primary input temperature [°C]')\n",
    "ax1.set_ylabel('Secondary output temperature [°C]')\n",
    "fig1.show"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## **6. Validation** <a class=\"anchor\" id=\"validation\" name=\"validation\"></a>\n",
    "\n",
    "The following plots will give you a detailed view on the differences between simulation and measurement from heat pump keymark. Therefore, all set points for all heat pumps are loaded from the file `database_heating_average_normalized_subtypes_validation.csv`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv('../output/database_heating_average_normalized_subtypes_validation.csv')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### **6.1 Air/Water | on/off** <a class=\"anchor\" id=\"air-water-onoff\" name=\"air-water-onoff\"></a>\n",
    "\n",
    "* The mean absolute percentage error (MAPE) over all heat pumps is\n",
    "    * 5.4 % for COP\n",
    "    * 2.5 % for P_el\n",
    "    * 5.8 % for P_th\n",
    "* The errors come from deviation mostly at low ambient / outside temperatures"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RE_COP     5.404139\n",
       "RE_P_el    2.525073\n",
       "RE_P_th    5.806641\n",
       "dtype: float64"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 14080 characters]",
      "text/plain": [
       "<Figure size 720x360 with 3 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Plot relative error for all heat pumps of type air/water | on-off\n",
    "Group = 4\n",
    "data = df.loc[(df['Group']==Group)]\n",
    "data = data[['T_amb [°C]','RE_COP', 'RE_P_el', 'RE_P_th']]\n",
    "ax = data.boxplot(by='T_amb [°C]', layout=(1,3), figsize=(10,5), showfliers=False)\n",
    "ax[0].set_ylim(-60,60)\n",
    "ax[0].set_ylabel('relative error in %')\n",
    "data.abs().mean()[1:4] # mean absolute percentage error (MAPE)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.0, 50000.0)"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 45664 characters]",
      "text/plain": [
       "<Figure size 1080x360 with 3 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Plot absolute values all heat pumps of type air/water | on-off as scatter plot\n",
    "Group = 4\n",
    "fig, ax = plt.subplots(1,3)\n",
    "data = df.loc[(df['Group']==Group)]\n",
    "data.plot.scatter(ax=ax[0], x='COP',y='COP_sim', alpha=0.3, figsize=(12,5), grid=True, title='Coefficient of performance')\n",
    "data.plot.scatter(ax=ax[1], x='P_el [W]',y='P_el_sim', alpha=0.3, figsize=(15,5), grid=True, title='Electrical input power [W]')\n",
    "data.plot.scatter(ax=ax[2], x='P_th [W]',y='P_th_sim', alpha=0.3, figsize=(15,5), grid=True, title='Thermal output power [W]')\n",
    "ax[0].set_xlim(0,10)\n",
    "ax[0].set_ylim(0,10)\n",
    "ax[1].set_xlim(0,20000)\n",
    "ax[1].set_ylim(0,20000)\n",
    "ax[2].set_xlim(0,50000)\n",
    "ax[2].set_ylim(0,50000)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### **6.2 Brine/Water | on/off** <a class=\"anchor\" id=\"brine-water-onoff\" name=\"brine-water-onoff\"></a>\n",
    "\n",
    "* The mean absolute percentage error (MAPE) over all heat pumps is\n",
    "    * 3.9 % for COP\n",
    "    * 1.7 % for P_el\n",
    "    * 2.7 % for P_th\n",
    "* **Important**: Validation data is only available at primary input temperature of 0 °C.  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RE_COP     3.897897\n",
       "RE_P_el    1.678427\n",
       "RE_P_th    2.668440\n",
       "dtype: float64"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 13924 characters]",
      "text/plain": [
       "<Figure size 720x360 with 3 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Plot relative error for all heat pumps of type brine/water | on-off\n",
    "Group = 5\n",
    "data = df.loc[(df['Group']==Group)]\n",
    "data = data[['T_amb [°C]','RE_COP', 'RE_P_el', 'RE_P_th']]\n",
    "ax = data.boxplot(by='T_amb [°C]', layout=(1,3), figsize=(10,5), showfliers=False)\n",
    "ax[0].set_ylim(-60,60)\n",
    "ax[0].set_ylabel('relative error in %')\n",
    "data.abs().mean()[1:4] # mean absolute percentage error (MAPE)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.0, 50000.0)"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 48268 characters]",
      "text/plain": [
       "<Figure size 1080x360 with 3 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Plot absolute values all heat pumps of type brine/water | on-off as scatter plot\n",
    "Group = 5\n",
    "fig, ax = plt.subplots(1,3)\n",
    "data = df.loc[(df['Group']==Group)]\n",
    "data.plot.scatter(ax=ax[0], x='COP',y='COP_sim', alpha=0.3, figsize=(12,5), grid=True, title='Coefficient of performance')\n",
    "data.plot.scatter(ax=ax[1], x='P_el [W]',y='P_el_sim', alpha=0.3, figsize=(15,5), grid=True, title='Electrical input power [W]')\n",
    "data.plot.scatter(ax=ax[2], x='P_th [W]',y='P_th_sim', alpha=0.3, figsize=(15,5), grid=True, title='Thermal output power [W]')\n",
    "ax[0].set_xlim(0,10)\n",
    "ax[0].set_ylim(0,10)\n",
    "ax[1].set_xlim(0,20000)\n",
    "ax[1].set_ylim(0,20000)\n",
    "ax[2].set_xlim(0,50000)\n",
    "ax[2].set_ylim(0,50000)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### **6.3 Water/Water | on/off** <a class=\"anchor\" id=\"water-water-onoff\" name=\"water-water-onoff\"></a>\n",
    "\n",
    "* The mean absolute percentage error (MAPE) over all heat pumps is\n",
    "    * 1.6 % for COP\n",
    "    * 1.6 % for P_el\n",
    "    * 2.4 % for P_th\n",
    "* **Important**: Validation data is only available at primary input temperature of 10 °C."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RE_COP     1.563460\n",
       "RE_P_el    1.582038\n",
       "RE_P_th    2.415430\n",
       "dtype: float64"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 13844 characters]",
      "text/plain": [
       "<Figure size 720x360 with 3 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Plot relative error for all heat pumps of type water/water | on-off\n",
    "Group = 6\n",
    "data = df.loc[(df['Group']==Group)]\n",
    "data = data[['T_amb [°C]','RE_COP', 'RE_P_el', 'RE_P_th']]\n",
    "ax = data.boxplot(by='T_amb [°C]', layout=(1,3), figsize=(10,5), showfliers=False)\n",
    "ax[0].set_ylim(-60,60)\n",
    "ax[0].set_ylabel('relative error in %')\n",
    "data.abs().mean()[1:4] # mean absolute percentage error (MAPE)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.0, 50000.0)"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 36568 characters]",
      "text/plain": [
       "<Figure size 1080x360 with 3 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Plot absolute values all heat pumps of type water/water | on-off as scatter plot\n",
    "Group = 6\n",
    "fig, ax = plt.subplots(1,3)\n",
    "data = df.loc[(df['Group']==Group)]\n",
    "data.plot.scatter(ax=ax[0], x='COP',y='COP_sim', alpha=0.3, figsize=(12,5), grid=True, title='Coefficient of performance')\n",
    "data.plot.scatter(ax=ax[1], x='P_el [W]',y='P_el_sim', alpha=0.3, figsize=(15,5), grid=True, title='Electrical input power [W]')\n",
    "data.plot.scatter(ax=ax[2], x='P_th [W]',y='P_th_sim', alpha=0.3, figsize=(15,5), grid=True, title='Thermal output power [W]')\n",
    "ax[0].set_xlim(0,10)\n",
    "ax[0].set_ylim(0,10)\n",
    "ax[1].set_xlim(0,20000)\n",
    "ax[1].set_ylim(0,20000)\n",
    "ax[2].set_xlim(0,50000)\n",
    "ax[2].set_ylim(0,50000)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### **6.4 Air/Water | regulated** <a class=\"anchor\" id=\"air-water-regulated\" name=\"air-water-regulated\"></a>\n",
    "\n",
    "**Heating**\n",
    "* The mean absolute percentage error (MAPE) over all heat pumps is\n",
    "    * 12.1 % for COP\n",
    "    * 19.5 % for P_el\n",
    "    * 23.5 % for P_th\n",
    "\n",
    "**Cooling**\n",
    "* The mean absolute percentage error (MAPE) over all heat pumps is\n",
    "    * 4.8 % for EER\n",
    "    * 16.5 % for P_el\n",
    "    * 17.0 % for P_th\n",
    "    \n",
    "Because of different control strategies, the deviation over different heat pump models is much higher compared to on/off types."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### **6.4.1 Heating** <a class=\"anchor\" id=\"air-water-regulated-heating\" name=\"air-water-regulated-heating\"></a>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RE_COP     12.076160\n",
       "RE_P_el    19.456473\n",
       "RE_P_th    23.522542\n",
       "dtype: float64"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 14392 characters]",
      "text/plain": [
       "<Figure size 720x360 with 3 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Plot relative error for all heat pumps of type air/water | regulated\n",
    "Group = 1\n",
    "data = df.loc[(df['Group']==Group)]\n",
    "data = data[['T_amb [°C]','RE_COP', 'RE_P_el', 'RE_P_th']]\n",
    "ax = data.boxplot(by='T_amb [°C]', layout=(1,3), figsize=(10,5), showfliers=False)\n",
    "ax[0].set_ylim(-60,60)\n",
    "ax[0].set_ylabel('relative error in %')\n",
    "data.abs().mean()[1:4] # mean absolute percentage error (MAPE)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.0, 50000.0)"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 76216 characters]",
      "text/plain": [
       "<Figure size 1080x360 with 3 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Plot absolute values all heat pumps of type air/water | regulated as scatter plot\n",
    "Group = 1\n",
    "fig, ax = plt.subplots(1,3)\n",
    "data = df.loc[(df['Group']==Group)]\n",
    "data.plot.scatter(ax=ax[0], x='COP',y='COP_sim', alpha=0.3, figsize=(12,5), grid=True, title='Coefficient of performance')\n",
    "data.plot.scatter(ax=ax[1], x='P_el [W]',y='P_el_sim', alpha=0.1, figsize=(15,5), grid=True, title='Electrical input power [W]')\n",
    "data.plot.scatter(ax=ax[2], x='P_th [W]',y='P_th_sim', alpha=0.1, figsize=(15,5), grid=True, title='Thermal output power [W]')\n",
    "ax[0].set_xlim(0,10)\n",
    "ax[0].set_ylim(0,10)\n",
    "ax[1].set_xlim(0,20000)\n",
    "ax[1].set_ylim(0,20000)\n",
    "ax[2].set_xlim(0,50000)\n",
    "ax[2].set_ylim(0,50000)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### **6.4.2 Cooling** <a class=\"anchor\" id=\"air-water-regulated-cooling\" name=\"air-water-regulated-cooling\"></a>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RE_Pdc     16.964163\n",
       "RE_P_el    16.476100\n",
       "RE_EER      4.843020\n",
       "dtype: float64"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 14652 characters]",
      "text/plain": [
       "<Figure size 720x360 with 3 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "data = pd.read_csv('../output/database_cooling_reduced_normalized_validation.csv')\n",
    "data = data[['T_outside [°C]','RE_Pdc', 'RE_P_el', 'RE_EER']]\n",
    "ax = data.boxplot(by='T_outside [°C]', layout=(1,3), figsize=(10,5), showfliers=False)\n",
    "ax[0].set_ylim(-60,60)\n",
    "ax[0].set_ylabel('relative error in %')\n",
    "data.abs().mean()[1:4] # mean absolute percentage error (MAPE)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.0, 15000.0)"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 51784 characters]",
      "text/plain": [
       "<Figure size 1080x360 with 3 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "data = pd.read_csv('../output/database_cooling_reduced_normalized_validation.csv')\n",
    "fig, ax = plt.subplots(1,3)\n",
    "data.plot.scatter(ax=ax[0], x='EER',y='EER_sim', alpha=0.3, figsize=(12,5), grid=True, title='Coefficient of performance')\n",
    "data.plot.scatter(ax=ax[1], x='P_el [W]',y='P_el_sim', alpha=0.1, figsize=(15,5), grid=True, title='Electrical input power [W]')\n",
    "data.plot.scatter(ax=ax[2], x='Pdc [W]',y='Pdc_sim', alpha=0.1, figsize=(15,5), grid=True, title='Thermal output power [W]')\n",
    "ax[0].set_xlim(0,10)\n",
    "ax[0].set_ylim(0,10)\n",
    "ax[1].set_xlim(0,6000)\n",
    "ax[1].set_ylim(0,6000)\n",
    "ax[2].set_xlim(0,15000)\n",
    "ax[2].set_ylim(0,15000)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### **6.5 Brine/Water | regulated** <a class=\"anchor\" id=\"brine-water-regulated\" name=\"brine-water-regulated\"></a>\n",
    "\n",
    "* The mean absolute percentage error (MAPE) is over all heat pumps is\n",
    "    * 4.2 % for COP\n",
    "    * 17.7 % for P_el\n",
    "    * 19.7 % for P_th\n",
    "* **Important**: Validation data is only available at primary input temperature of 0 °C.  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RE_COP      4.228648\n",
       "RE_P_el    17.650300\n",
       "RE_P_th    19.737515\n",
       "dtype: float64"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 14316 characters]",
      "text/plain": [
       "<Figure size 720x360 with 3 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Plot relative error for all heat pumps of type brine/water | regulated\n",
    "Group = 2\n",
    "data = df.loc[(df['Group']==Group)]\n",
    "data = data[['T_amb [°C]','RE_COP', 'RE_P_el', 'RE_P_th']]\n",
    "ax = data.boxplot(by='T_amb [°C]', layout=(1,3), figsize=(10,5), showfliers=False)\n",
    "ax[0].set_ylim(-60,60)\n",
    "ax[0].set_ylabel('relative error in %')\n",
    "data.abs().mean()[1:4] # mean absolute percentage error (MAPE)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.0, 50000.0)"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 59640 characters]",
      "text/plain": [
       "<Figure size 1080x360 with 3 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Plot absolute values all heat pumps of type brine/water | regulated as scatter plot\n",
    "Group = 2\n",
    "fig, ax = plt.subplots(1,3)\n",
    "data = df.loc[(df['Group']==Group)]\n",
    "data.plot.scatter(ax=ax[0], x='COP',y='COP_sim', alpha=0.3, figsize=(12,5), grid=True, title='Coefficient of performance')\n",
    "data.plot.scatter(ax=ax[1], x='P_el [W]',y='P_el_sim', alpha=0.1, figsize=(15,5), grid=True, title='Electrical input power [W]')\n",
    "data.plot.scatter(ax=ax[2], x='P_th [W]',y='P_th_sim', alpha=0.1, figsize=(15,5), grid=True, title='Thermal output power [W]')\n",
    "ax[0].set_xlim(0,10)\n",
    "ax[0].set_ylim(0,10)\n",
    "ax[1].set_xlim(0,20000)\n",
    "ax[1].set_ylim(0,20000)\n",
    "ax[2].set_xlim(0,50000)\n",
    "ax[2].set_ylim(0,50000)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## **7. Conclusion** <a class=\"anchor\" id=\"conclusion\" name=\"conclusion\"></a>\n",
    "\n",
    "- On/Off heat pumps can be simulated very well (mean relative error < 6 %)\n",
    "- Regulated heat pumps show a good values in terms of COP and EER but relative mean errors about 15-20 % for electrical and thermal power, because of the non-linearity regarding different primary / secondary temperatures.\n",
    "- Despite of that, generic heat pumps should work well, because the median shows only a small relative error"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## **8. Additional functions** <a class=\"anchor\" id=\"additional-functions\" name=\"additional-functions\"></a>\n",
    "\n",
    "The hplib has an additonal class with functions regarding the heating system. For example it is possible to calculate the brine temperatur or the calculate the temperature of the heating distribution system."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Initialize a heating system\n",
    "t_hs_set = [35,28]  # example for floor heating\n",
    "f_hs_exp = 1.1      # example for floor heating\n",
    "t_min = -11         # example minimum reference outside temperature for building\n",
    "\n",
    "HS = hpl.HeatingSystem(t_outside_min=-11,t_hs_set=t_hs_set,f_hs_exp=f_hs_exp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Heating flow temperatur = 31.4\n",
      "Heating return temperatur = 26.1\n"
     ]
    }
   ],
   "source": [
    "# Calculate heating flow and return temperature\n",
    "t_avg_d = -3        # average temperatur of day\n",
    "\n",
    "t_dist = HS.calc_heating_dist_temp(t_avg_d=t_avg_d)\n",
    "print('Heating flow temperatur = '+str(round(t_dist[0],1)))\n",
    "print('Heating return temperatur = '+str(round(t_dist[1],1)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Brine flow temperatur = 4.2\n"
     ]
    }
   ],
   "source": [
    "# Calculate brine temperature as function of outside temperature\n",
    "# for heat pumps with earth probes\n",
    "t_avg_d = -3\n",
    "\n",
    "t_brine = HS.calc_brine_temp(t_avg_d = t_avg_d)\n",
    "print('Brine flow temperatur = '+str(round(t_brine,1)))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "913f7adb7c9036a7fff91eab457e837b7032b5c4a88fb914562ef959176dd2a5"
  },
  "kernelspec": {
   "display_name": "Python 3.8.8 64-bit ('hplib-database': conda)",
   "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.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
