diff --git a/LESO_code17-v5.ipynb b/LESO_code17-v5.ipynb new file mode 100644 index 0000000..6180278 --- /dev/null +++ b/LESO_code17-v5.ipynb @@ -0,0 +1,1398 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 46, + "metadata": { + "collapsed": true, + "scrolled": true + }, + "outputs": [], + "source": [ + "#importing packages\n", + "\n", + "import pandas as pd\n", + "import json\n", + "import numpy as np" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#reading input data\n", + "\n", + "array=[\"Irradiation\",\"Demand\",\"Heating\"]\n", + "df = pd.read_excel(\"Projet_Energie.xlsx\", sheetname=0,names=array)\n", + "\n", + "with open(\"donnees.json\") as f:\n", + " parameters = json.load(f)\n", + "\n", + "percentage_SP = parameters[\"percentage_SP\"]\n", + "buying_price = parameters[\"buying_price\"]\n", + "selling_price = parameters[\"selling_price\"]\n", + "solar_pv_price = parameters[\"solar_pv_price\"]\n", + "solar_pv_efficacity=parameters[\"solar_pv_efficacity\"] \n", + "maintenance_SP = parameters[\"maintenance_SP\"]\n", + "lifetime_SP = parameters[\"lifetime_SP\"]\n", + "solar_PV_CO2 = parameters[\"solar_PV_CO2\"]\n", + "grid_CO2 = parameters[\"grid_CO2\"]\n", + "percentage_battery_lea=parameters[\"percentage_battery_lea\"]\n", + "percentage_battery_li=parameters[\"percentage_battery_li\"]\n", + "percentage_battery_ni=parameters[\"percentage_battery_ni\"]\n", + "capacity_battery=parameters[\"capacity_battery\"]\n", + "lea_efficacity=parameters[\"lea_efficacity\"]\n", + "li_efficacity=parameters[\"li_efficacity\"]\n", + "ni_efficacity=parameters[\"ni_efficacity\"]\n", + "maintenance_battery_lea=parameters[\"maintenance_battery_lea\"]\n", + "maintenance_battery_li=parameters[\"maintenance_battery_li\"]\n", + "maintenance_battery_ni=parameters[\"maintenance_battery_ni\"]\n", + "lea_battery_price=parameters[\"lea_battery_price\"]\n", + "li_battery_price=parameters[\"li_battery_price\"]\n", + "ni_battery_price=parameters[\"ni_battery_price\"]\n", + "lea_lifetime_battery=parameters[\"lea_lifetime_battery\"]\n", + "li_lifetime_battery=parameters[\"li_lifetime_battery\"]\n", + "ni_lifetime_battery=parameters[\"ni_lifetime_battery\"]\n", + "lea_bat_CO2=parameters[\"lea_bat_CO2\"]\n", + "li_bat_CO2=parameters[\"li_bat_CO2\"]\n", + "ni_bat_CO2=parameters[\"ni_bat_CO2\"]\n", + "li_minsoc=parameters[\"li_minsoc\"]\n", + "ni_minsoc=parameters[\"ni_minsoc\"]\n", + "lea_minsoc=parameters[\"lea_minsoc\"]\n", + "capacity_boiler=parameters[\"capacity_boiler\"]\n", + "boiler_efficacity=parameters[\"boiler_efficacity\"]\n", + "HP_COP=parameters[\"HP_COP\"]\n", + "solar_thermal_CO2=parameters[\"solar_thermal_CO2\"]\n", + "max_global_irradiance=parameters[\"max_global_irradiance\"]\n", + "solar_thermal_efficacity=parameters[\"solar_thermal_efficacity\"]\n", + "percentage_ST=parameters[\"percentage_ST\"]\n", + "boiler_price=parameters[\"boiler_price\"]\n", + "thermal_grid_price=parameters[\"thermal_grid_price\"]\n", + "maintenance_solarthermal=parameters[\"maintenance_solarthermal\"]\n", + "ng_buying_price=parameters[\"ng_buying_price\"]\n", + "ng_selling_price=parameters[\"ng_selling_price\"]\n", + "boiler_lifetime=parameters[\"boiler_lifetime\"]\n", + "thermal_grid_lifetime=parameters[\"thermal_grid_lifetime\"]\n", + "co2_natural_gas_boiler=parameters[\"co2_natural_gas_boiler\"]\n", + "co2_heatpump=parameters[\"co2_heatpump\"]\n", + "co2_naturalgas_grid=parameters[\"co2_naturalgas_grid\"]\n", + "heatpump_price=parameters[\"heatpump_price\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#SOLAR PV\n", + "#defining generation\n", + "\n", + "df[\"Generation\"] = df[\"Irradiation\"]/1000*solar_pv_efficacity*percentage_SP\n", + "\n", + "#defining self consumption\n", + "\n", + "df[\"SelfConsumption\"] = df[\"Generation\"].where(\n", + " df[\"Generation\"] - df[\"Demand\"]/1000 < 0, other=df[\"Demand\"]/1000\n", + ")\n", + "\n", + "#defining the amount sell to grid\n", + "\n", + "df[\"Sell_grid\"] = (df[\"Generation\"] - df[\"Demand\"]/1000).where(\n", + " df[\"Generation\"] - df[\"Demand\"]/1000 > 0, other=0\n", + ")\n", + "#defining the amount buy from grid\n", + "\n", + "df[\"Buy_grid\"] = (df[\"Generation\"] - df[\"Demand\"]/1000).where(\n", + " df[\"Generation\"] - df[\"Demand\"]/1000 < 0, other=0\n", + ")\n", + "\n", + "#defining heating demand\n", + "df[\"Heating\"]=df[\"Heating\"]/1000" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#Calculation over a year\n", + "total_Demand=sum(df[\"Demand\"]/1000)\n", + "total_Generation=sum(df[\"Generation\"])\n", + "buying_PV=-sum(df[\"Buy_grid\"])\n", + "selling_PV=sum(df[\"Sell_grid\"])\n", + "capacity_PV=max(df[\"Generation\"])\n", + "cost_SP=round(capacity_PV*solar_pv_price,2)\n", + "subvention=round(0.25*cost_SP,2)\n", + "deduction_impot=round(cost_SP*0.19,2)" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#annualizing the maintenance cost, selling price and buying price\n", + "def maintenance(n):\n", + " maintenance_cost=0\n", + " for k in range(1,n+1):\n", + " maintenance_cost += (capacity_PV*maintenance_SP)/(1+0.01)**k\n", + " return maintenance_cost\n", + "\n", + "def selling(n):\n", + " selling_cost=0\n", + " for k in range(1,n+1):\n", + " selling_cost += (selling_PV*selling_price)*(1+0.02)**k\n", + " return selling_cost\n", + "\n", + "def buying(n):\n", + " buying_cost=0\n", + " for k in range(1,n+1):\n", + " buying_cost += (buying_PV*buying_price)*(1+0.02)**k\n", + " return buying_cost" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#NPV calculation: Solar PV\n", + "total_cost=maintenance(lifetime_SP-1)+cost_SP-subvention-deduction_impot\n", + "\n", + "selling_cost_tot=selling(lifetime_SP-1)+(selling_PV*selling_price)\n", + "\n", + "buying_cost_tot=buying(lifetime_SP-1)+(buying_PV*buying_price)\n", + "\n", + "NPV=(-total_cost-buying_cost_tot+selling_cost_tot)" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#BATTERY\n", + "#defining variables\n", + "df[\"Delta\"]=df[\"Generation\"] - df[\"Demand\"]/1000\n", + "#battery capacity : lead acid, lithium ion, nickel iron battery\n", + "capacity_bat_lea=capacity_battery*percentage_battery_lea\n", + "capacity_bat_li=capacity_battery*percentage_battery_li\n", + "capacity_bat_ni=capacity_battery*percentage_battery_ni\n", + "\n", + "#minimum state of charge\n", + "min_soc_lea=lea_minsoc*capacity_bat_lea\n", + "min_soc_li=li_minsoc*capacity_bat_li\n", + "min_soc_ni=ni_minsoc*capacity_bat_ni\n", + "\n", + "#usuable in the battery\n", + "usuable_battery_lea =capacity_bat_lea-min_soc_lea\n", + "usuable_battery_li =capacity_bat_li-min_soc_li\n", + "usuable_battery_ni =capacity_bat_ni-min_soc_ni" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#initializing battery variables\n", + "#lead acid battery\n", + "df[\"energy_storage_bat_lea\"] = np.zeros(len(df))\n", + "df[\"usuable_battery_lea\"] = np.zeros(len(df))\n", + "df[\"add_battery_lea\"] = np.zeros(len(df))\n", + "df[\"Sell_grid_battery_lea\"] = np.zeros(len(df))\n", + "df[\"usuable_battery_lea\"].iloc[0] = usuable_battery_lea\n", + "\n", + "#lithium ion battery\n", + "df[\"energy_storage_bat_li\"] = np.zeros(len(df))\n", + "df[\"usuable_battery_li\"] = np.zeros(len(df))\n", + "df[\"add_battery_li\"] = np.zeros(len(df))\n", + "df[\"Sell_grid_battery_li\"] = np.zeros(len(df))\n", + "df[\"usuable_battery_li\"].iloc[0] = usuable_battery_li\n", + "\n", + "#nickel iron battery\n", + "df[\"energy_storage_bat_ni\"] = np.zeros(len(df))\n", + "df[\"usuable_battery_ni\"] = np.zeros(len(df))\n", + "df[\"add_battery_ni\"] = np.zeros(len(df))\n", + "df[\"Sell_grid_battery_ni\"] = np.zeros(len(df))\n", + "df[\"usuable_battery_ni\"].iloc[0] = usuable_battery_ni" + ] + }, + { + "cell_type": "code", + "execution_count": 54, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + " #initial variables: Lead acid battery\n", + " if df[\"Delta\"].iloc[0] < 0:\n", + " if df[\"usuable_battery_lea\"].iloc[0] >= 0:\n", + " if -df[\"Delta\"].iloc[0] < df[\"usuable_battery_lea\"].iloc[0]:\n", + " \n", + " df[\"energy_storage_bat_lea\"].iloc[0] = capacity_bat_lea + df[\"Delta\"].iloc[0]\n", + " else:\n", + " df[\"energy_storage_bat_lea\"].iloc[0]=min_soc_lea\n", + " else:\n", + " df[\"energy_storage_bat_lea\"].iloc[0] = min_soc_lea\n", + " else:\n", + " df[\"usuable_battery_lea\"].iloc[1]=df[\"energy_storage_bat_lea\"].iloc[0]-min_soc_lea\n", + " df[\"energy_storage_bat_lea\"].iloc[0]=df[\"usuable_battery_lea\"].iloc[1]\n", + " \n", + " #initial variables: Lithium-Ion battery\n", + " if df[\"Delta\"].iloc[0] < 0:\n", + " if df[\"usuable_battery_li\"].iloc[0] >= 0:\n", + " if -df[\"Delta\"].iloc[0] < df[\"usuable_battery_li\"].iloc[0]:\n", + " \n", + " df[\"energy_storage_bat_li\"].iloc[0] = capacity_bat_li + df[\"Delta\"].iloc[0]\n", + " else:\n", + " df[\"energy_storage_bat_li\"].iloc[0]=min_soc_li\n", + " else:\n", + " df[\"energy_storage_bat_li\"].iloc[0] = min_soc_li\n", + " else:\n", + " df[\"usuable_battery_li\"].iloc[1]=df[\"energy_storage_bat_li\"].iloc[0]-min_soc_li\n", + " df[\"energy_storage_bat_li\"].iloc[0]=df[\"usuable_battery_li\"].iloc[1]\n", + " \n", + " #initial variables: Nickel-Iron battery\n", + " if df[\"Delta\"].iloc[0] < 0:\n", + " if df[\"usuable_battery_ni\"].iloc[0] >= 0:\n", + " if -df[\"Delta\"].iloc[0] < df[\"usuable_battery_ni\"].iloc[0]:\n", + " \n", + " df[\"energy_storage_bat_ni\"].iloc[0] = capacity_bat_ni + df[\"Delta\"].iloc[0]\n", + " else:\n", + " df[\"energy_storage_bat_ni\"].iloc[0]=min_soc_ni\n", + " else:\n", + " df[\"energy_storage_bat_ni\"].iloc[0] = min_soc_ni\n", + " else:\n", + " df[\"usuable_battery_ni\"].iloc[1]=df[\"energy_storage_bat_ni\"].iloc[0]-min_soc_ni\n", + " df[\"energy_storage_bat_ni\"].iloc[0]=df[\"usuable_battery_ni\"].iloc[1]" + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#energy storage battery\n", + "#Lead Acid Battery\n", + "for i, row in df[1:].iterrows():\n", + " old_value = df[\"energy_storage_bat_lea\"].iloc[i-1] \n", + " df[\"usuable_battery_lea\"].iloc[i] = old_value - min_soc_lea\n", + "\n", + " if row[\"Delta\"] < 0:\n", + " if row[\"usuable_battery_lea\"] > 0:\n", + " if -row[\"Delta\"] < row[\"usuable_battery_lea\"]:\n", + " df[\"energy_storage_bat_lea\"].iloc[i] = df[\"energy_storage_bat_lea\"].iloc[i-1] + row[\"Delta\"]\n", + " else:\n", + " df[\"energy_storage_bat_lea\"].iloc[i] = min_soc_lea\n", + " else:\n", + " df[\"energy_storage_bat_lea\"].iloc[i] = min_soc_lea\n", + " else:\n", + " if lea_efficacity*row[\"Delta\"] + df[\"energy_storage_bat_lea\"].iloc[i-1] <= capacity_bat_lea:\n", + " \n", + " df[\"energy_storage_bat_lea\"].iloc[i] = lea_efficacity*row[\"Delta\"] + df[\"energy_storage_bat_lea\"].iloc[i-1]\n", + " \n", + " else:\n", + " df[\"energy_storage_bat_lea\"].iloc[i] = capacity_bat_li\n", + "\n", + "#energy storage battery\n", + "#Lithium-Ion Battery\n", + "for i, row in df[1:].iterrows():\n", + " old_value = df[\"energy_storage_bat_li\"].iloc[i-1] \n", + " df[\"usuable_battery_li\"].iloc[i] = old_value - min_soc_li\n", + "\n", + " if row[\"Delta\"] < 0:\n", + " if row[\"usuable_battery_li\"] > 0:\n", + " if -row[\"Delta\"] < row[\"usuable_battery_li\"]:\n", + " df[\"energy_storage_bat_li\"].iloc[i] = df[\"energy_storage_bat_li\"].iloc[i-1] + row[\"Delta\"]\n", + " else:\n", + " df[\"energy_storage_bat_li\"].iloc[i] = min_soc_li\n", + " else:\n", + " df[\"energy_storage_bat_li\"].iloc[i] = min_soc_li\n", + " else:\n", + " if li_efficacity*row[\"Delta\"] + df[\"energy_storage_bat_li\"].iloc[i-1] <= capacity_bat_li:\n", + " \n", + " df[\"energy_storage_bat_li\"].iloc[i] = li_efficacity*row[\"Delta\"] + df[\"energy_storage_bat_li\"].iloc[i-1]\n", + " \n", + " else:\n", + " df[\"energy_storage_bat_li\"].iloc[i] = capacity_bat_li\n", + " \n", + "#energy storage battery\n", + "#Nickel-Iron Battery\n", + "for i, row in df[1:].iterrows():\n", + " old_value = df[\"energy_storage_bat_ni\"].iloc[i-1] \n", + " df[\"usuable_battery_ni\"].iloc[i] = old_value - min_soc_ni\n", + "\n", + " if row[\"Delta\"] < 0:\n", + " if row[\"usuable_battery_ni\"] > 0:\n", + " if -row[\"Delta\"] < row[\"usuable_battery_ni\"]:\n", + " df[\"energy_storage_bat_ni\"].iloc[i] = df[\"energy_storage_bat_ni\"].iloc[i-1] + row[\"Delta\"]\n", + " else:\n", + " df[\"energy_storage_bat_ni\"].iloc[i] = min_soc_ni\n", + " else:\n", + " df[\"energy_storage_bat_ni\"].iloc[i] = min_soc_ni\n", + " else:\n", + " if ni_efficacity*row[\"Delta\"] + df[\"energy_storage_bat_ni\"].iloc[i-1] <= capacity_bat_ni:\n", + " \n", + " df[\"energy_storage_bat_ni\"].iloc[i] = ni_efficacity*row[\"Delta\"] + df[\"energy_storage_bat_ni\"].iloc[i-1]\n", + " \n", + " else:\n", + " df[\"energy_storage_bat_ni\"].iloc[i] = capacity_bat_ni\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#add to the battery\n", + "#lead acid battery\n", + "df[\"add_battery_lea\"].iloc[0]=df[\"energy_storage_bat_lea\"].iloc[0]-capacity_bat_lea\n", + "for i, row in df[1:].iterrows():\n", + " df[\"add_battery_lea\"].iloc[i] = df[\"energy_storage_bat_lea\"].iloc[i]-df[\"energy_storage_bat_lea\"].iloc[i-1] \n", + "\n", + "#lithium ion battery\n", + "df[\"add_battery_li\"].iloc[0]=df[\"energy_storage_bat_li\"].iloc[0]-capacity_bat_li\n", + "for i, row in df[1:].iterrows():\n", + " df[\"add_battery_li\"].iloc[i] = df[\"energy_storage_bat_li\"].iloc[i]-df[\"energy_storage_bat_li\"].iloc[i-1] \n", + "\n", + "#nickel iron battery\n", + "df[\"add_battery_ni\"].iloc[0]=df[\"energy_storage_bat_ni\"].iloc[0]-capacity_bat_ni\n", + "for i, row in df[1:].iterrows():\n", + " df[\"add_battery_ni\"].iloc[i] = df[\"energy_storage_bat_ni\"].iloc[i]-df[\"energy_storage_bat_ni\"].iloc[i-1] \n" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#defining self consumption with battery\n", + "#lead acid battery\n", + "df[\"SelfConsumption_battery_lea\"] = df[\"SelfConsumption\"]-df[\"add_battery_lea\"].where(\n", + " df[\"add_battery_lea\"] < 0, other=0\n", + ")\n", + "#lithium ion battery\n", + "df[\"SelfConsumption_battery_li\"] = df[\"SelfConsumption\"]-df[\"add_battery_li\"].where(\n", + " df[\"add_battery_li\"] < 0, other=0\n", + ")\n", + "#nickel iron battery\n", + "df[\"SelfConsumption_battery_ni\"] = df[\"SelfConsumption\"]-df[\"add_battery_ni\"].where(\n", + " df[\"add_battery_ni\"] < 0, other=0\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + " #initial variable: sell grid battery\n", + " #lead acid battery\n", + " if df[\"Delta\"].iloc[0] > 0:\n", + " \n", + " df[\"Sell_grid_battery_lea\"].iloc[0] = df[\"Delta\"].iloc[0]\n", + " else: \n", + " df[\"Sell_grid_battery_lea\"].iloc[0] = 0\n", + "\n", + " #lithium ion battery\n", + " if df[\"Delta\"].iloc[0] > 0:\n", + " \n", + " df[\"Sell_grid_battery_li\"].iloc[0] = df[\"Delta\"].iloc[0]\n", + " else: \n", + " df[\"Sell_grid_battery_li\"].iloc[0] = 0\n", + " #nickel iron battery\n", + " if df[\"Delta\"].iloc[0] > 0:\n", + " \n", + " df[\"Sell_grid_battery_ni\"].iloc[0] = df[\"Delta\"].iloc[0]\n", + " else: \n", + " df[\"Sell_grid_battery_ni\"].iloc[0] = 0" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#reinjection in the grid with battery\n", + "#lead acid battery\n", + "for i, row in df[1:].iterrows():\n", + "\n", + " if row[\"Delta\"]+df[\"energy_storage_bat_lea\"].iloc[i-1] > capacity_bat_lea:\n", + " df[\"Sell_grid_battery_lea\"].iloc[i] = df[\"energy_storage_bat_lea\"].iloc[i-1] + row[\"Delta\"]-capacity_bat_lea\n", + " else:\n", + " df[\"Sell_grid_battery_lea\"].iloc[i] =0\n", + " \n", + "#lithium ion battery\n", + "for i, row in df[1:].iterrows():\n", + "\n", + " if row[\"Delta\"]+df[\"energy_storage_bat_li\"].iloc[i-1] > capacity_bat_li:\n", + " df[\"Sell_grid_battery_li\"].iloc[i] = df[\"energy_storage_bat_li\"].iloc[i-1] + row[\"Delta\"]-capacity_bat_li\n", + " else:\n", + " df[\"Sell_grid_battery_li\"].iloc[i] =0\n", + "\n", + "#nickel iron battery\n", + "for i, row in df[1:].iterrows():\n", + "\n", + " if row[\"Delta\"]+df[\"energy_storage_bat_ni\"].iloc[i-1] > capacity_bat_ni:\n", + " df[\"Sell_grid_battery_ni\"].iloc[i] = df[\"energy_storage_bat_ni\"].iloc[i-1] + row[\"Delta\"]-capacity_bat_ni\n", + " else:\n", + " df[\"Sell_grid_battery_ni\"].iloc[i] =0" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#buy from grid with battery\n", + "\n", + "#lead acid battery\n", + "df[\"Buy_grid_battery_lea\"] = ((-1)*(df[\"Delta\"]+df[\"usuable_battery_lea\"])).where(\n", + " (df[\"Delta\"] < 0) & ((-1)*df[\"Delta\"] > df[\"usuable_battery_lea\"]), other=0\n", + ")\n", + "#lithium ion battery\n", + "df[\"Buy_grid_battery_li\"] = ((-1)*(df[\"Delta\"]+df[\"usuable_battery_li\"])).where(\n", + " (df[\"Delta\"] < 0) & ((-1)*df[\"Delta\"] > df[\"usuable_battery_li\"]), other=0\n", + ")\n", + "#nickel iron battery\n", + "df[\"Buy_grid_battery_ni\"] = ((-1)*(df[\"Delta\"]+df[\"usuable_battery_ni\"])).where(\n", + " (df[\"Delta\"] < 0) & ((-1)*df[\"Delta\"] > df[\"usuable_battery_ni\"]), other=0\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#Calculation over a year\n", + "#lead acid battery\n", + "buying_PV_bat_lea=sum(df[\"Buy_grid_battery_lea\"])\n", + "selling_PV_bat_lea=sum(df[\"Sell_grid_battery_lea\"])\n", + "self_conso_PV_bat=sum(df[\"SelfConsumption_battery_lea\"])\n", + "\n", + "#lithium ion battery\n", + "buying_PV_bat_li=sum(df[\"Buy_grid_battery_li\"])\n", + "selling_PV_bat_li=sum(df[\"Sell_grid_battery_li\"])\n", + "self_conso_PV_bat_li=sum(df[\"SelfConsumption_battery_li\"])\n", + "\n", + "#nickel iron battery\n", + "buying_PV_bat_ni=sum(df[\"Buy_grid_battery_ni\"])\n", + "selling_PV_bat_ni=sum(df[\"Sell_grid_battery_ni\"])\n", + "self_conso_PV_bat_ni=sum(df[\"SelfConsumption_battery_ni\"])" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#annualizing the maintenance cost, selling price and buying price with battery\n", + "#lead acid battery\n", + "def maintenancebat_lea(n):\n", + " maintenance_cost_lea=0\n", + " for k in range(1,n+1):\n", + " maintenance_cost_lea += (capacity_bat_lea*maintenance_battery_lea)/(1+0.16)**k\n", + " return maintenance_cost_lea\n", + "\n", + "def selling_bat_lea(n):\n", + " selling_cost_bat_lea=0\n", + " for k in range(1,n+1):\n", + " selling_cost_bat_lea += (selling_PV_bat_lea*selling_price)*(1+0.02)**k\n", + " return selling_cost_bat_lea\n", + "\n", + "def buying_bat_lea(n):\n", + " buying_cost_bat_lea=0\n", + " for k in range(1,n+1):\n", + " buying_cost_bat_lea += (buying_PV_bat_lea*buying_price)*(1+0.02)**k\n", + " return buying_cost_bat_lea\n", + "\n", + "#lithium ion battery\n", + "def maintenancebat_li(n):\n", + " maintenance_cost_li=0\n", + " for k in range(1,n+1):\n", + " maintenance_cost_li += (capacity_bat_li*maintenance_battery_li)/(1+0.08)**k\n", + " return maintenance_cost_li\n", + "\n", + "def selling_bat_li(n):\n", + " selling_cost_bat_li=0\n", + " for k in range(1,n+1):\n", + " selling_cost_bat_li += (selling_PV_bat_li*selling_price)*(1+0.02)**k\n", + " return selling_cost_bat_li\n", + "\n", + "def buying_bat_li(n):\n", + " buying_cost_bat_li=0\n", + " for k in range(1,n+1):\n", + " buying_cost_bat_li += (buying_PV_bat_li*buying_price)*(1+0.02)**k\n", + " return buying_cost_bat_li\n", + "\n", + "#nickel iron battery\n", + "def maintenancebat_ni(n):\n", + " maintenance_cost_ni=0\n", + " for k in range(1,n+1):\n", + " maintenance_cost_ni += (capacity_bat_ni*maintenance_battery_ni)/(1+0.04)**k\n", + " return maintenance_cost_ni\n", + "\n", + "def selling_bat_ni(n):\n", + " selling_cost_bat_ni=0\n", + " for k in range(1,n+1):\n", + " selling_cost_bat_ni += (selling_PV_bat_ni*selling_price)*(1+0.02)**k\n", + " return selling_cost_bat_ni\n", + "\n", + "def buying_bat_ni(n):\n", + " buying_cost_bat_ni=0\n", + " for k in range(1,n+1):\n", + " buying_cost_bat_ni += (buying_PV_bat_ni*buying_price)*(1+0.02)**k\n", + " return buying_cost_bat_ni" + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#NPV calculation with solar PV and battery\n", + "#lead acid battery\n", + "cost_bat_lea=round(capacity_bat_lea*lea_battery_price,2)\n", + "\n", + "total_cost_PV_leabat=total_cost+3*cost_bat_lea+2*maintenancebat_lea(lea_lifetime_battery-1)+maintenancebat_lea(lea_lifetime_battery-2)\n", + "\n", + "sewage_cost_lea=(cost_bat_lea/(1+0.076)**(lea_lifetime_battery-1))/3\n", + "\n", + "selling_cost_tot_lea=selling_bat_lea(lifetime_SP-1)+(selling_PV_bat_lea*selling_price)\n", + "\n", + "buying_cost_tot_lea=buying_bat_lea(lifetime_SP-1)+(buying_PV_bat_lea*buying_price)\n", + "\n", + "NPV_bat_lea=(-total_cost_PV_leabat-buying_cost_tot_lea+selling_cost_tot_lea+sewage_cost_lea)\n", + "\n", + "#lithium ion battery\n", + "cost_bat_li=round(capacity_bat_li*li_battery_price,2)\n", + "\n", + "total_cost_PV_libat=total_cost+2*cost_bat_li+maintenancebat_li(li_lifetime_battery-1)+maintenancebat_li(li_lifetime_battery-10)\n", + "\n", + "sewage_cost_li=(cost_bat_li/(1+0.076)**(li_lifetime_battery-1))/3\n", + "\n", + "selling_cost_tot_li=selling_bat_li(lifetime_SP-1)+(selling_PV_bat_li*selling_price)\n", + "\n", + "buying_cost_tot_li=buying_bat_li(lifetime_SP-1)+(buying_PV_bat_li*buying_price)\n", + "\n", + "NPV_bat_li=(-total_cost_PV_libat-buying_cost_tot_li+selling_cost_tot_li+sewage_cost_li)\n", + "\n", + "#nickel iron battery\n", + "cost_bat_ni=round(capacity_bat_ni*ni_battery_price,2)\n", + "\n", + "total_cost_PV_nibat=total_cost+cost_bat_ni+maintenancebat_ni(lifetime_SP-1)\n", + "\n", + "sewage_cost_ni=(cost_bat_ni/(1+0.076)**(ni_lifetime_battery-11))/3\n", + "\n", + "selling_cost_tot_ni=selling_bat_ni(lifetime_SP-1)+(selling_PV_bat_ni*selling_price)\n", + "\n", + "buying_cost_tot_ni=buying_bat_ni(lifetime_SP-1)+(buying_PV_bat_ni*buying_price)\n", + "\n", + "NPV_bat_ni=(-total_cost_PV_nibat-buying_cost_tot_ni+selling_cost_tot_ni+sewage_cost_ni)" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#SOLAR THERMAL\n", + "#defining solar thermal generation\n", + "\n", + "df[\"Generation_ST\"] = df[\"Irradiation\"]/1000*solar_thermal_efficacity*percentage_ST\n", + "\n", + "#defining the difference between solar thermal generation and heating demand\n", + "df[\"Delta_ST\"]=df[\"Generation_ST\"] - df[\"Heating\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#initializing variables\n", + "capacity_bo=capacity_boiler*percentage_ST\n", + "df[\"energy_storage_boiler\"] = np.zeros(len(df))\n", + "df[\"usuable_boiler\"] = np.zeros(len(df))\n", + "df[\"add_boiler\"] = np.zeros(len(df))\n", + "df[\"usuable_boiler\"].iloc[0] = 0" + ] + }, + { + "cell_type": "code", + "execution_count": 66, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#energy storage battery\n", + "#Lead Acid Battery\n", + "for i, row in df[1:].iterrows():\n", + " old_value = df[\"energy_storage_boiler\"].iloc[i-1] \n", + " df[\"usuable_boiler\"].iloc[i] = old_value\n", + "\n", + " if row[\"Delta_ST\"] < 0:\n", + " if row[\"usuable_boiler\"] > 0:\n", + " if -row[\"Delta_ST\"] < row[\"usuable_boiler\"]:\n", + " df[\"energy_storage_boiler\"].iloc[i] = df[\"energy_storage_boiler\"].iloc[i-1] + row[\"Delta_ST\"]\n", + " else:\n", + " df[\"energy_storage_boiler\"].iloc[i] = 0\n", + " else:\n", + " df[\"energy_storage_boiler\"].iloc[i] = 0\n", + " else:\n", + " if boiler_efficacity*row[\"Delta_ST\"] + df[\"energy_storage_boiler\"].iloc[i-1] <= capacity_bo:\n", + " \n", + " df[\"energy_storage_boiler\"].iloc[i] = boiler_efficacity*row[\"Delta_ST\"] + df[\"energy_storage_boiler\"].iloc[i-1]\n", + " \n", + " else:\n", + " df[\"energy_storage_boiler\"].iloc[i] = capacity_bo" + ] + }, + { + "cell_type": "code", + "execution_count": 67, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#add to the boiler\n", + "for i, row in df[1:].iterrows():\n", + " df[\"add_boiler\"].iloc[i] = df[\"energy_storage_boiler\"].iloc[i]-df[\"energy_storage_boiler\"].iloc[i-1] \n" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#reinjection in the grid\n", + "\n", + "df[\"Reinjection_ST\"] = (df[\"Delta_ST\"]).where(\n", + " (df[\"Delta_ST\"] > 0) & (df[\"usuable_boiler\"] == capacity_bo), other=0\n", + ")\n", + "\n", + "#Buy from grid\n", + "df[\"Buygrid_ST\"] = ((-1)*(df[\"usuable_boiler\"]+df[\"Delta_ST\"])).where(\n", + " (df[\"Delta_ST\"] < 0) & (df[\"usuable_boiler\"]+df[\"Delta_ST\"] <0), other=0\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#Calculation over a year: Solar thermal\n", + "buying_ST=sum(df[\"Buygrid_ST\"])\n", + "selling_ST=sum(df[\"Reinjection_ST\"])\n", + "heating_demand=sum(df[\"Heating\"])\n", + "#capacity boiler\n", + "capacity_boiler_m3=(capacity_bo*3600)/(4.2*60*1000)\n", + "\n", + "#area solar thermal\n", + "max_peak_thermal=max(df[\"Generation_ST\"])\n", + "area_solar_thermal=max_peak_thermal/max_global_irradiance\n", + "\n", + "#autonomy level\n", + "autonomy_level_ST=round((heating_demand-buying_ST)/heating_demand*100,0)" + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#COSTS\n", + "#thermal grid installation cost\n", + "thermal_grid=thermal_grid_price*area_solar_thermal\n", + "#boiler installation cost\n", + "boiler_prix=boiler_price*capacity_boiler_m3\n", + "#taxes\n", + "subvention_ST=round(0.16*thermal_grid,2)\n", + "deduction_impot_ST=round(thermal_grid*0.2,2)\n", + "#maintenance cost boiler\n", + "maintenance_boiler=351.7*(boiler_lifetime+3)\n", + "#maintenance cost solar thermal\n", + "maintenance_ST=maintenance_solarthermal*(thermal_grid_lifetime-1)" + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def selling_gas(n):\n", + " selling_cost_gas=0\n", + " for k in range(1,n+1):\n", + " selling_cost_gas += (selling_ST*ng_selling_price)*(1+0.02)**k\n", + " return selling_cost_gas\n", + "\n", + "def buying_gas(n):\n", + " buying_cost_gas=0\n", + " for k in range(1,n+1):\n", + " buying_cost_gas += (buying_ST*ng_buying_price)*(1+0.02)**k\n", + " return buying_cost_gas" + ] + }, + { + "cell_type": "code", + "execution_count": 72, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#NPV and LCOE calculation\n", + "#Investment solar thermal\n", + "Investment_ST=maintenance_boiler+maintenance_ST+thermal_grid+2*boiler_prix-subvention_ST-deduction_impot_ST\n", + "\n", + "#Solar Panel , Lead-acid battery + Solar thermal\n", + "NPV_ST_SP_lea=+selling_gas(thermal_grid_lifetime-1)+(selling_ST*ng_selling_price)-(buying_ST*ng_buying_price)-buying_gas(thermal_grid_lifetime-1)-Investment_ST+NPV_bat_lea\n", + "LCOE_ST_SP_lea=-NPV_ST_SP_lea/(20*(total_Demand+heating_demand))\n", + "\n", + "#Solar Panel , Lithium Ion battery + Solar thermal\n", + "NPV_ST_SP_li=+selling_gas(thermal_grid_lifetime-1)+(selling_ST*ng_selling_price)-(buying_ST*ng_buying_price)-buying_gas(thermal_grid_lifetime-1)-Investment_ST+NPV_bat_li\n", + "LCOE_ST_SP_li=-NPV_ST_SP_li/(20*(total_Demand+heating_demand))\n", + "\n", + "#Solar Panel , Nickel Iron battery + Solar thermal\n", + "NPV_ST_SP_ni=+selling_gas(thermal_grid_lifetime-1)+(selling_ST*ng_selling_price)-(buying_ST*ng_buying_price)-buying_gas(thermal_grid_lifetime-1)-Investment_ST+NPV_bat_ni\n", + "LCOE_ST_SP_ni=-NPV_ST_SP_ni/(20*(total_Demand+heating_demand))\n" + ] + }, + { + "cell_type": "code", + "execution_count": 73, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#HEAT PUMP\n", + "#Electricity demand of the heat pump\n", + "df[\"Electrical_Demand_HeatPump\"] = df[\"Heating\"]/HP_COP\n", + "#total electricity demand by adding the electricity demand of the heat pump\n", + "df[\"Total_Electric_Demand_HP\"]=df[\"Electrical_Demand_HeatPump\"]+df[\"Demand\"]/1000\n", + "#difference between generation and total electricity demand\n", + "df[\"Delta_HP\"]=df[\"Generation\"] - df[\"Total_Electric_Demand_HP\"]\n", + "#total demand over a year\n", + "total_Demand_HP=sum(df[\"Total_Electric_Demand_HP\"])\n", + "#capacity of the heat pump\n", + "capacity_HP=max_peak_thermal/HP_COP\n", + "\n", + "#initializing battery variables\n", + "#lead acid battery\n", + "df[\"energy_storage_bat_lea_HP\"] = np.zeros(len(df))\n", + "df[\"usuable_battery_lea_HP\"] = np.zeros(len(df))\n", + "df[\"add_battery_lea_HP\"] = np.zeros(len(df))\n", + "df[\"Sell_grid_battery_lea_HP\"] = np.zeros(len(df))\n", + "df[\"usuable_battery_lea_HP\"].iloc[0] = usuable_battery_lea\n", + "\n", + "#lithium ion battery\n", + "df[\"energy_storage_bat_li_HP\"] = np.zeros(len(df))\n", + "df[\"usuable_battery_li_HP\"] = np.zeros(len(df))\n", + "df[\"add_battery_li_HP\"] = np.zeros(len(df))\n", + "df[\"Sell_grid_battery_li_HP\"] = np.zeros(len(df))\n", + "df[\"usuable_battery_li_HP\"].iloc[0] = usuable_battery_li\n", + "\n", + "#nickel iron battery\n", + "df[\"energy_storage_bat_ni_HP\"] = np.zeros(len(df))\n", + "df[\"usuable_battery_ni_HP\"] = np.zeros(len(df))\n", + "df[\"add_battery_ni_HP\"] = np.zeros(len(df))\n", + "df[\"Sell_grid_battery_ni_HP\"] = np.zeros(len(df))\n", + "df[\"usuable_battery_ni_HP\"].iloc[0] = usuable_battery_ni\n" + ] + }, + { + "cell_type": "code", + "execution_count": 74, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + " #initial variables: Lead acid battery\n", + " if df[\"Delta_HP\"].iloc[0] < 0:\n", + " if df[\"usuable_battery_lea_HP\"].iloc[0] >= 0:\n", + " if -df[\"Delta_HP\"].iloc[0] < df[\"usuable_battery_lea_HP\"].iloc[0]:\n", + " \n", + " df[\"energy_storage_bat_lea_HP\"].iloc[0] = capacity_bat_lea + df[\"Delta_HP\"].iloc[0]\n", + " else:\n", + " df[\"energy_storage_bat_lea_HP\"].iloc[0]=min_soc_lea\n", + " else:\n", + " df[\"energy_storage_bat_lea_HP\"].iloc[0] = min_soc_lea\n", + " else:\n", + " df[\"usuable_battery_lea_HP\"].iloc[1]=df[\"energy_storage_bat_lea_HP\"].iloc[0]-min_soc_lea\n", + " df[\"energy_storage_bat_lea_HP\"].iloc[0]=df[\"usuable_battery_lea_HP\"].iloc[1]\n", + " \n", + " #initial variables: Lithium-Ion battery\n", + " if df[\"Delta_HP\"].iloc[0] < 0:\n", + " if df[\"usuable_battery_li_HP\"].iloc[0] >= 0:\n", + " if -df[\"Delta_HP\"].iloc[0] < df[\"usuable_battery_li_HP\"].iloc[0]:\n", + " \n", + " df[\"energy_storage_bat_li_HP\"].iloc[0] = capacity_bat_li + df[\"Delta_HP\"].iloc[0]\n", + " else:\n", + " df[\"energy_storage_bat_li_HP\"].iloc[0]=min_soc_li\n", + " else:\n", + " df[\"energy_storage_bat_li_HP\"].iloc[0] = min_soc_li\n", + " else:\n", + " df[\"usuable_battery_li_HP\"].iloc[1]=df[\"energy_storage_bat_li_HP\"].iloc[0]-min_soc_li\n", + " df[\"energy_storage_bat_li_HP\"].iloc[0]=df[\"usuable_battery_li_HP\"].iloc[1]\n", + " \n", + " #initial variables: Nickel-Iron battery\n", + " if df[\"Delta_HP\"].iloc[0] < 0:\n", + " if df[\"usuable_battery_ni_HP\"].iloc[0] >= 0:\n", + " if -df[\"Delta_HP\"].iloc[0] < df[\"usuable_battery_ni_HP\"].iloc[0]:\n", + " \n", + " df[\"energy_storage_bat_ni_HP\"].iloc[0] = capacity_bat_ni + df[\"Delta_HP\"].iloc[0]\n", + " else:\n", + " df[\"energy_storage_bat_ni_HP\"].iloc[0]=min_soc_ni\n", + " else:\n", + " df[\"energy_storage_bat_ni_HP\"].iloc[0] = min_soc_ni\n", + " else:\n", + " df[\"usuable_battery_ni_HP\"].iloc[1]=df[\"energy_storage_bat_ni_HP\"].iloc[0]-min_soc_ni\n", + " df[\"energy_storage_bat_ni_HP\"].iloc[0]=df[\"usuable_battery_ni_HP\"].iloc[1]\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#energy storage battery\n", + "#Lead Acid Battery\n", + "for i, row in df[1:].iterrows():\n", + " old_value = df[\"energy_storage_bat_lea_HP\"].iloc[i-1] \n", + " df[\"usuable_battery_lea_HP\"].iloc[i] = old_value - min_soc_lea\n", + "\n", + " if row[\"Delta_HP\"] < 0:\n", + " if row[\"usuable_battery_lea_HP\"] > 0:\n", + " if -row[\"Delta_HP\"] < row[\"usuable_battery_lea_HP\"]:\n", + " df[\"energy_storage_bat_lea_HP\"].iloc[i] = df[\"energy_storage_bat_lea_HP\"].iloc[i-1] + row[\"Delta_HP\"]\n", + " else:\n", + " df[\"energy_storage_bat_lea_HP\"].iloc[i] = min_soc_lea\n", + " else:\n", + " df[\"energy_storage_bat_lea_HP\"].iloc[i] = min_soc_lea\n", + " else:\n", + " if lea_efficacity*row[\"Delta_HP\"] + df[\"energy_storage_bat_lea_HP\"].iloc[i-1] <= capacity_bat_lea:\n", + " \n", + " df[\"energy_storage_bat_lea_HP\"].iloc[i] = lea_efficacity*row[\"Delta_HP\"] + df[\"energy_storage_bat_lea_HP\"].iloc[i-1]\n", + " \n", + " else:\n", + " df[\"energy_storage_bat_lea_HP\"].iloc[i] = capacity_bat_li\n", + "\n", + "#energy storage battery\n", + "#Lithium-Ion Battery\n", + "for i, row in df[1:].iterrows():\n", + " old_value = df[\"energy_storage_bat_li_HP\"].iloc[i-1] \n", + " df[\"usuable_battery_li_HP\"].iloc[i] = old_value - min_soc_li\n", + "\n", + " if row[\"Delta_HP\"] < 0:\n", + " if row[\"usuable_battery_li_HP\"] > 0:\n", + " if -row[\"Delta_HP\"] < row[\"usuable_battery_li_HP\"]:\n", + " df[\"energy_storage_bat_li_HP\"].iloc[i] = df[\"energy_storage_bat_li_HP\"].iloc[i-1] + row[\"Delta_HP\"]\n", + " else:\n", + " df[\"energy_storage_bat_li_HP\"].iloc[i] = min_soc_li\n", + " else:\n", + " df[\"energy_storage_bat_li_HP\"].iloc[i] = min_soc_li\n", + " else:\n", + " if li_efficacity*row[\"Delta_HP\"] + df[\"energy_storage_bat_li_HP\"].iloc[i-1] <= capacity_bat_li:\n", + " \n", + " df[\"energy_storage_bat_li_HP\"].iloc[i] = li_efficacity*row[\"Delta_HP\"] + df[\"energy_storage_bat_li_HP\"].iloc[i-1]\n", + " \n", + " else:\n", + " df[\"energy_storage_bat_li_HP\"].iloc[i] = capacity_bat_li\n", + " \n", + "#energy storage battery\n", + "#Nickel-Iron Battery\n", + "for i, row in df[1:].iterrows():\n", + " old_value = df[\"energy_storage_bat_ni_HP\"].iloc[i-1] \n", + " df[\"usuable_battery_ni_HP\"].iloc[i] = old_value - min_soc_ni\n", + "\n", + " if row[\"Delta_HP\"] < 0:\n", + " if row[\"usuable_battery_ni_HP\"] > 0:\n", + " if -row[\"Delta_HP\"] < row[\"usuable_battery_ni_HP\"]:\n", + " df[\"energy_storage_bat_ni_HP\"].iloc[i] = df[\"energy_storage_bat_ni_HP\"].iloc[i-1] + row[\"Delta_HP\"]\n", + " else:\n", + " df[\"energy_storage_bat_ni_HP\"].iloc[i] = min_soc_ni\n", + " else:\n", + " df[\"energy_storage_bat_ni_HP\"].iloc[i] = min_soc_ni\n", + " else:\n", + " if ni_efficacity*row[\"Delta_HP\"] + df[\"energy_storage_bat_ni_HP\"].iloc[i-1] <= capacity_bat_ni:\n", + " \n", + " df[\"energy_storage_bat_ni_HP\"].iloc[i] = ni_efficacity*row[\"Delta_HP\"] + df[\"energy_storage_bat_ni_HP\"].iloc[i-1]\n", + " \n", + " else:\n", + " df[\"energy_storage_bat_ni_HP\"].iloc[i] = capacity_bat_ni\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#add to the battery\n", + "#lead acid battery\n", + "df[\"add_battery_lea_HP\"].iloc[0]=df[\"energy_storage_bat_lea_HP\"].iloc[0]-capacity_bat_lea\n", + "for i, row in df[1:].iterrows():\n", + " df[\"add_battery_lea_HP\"].iloc[i] = df[\"energy_storage_bat_lea_HP\"].iloc[i]-df[\"energy_storage_bat_lea_HP\"].iloc[i-1] \n", + "\n", + "#lithium ion battery\n", + "df[\"add_battery_li_HP\"].iloc[0]=df[\"energy_storage_bat_li_HP\"].iloc[0]-capacity_bat_li\n", + "for i, row in df[1:].iterrows():\n", + " df[\"add_battery_li_HP\"].iloc[i] = df[\"energy_storage_bat_li_HP\"].iloc[i]-df[\"energy_storage_bat_li_HP\"].iloc[i-1] \n", + "\n", + "#nickel iron battery\n", + "df[\"add_battery_ni_HP\"].iloc[0]=df[\"energy_storage_bat_ni_HP\"].iloc[0]-capacity_bat_ni\n", + "for i, row in df[1:].iterrows():\n", + " df[\"add_battery_ni_HP\"].iloc[i] = df[\"energy_storage_bat_ni_HP\"].iloc[i]-df[\"energy_storage_bat_ni_HP\"].iloc[i-1] \n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#defining self consumption with battery\n", + "#lead acid battery\n", + "df[\"SelfConsumption_battery_lea_HP\"] = df[\"SelfConsumption\"]-df[\"add_battery_lea_HP\"].where(\n", + " df[\"add_battery_lea_HP\"] < 0, other=0\n", + ")\n", + "#lithium ion battery\n", + "df[\"SelfConsumption_battery_li_HP\"] = df[\"SelfConsumption\"]-df[\"add_battery_li_HP\"].where(\n", + " df[\"add_battery_li_HP\"] < 0, other=0\n", + ")\n", + "#nickel iron battery\n", + "df[\"SelfConsumption_battery_ni_HP\"] = df[\"SelfConsumption\"]-df[\"add_battery_ni_HP\"].where(\n", + " df[\"add_battery_ni_HP\"] < 0, other=0\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + " #initial variable: sell grid battery\n", + " #lead acid battery\n", + " if df[\"Delta_HP\"].iloc[0] > 0:\n", + " \n", + " df[\"Sell_grid_battery_lea_HP\"].iloc[0] = df[\"Delta_HP\"].iloc[0]\n", + " else: \n", + " df[\"Sell_grid_battery_lea_HP\"].iloc[0] = 0\n", + "\n", + " #lithium ion battery\n", + " if df[\"Delta_HP\"].iloc[0] > 0:\n", + " \n", + " df[\"Sell_grid_battery_li_HP\"].iloc[0] = df[\"Delta_HP\"].iloc[0]\n", + " else: \n", + " df[\"Sell_grid_battery_li_HP\"].iloc[0] = 0\n", + " #nickel iron battery\n", + " if df[\"Delta_HP\"].iloc[0] > 0:\n", + " \n", + " df[\"Sell_grid_battery_ni_HP\"].iloc[0] = df[\"Delta_HP\"].iloc[0]\n", + " else: \n", + " df[\"Sell_grid_battery_ni_HP\"].iloc[0] = 0" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#reinjection in the grid with battery\n", + "#lead acid battery\n", + "for i, row in df[1:].iterrows():\n", + "\n", + " if row[\"Delta_HP\"]+df[\"energy_storage_bat_lea_HP\"].iloc[i-1] > capacity_bat_lea:\n", + " df[\"Sell_grid_battery_lea_HP\"].iloc[i] = df[\"energy_storage_bat_lea_HP\"].iloc[i-1] + row[\"Delta_HP\"]-capacity_bat_lea\n", + " else:\n", + " df[\"Sell_grid_battery_lea_HP\"].iloc[i] =0\n", + " \n", + "#lithium ion battery\n", + "for i, row in df[1:].iterrows():\n", + "\n", + " if row[\"Delta_HP\"]+df[\"energy_storage_bat_li_HP\"].iloc[i-1] > capacity_bat_li:\n", + " df[\"Sell_grid_battery_li_HP\"].iloc[i] = df[\"energy_storage_bat_li_HP\"].iloc[i-1] + row[\"Delta_HP\"]-capacity_bat_li\n", + " else:\n", + " df[\"Sell_grid_battery_li_HP\"].iloc[i] =0\n", + "\n", + "#nickel iron battery\n", + "for i, row in df[1:].iterrows():\n", + "\n", + " if row[\"Delta_HP\"]+df[\"energy_storage_bat_ni_HP\"].iloc[i-1] > capacity_bat_ni:\n", + " df[\"Sell_grid_battery_ni_HP\"].iloc[i] = df[\"energy_storage_bat_ni_HP\"].iloc[i-1] + row[\"Delta_HP\"]-capacity_bat_ni\n", + " else:\n", + " df[\"Sell_grid_battery_ni_HP\"].iloc[i] =0" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#buy from grid with battery\n", + "\n", + "#lead acid battery\n", + "df[\"Buy_grid_battery_lea_HP\"] = ((-1)*(df[\"Delta_HP\"]+df[\"usuable_battery_lea_HP\"])).where(\n", + " (df[\"Delta_HP\"] < 0) & ((-1)*df[\"Delta_HP\"] > df[\"usuable_battery_lea_HP\"]), other=0\n", + ")\n", + "#lithium ion battery\n", + "df[\"Buy_grid_battery_li_HP\"] = ((-1)*(df[\"Delta_HP\"]+df[\"usuable_battery_li_HP\"])).where(\n", + " (df[\"Delta_HP\"] < 0) & ((-1)*df[\"Delta_HP\"] > df[\"usuable_battery_li_HP\"]), other=0\n", + ")\n", + "#nickel iron battery\n", + "df[\"Buy_grid_battery_ni_HP\"] = ((-1)*(df[\"Delta_HP\"]+df[\"usuable_battery_ni_HP\"])).where(\n", + " (df[\"Delta_HP\"] < 0) & ((-1)*df[\"Delta_HP\"] > df[\"usuable_battery_ni_HP\"]), other=0\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#Calculation over a year\n", + "#lead acid battery\n", + "buying_PV_bat_lea_HP=sum(df[\"Buy_grid_battery_lea_HP\"])\n", + "selling_PV_bat_lea_HP=sum(df[\"Sell_grid_battery_lea_HP\"])\n", + "self_conso_PV_bat_HP=sum(df[\"SelfConsumption_battery_lea_HP\"])\n", + "\n", + "#lithium ion battery\n", + "buying_PV_bat_li_HP=sum(df[\"Buy_grid_battery_li_HP\"])\n", + "selling_PV_bat_li_HP=sum(df[\"Sell_grid_battery_li_HP\"])\n", + "self_conso_PV_bat_li_HP=sum(df[\"SelfConsumption_battery_li_HP\"])\n", + "\n", + "#nickel iron battery\n", + "buying_PV_bat_ni_HP=sum(df[\"Buy_grid_battery_ni_HP\"])\n", + "selling_PV_bat_ni_HP=sum(df[\"Sell_grid_battery_ni_HP\"])\n", + "self_conso_PV_bat_ni_HP=sum(df[\"SelfConsumption_battery_ni_HP\"])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#annualizing the maintenance cost, selling price and buying price with battery\n", + "#lead acid battery\n", + "\n", + "def selling_bat_lea_HP(n):\n", + " selling_cost_bat_lea=0\n", + " for k in range(1,n+1):\n", + " selling_cost_bat_lea += (selling_PV_bat_lea_HP*selling_price)*(1+0.02)**k\n", + " return selling_cost_bat_lea\n", + "\n", + "def buying_bat_lea_HP(n):\n", + " buying_cost_bat_lea=0\n", + " for k in range(1,n+1):\n", + " buying_cost_bat_lea += (buying_PV_bat_lea_HP*buying_price)*(1+0.02)**k\n", + " return buying_cost_bat_lea\n", + "\n", + "#lithium ion battery\n", + "\n", + "def selling_bat_li_HP(n):\n", + " selling_cost_bat_li=0\n", + " for k in range(1,n+1):\n", + " selling_cost_bat_li += (selling_PV_bat_li_HP*selling_price)*(1+0.02)**k\n", + " return selling_cost_bat_li\n", + "\n", + "def buying_bat_li_HP(n):\n", + " buying_cost_bat_li=0\n", + " for k in range(1,n+1):\n", + " buying_cost_bat_li += (buying_PV_bat_li_HP*buying_price)*(1+0.02)**k\n", + " return buying_cost_bat_li\n", + "\n", + "#nickel iron battery\n", + "\n", + "def selling_bat_ni_HP(n):\n", + " selling_cost_bat_ni=0\n", + " for k in range(1,n+1):\n", + " selling_cost_bat_ni += (selling_PV_bat_ni_HP*selling_price)*(1+0.02)**k\n", + " return selling_cost_bat_ni\n", + "\n", + "def buying_bat_ni_HP(n):\n", + " buying_cost_bat_ni=0\n", + " for k in range(1,n+1):\n", + " buying_cost_bat_ni += (buying_PV_bat_ni_HP*buying_price)*(1+0.02)**k\n", + " return buying_cost_bat_ni" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#NPV calculation with solar PV , Battery and Heat Pump\n", + "#lead acid battery\n", + "cost_HP=capacity_HP*heatpump_price\n", + "selling_cost_tot_lea_HP=selling_bat_lea_HP(lifetime_SP-1)+(selling_PV_bat_lea_HP*selling_price)\n", + "\n", + "buying_cost_tot_lea_HP=buying_bat_lea_HP(lifetime_SP-1)+(buying_PV_bat_lea_HP*buying_price)\n", + "\n", + "NPV_bat_lea_HP=(-total_cost_PV_leabat-buying_cost_tot_lea_HP-2*cost_HP+selling_cost_tot_lea_HP+sewage_cost_lea)\n", + "\n", + "#lithium ion battery\n", + "\n", + "selling_cost_tot_li_HP=selling_bat_li_HP(lifetime_SP-1)+(selling_PV_bat_li_HP*selling_price)\n", + "\n", + "buying_cost_tot_li_HP=buying_bat_li_HP(lifetime_SP-1)+(buying_PV_bat_li_HP*buying_price)\n", + "\n", + "NPV_bat_li_HP=(-total_cost_PV_libat-buying_cost_tot_li_HP-2*cost_HP+selling_cost_tot_li_HP+sewage_cost_li)\n", + "\n", + "#nickel iron battery\n", + "selling_cost_tot_ni_HP=selling_bat_ni_HP(lifetime_SP-1)+(selling_PV_bat_ni_HP*selling_price)\n", + "\n", + "buying_cost_tot_ni_HP=buying_bat_ni_HP(lifetime_SP-1)+(buying_PV_bat_ni_HP*buying_price)\n", + "\n", + "NPV_bat_ni_HP=(-total_cost_PV_nibat-buying_cost_tot_ni_HP-2*cost_HP+selling_cost_tot_ni_HP+sewage_cost_ni)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#Results: LCOE , autonomy level and co2 emissions\n", + "#Results SOLAR PV\n", + "#LCOE\n", + "LCOE=round(-NPV/(20*total_Demand),2)\n", + "print(\"LCOE Solar PV:\",LCOE,\"CHF/kWh\")\n", + "#Autonomy level\n", + "autonomy_level=round(sum(df[\"SelfConsumption\"])*100/total_Demand,2)\n", + "print(\"Autonomy_level Solar PV:\",autonomy_level,\"%\")\n", + "#CO2 emissions \n", + "co2_emissions_PV=round((total_Generation*solar_PV_CO2+buying_PV*grid_CO2)/total_Demand,3)\n", + "print(\"CO2 emissions solar PV panel:\",co2_emissions_PV,\"kg/kWh\")\n", + "\n", + "#Results with battery\n", + "#LCOE lead acid battery\n", + "LCOE_bat_lea=round(-NPV_bat_lea/(20*total_Demand),2)\n", + "print(\"LCOE lead acid battery:\",LCOE_bat_lea,\"CHF/kWh\")\n", + "\n", + "#LCOE lithium ion battery\n", + "LCOE_bat_li=round(-NPV_bat_li/(20*total_Demand),2)\n", + "print(\"LCOE lithium ion battery:\",LCOE_bat_li,\"CHF/kWh\")\n", + "\n", + "#LCOE nickel iron battery\n", + "LCOE_bat_ni=round(-NPV_bat_ni/(20*total_Demand),2)\n", + "print(\"LCOE nickel iron:\",LCOE_bat_ni,\"CHF/kWh\")\n", + "\n", + "#Autonomy level lead acid battery\n", + "autonomy_level_leabat=round(sum(df[\"SelfConsumption_battery_lea\"])*100/total_Demand,0)\n", + "print(\"Autonomy level lead-acid battery:\",autonomy_level_leabat,\"%\")\n", + "\n", + "#Autonomy level lithium ion battery\n", + "autonomy_level_libat=round(sum(df[\"SelfConsumption_battery_li\"])*100/total_Demand,0)\n", + "print(\"Autonomy level lithium ion battery:\",autonomy_level_libat,\"%\")\n", + "\n", + "#Autonomy level nickel iron battery\n", + "autonomy_level_nibat=round(sum(df[\"SelfConsumption_battery_ni\"])*100/total_Demand,0)\n", + "print(\"Autonomy level nickel iron battery:\",autonomy_level_nibat,\"%\")\n", + "\n", + "#CO2 emissions lead acid battery\n", + "co2_emissions_PV_leabat=round((total_Generation*solar_PV_CO2+buying_PV_bat_lea*grid_CO2+capacity_bat_lea*3*lea_bat_CO2)/total_Demand,2)\n", + "print(\"CO2 emissions of solar PV panel and lead acid battery:\",co2_emissions_PV_leabat,\"kg/kWh\")\n", + "\n", + "#CO2 emissions lithium ion battery\n", + "co2_emissions_PV_libat=round((total_Generation*solar_PV_CO2+buying_PV_bat_li*grid_CO2+capacity_bat_li*2*li_bat_CO2)/total_Demand,2)\n", + "print(\"CO2 emissions of solar PV panel and lithium ion battery:\",co2_emissions_PV_libat,\"kg/kWh\")\n", + "\n", + "#CO2 emissions nickel iron battery\n", + "co2_emissions_PV_nibat=round((total_Generation*solar_PV_CO2+buying_PV_bat_ni*grid_CO2+capacity_bat_ni*ni_bat_CO2)/total_Demand,2)\n", + "print(\"CO2 emissions of solar PV panel and nickel iron battery:\",co2_emissions_PV_nibat,\"kg/kWh\")\n", + "\n", + "\n", + "#Results with solar thermal\n", + "#LCOE\n", + "print(\"LCOE Solar PV & Lead acid battery & Solar thermal :\",round(LCOE_ST_SP_lea,2),\"CHF/kWh\")\n", + "print(\"LCOE Solar PV & Lithium Ion battery & Solar thermal :\",round(LCOE_ST_SP_li,2),\"CHF/kWh\")\n", + "print(\"LCOE Solar PV & Nickel iron battery & Solar thermal :\",round(LCOE_ST_SP_ni,2),\"CHF/kWh\")\n", + "#Autonomy level with solar thermal\n", + "print(\"Autonomy level solar thermal\",autonomy_level_ST,\"%\")\n", + "\n", + "#CO2 emissions Solar PV & lead acid battery & Solar thermal\n", + "co2_emissions_SP_ST_lea=round(((total_Generation*solar_PV_CO2+buying_PV_bat_lea*grid_CO2+capacity_bat_lea*3*lea_bat_CO2)+(solar_thermal_CO2*area_solar_thermal)+(2*capacity_bo*co2_natural_gas_boiler)+(buying_ST*co2_naturalgas_grid))/(heating_demand+total_Demand),2)\n", + "print(\"CO2 emissions of solar PV panel, lead acid battery and solar thermal panel:\",co2_emissions_SP_ST_lea,\"kg/kWh\")\n", + "\n", + "#CO2 emissions Solar PV & lithium ion battery & Solar thermal\n", + "co2_emissions_SP_ST_li=round(((total_Generation*solar_PV_CO2+buying_PV_bat_li*grid_CO2+capacity_bat_li*2*li_bat_CO2)+(solar_thermal_CO2*area_solar_thermal)+(2*capacity_bo*co2_natural_gas_boiler)+(buying_ST*co2_naturalgas_grid))/(heating_demand+total_Demand),2)\n", + "print(\"CO2 emissions of solar PV panel, lithium ion battery and solar thermal panel:\",co2_emissions_SP_ST_li,\"kg/kWh\")\n", + "\n", + "#CO2 emissions Solar PV & nickel iron battery & Solar thermal\n", + "co2_emissions_SP_ST_ni=round(((total_Generation*solar_PV_CO2+buying_PV_bat_ni*grid_CO2+capacity_bat_ni*1*ni_bat_CO2)+(solar_thermal_CO2*area_solar_thermal)+(2*capacity_bo*co2_natural_gas_boiler)+(buying_ST*co2_naturalgas_grid))/(heating_demand+total_Demand),2)\n", + "print(\"CO2 emissions of solar PV panel, nickel iron battery and solar thermal panel:\",co2_emissions_SP_ST_ni,\"kg/kWh\")\n", + "\n", + "\n", + "#Results with Solar PV, Battery and heat pump\n", + "#LCOE lead acid battery\n", + "LCOE_bat_lea_HP=round(-NPV_bat_lea_HP/(20*total_Demand_HP),2)\n", + "print(\"LCOE SP& lead-acid battery & Heat Pump:\",LCOE_bat_lea_HP,\"CHF/kWh\")\n", + "\n", + "#LCOE lithium ion battery\n", + "LCOE_bat_li_HP=round(-NPV_bat_li_HP/(20*total_Demand_HP),2)\n", + "print(\"LCOE SP& lithium ion battery & Heat Pump:\",LCOE_bat_li_HP,\"CHF/kWh\")\n", + "\n", + "#LCOE nickel iron battery\n", + "LCOE_bat_ni_HP=round(-NPV_bat_ni_HP/(20*total_Demand_HP),2)\n", + "print(\"LCOE SP & nickel iron battery & Heat Pump:\",LCOE_bat_ni_HP,\"CHF/kWh\")\n", + "\n", + "#Autonomy level lead acid battery\n", + "autonomy_level_leabat_HP=round(sum(df[\"SelfConsumption_battery_lea_HP\"])*100/total_Demand_HP,0)\n", + "print(\"Autonomy level SP& lead-acid battery & Heat Pump:\",autonomy_level_leabat_HP,\"%\")\n", + "\n", + "#Autonomy level lithium ion battery\n", + "autonomy_level_libat_HP=round(sum(df[\"SelfConsumption_battery_li_HP\"])*100/total_Demand_HP,0)\n", + "print(\"Autonomy level SP& lithium ion battery & Heat Pump:\",autonomy_level_libat_HP,\"%\")\n", + "\n", + "#Autonomy level nickel iron battery\n", + "autonomy_level_nibat_HP=round(sum(df[\"SelfConsumption_battery_ni_HP\"])*100/total_Demand_HP,0)\n", + "print(\"Autonomy level SP & nickel iron battery & Heat Pump:\",autonomy_level_nibat_HP,\"%\")\n", + "\n", + "#CO2 emissions lead acid battery\n", + "co2_emissions_PV_leabat_HP=round((total_Generation*solar_PV_CO2+buying_PV_bat_lea_HP*grid_CO2+capacity_bat_lea*3*lea_bat_CO2+2*co2_heatpump*capacity_HP)/total_Demand_HP,2)\n", + "print(\"CO2 emissions of solar PV panel, lead acid battery and heat pump:\",co2_emissions_PV_leabat_HP,\"kg/kWh\")\n", + "\n", + "#CO2 emissions lithium ion battery\n", + "co2_emissions_PV_libat_HP=round((total_Generation*solar_PV_CO2+buying_PV_bat_li_HP*grid_CO2+capacity_bat_li*2*li_bat_CO2+2*co2_heatpump*capacity_HP)/total_Demand_HP,2)\n", + "print(\"CO2 emissions of solar PV panel, lithium ion battery and heat pump:\",co2_emissions_PV_libat_HP,\"kg/kWh\")\n", + "\n", + "#CO2 emissions nickel iron battery\n", + "co2_emissions_PV_nibat_HP=round((total_Generation*solar_PV_CO2+buying_PV_bat_ni_HP*grid_CO2+capacity_bat_ni*ni_bat_CO2+2*co2_heatpump*capacity_HP)/total_Demand_HP,2)\n", + "print(\"CO2 emissions of solar PV panel, nickel iron battery and heat pump:\",co2_emissions_PV_nibat_HP,\"kg/kWh\")\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "12/1000" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python [default]", + "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": 2 +} diff --git a/donnees.json b/donnees.json new file mode 100644 index 0000000..6a4ef84 --- /dev/null +++ b/donnees.json @@ -0,0 +1,52 @@ +{ + "percentage_SP": 0.3, + "buying_price": 0.206, + "selling_price": 0.109, + "solar_pv_price":1350, + "solar_pv_efficacity":0.15, + "maintenance_SP":20.25, + "lifetime_SP":20, + "solar_PV_CO2":0.044, + "grid_CO2":0.012, + "percentage_battery_lea":0.3, + "percentage_battery_li":0.3, + "percentage_battery_ni":0.3, + "capacity_battery":7582.9, + "lea_efficacity":0.81, + "li_efficacity":0.92, + "ni_efficacity":0.65, + "li_minsoc":0.2, + "lea_minsoc":0.3, + "ni_minsoc":0.3, + "maintenance_battery_lea":23.694, + "maintenance_battery_li":20.463, + "maintenance_battery_ni":20.463, + "lea_battery_price":163, + "li_battery_price":440, + "ni_battery_price":491, + "lea_lifetime_battery":7, + "li_lifetime_battery":15, + "ni_lifetime_battery":30, + "li_bat_CO2":70, + "ni_bat_CO2":200, + "lea_bat_CO2":15, + "capacity_boiler":40442, + "boiler_efficacity":0.93, + "HP_COP":3.2, + "solar_thermal_CO2":0.04, + "max_global_irradiance":1.094, + "solar_thermal_efficacity":0.8, + "percentage_ST":0.7, + "boiler_price":4475, + "thermal_grid_price":432.61, + "maintenance_solarthermal":20909, + "ng_buying_price":0.063, + "ng_selling_price":0.063, + "boiler_lifetime":15, + "thermal_grid_lifetime":20, + "co2_natural_gas_boiler":0.225, + "co2_heatpump":0.04, + "co2_naturalgas_grid":0.205, + "heatpump_price":1326.54 +} + diff --git a/read.me b/read.me new file mode 100644 index 0000000..bc5aa85 --- /dev/null +++ b/read.me @@ -0,0 +1,5 @@ +This is a repo for the Eco-Sim tool. +More info. on the tool can be found here: +https://www.mdpi.com/1996-1073/12/5/776 + +