Skip to content

Commit

Permalink
Merge pull request #102 from oemof/feature/postprocessing
Browse files Browse the repository at this point in the history
Add postprocessing module
  • Loading branch information
nailend committed Aug 24, 2023
2 parents a3e9cba + 98db9fc commit 72cba6e
Show file tree
Hide file tree
Showing 21 changed files with 1,242 additions and 352 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@
Changelog
=========



Unreleased
------------------
Features

* Add postprocessing module `#102 <https://github.com/oemof/oemof-tabular/pull/102>`_

0.0.3 (2022-01-26)
------------------
Fixes
#####

* Fix link by not setting constraints that limit direction `#38 <https://github.com/oemof/oemof-tabular/pull/38>`_
* Fix storage investment `#33 <https://github.com/oemof/oemof-tabular/pull/33>`_
Expand All @@ -14,7 +21,6 @@ Fixes
* Marginal cost `#23 <https://github.com/oemof/oemof-tabular/pull/23>`_

Features
########

* Adjust to new oemof.solph structure `#21 <https://github.com/oemof/oemof-tabular/pull/21>`_
* Allow to define custom foreign keys `#39 <https://github.com/oemof/oemof-tabular/pull/39>`_
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ Overview
:alt: PyPI Package latest release
:target: https://pypi.org/project/oemof.tabular

.. |commits-since| image:: https://img.shields.io/badge/dynamic/json.svg?label=%2B&url=https%3A%2F%2Fapi.github.com%2Frepos%2Foemof%2Foemof-tabular%2Fcompare%2Fv0.0.3...dev&query=%24.total_commits&colorB=blue
.. |commits-since| image:: https://img.shields.io/badge/dynamic/json.svg?label=%2B&url=https%3A%2F%2Fapi.github.com%2Frepos%2Foemof%2Foemof-tabular%2Fcompare%2Fv0.0.5...dev&query=%24.total_commits&colorB=blue
:alt: Commits since latest release
:target: https://github.com/oemof/oemof-tabular/compare/v0.0.3...dev
:target: https://github.com/oemof/oemof-tabular/compare/v0.0.5...dev

.. |wheel| image:: https://img.shields.io/pypi/wheel/oemof.tabular.svg
:alt: PyPI Wheel
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
year = '2018'
author = 'Stephan Günther'
copyright = '{0}, {1}'.format(year, author)
version = release = '0.0.4dev'
version = release = '0.0.5dev'

pygments_style = 'trac'
templates_path = ['.']
Expand Down
63 changes: 46 additions & 17 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -370,20 +370,20 @@ the results.

.. code-block:: python
from oemof.solph import EnergySystem, Model
from renpass.facades import Load, Dispatchable, Bus
from oemof.solph import EnergySystem, Model
from renpass.facades import Load, Dispatchable, Bus
es = EnergySystem.from_datapackage(
'datapackage.json',
attributemap={
Demand: {"demand-profiles": "profile"}},
typemap={
'load': Load,
'dispatchable': Dispatchable,
'bus': Bus})
es = EnergySystem.from_datapackage(
'datapackage.json',
attributemap={
Demand: {"demand-profiles": "profile"}},
typemap={
'load': Load,
'dispatchable': Dispatchable,
'bus': Bus})
m = Model(es)
m.solve()
m = Model(es)
m.solve()
.. note::
Expand All @@ -393,17 +393,46 @@ the results.
datapackage and map those to the facade classes (use `typemap` attribute for
this)

Write results
Postprocessing
--------------
After solving the energysystem model, results can be calculated using the
:py:mod:`~oemof.tabular.postprocessing` module. The postprocessing module itself consists of four modules:
- :py:mod:`~oemof.tabular.postprocessing.core` holds base classes for postprocessing
- :py:mod:`~oemof.tabular.postprocessing.calculations` holds predefined calculations
- :py:mod:`~oemof.tabular.postprocessing.helper` holds helper functions which are used in calculations
- :py:mod:`~oemof.tabular.postprocessing.naming` holds functions for naming results and adding additional information

