Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjustments regarding the new solph structure #21

Merged
merged 13 commits into from
Mar 29, 2022
26 changes: 20 additions & 6 deletions docs/tutorials/datapackage-reader.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
" m.solve(\"cbc\")\n",
"\n",
" # get the results from the the solved model(still oemof.solph)\n",
" m.results = m.results()"
" results = m.results()"
]
},
{
Expand All @@ -204,7 +204,7 @@
"if cbc:\n",
" # now we use the write results method to write the results in oemof-tabular\n",
" # format\n",
" pp.write_results(m, results_path)\n",
" pp.write_results(m, results, results_path)\n",
"\n"
]
},
Expand All @@ -225,15 +225,29 @@
" print(os.listdir(results_path))\n",
" bus = 'bus0'\n",
" path = os.path.join(results_path, (\"\").join([bus, '.csv']))\n",
" df = pd.read_csv(path, index_col=0, parse_dates=True).loc[:, 'wind'].plot()"
" df = pd.read_csv(path, index_col=0, parse_dates=True)\n",
" df.loc[:, 'bp'].plot()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"m.write(io_options={\"symbolic_solver_labels\": True})"
]
}
],
"metadata": {
"@webio": {
"lastCommId": null,
"lastKernelId": null
},
"kernelspec": {
"display_name": "Python 3",
"display_name": "tabular-env",
"language": "python",
"name": "python3"
"name": "tabular-env"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -245,7 +259,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
"version": "3.6.9"
}
},
"nbformat": 4,
Expand Down
26 changes: 7 additions & 19 deletions docs/tutorials/facade-usage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -193,22 +193,6 @@
")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Add the subnodes of the Reservoir to energy system (hopefully soon obsolete). When reading from datapackage resource this is not necessary as the datapackage reader takes care of this."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"es.add(*es.groups['rsv'].subnodes)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -453,10 +437,14 @@
}
],
"metadata": {
"@webio": {
"lastCommId": null,
"lastKernelId": null
},
"kernelspec": {
"display_name": "Python 3",
"display_name": "tabular-env",
"language": "python",
"name": "python3"
"name": "tabular-env"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -468,7 +456,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
"version": "3.6.9"
}
},
"nbformat": 4,
Expand Down
8 changes: 4 additions & 4 deletions docs/tutorials/model-from-tabular-data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@
"\n",
"Intertemporal energy balance of the storage:\n",
"\n",
"$$ x^{level}_{s}(t) = \\eta^{loss} x^{level}_{s}(t) + \\eta x^{flow}_{s, in} - \\eta x^{flow}_{s, out}(t) \\qquad \\forall t \\in T, \\forall s \\in S$$ \n",
"$$ x^{level}_{s}(t) = \\eta^{loss} x^{level}_{s}(t) + \\eta^{in} x^{flow}_{s, in} - \\frac{x^{flow}_{s, out}(t)}{\\eta^{out}} \\qquad \\forall t \\in T, \\forall s \\in S$$ \n",
"\n",
"Bounds of the storage level variable $x^{level}_s(t)$:\n",
"\n",
Expand Down Expand Up @@ -679,9 +679,9 @@
"lastKernelId": null
},
"kernelspec": {
"display_name": "angus-env",
"display_name": "tabular-env",
"language": "python",
"name": "angus-env"
"name": "tabular-env"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -693,7 +693,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
"version": "3.6.9"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def read(*names, **kwargs):
"datapackage==1.5.1",
"tableschema==1.3.0",
"geojson",
"oemof>=0.3.1",
"oemof.solph>=0.4.0",
"pandas>=0.22",
"seaborn",
"paramiko",
Expand Down
38 changes: 38 additions & 0 deletions src/oemof/tabular/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,48 @@
Module that contains the command line app.

"""
import copy

from datapackage import Package, exceptions
import click
import pandas as pd
from .datapackage import building
import collections


def update(d, u):
for k, v in u.items():
if isinstance(v, collections.Mapping):
d[k] = update(d.get(k, {}), v)
else:
d[k] = v
return d

scenarios = {}
# TODO: This definitely needs docstrings.
class Scenario(dict):
@classmethod
def from_path(cls, path):
scenarios[path] = cls(
building.read_build_config(path)
)
if "name" in scenarios[path]:
name = scenarios[path]["name"]
scenarios[name] = scenarios[path]
return scenarios[path]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if "parents" in self:
for parent in self["parents"]:
if parent in scenarios:
scenario = copy.deepcopy(scenarios[parent])
else:
scenario = copy.deepcopy(type(self).from_path(parent))

# hackish, but necessary to get self (the child) right
# with all key/values of the parent and it's own key/value pairs
update(scenario, self)
update(self, scenario)

def _test(ctx, package):
"""
Expand Down
3 changes: 2 additions & 1 deletion src/oemof/tabular/datapackage/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from oemof.energy_system import EnergySystem
from oemof.network.energy_system import EnergySystem

from .reading import deserialize_energy_system
from . import processing, building, aggregation

EnergySystem.from_datapackage = classmethod(deserialize_energy_system)
2 changes: 0 additions & 2 deletions src/oemof/tabular/datapackage/building.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ def infer_metadata(
}
)


r.commit()
r.save(os.path.join("resources", f.replace(".csv", ".json")))
p.add_resource(r.descriptor)
Expand All @@ -193,7 +192,6 @@ def infer_metadata(
r.save(os.path.join("resources", f.replace(".csv", ".json")))
p.add_resource(r.descriptor)


if not os.path.exists("data/geometries"):
print(
"No geometries path found in directory {}. Skipping...".format(
Expand Down
2 changes: 1 addition & 1 deletion src/oemof/tabular/datapackage/reading.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import datapackage as dp
import pandas as pd

from oemof.network import Bus, Component
from oemof.network.network import Bus, Component

from ..tools import HSN, raisestatement, remap

Expand Down
6 changes: 2 additions & 4 deletions src/oemof/tabular/examples/scripting/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@
# select solver 'gurobi', 'cplex', 'glpk' etc
m.solve("cbc")

# get the results from the the solved model(still oemof.solph)
m.results = m.results()

results = m.results()
# now we use the write results method to write the results in oemof-tabular
# format
pp.write_results(m, results_path)
pp.write_results(m, results, results_path)
4 changes: 1 addition & 3 deletions src/oemof/tabular/examples/scripting/postprocessing.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import pkg_resources as pkg

from oemof.outputlib import views
from oemof.solph import EnergySystem, Model
from oemof.solph import EnergySystem, Model, views

from oemof.tabular.facades import TYPEMAP
import oemof.tabular.datapackage # noqa
import oemof.tabular.tools.postprocessing as pp


examples = ["dispatch", "investment", "foreignkeys"]
for example in examples:
print("Runnig postprocessing example with datapackage {}".format(example))
Expand Down
Loading