From aab3f9541fdc3a886bf757d1603234222dce54e1 Mon Sep 17 00:00:00 2001 From: ShahlaHuseynova <121937511+ShahlaHuseynova@users.noreply.github.com> Date: Wed, 12 Jun 2024 10:39:38 +0200 Subject: [PATCH] correct version --- .../V2/simulations-storageEncore_final.ipynb | 123 +++++++++++------- 1 file changed, 74 insertions(+), 49 deletions(-) diff --git a/Kickstart/V2/simulations-storageEncore_final.ipynb b/Kickstart/V2/simulations-storageEncore_final.ipynb index 82fa901..f1d018b 100644 --- a/Kickstart/V2/simulations-storageEncore_final.ipynb +++ b/Kickstart/V2/simulations-storageEncore_final.ipynb @@ -43,13 +43,32 @@ }, "metadata": {}, "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "None\n" + ] + }, + { + "ename": "ModuleNotFoundError", + "evalue": "No module named 'pyrecoy2.assets'", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[1], line 37\u001b[0m\n\u001b[0;32m 32\u001b[0m \u001b[38;5;66;03m# Check the version or path to confirm\u001b[39;00m\n\u001b[0;32m 34\u001b[0m \u001b[38;5;28mprint\u001b[39m(pyrecoy2\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__file__\u001b[39m)\n\u001b[1;32m---> 37\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mpyrecoy2\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01massets\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m Heatpump, Eboiler, GasBoiler, HotWaterStorage\n\u001b[0;32m 38\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mpyrecoy2\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mcolors\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;241m*\u001b[39m\n\u001b[0;32m 39\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mpyrecoy2\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mconverters\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;241m*\u001b[39m\n", + "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'pyrecoy2.assets'" + ] } ], "source": [ - "from datetime import timedelta\n", + "from datetime import timedelta, datetime\n", "import json\n", "import pprint\n", "from copy import deepcopy\n", + "import pytz\n", "\n", "import cufflinks\n", "cufflinks.go_offline()\n", @@ -58,17 +77,40 @@ "import pandas as pd\n", "from tqdm.notebook import tqdm\n", "\n", - "from pyrecoy.assets import Heatpump, Eboiler, GasBoiler, HotWaterStorage\n", - "from pyrecoy.colors import *\n", - "from pyrecoy.converters import *\n", - "from pyrecoy.financial import calculate_eb_ode, get_tax_tables, get_tax_rate, get_grid_tariffs_electricity\n", - "from pyrecoy.framework import TimeFramework\n", - "from pyrecoy.casestudy import CaseStudy\n", - "from pyrecoy.plotting import ebitda_bar_chart, npv_bar_chart\n", - "from pyrecoy.reports import CaseReport, ComparisonReport, BusinessCaseReport, SingleFigureComparison\n", - "from pyrecoy.sensitivity import SensitivityAnalysis\n", - "from pyrecoy.prices import get_tennet_data, get_afrr_capacity_fees_nl\n", - "from pyrecoy.forecasts import Mipf\n", + "import sys\n", + "\n", + "import os\n", + " \n", + "# Path to the folder containing the alternate version of PyRecoy\n", + "\n", + "alternate_pyrecoy_path = 'C:\\\\Users\\\\shahla.huseynova\\\\source\\\\repos\\\\Mooi-Kickstart\\\\pyrecoy\\\\pyrecoy'\n", + " \n", + "# Add the path to sys.path\n", + "\n", + "if alternate_pyrecoy_path not in sys.path:\n", + "\n", + " sys.path.insert(0, alternate_pyrecoy_path)\n", + " \n", + "# Now import PyRecoy\n", + "\n", + "import pyrecoy2\n", + "\n", + "# Check the version or path to confirm\n", + "\n", + "print(pyrecoy2.__file__)\n", + "\n", + "\n", + "from pyrecoy2.assets import Heatpump, Eboiler, GasBoiler, HotWaterStorage\n", + "from pyrecoy2.colors import *\n", + "from pyrecoy2.converters import *\n", + "from pyrecoy2.financial import calculate_eb_ode, get_tax_tables, get_tax_rate, get_grid_tariffs_electricity\n", + "from pyrecoy2.framework import TimeFramework\n", + "from pyrecoy2.casestudy import CaseStudy\n", + "from pyrecoy2.plotting import ebitda_bar_chart, npv_bar_chart\n", + "from pyrecoy2.reports import CaseReport, ComparisonReport, BusinessCaseReport, SingleFigureComparison\n", + "from pyrecoy2.sensitivity import SensitivityAnalysis\n", + "from pyrecoy2.prices import get_tennet_data, get_afrr_capacity_fees_nl\n", + "from pyrecoy2.forecasts import Mipf, Forecast\n", "\n", "%load_ext autoreload\n", "%autoreload 2" @@ -184,7 +226,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": { "tags": [ "exclude" @@ -195,6 +237,13 @@ "class Config():\n", " start = '2019-01-01'\n", " end = '2019-12-31'\n", + " # year = '2019'\n", + " # startdate = year + '-01-01'\n", + " # enddate = str(year) + '-12-31'\n", + " # start = datetime.strptime(startdate, \"%Y-%m-%d\").astimezone(pytz.timezone('Europe/Amsterdam'))\n", + " # end = datetime.strptime(enddate, \"%Y-%m-%d\").astimezone(pytz.timezone('Europe/Amsterdam'))\n", + " # start = start.astimezone(pytz.UTC)\n", + " # end = end.astimezone(pytz.UTC)\n", " \n", " hp_vdg_e_power = 23.3 # MW\n", " hp_ndg_e_power = 7.7 # MW\n", @@ -253,7 +302,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": { "tags": [ "exclude" @@ -278,7 +327,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": { "tags": [ "exclude" @@ -290,9 +339,10 @@ " demand = pd.read_csv('data/smurfit_demand_preprocessed.csv', delimiter=';', decimal=',')\n", " dt_index = pd.date_range(\n", " start=s.time_fw.start,\n", - " end=s.time_fw.start + timedelta(days=365), freq='1T',\n", - " closed='left',\n", + " end=s.time_fw.start + timedelta(days=365), \n", + " freq='1T',\n", " tz='Europe/Amsterdam')\n", + " dt_index = dt_index[:len(demand)]\n", " demand.index = dt_index\n", " demand['Total demand'] = demand['MW (VDG)'] + demand['MW (NDG)']\n", " demand = demand[c.start:c.end]\n", @@ -301,7 +351,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -310,46 +360,21 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": { "tags": [ "exclude" ] }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "c:\\users\\shahla.huseynova\\documents\\asset_studies_recoy\\asset-case-studies\\asset-case-studies\\pyrecoy\\pyrecoy\\pyrecoy\\framework.py:40: UserWarning:\n", - "\n", - "The chosen timeperiod spans 365.99930555555557 days, which is not a full year. Beware that certain functions that use yearly rates might return incorrect values.\n", - "\n" - ] - }, - { - "ename": "TypeError", - "evalue": "Forecast.__init__() got an unexpected keyword argument 'tidy'", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[1;32mIn[6], line 25\u001b[0m\n\u001b[0;32m 22\u001b[0m s\u001b[38;5;241m.\u001b[39mdemand \u001b[38;5;241m=\u001b[39m load_demand_data(c, s)\n\u001b[0;32m 23\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m s\n\u001b[1;32m---> 25\u001b[0m s \u001b[38;5;241m=\u001b[39m \u001b[43msetup_model\u001b[49m\u001b[43m(\u001b[49m\u001b[43mc\u001b[49m\u001b[43m)\u001b[49m\n", - "Cell \u001b[1;32mIn[6], line 5\u001b[0m, in \u001b[0;36msetup_model\u001b[1;34m(c)\u001b[0m\n\u001b[0;32m 2\u001b[0m s \u001b[38;5;241m=\u001b[39m Store()\n\u001b[0;32m 4\u001b[0m s\u001b[38;5;241m.\u001b[39mtime_fw \u001b[38;5;241m=\u001b[39m TimeFramework(start\u001b[38;5;241m=\u001b[39mc\u001b[38;5;241m.\u001b[39mstart, end\u001b[38;5;241m=\u001b[39mc\u001b[38;5;241m.\u001b[39mend)\n\u001b[1;32m----> 5\u001b[0m mipf \u001b[38;5;241m=\u001b[39m \u001b[43mMipf\u001b[49m\u001b[43m(\u001b[49m\u001b[43mstart\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43ms\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mtime_fw\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mstart\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mend\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43ms\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mtime_fw\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mend\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtidy\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43minclude_nextQ\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[0;32m 6\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;66;43;03m#folder_path = r\"C:\\Users\\Shahla Huseynova\\Recoy\\Recoy - Documents\\03 - Libraries\\12 - Data Management\\Forecast Data\"\u001b[39;49;00m\n\u001b[0;32m 7\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241m.\u001b[39mdata\n\u001b[0;32m 9\u001b[0m s\u001b[38;5;241m.\u001b[39mbaseline \u001b[38;5;241m=\u001b[39m CaseStudy(time_fw\u001b[38;5;241m=\u001b[39ms\u001b[38;5;241m.\u001b[39mtime_fw, freq\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m1T\u001b[39m\u001b[38;5;124m'\u001b[39m, name\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mBaseline\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m 10\u001b[0m s\u001b[38;5;241m.\u001b[39mhpcase \u001b[38;5;241m=\u001b[39m CaseStudy(time_fw\u001b[38;5;241m=\u001b[39ms\u001b[38;5;241m.\u001b[39mtime_fw, freq\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m1T\u001b[39m\u001b[38;5;124m'\u001b[39m, name\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mHeatpump only\u001b[39m\u001b[38;5;124m'\u001b[39m, data\u001b[38;5;241m=\u001b[39mmipf)\n", - "File \u001b[1;32mc:\\users\\shahla.huseynova\\documents\\asset_studies_recoy\\asset-case-studies\\asset-case-studies\\pyrecoy\\pyrecoy\\pyrecoy\\forecasts.py:98\u001b[0m, in \u001b[0;36mMipf.__init__\u001b[1;34m(self, *args, **kwargs)\u001b[0m\n\u001b[0;32m 97\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__init__\u001b[39m(\u001b[38;5;28mself\u001b[39m, \u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs):\n\u001b[1;32m---> 98\u001b[0m \u001b[38;5;28msuper\u001b[39m()\u001b[38;5;241m.\u001b[39m\u001b[38;5;21m__init__\u001b[39m(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[0;32m 99\u001b[0m forecasts \u001b[38;5;241m=\u001b[39m get_imbalance_forecasts_from_database_on_quarter_start_time(kwargs[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mstart\u001b[39m\u001b[38;5;124m'\u001b[39m], kwargs[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mend\u001b[39m\u001b[38;5;124m'\u001b[39m],\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mNLD\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m 100\u001b[0m forecasts[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mPublicationTime\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m=\u001b[39m pd\u001b[38;5;241m.\u001b[39mto_datetime(forecasts[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mPublicationTime\u001b[39m\u001b[38;5;124m'\u001b[39m], utc\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n", - "\u001b[1;31mTypeError\u001b[0m: Forecast.__init__() got an unexpected keyword argument 'tidy'" - ] - } - ], + "outputs": [], "source": [ "def setup_model(c):\n", " s = Store()\n", " \n", " s.time_fw = TimeFramework(start=c.start, end=c.end)\n", - " mipf = Mipf(start=s.time_fw.start, end=s.time_fw.end, tidy=True, include_nextQ=True,\n", - " #folder_path = r\"C:\\Users\\Shahla Huseynova\\Recoy\\Recoy - Documents\\03 - Libraries\\12 - Data Management\\Forecast Data\"\n", - " ).data\n", - " \n", + " # s.minute_ix = s.time_fw.dt_index(freq='1T')\n", + " mipf = Mipf(None, start=s.time_fw.start, end=s.time_fw.end, from_database=True, add_days_to_start_end=False).data\n", + " s.mipf = mipf\n", " s.baseline = CaseStudy(time_fw=s.time_fw, freq='1T', name='Baseline')\n", " s.hpcase = CaseStudy(time_fw=s.time_fw, freq='1T', name='Heatpump only', data=mipf)\n", " #s.hpcase_sde = CaseStudy(time_fw=s.time_fw, freq='1T', name='Heatpump + SDE', data=mipf)\n", @@ -1910,7 +1935,7 @@ "source": [ "def calculate_financials(c, s):\n", " for case in s.cases:\n", - " case.calculate_ebitda()\n", + " case.calculate_ebitda(c.project_duration)\n", "\n", " for case in [s.hpcase, s.storage_case]: #, s.hpcase_sde, s.optcase1, s.afrr_case]:\n", " case.calculate_business_case(\n",