The standard way of using the postprocessing module is to initiate the
:py:class:`~oemof.tabular.postprocessing.core.Calculator` class from
:py:mod:`~oemof.tabular.postprocessing.core` module with parameters and results from an optimized :py:mod:`~oemof.solph` `Energysystem`.
Afterwards, calculations can be performed by either using predefined calculations from :py:mod:`~oemof.tabular.postprocessing.calculations` or
by self-defined calculations inherited from :py:class:`~oemof.tabular.postprocessing.core.Calculation` class in
:py:mod:`~oemof.tabular.postprocessing.core`.

See the following example on how to use the :py:mod:`~oemof.tabular.postprocessing` module:

.. code-block:: python
from oemoflex.postprocessing import core, calculations
calculator = core.Calculator(es.params, es.results)
aggregated_flows = calculations.AggregatedFlows(calculator).result
storage_losses = calculations.StorageLosses(calculator).result
transmission_losses = calculations.TransmissionLosses(calculator).result
invested_capacity = calculations.InvestedCapacity(calculator).result
invested_storage_capacity = calculations.InvestedStorageCapacity(calculator).result
invested_capacity_costs = calculations.InvestedCapacityCosts(calculator).result
invested_storage_capacity_costs = calculations.InvestedStorageCapacityCosts(calculator).result
summed_carrier_costs = calculations.SummedCarrierCosts(calculator).result
summed_marginal_costs = calculations.SummedMarginalCosts(calculator).result
total_system_costs = calculations.TotalSystemCosts(calculator).result
For writing results you either use the `oemof.outputlib` functionalities or
/ and the oemof tabular specific postprocessing functionalities of this
package.
Reproducible Workflows
=======================

To get reproducible results we recommend setting up a folder strucutre
To get reproducible results we recommend setting up a folder structure
as follows:

