Skip to content

Commit

Permalink
Update to latest solph offsetconverter API
Browse files Browse the repository at this point in the history
  • Loading branch information
fwitte committed Jul 16, 2024
1 parent 2ed2a15 commit c820a04
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 49 deletions.
62 changes: 31 additions & 31 deletions workshop/model/coefficients-offset-converter.csv
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
,slope,offset
-10,3.975280241741998,-1714.9334035658824
-9,4.052064477064582,-1707.8183400920395
-8,4.130368258042325,-1697.7399675074953
-7,4.210807840888694,-1685.6739325028082
-6,4.294086559705077,-1672.7372223695832
-5,4.380367691459657,-1658.8276622190456
-4,4.46976125681571,-1643.7958599132035
-3,4.562424139153032,-1627.573699958455
-2,4.658482051105536,-1610.0984022218279
-1,4.758170905891813,-1591.4041050431654
0,4.861762313822266,-1571.4394473210048
1,4.969579082090264,-1550.321952503379
2,5.081641706894415,-1527.663676402653
3,5.198201148240096,-1503.390331703682
4,5.319713370023736,-1477.5902081719444
5,5.446447347496535,-1450.1180916157882
6,5.5779996989706575,-1419.9975105784702
7,5.715644172000148,-1388.3297890356873
8,5.85618246716041,-1350.4422331057672
9,6.002454159520156,-1309.5088515180098
10,6.155918795220834,-1266.6590772305244
11,6.317010535301569,-1221.603519107183
12,6.486327442296935,-1174.2286790378441
13,6.664596944175324,-1124.5256860509512
14,6.852371369223604,-1072.0632031170894
15,7.050511261548551,-1016.7294502161973
16,7.259834140017434,-958.2093295712332
17,7.4813714982636395,-896.3184071761398
18,7.716333624621206,-830.9886618956353
19,7.965894617708117,-761.7166759588404
20,8.231454187857127,-688.1279745186911
-10,0.2514753973628667,0.047465920610585424
-9,0.2467066780860508,0.046376068603306536
-8,0.24202237825654546,0.04523414336514062
-7,0.2373889935552128,0.04406264169407032
-6,0.23277409384286044,0.042885301394440745
-5,0.2281768386928062,0.04170081779701975
-4,0.22359993078865406,0.040507348499998756
-3,0.21904393780419062,0.0393049254633848
-2,0.2145123901760269,0.038093374383691224
-1,0.21000320440637657,0.036874719813637796
0,0.20551287772920454,0.035649538050854086
1,0.20103758057622914,0.03442161409493974
2,0.19658786890159344,0.03318480596512727
3,0.19216390349494594,0.031939464477977984
4,0.18775806141243687,0.030689294100602258
5,0.18337221719056557,0.029433552146105962
6,0.17903208650292057,0.028157582916574646
7,0.17470463452900237,0.02688263367167814
8,0.17048685743587452,0.025545419256832468
9,0.1663059406290256,0.02419330976026105
10,0.16213264579147624,0.022845777978628613
11,0.15796990114171103,0.02150051783028696
12,0.1538175277169986,0.020158245387420278
13,0.14967395822141574,0.01882136291958618
14,0.14554286452247295,0.017486475612832945
15,0.14142250383812638,0.01615525312325488
16,0.13731423432157253,0.014826620250179971
17,0.13321734077617234,0.013501563990726533
18,0.12913109223577152,0.012182404004897028
19,0.12505576707747823,0.01086749662234873
20,0.12099133338489505,0.00955693776132666
22 changes: 11 additions & 11 deletions workshop/model/solph-offset.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -144,22 +144,22 @@
"hp_thermal_power = 9.1 # kW\n",
"\n",
"slope = input_data[\"slope\"][:-1]\n",
"offset = input_data[\"offset\"][:-1]/1e3\n",
"offset = input_data[\"offset\"][:-1]\n",
"demand = input_data[\"Heat load (kW)\"][:-1]\n",
"\n",
"\n",
"heat_pump = solph.components.OffsetConverter(\n",
" label=f\"heat pump\",\n",
" inputs={bus_electricity: solph.Flow(\n",
" nominal_value=5,\n",
" min=0.0,\n",
" )},\n",
" outputs={bus_heat_35C: solph.Flow(\n",
" nominal_value=hp_thermal_power,\n",
" nonconvex=solph.NonConvex(),\n",
" min=0.5,\n",
" )},\n",
" coefficients=[offset, slope]\n",
" inputs={bus_electricity: solph.Flow()},\n",
" outputs={\n",
" bus_heat_35C: solph.Flow(\n",
" nominal_value=hp_thermal_power,\n",
" nonconvex=solph.NonConvex(),\n",
" min=0.5,\n",
" )\n",
" },\n",
" conversion_factors={bus_electricity: slope},\n",
" normed_offsets={bus_electricity: offset}\n",
")\n",
"\n",
"es.add(heat_pump)"
Expand Down
16 changes: 9 additions & 7 deletions workshop/model/tespy-partload-performance.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -909,13 +909,14 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The final step to provide the data for the `OffsetConverter` of `oemof-solph` is to change the output structure.\n",
"`oemof-solph` expects the coefficients (offset and slope) per ambient temperature level and inverted, i.e. the heat\n",
"output as function of the electricity input. We can build a new dataframe, that holds the information and exports it\n",
"into csv format and export that information. \n",
"The final step is to export the data for the `OffsetConverter` of `oemof-solph`.\n",
"`oemof-solph` expects a conversion factor and the normed offset per ambient temperature level for the input and\n",
"output flows except a single reference flow. The reference flow will be the heat output of the heat pump. Therefore,\n",
"we need to calculate the electricity conversion factor and normed offset as a function of the heat output with the\n",
"`least_squares` function, dump the results into a new `DataFrame` and export to csv.\n",
"\n",
"```{caution}\n",
"The x and y axes are swapped. Before, the heat load was on the x-axis, the compressor power input on the y-axis.\n",
"`oemof-solph` expects a normed offset, that is the offset value divided by the rated heat output.\n",
"```"
]
},
Expand All @@ -928,10 +929,11 @@
"export_df = pd.DataFrame(index=temperature_range, columns=[\"slope\", \"offset\"])\n",
"\n",
"for key, data in results.items():\n",
" y = -data.index.values.astype(float)\n",
" x = data[\"compressor-power\"].values.astype(float)\n",
" x = -data.index.values.astype(float)\n",
" y = data[\"compressor-power\"].values.astype(float)\n",
" export_df.loc[key] = least_squares(x, y)\n",
"\n",
"export_df[\"offset\"] /= -Q_design\n",
"export_df.to_csv(\"coefficients-offset-converter.csv\")"
]
}
Expand Down

0 comments on commit c820a04

Please sign in to comment.