diff --git a/data/energiedelen/sample_input.json b/data/energiedelen/sample_input.json index 357c376..3bbf0ec 100644 --- a/data/energiedelen/sample_input.json +++ b/data/energiedelen/sample_input.json @@ -1 +1 @@ -{"grossInjection":{"index":["2024-01-01T12:00:00+01:00","2024-01-01T12:15:00+01:00","2024-01-01T12:30:00+01:00","2024-01-01T12:45:00+01:00"],"columns":["P1","P2","P3","P4","P5","P6"],"data":[[70.0,10.0,20.0,0.0,0.0,0.0],[20.0,10.0,30.0,0.0,0.0,0.0],[100.0,10.0,40.0,0.0,0.0,0.0],[0.0,10.0,50.0,0.0,0.0,0.0]]},"grossOfftake":{"index":["2024-01-01T12:00:00+01:00","2024-01-01T12:15:00+01:00","2024-01-01T12:30:00+01:00","2024-01-01T12:45:00+01:00"],"columns":["P1","P2","P3","P4","P5","P6"],"data":[[0.0,30.0,22.0,30.0,18.0,20.0],[0.0,20.0,20.0,25.0,17.0,22.0],[0.0,10.0,30.0,35.0,19.0,24.0],[0.0,0.0,40.0,10.0,25.0,26.0]]},"key":{"index":["2024-01-01T12:00:00+01:00","2024-01-01T12:15:00+01:00","2024-01-01T12:30:00+01:00","2024-01-01T12:45:00+01:00"],"columns":["P1","P2","P3","P4","P5","P6"],"data":[[0.0,0.1,0.225,0.225,0.225,0.225],[0.0,0.1,0.225,0.225,0.225,0.225],[0.0,0.1,0.225,0.225,0.225,0.225],[0.0,0.1,0.225,0.225,0.225,0.225]]}} \ No newline at end of file +{"grossInjection":{"index":["2024-01-01T12:00:00+01:00","2024-01-01T12:15:00+01:00","2024-01-01T12:30:00+01:00","2024-01-01T12:45:00+01:00"],"columns":["P1","P2","P3"],"data":[[70.0,10.0,20.0],[20.0,10.0,30.0],[100.0,10.0,40.0],[0.0,10.0,50.0]]},"grossOfftake":{"index":["2024-01-01T12:00:00+01:00","2024-01-01T12:15:00+01:00","2024-01-01T12:30:00+01:00","2024-01-01T12:45:00+01:00"],"columns":["P2","P3","P4","P5","P6"],"data":[[30.0,22.0,30.0,18.0,20.0],[20.0,20.0,25.0,17.0,22.0],[10.0,30.0,35.0,19.0,24.0],[0.0,40.0,10.0,25.0,26.0]]},"key":{"index":["2024-01-01T12:00:00+01:00","2024-01-01T12:15:00+01:00","2024-01-01T12:30:00+01:00","2024-01-01T12:45:00+01:00"],"columns":["P2","P3","P4","P5","P6"],"data":[[0.1,0.225,0.225,0.225,0.225],[0.1,0.225,0.225,0.225,0.225],[0.1,0.225,0.225,0.225,0.225],[0.1,0.225,0.225,0.225,0.225]]}} \ No newline at end of file diff --git a/demo_energiedelen.ipynb b/demo_energiedelen.ipynb index b6f23be..eaa8d11 100644 --- a/demo_energiedelen.ipynb +++ b/demo_energiedelen.ipynb @@ -27,7 +27,13 @@ "outputs": [], "source": [ "from openenergyid import TimeDataFrame\n", - "from openenergyid.energysharing import EnergySharingInput, EnergySharingOutput, calculate, CalculationMethod, KeyInput" + "from openenergyid.energysharing import (\n", + " EnergySharingInput,\n", + " EnergySharingOutput,\n", + " calculate,\n", + " CalculationMethod,\n", + " KeyInput,\n", + ")" ] }, { @@ -50,9 +56,9 @@ "outputs": [], "source": [ "index = pd.date_range(\n", - " start=pd.Timestamp('2024-01-01 12:00:00', tz='Europe/Brussels'),\n", - " end=pd.Timestamp('2024-01-01 12:45:00', tz='Europe/Brussels'),\n", - " freq='15T',\n", + " start=pd.Timestamp(\"2024-01-01 12:00:00\", tz=\"Europe/Brussels\"),\n", + " end=pd.Timestamp(\"2024-01-01 12:45:00\", tz=\"Europe/Brussels\"),\n", + " freq=\"15T\",\n", ")" ] }, @@ -67,16 +73,12 @@ " \"P1\": [70, 20, 100, 0],\n", " \"P2\": [10, 10, 10, 10],\n", " \"P3\": [20, 30, 40, 50],\n", - " \"P4\": [0, 0, 0, 0],\n", - " \"P5\": [0, 0, 0, 0],\n", - " \"P6\": [0, 0, 0, 0],\n", " },\n", " index=index,\n", ")\n", "\n", "gross_offtake = pd.DataFrame(\n", " data={\n", - " \"P1\": [0, 0, 0, 0],\n", " \"P2\": [30, 20, 10, 0],\n", " \"P3\": [22, 20, 30, 40],\n", " \"P4\": [30, 25, 35, 10],\n", @@ -88,7 +90,6 @@ "\n", "key = pd.DataFrame(\n", " data={\n", - " \"P1\": [0, 0, 0, 0],\n", " \"P2\": [10, 10, 10, 10],\n", " \"P3\": [22.5, 22.5, 22.5, 22.5],\n", " \"P4\": [22.5, 22.5, 22.5, 22.5],\n", @@ -129,9 +130,6 @@ " P1\n", " P2\n", " P3\n", - " P4\n", - " P5\n", - " P6\n", " \n", " \n", " \n", @@ -140,47 +138,35 @@ " 70\n", " 10\n", " 20\n", - " 0\n", - " 0\n", - " 0\n", " \n", " \n", " 2024-01-01 12:15:00+01:00\n", " 20\n", " 10\n", " 30\n", - " 0\n", - " 0\n", - " 0\n", " \n", " \n", " 2024-01-01 12:30:00+01:00\n", " 100\n", " 10\n", " 40\n", - " 0\n", - " 0\n", - " 0\n", " \n", " \n", " 2024-01-01 12:45:00+01:00\n", " 0\n", " 10\n", " 50\n", - " 0\n", - " 0\n", - " 0\n", " \n", " \n", "\n", "" ], "text/plain": [ - " P1 P2 P3 P4 P5 P6\n", - "2024-01-01 12:00:00+01:00 70 10 20 0 0 0\n", - "2024-01-01 12:15:00+01:00 20 10 30 0 0 0\n", - "2024-01-01 12:30:00+01:00 100 10 40 0 0 0\n", - "2024-01-01 12:45:00+01:00 0 10 50 0 0 0" + " P1 P2 P3\n", + "2024-01-01 12:00:00+01:00 70 10 20\n", + "2024-01-01 12:15:00+01:00 20 10 30\n", + "2024-01-01 12:30:00+01:00 100 10 40\n", + "2024-01-01 12:45:00+01:00 0 10 50" ] }, "execution_count": 5, @@ -218,7 +204,6 @@ " \n", " \n", " \n", - " P1\n", " P2\n", " P3\n", " P4\n", @@ -229,7 +214,6 @@ " \n", " \n", " 2024-01-01 12:00:00+01:00\n", - " 0\n", " 30\n", " 22\n", " 30\n", @@ -238,7 +222,6 @@ " \n", " \n", " 2024-01-01 12:15:00+01:00\n", - " 0\n", " 20\n", " 20\n", " 25\n", @@ -247,7 +230,6 @@ " \n", " \n", " 2024-01-01 12:30:00+01:00\n", - " 0\n", " 10\n", " 30\n", " 35\n", @@ -257,7 +239,6 @@ " \n", " 2024-01-01 12:45:00+01:00\n", " 0\n", - " 0\n", " 40\n", " 10\n", " 25\n", @@ -268,11 +249,11 @@ "" ], "text/plain": [ - " P1 P2 P3 P4 P5 P6\n", - "2024-01-01 12:00:00+01:00 0 30 22 30 18 20\n", - "2024-01-01 12:15:00+01:00 0 20 20 25 17 22\n", - "2024-01-01 12:30:00+01:00 0 10 30 35 19 24\n", - "2024-01-01 12:45:00+01:00 0 0 40 10 25 26" + " P2 P3 P4 P5 P6\n", + "2024-01-01 12:00:00+01:00 30 22 30 18 20\n", + "2024-01-01 12:15:00+01:00 20 20 25 17 22\n", + "2024-01-01 12:30:00+01:00 10 30 35 19 24\n", + "2024-01-01 12:45:00+01:00 0 40 10 25 26" ] }, "execution_count": 6, @@ -310,7 +291,6 @@ " \n", " \n", " \n", - " P1\n", " P2\n", " P3\n", " P4\n", @@ -321,7 +301,6 @@ " \n", " \n", " 2024-01-01 12:00:00+01:00\n", - " 0.0\n", " 0.1\n", " 0.225\n", " 0.225\n", @@ -330,7 +309,6 @@ " \n", " \n", " 2024-01-01 12:15:00+01:00\n", - " 0.0\n", " 0.1\n", " 0.225\n", " 0.225\n", @@ -339,7 +317,6 @@ " \n", " \n", " 2024-01-01 12:30:00+01:00\n", - " 0.0\n", " 0.1\n", " 0.225\n", " 0.225\n", @@ -348,7 +325,6 @@ " \n", " \n", " 2024-01-01 12:45:00+01:00\n", - " 0.0\n", " 0.1\n", " 0.225\n", " 0.225\n", @@ -360,11 +336,11 @@ "" ], "text/plain": [ - " P1 P2 P3 P4 P5 P6\n", - "2024-01-01 12:00:00+01:00 0.0 0.1 0.225 0.225 0.225 0.225\n", - "2024-01-01 12:15:00+01:00 0.0 0.1 0.225 0.225 0.225 0.225\n", - "2024-01-01 12:30:00+01:00 0.0 0.1 0.225 0.225 0.225 0.225\n", - "2024-01-01 12:45:00+01:00 0.0 0.1 0.225 0.225 0.225 0.225" + " P2 P3 P4 P5 P6\n", + "2024-01-01 12:00:00+01:00 0.1 0.225 0.225 0.225 0.225\n", + "2024-01-01 12:15:00+01:00 0.1 0.225 0.225 0.225 0.225\n", + "2024-01-01 12:30:00+01:00 0.1 0.225 0.225 0.225 0.225\n", + "2024-01-01 12:45:00+01:00 0.1 0.225 0.225 0.225 0.225" ] }, "execution_count": 7, @@ -388,10 +364,10 @@ "input = EnergySharingInput.model_construct(\n", " gross_injection=TimeDataFrame.from_pandas(gross_injection),\n", " gross_offtake=TimeDataFrame.from_pandas(gross_offtake),\n", - " key=KeyInput.from_pandas(key)\n", + " key=KeyInput.from_pandas(key),\n", ")\n", "\n", - "with open('data/energiedelen/sample_input.json', 'w') as f:\n", + "with open(\"data/energiedelen/sample_input.json\", \"w\") as f:\n", " f.write(input.model_dump_json(by_alias=True))\n", "\n", "df = input.to_pandas()" @@ -423,25 +399,20 @@ " \n", " \n", " \n", - " Gross Injection\n", - " Gross Offtake\n", - " Key\n", + " Gross Injection\n", + " Gross Offtake\n", + " Key\n", " \n", " \n", " \n", " P1\n", " P2\n", " P3\n", - " P4\n", - " P5\n", - " P6\n", - " P1\n", " P2\n", " P3\n", " P4\n", " P5\n", " P6\n", - " P1\n", " P2\n", " P3\n", " P4\n", @@ -455,16 +426,11 @@ " 70\n", " 10\n", " 20\n", - " 0\n", - " 0\n", - " 0\n", - " 0\n", " 30\n", " 22\n", " 30\n", " 18\n", " 20\n", - " 0.0\n", " 0.1\n", " 0.225\n", " 0.225\n", @@ -476,16 +442,11 @@ " 20\n", " 10\n", " 30\n", - " 0\n", - " 0\n", - " 0\n", - " 0\n", " 20\n", " 20\n", " 25\n", " 17\n", " 22\n", - " 0.0\n", " 0.1\n", " 0.225\n", " 0.225\n", @@ -497,16 +458,11 @@ " 100\n", " 10\n", " 40\n", - " 0\n", - " 0\n", - " 0\n", - " 0\n", " 10\n", " 30\n", " 35\n", " 19\n", " 24\n", - " 0.0\n", " 0.1\n", " 0.225\n", " 0.225\n", @@ -519,15 +475,10 @@ " 10\n", " 50\n", " 0\n", - " 0\n", - " 0\n", - " 0\n", - " 0\n", " 40\n", " 10\n", " 25\n", " 26\n", - " 0.0\n", " 0.1\n", " 0.225\n", " 0.225\n", @@ -539,26 +490,19 @@ "" ], "text/plain": [ - " Gross Injection Gross Offtake \\\n", - " P1 P2 P3 P4 P5 P6 P1 P2 \n", - "2024-01-01 11:00:00+00:00 70 10 20 0 0 0 0 30 \n", - "2024-01-01 11:15:00+00:00 20 10 30 0 0 0 0 20 \n", - "2024-01-01 11:30:00+00:00 100 10 40 0 0 0 0 10 \n", - "2024-01-01 11:45:00+00:00 0 10 50 0 0 0 0 0 \n", - "\n", - " Key \\\n", - " P3 P4 P5 P6 P1 P2 P3 P4 P5 \n", - "2024-01-01 11:00:00+00:00 22 30 18 20 0.0 0.1 0.225 0.225 0.225 \n", - "2024-01-01 11:15:00+00:00 20 25 17 22 0.0 0.1 0.225 0.225 0.225 \n", - "2024-01-01 11:30:00+00:00 30 35 19 24 0.0 0.1 0.225 0.225 0.225 \n", - "2024-01-01 11:45:00+00:00 40 10 25 26 0.0 0.1 0.225 0.225 0.225 \n", + " Gross Injection Gross Offtake \\\n", + " P1 P2 P3 P2 P3 P4 P5 \n", + "2024-01-01 11:00:00+00:00 70 10 20 30 22 30 18 \n", + "2024-01-01 11:15:00+00:00 20 10 30 20 20 25 17 \n", + "2024-01-01 11:30:00+00:00 100 10 40 10 30 35 19 \n", + "2024-01-01 11:45:00+00:00 0 10 50 0 40 10 25 \n", "\n", - " \n", - " P6 \n", - "2024-01-01 11:00:00+00:00 0.225 \n", - "2024-01-01 11:15:00+00:00 0.225 \n", - "2024-01-01 11:30:00+00:00 0.225 \n", - "2024-01-01 11:45:00+00:00 0.225 " + " Key \n", + " P6 P2 P3 P4 P5 P6 \n", + "2024-01-01 11:00:00+00:00 20 0.1 0.225 0.225 0.225 0.225 \n", + "2024-01-01 11:15:00+00:00 22 0.1 0.225 0.225 0.225 0.225 \n", + "2024-01-01 11:30:00+00:00 24 0.1 0.225 0.225 0.225 0.225 \n", + "2024-01-01 11:45:00+00:00 26 0.1 0.225 0.225 0.225 0.225 " ] }, "execution_count": 9, @@ -605,25 +549,20 @@ " \n", " \n", " \n", - " Net Injection\n", - " Net Offtake\n", - " Shared Energy\n", + " Net Injection\n", + " Net Offtake\n", + " Shared Energy\n", " \n", " \n", " \n", " P1\n", " P2\n", " P3\n", - " P4\n", - " P5\n", - " P6\n", - " P1\n", " P2\n", " P3\n", " P4\n", " P5\n", " P6\n", - " P1\n", " P2\n", " P3\n", " P4\n", @@ -637,16 +576,11 @@ " 4.9\n", " 1.70\n", " 5.90\n", - " 0.0\n", - " 0.0\n", - " 0.0\n", - " 0.0\n", " 21.0\n", " 4.00\n", " 7.50\n", " 0.0\n", " 0.0\n", - " 0.0\n", " 9.0\n", " 18.00\n", " 22.50\n", @@ -658,16 +592,11 @@ " 0.0\n", " 1.00\n", " 6.75\n", - " 0.0\n", - " 0.0\n", - " 0.0\n", - " 0.0\n", " 15.0\n", " 13.25\n", " 11.50\n", " 3.5\n", " 8.5\n", - " 0.0\n", " 5.0\n", " 6.75\n", " 13.50\n", @@ -680,15 +609,10 @@ " 2.90\n", " 16.60\n", " 0.0\n", - " 0.0\n", - " 0.0\n", - " 0.0\n", - " 0.0\n", " 5.25\n", " 1.25\n", " 0.0\n", " 0.0\n", - " 0.0\n", " 10.0\n", " 24.75\n", " 33.75\n", @@ -701,16 +625,11 @@ " 2.42\n", " 18.33\n", " 0.0\n", - " 0.0\n", - " 0.0\n", - " 0.0\n", - " 0.0\n", " 37.75\n", " 0.00\n", " 11.5\n", " 12.5\n", " 0.0\n", - " 0.0\n", " 2.25\n", " 10.00\n", " 13.5\n", @@ -721,26 +640,26 @@ "" ], "text/plain": [ - " Net Injection \\\n", - " P1 P2 P3 P4 P5 P6 \n", - "2024-01-01 11:00:00+00:00 4.9 1.70 5.90 0.0 0.0 0.0 \n", - "2024-01-01 11:15:00+00:00 0.0 1.00 6.75 0.0 0.0 0.0 \n", - "2024-01-01 11:30:00+00:00 19.0 2.90 16.60 0.0 0.0 0.0 \n", - "2024-01-01 11:45:00+00:00 0.0 2.42 18.33 0.0 0.0 0.0 \n", + " Net Injection Net Offtake \\\n", + " P1 P2 P3 P2 P3 \n", + "2024-01-01 11:00:00+00:00 4.9 1.70 5.90 21.0 4.00 \n", + "2024-01-01 11:15:00+00:00 0.0 1.00 6.75 15.0 13.25 \n", + "2024-01-01 11:30:00+00:00 19.0 2.90 16.60 0.0 5.25 \n", + "2024-01-01 11:45:00+00:00 0.0 2.42 18.33 0.0 37.75 \n", "\n", - " Net Offtake \\\n", - " P1 P2 P3 P4 P5 P6 \n", - "2024-01-01 11:00:00+00:00 0.0 21.0 4.00 7.50 0.0 0.0 \n", - "2024-01-01 11:15:00+00:00 0.0 15.0 13.25 11.50 3.5 8.5 \n", - "2024-01-01 11:30:00+00:00 0.0 0.0 5.25 1.25 0.0 0.0 \n", - "2024-01-01 11:45:00+00:00 0.0 0.0 37.75 0.00 11.5 12.5 \n", + " Shared Energy \\\n", + " P4 P5 P6 P2 P3 P4 \n", + "2024-01-01 11:00:00+00:00 7.50 0.0 0.0 9.0 18.00 22.50 \n", + "2024-01-01 11:15:00+00:00 11.50 3.5 8.5 5.0 6.75 13.50 \n", + "2024-01-01 11:30:00+00:00 1.25 0.0 0.0 10.0 24.75 33.75 \n", + "2024-01-01 11:45:00+00:00 0.00 11.5 12.5 0.0 2.25 10.00 \n", "\n", - " Shared Energy \n", - " P1 P2 P3 P4 P5 P6 \n", - "2024-01-01 11:00:00+00:00 0.0 9.0 18.00 22.50 18.0 20.0 \n", - "2024-01-01 11:15:00+00:00 0.0 5.0 6.75 13.50 13.5 13.5 \n", - "2024-01-01 11:30:00+00:00 0.0 10.0 24.75 33.75 19.0 24.0 \n", - "2024-01-01 11:45:00+00:00 0.0 0.0 2.25 10.00 13.5 13.5 " + " \n", + " P5 P6 \n", + "2024-01-01 11:00:00+00:00 18.0 20.0 \n", + "2024-01-01 11:15:00+00:00 13.5 13.5 \n", + "2024-01-01 11:30:00+00:00 19.0 24.0 \n", + "2024-01-01 11:45:00+00:00 13.5 13.5 " ] }, "execution_count": 10, @@ -787,25 +706,20 @@ " \n", " \n", " \n", - " Net Injection\n", - " Net Offtake\n", - " Shared Energy\n", + " Net Injection\n", + " Net Offtake\n", + " Shared Energy\n", " \n", " \n", " \n", " P1\n", " P2\n", " P3\n", - " P4\n", - " P5\n", - " P6\n", - " P1\n", " P2\n", " P3\n", " P4\n", " P5\n", " P6\n", - " P1\n", " P2\n", " P3\n", " P4\n", @@ -819,16 +733,11 @@ " 7.08\n", " 1.01\n", " 2.02\n", - " 0.0\n", - " 0.0\n", - " 0.0\n", - " 0.0\n", " 20.42\n", " 3.75\n", " 5.94\n", " 0.00\n", " 0.00\n", - " 0.0\n", " 9.58\n", " 18.25\n", " 24.06\n", @@ -840,16 +749,11 @@ " 0.00\n", " 0.00\n", " -0.00\n", - " 0.0\n", - " 0.0\n", - " 0.0\n", - " 0.0\n", " 14.13\n", " 13.00\n", " 9.29\n", " 1.29\n", " 6.29\n", - " 0.0\n", " 5.87\n", " 7.00\n", " 15.71\n", @@ -861,16 +765,11 @@ " 24.67\n", " 2.47\n", " 9.87\n", - " 0.0\n", - " 0.0\n", - " 0.0\n", - " 0.0\n", " 0.00\n", " 5.00\n", " 0.00\n", " 0.00\n", " 0.00\n", - " 0.0\n", " 10.00\n", " 25.00\n", " 35.00\n", @@ -882,16 +781,11 @@ " 0.00\n", " 2.24\n", " 11.22\n", - " 0.0\n", - " 0.0\n", - " 0.0\n", - " 0.0\n", " 0.00\n", " 37.50\n", " 0.00\n", " 7.98\n", " 8.98\n", - " 0.0\n", " 0.00\n", " 2.50\n", " 10.00\n", @@ -903,26 +797,26 @@ "" ], "text/plain": [ - " Net Injection \\\n", - " P1 P2 P3 P4 P5 P6 \n", - "2024-01-01 11:00:00+00:00 7.08 1.01 2.02 0.0 0.0 0.0 \n", - "2024-01-01 11:15:00+00:00 0.00 0.00 -0.00 0.0 0.0 0.0 \n", - "2024-01-01 11:30:00+00:00 24.67 2.47 9.87 0.0 0.0 0.0 \n", - "2024-01-01 11:45:00+00:00 0.00 2.24 11.22 0.0 0.0 0.0 \n", + " Net Injection Net Offtake \\\n", + " P1 P2 P3 P2 P3 P4 \n", + "2024-01-01 11:00:00+00:00 7.08 1.01 2.02 20.42 3.75 5.94 \n", + "2024-01-01 11:15:00+00:00 0.00 0.00 -0.00 14.13 13.00 9.29 \n", + "2024-01-01 11:30:00+00:00 24.67 2.47 9.87 0.00 5.00 0.00 \n", + "2024-01-01 11:45:00+00:00 0.00 2.24 11.22 0.00 37.50 0.00 \n", "\n", - " Net Offtake \\\n", - " P1 P2 P3 P4 P5 P6 \n", - "2024-01-01 11:00:00+00:00 0.0 20.42 3.75 5.94 0.00 0.00 \n", - "2024-01-01 11:15:00+00:00 0.0 14.13 13.00 9.29 1.29 6.29 \n", - "2024-01-01 11:30:00+00:00 0.0 0.00 5.00 0.00 0.00 0.00 \n", - "2024-01-01 11:45:00+00:00 0.0 0.00 37.50 0.00 7.98 8.98 \n", + " Shared Energy \\\n", + " P5 P6 P2 P3 P4 P5 \n", + "2024-01-01 11:00:00+00:00 0.00 0.00 9.58 18.25 24.06 18.00 \n", + "2024-01-01 11:15:00+00:00 1.29 6.29 5.87 7.00 15.71 15.71 \n", + "2024-01-01 11:30:00+00:00 0.00 0.00 10.00 25.00 35.00 19.00 \n", + "2024-01-01 11:45:00+00:00 7.98 8.98 0.00 2.50 10.00 17.02 \n", "\n", - " Shared Energy \n", - " P1 P2 P3 P4 P5 P6 \n", - "2024-01-01 11:00:00+00:00 0.0 9.58 18.25 24.06 18.00 20.00 \n", - "2024-01-01 11:15:00+00:00 0.0 5.87 7.00 15.71 15.71 15.71 \n", - "2024-01-01 11:30:00+00:00 0.0 10.00 25.00 35.00 19.00 24.00 \n", - "2024-01-01 11:45:00+00:00 0.0 0.00 2.50 10.00 17.02 17.02 " + " \n", + " P6 \n", + "2024-01-01 11:00:00+00:00 20.00 \n", + "2024-01-01 11:15:00+00:00 15.71 \n", + "2024-01-01 11:30:00+00:00 24.00 \n", + "2024-01-01 11:45:00+00:00 17.02 " ] }, "execution_count": 11, @@ -975,25 +869,20 @@ " \n", " \n", " \n", - " Net Injection\n", - " Net Offtake\n", - " Shared Energy\n", + " Net Injection\n", + " Net Offtake\n", + " Shared Energy\n", " \n", " \n", " \n", " P1\n", " P2\n", " P3\n", - " P4\n", - " P5\n", - " P6\n", - " P1\n", " P2\n", " P3\n", " P4\n", " P5\n", " P6\n", - " P1\n", " P2\n", " P3\n", " P4\n", @@ -1007,16 +896,11 @@ " 0.00\n", " 0.00\n", " 0.00\n", - " 0.0\n", - " 0.0\n", - " 0.0\n", - " 0.0\n", " 18.51\n", " 0.35\n", " 1.14\n", " 0.00\n", " 0.00\n", - " 0.0\n", " 11.49\n", " 21.65\n", " 28.86\n", @@ -1028,16 +912,11 @@ " 0.00\n", " 0.00\n", " 0.00\n", - " 0.0\n", - " 0.0\n", - " 0.0\n", - " 0.0\n", " 14.13\n", " 13.00\n", " 9.29\n", " 1.29\n", " 6.29\n", - " 0.0\n", " 5.87\n", " 7.00\n", " 15.71\n", @@ -1049,16 +928,11 @@ " 14.76\n", " 1.48\n", " 15.77\n", - " 0.0\n", - " 0.0\n", - " 0.0\n", - " 0.0\n", " 0.00\n", " 0.00\n", " 0.00\n", " 0.00\n", " 0.00\n", - " 0.0\n", " 10.00\n", " 30.00\n", " 35.00\n", @@ -1070,16 +944,11 @@ " 0.00\n", " 0.00\n", " 0.00\n", - " 0.0\n", - " 0.0\n", - " 0.0\n", - " 0.0\n", " 0.00\n", " 36.75\n", " 0.00\n", " 1.62\n", " 2.62\n", - " 0.0\n", " 0.00\n", " 3.25\n", " 10.00\n", @@ -1091,26 +960,26 @@ "" ], "text/plain": [ - " Net Injection \\\n", - " P1 P2 P3 P4 P5 P6 \n", - "2024-01-01 11:00:00+00:00 0.00 0.00 0.00 0.0 0.0 0.0 \n", - "2024-01-01 11:15:00+00:00 0.00 0.00 0.00 0.0 0.0 0.0 \n", - "2024-01-01 11:30:00+00:00 14.76 1.48 15.77 0.0 0.0 0.0 \n", - "2024-01-01 11:45:00+00:00 0.00 0.00 0.00 0.0 0.0 0.0 \n", + " Net Injection Net Offtake \\\n", + " P1 P2 P3 P2 P3 P4 \n", + "2024-01-01 11:00:00+00:00 0.00 0.00 0.00 18.51 0.35 1.14 \n", + "2024-01-01 11:15:00+00:00 0.00 0.00 0.00 14.13 13.00 9.29 \n", + "2024-01-01 11:30:00+00:00 14.76 1.48 15.77 0.00 0.00 0.00 \n", + "2024-01-01 11:45:00+00:00 0.00 0.00 0.00 0.00 36.75 0.00 \n", "\n", - " Net Offtake \\\n", - " P1 P2 P3 P4 P5 P6 \n", - "2024-01-01 11:00:00+00:00 0.0 18.51 0.35 1.14 0.00 0.00 \n", - "2024-01-01 11:15:00+00:00 0.0 14.13 13.00 9.29 1.29 6.29 \n", - "2024-01-01 11:30:00+00:00 0.0 0.00 0.00 0.00 0.00 0.00 \n", - "2024-01-01 11:45:00+00:00 0.0 0.00 36.75 0.00 1.62 2.62 \n", + " Shared Energy \\\n", + " P5 P6 P2 P3 P4 P5 \n", + "2024-01-01 11:00:00+00:00 0.00 0.00 11.49 21.65 28.86 18.00 \n", + "2024-01-01 11:15:00+00:00 1.29 6.29 5.87 7.00 15.71 15.71 \n", + "2024-01-01 11:30:00+00:00 0.00 0.00 10.00 30.00 35.00 19.00 \n", + "2024-01-01 11:45:00+00:00 1.62 2.62 0.00 3.25 10.00 23.38 \n", "\n", - " Shared Energy \n", - " P1 P2 P3 P4 P5 P6 \n", - "2024-01-01 11:00:00+00:00 0.0 11.49 21.65 28.86 18.00 20.00 \n", - "2024-01-01 11:15:00+00:00 0.0 5.87 7.00 15.71 15.71 15.71 \n", - "2024-01-01 11:30:00+00:00 0.0 10.00 30.00 35.00 19.00 24.00 \n", - "2024-01-01 11:45:00+00:00 0.0 0.00 3.25 10.00 23.38 23.38 " + " \n", + " P6 \n", + "2024-01-01 11:00:00+00:00 20.00 \n", + "2024-01-01 11:15:00+00:00 15.71 \n", + "2024-01-01 11:30:00+00:00 24.00 \n", + "2024-01-01 11:45:00+00:00 23.38 " ] }, "execution_count": 12, @@ -1167,42 +1036,27 @@ " \"columns\": [\n", " \"P1\",\n", " \"P2\",\n", - " \"P3\",\n", - " \"P4\",\n", - " \"P5\",\n", - " \"P6\"\n", + " \"P3\"\n", " ],\n", " \"data\": [\n", " [\n", " 0.0,\n", " 0.0,\n", - " 0.0,\n", - " 0.0,\n", - " 0.0,\n", " 0.0\n", " ],\n", " [\n", " 0.0,\n", " 0.0,\n", - " 0.0,\n", - " 0.0,\n", - " 0.0,\n", " 0.0\n", " ],\n", " [\n", " 14.76,\n", " 1.48,\n", - " 15.77,\n", - " 0.0,\n", - " 0.0,\n", - " 0.0\n", + " 15.77\n", " ],\n", " [\n", " 0.0,\n", " 0.0,\n", - " 0.0,\n", - " 0.0,\n", - " 0.0,\n", " 0.0\n", " ]\n", " ]\n", @@ -1215,7 +1069,6 @@ " \"2024-01-01T11:45:00Z\"\n", " ],\n", " \"columns\": [\n", - " \"P1\",\n", " \"P2\",\n", " \"P3\",\n", " \"P4\",\n", @@ -1224,7 +1077,6 @@ " ],\n", " \"data\": [\n", " [\n", - " 0.0,\n", " 18.51,\n", " 0.35,\n", " 1.14,\n", @@ -1232,7 +1084,6 @@ " 0.0\n", " ],\n", " [\n", - " 0.0,\n", " 14.13,\n", " 13.0,\n", " 9.29,\n", @@ -1244,12 +1095,10 @@ " 0.0,\n", " 0.0,\n", " 0.0,\n", - " 0.0,\n", " 0.0\n", " ],\n", " [\n", " 0.0,\n", - " 0.0,\n", " 36.75,\n", " 0.0,\n", " 1.62,\n", @@ -1265,7 +1114,6 @@ " \"2024-01-01T11:45:00Z\"\n", " ],\n", " \"columns\": [\n", - " \"P1\",\n", " \"P2\",\n", " \"P3\",\n", " \"P4\",\n", @@ -1274,7 +1122,6 @@ " ],\n", " \"data\": [\n", " [\n", - " 0.0,\n", " 11.49,\n", " 21.65,\n", " 28.86,\n", @@ -1282,7 +1129,6 @@ " 20.0\n", " ],\n", " [\n", - " 0.0,\n", " 5.87,\n", " 7.0,\n", " 15.71,\n", @@ -1290,7 +1136,6 @@ " 15.71\n", " ],\n", " [\n", - " 0.0,\n", " 10.0,\n", " 30.0,\n", " 35.0,\n", @@ -1299,7 +1144,6 @@ " ],\n", " [\n", " 0.0,\n", - " 0.0,\n", " 3.25,\n", " 10.0,\n", " 23.38,\n", diff --git a/openenergyid/energysharing/main.py b/openenergyid/energysharing/main.py index e7d5e73..2550b23 100644 --- a/openenergyid/energysharing/main.py +++ b/openenergyid/energysharing/main.py @@ -16,23 +16,24 @@ def _calculate(df: pd.DataFrame, method: CalculationMethod) -> pd.DataFrame: injections_to_share = [] rest = {} - for participant in df.columns.levels[1]: + for participant in df[GROSS_INJECTION].columns: injection_to_share = df[GROSS_INJECTION][participant].copy() + key = df[KEY].copy() if method == CalculationMethod.RELATIVE or method == CalculationMethod.OPTIMAL: # Set the key of the current participant to 0 # Re-normalize the keys for the other participants - key = df[KEY].copy() - key.loc[:, participant] = 0 - key = key.div(key.sum(axis=1), axis=0) - elif method == CalculationMethod.FIXED: - key = df[KEY].copy() + if participant in df[KEY].columns: + key.loc[:, participant] = 0 + key = key.div(key.sum(axis=1), axis=0) # Multiply injection_to_share with the key of each participant shared_by_participant = (injection_to_share * key.T).T shared_by_participant.fillna(0, inplace=True) + # Set the value for the current participant to 0 - shared_by_participant.loc[:, participant] = 0 + if participant in shared_by_participant.columns: + shared_by_participant.loc[:, participant] = 0 # Put the not shared injection in the rest rest[participant] = injection_to_share - shared_by_participant.sum(axis=1)