::
Expand Down
2 changes: 1 addition & 1 deletion punch_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
major = 0
minor = 0
patch = 2
patch = 5
status = "dev"

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,4 @@
}
}
]
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name;type;carrier;tech;capacity;capacity_cost;bus;marginal_cost;profile;output_parameters;expandable;lifetime;age
gas-gt;dispatchable;gas;gt;0;100;bus1;40;;{"full_load_time_max": 2000};True;40;5
coal-st;dispatchable;coal;st;0;100;bus0;40;;{};True;40;10
lignite-st;dispatchable;lignite;st;0;50;bus0;20;;{};True;40;20
wind;volatile;wind;onshore;0;50;bus0;0;wind-profile;{};True;20;5
pv;volatile;solar;pv;0;20;bus1;0;pv-profile;{};True;20;5
gas-gt;dispatchable;gas;gt;0;cc_profile;bus1;40;;{"full_load_time_max": 2000};True;40;5
coal-st;dispatchable;coal;st;0;cc_profile;bus0;40;;{};True;40;10
lignite-st;dispatchable;lignite;st;0;cc_profile;bus0;20;;{};True;40;20
wind;volatile;wind;onshore;0;cc_profile;bus0;0;wind-profile;{};True;20;5
pv;volatile;solar;pv;0;cc_profile;bus1;0;pv-profile;{};True;20;5
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
timeindex,cc_profile
2015-01-01T00:00:00Z,100
2015-01-01T01:00:00Z,101
2015-01-01T02:00:00Z,102
2015-01-01T03:00:00Z,103
2015-01-01T04:00:00Z,104
2015-01-01T05:00:00Z,105
2015-01-01T06:00:00Z,106
2015-01-01T07:00:00Z,107
2015-01-01T08:00:00Z,108
2015-01-01T09:00:00Z,109
2015-01-01T10:00:00Z,110
2015-01-01T11:00:00Z,111
2015-01-01T12:00:00Z,112
2035-01-01T00:00:00Z,113
2035-01-01T01:00:00Z,114
2035-01-01T02:00:00Z,115
2035-01-01T03:00:00Z,116
2035-01-01T04:00:00Z,117
2035-01-01T05:00:00Z,118
2035-01-01T06:00:00Z,119
2035-01-01T07:00:00Z,120
2035-01-01T08:00:00Z,121
2035-01-01T09:00:00Z,122
2035-01-01T10:00:00Z,123
2035-01-01T11:00:00Z,124
2035-01-01T12:00:00Z,125
2050-01-01T00:00:00Z,126
2050-01-01T01:00:00Z,127
2050-01-01T02:00:00Z,128
2050-01-01T03:00:00Z,129
2050-01-01T04:00:00Z,130
2050-01-01T05:00:00Z,131
2050-01-01T06:00:00Z,132
2050-01-01T07:00:00Z,133
2050-01-01T08:00:00Z,134
2050-01-01T09:00:00Z,135
2050-01-01T10:00:00Z,136
2050-01-01T11:00:00Z,137
2050-01-01T12:00:00Z,138
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@
},
{
"name": "capacity_cost",
"type": "integer",
"type": "string",
"format": "default"
},
{
Expand Down Expand Up @@ -451,6 +451,12 @@
"fields": "name"
}
},
{
"fields": "capacity_cost",
"reference": {
"resource": "capacity_cost_profile"
}
},
{
"fields": "profile",
"reference": {
Expand Down Expand Up @@ -555,6 +561,31 @@
]
}
},
{
"path": "data/sequences/capacity_cost_profile.csv",
"profile": "tabular-data-resource",
"name": "capacity_cost_profile",
"format": "csv",
"mediatype": "text/csv",
"encoding": "utf-8",
"schema": {
"fields": [
{
"name": "timeindex",
"type": "datetime",
"format": "default"
},
{
"name": "cc_profile",
"type": "integer",
"format": "default"
}
],
"missingValues": [
""
]
}
},
{
"path": "data/sequences/load_profile.csv",
"profile": "tabular-data-resource",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"profile": ["load", "source"],
"chp": ["chp"],
"from_to_bus": ["link", "conversion"],
"capacity_cost": ["source"],
},
**kwargs,
)
22 changes: 15 additions & 7 deletions src/oemof/tabular/examples/scripting/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@
import os

import pkg_resources as pkg
from oemof.solph import EnergySystem, Model

import oemof.tabular.tools.postprocessing as pp
from oemof.solph import EnergySystem, Model, processing

# DONT REMOVE THIS LINE!
from oemof.tabular import datapackage # noqa
from oemof.tabular.constraint_facades import CONSTRAINT_TYPE_MAP
from oemof.tabular.facades import TYPEMAP
from oemof.tabular.postprocessing import calculations

examples = ["dispatch", "investment", "foreignkeys", "emission_constraint"]
examples = [
"dispatch_multi_period",
"dispatch",
"investment",
"investment_multi_period",
"foreignkeys",
"emission_constraint",
]
for example in examples:
print("Running compute example with datapackage {}".format(example))

Expand All @@ -23,7 +29,7 @@

# create path for results (we use the datapackage_dir to store results)
results_path = os.path.join(
os.path.expanduser("~"), "oemof-results", example, "output"
os.path.expanduser("~"), "oemof-results", example
)
if not os.path.exists(results_path):
os.makedirs(results_path)
Expand All @@ -50,7 +56,9 @@
# select solver 'gurobi', 'cplex', 'glpk' etc
m.solve("cbc")

results = m.results()
es.params = processing.parameter_as_dict(es)
es.results = m.results()
# now we use the write results method to write the results in oemof-tabular
# format
pp.write_results(m, results, results_path)
postprocessed_results = calculations.run_postprocessing(es)
postprocessed_results.to_csv(os.path.join(results_path, "results.csv"))
45 changes: 0 additions & 45 deletions src/oemof/tabular/examples/scripting/postprocessing.py

This file was deleted.

Empty file.

0 comments on commit 72cba6e

Please sign in to comment.