-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example for pv-household in ipython notebook
- Loading branch information
Showing
1 changed file
with
191 additions
and
0 deletions.
There are no files selected for viewing
191 changes: 191 additions & 0 deletions
191
src/oemof/tabular/examples/scripting/pv_storage_household.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# PV + Storage modelling for household " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import os\n", | ||
"import pkg_resources as pkg\n", | ||
"import pandas as pd\n", | ||
"\n", | ||
"\n", | ||
"from oemof.solph import EnergySystem, Model, Bus\n", | ||
"import oemof.tabular.tools.postprocessing as pp\n", | ||
"import oemof.tabular.facades as fc" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Preparation" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# datapath for input data from the oemof tabular pacakge\n", | ||
"datapath = pkg.resource_filename(\"oemof.tabular\", \"examples/data/data.xls\")\n", | ||
"\n", | ||
"# results path for output\n", | ||
"results_path = os.path.join(\n", | ||
" os.path.expanduser(\"~\"), \"oemof-results\", \"pv-storage-household\", \"output\"\n", | ||
")\n", | ||
"\n", | ||
"if not os.path.exists(results_path):\n", | ||
" os.makedirs(results_path)\n", | ||
"\n", | ||
"timeseries = pd.read_excel(\n", | ||
" datapath, sheet_name=\"timeseries\", index_col=[0], parse_dates=True\n", | ||
")\n", | ||
"timeseries.index.freq = \"1H\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Create Energy System" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"es = EnergySystem(timeindex=timeseries.index)\n", | ||
"\n", | ||
"bus = Bus(label=\"household\")\n", | ||
"es.add(bus)\n", | ||
"\n", | ||
"es.add(\n", | ||
" fc.Volatile(\n", | ||
" label=\"pv\",\n", | ||
" carrier=\"solar\",\n", | ||
" tech=\"pv\",\n", | ||
" capacity=10,\n", | ||
" bus=bus,\n", | ||
" profile=timeseries[\"pv\"],\n", | ||
" )\n", | ||
")\n", | ||
"\n", | ||
"es.add(\n", | ||
" fc.Storage(\n", | ||
" label=\"storage\",\n", | ||
" bus=bus,\n", | ||
" carrier=\"lithium\",\n", | ||
" tech=\"battery\",\n", | ||
" capacity=3,\n", | ||
" storage_capacity=12,\n", | ||
" )\n", | ||
")\n", | ||
"\n", | ||
"es.add(\n", | ||
" fc.Shortage(\n", | ||
" label=\"grid_buy\",\n", | ||
" bus=bus,\n", | ||
" carrier=\"electricity\",\n", | ||
" tech=\"grid\",\n", | ||
" capacity=100,\n", | ||
" marginal_cost=0.3,\n", | ||
" )\n", | ||
")\n", | ||
"\n", | ||
"es.add(\n", | ||
" fc.Excess(\n", | ||
" label=\"grid_sell\",\n", | ||
" bus=bus,\n", | ||
" carrier=\"electricity\",\n", | ||
" tech=\"grid\",\n", | ||
" marginal_cost=-0.1,\n", | ||
" )\n", | ||
")\n", | ||
"\n", | ||
"es.add(fc.Load(label=\"load\", bus=bus, amount=20e3, profile=timeseries[\"load\"]))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Create model and solve" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# create the model using the energy system with its components (see: es.nodes)\n", | ||
"m = Model(es)\n", | ||
"\n", | ||
"# solve model using cbc solver\n", | ||
"m.solve(\"cbc\")\n", | ||
"\n", | ||
"# write back results\n", | ||
"m.results = m.results()\n", | ||
"\n", | ||
"supply = pp.supply_results(bus=[\"household\"], es=es, results=m.results)\n", | ||
"demand = pp.demand_results(bus=[\"household\"], es=es, results=m.results)\n", | ||
"# pd.concat([supply, demand], axis=1).to_csv('results.csv')\n", | ||
"\n", | ||
"pp.write_results(m, results_path)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"%matplotlib inline\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"s=1000\n", | ||
"e=1048\n", | ||
"\n", | ||
"fig = plt.figure(figsize=(20,10))\n", | ||
"ax = plt.subplot(111)\n", | ||
"\n", | ||
"supply.iloc[s:e].plot(ax=ax)\n", | ||
"demand.iloc[s:e].plot(ax=ax)\n", | ||
"\n", | ||
"ax.legend(loc='upper right')" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"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.6.7" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |