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

Add postprocessing module #102

Merged
merged 23 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
848008c
Add postprocessing module
henhuy May 4, 2023
ff5b4fa
Minor change
henhuy May 4, 2023
e7b0446
Update version to v0.0.5dev
henhuy May 4, 2023
f75e45f
Remove headings in CHANGELOG.rst
henhuy May 4, 2023
a6a6c9a
Fix test examples error due to version in datapackage.json
henhuy May 4, 2023
40be324
Make linter happy
henhuy May 4, 2023
fe22df8
Add usage section for new postprocessing module
henhuy May 12, 2023
e6bc50d
Remove legacy postprocessing from oemof.tabular
henhuy Jul 25, 2023
61b681e
Fix summed variable cost calculation in case of empty variable costs
henhuy Jul 25, 2023
71b2998
Fix carrier extraction if busses are named differently
henhuy Jul 25, 2023
15cb1a7
Adapt new postprocessing module in example compute script
henhuy Jul 25, 2023
cc5b760
Reactivate testing of example scripts
henhuy Jul 25, 2023
0269e06
Fix oemof.tabular version in multi period example datapackages
henhuy Jul 25, 2023
7524e95
Add multi period examples to compute script and thus to the tests
nailend Jul 26, 2023
f456995
Fix initialization of postprocessing calculator for multi-period simu…
henhuy Jul 26, 2023
44eaa4d
Transpose period scalars in core results
henhuy Jul 26, 2023
ff6383d
Change investment-multi-period datapackage to hold varying capacity c…
henhuy Jul 26, 2023
31a5196
Change investment-multi-period datapackage to hold varying capacity c…
henhuy Jul 26, 2023
52c1f66
Fix invested (storage) capacity for multi-period simulation
henhuy Jul 26, 2023
f1b7ec5
Fix solph version to current dev until v0.5.1 is out
nailend Aug 21, 2023
ae0cde8
Fix tabular version to 0.0.4dev in init
nailend Aug 21, 2023
0b17194
Revert "Fix solph version to current dev until v0.5.1 is out
nailend Aug 21, 2023
98db9fc
Merge branch 'dev' into feature/postprocessing
nailend Aug 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
nailend marked this conversation as resolved.
Show resolved Hide resolved
"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.
Loading
Loading