Skip to content

Commit 3be062c

Browse files
authored
fix:use sources param in 5th tutorial due to PV schedules in 3rd tutorial (#1846)
* fix:use sources param in 5th tutorial due to PV schedules in 3rd tutorial Signed-off-by: Nicolas Höning <nicolas@seita.nl> * remove whitespace Signed-off-by: Nicolas Höning <nicolas@seita.nl> * add changelog entry Signed-off-by: Nicolas Höning <nicolas@seita.nl> * no spaces before colons, fix wording Signed-off-by: Nicolas Höning <nicolas@seita.nl> --------- Signed-off-by: Nicolas Höning <nicolas@seita.nl>
1 parent 08e26e9 commit 3be062c

File tree

4 files changed

+22
-17
lines changed

4 files changed

+22
-17
lines changed

documentation/changelog.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Infrastructure / Support
3333
----------------------
3434
* Updated dependencies [see `PR #1752 <https://www.github.com/FlexMeasures/flexmeasures/pull/1752>`_, `PR #1820 <https://www.github.com/FlexMeasures/flexmeasures/pull/1820>`_ and `PR #1842 <https://www.github.com/FlexMeasures/flexmeasures/pull/1842>`_]
3535
* Speed up data searches by refactoring our filter for selecting data from the latest version of a data generating model [see `PR #1698 <https://github.com/FlexMeasures/flexmeasures/pull/1698>`_]
36-
* Add new tutorial for PV curtailment and multi-asset scheduling [see `PR #1804 <https://github.com/FlexMeasures/flexmeasures/pull/1804>`_]
36+
* Add new tutorial for PV curtailment and multi-asset scheduling [see `PR #1804 <https://github.com/FlexMeasures/flexmeasures/pull/1804>`_ and `PR #1846 <https://github.com/FlexMeasures/flexmeasures/pull/1846>`_]
3737
* Drop need for .env file in favour of more adaptation of flexmeasures.cfg config file [see `PR #1759 <https://github.com/FlexMeasures/flexmeasures/pull/1759>`_]
3838
* Support saving beliefs with a ``belief_horizon`` in the ``AggregatorReporter`` [see `PR #1735 <https://www.github.com/FlexMeasures/flexmeasures/pull/1735>`_]
3939
* Support skipping a ``PandasReporter`` transformation if any of its (keyword) arguments has no data [see `PR #1669 <https://www.github.com/FlexMeasures/flexmeasures/pull/1669>`_]

documentation/tut/scripts/run-tutorial5-in-docker.sh

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,27 @@ docker exec -it flexmeasures-server-1 flexmeasures show beliefs --sensor 7 --sta
1313

1414
docker exec -it flexmeasures-server-1 flexmeasures show data-sources --show-attributes --id 6
1515

16-
echo "[TUTORIAL-RUNNER] Configure reporter ..."
16+
echo "[TUTORIAL-RUNNER] Configure headroom reporter ..."
1717

1818
echo "
1919
{
20-
'weights' : {
21-
'grid connection capacity' : 1.0,
22-
'PV' : -1.0,
20+
'weights': {
21+
'grid connection capacity': 1.0,
22+
'PV': -1.0,
2323
}
2424
}" > headroom-config.json
2525
docker cp headroom-config.json flexmeasures-server-1:/app
2626

2727
echo "
2828
{
29-
'input' : [{'name' : 'grid connection capacity','sensor' : 7},
30-
{'name' : 'PV', 'sensor' : 3}],
31-
'output' : [{'sensor' : 8}]
29+
'input': [{'name': 'grid connection capacity', 'sensor': 7},
30+
{'name': 'PV', 'sensor': 3, 'sources': [4]}],
31+
'output': [{'sensor': 8}]
3232
}" > headroom-parameters.json
3333
docker cp headroom-parameters.json flexmeasures-server-1:/app
3434

3535

36-
echo "[TUTORIAL-RUNNER] add report ..."
36+
echo "[TUTORIAL-RUNNER] add headroom report ..."
3737

3838
docker exec -it flexmeasures-server-1 flexmeasures add report --reporter AggregatorReporter \
3939
--parameters headroom-parameters.json --config headroom-config.json \
@@ -49,8 +49,8 @@ echo "[TUTORIAL-RUNNER] now the inflexible process ..."
4949

5050
echo "
5151
{
52-
'input' : [{'sensor' : 4}],
53-
'output' : [{'sensor' : 9}]
52+
'input': [{'sensor': 4}],
53+
'output': [{'sensor': 9}]
5454
}" > inflexible-parameters.json
5555

5656
docker cp inflexible-parameters.json flexmeasures-server-1:/app
@@ -67,8 +67,8 @@ echo "[TUTORIAL-RUNNER] now the breakable process ..."
6767

6868
echo "
6969
{
70-
'input' : [{'sensor' : 5}],
71-
'output' : [{'sensor' : 10}]
70+
'input': [{'sensor': 5}],
71+
'output': [{'sensor': 10}]
7272
}" > breakable-parameters.json
7373

7474
docker cp breakable-parameters.json flexmeasures-server-1:/app
@@ -86,8 +86,8 @@ echo "[TUTORIAL-RUNNER] now the breakable process ..."
8686

8787
echo "
8888
{
89-
'input' : [{'sensor' : 6}],
90-
'output' : [{'sensor' : 11}]
89+
'input' : [{'sensor': 6}],
90+
'output' : [{'sensor': 11}]
9191
}" > shiftable-parameters.json
9292

9393
docker cp shiftable-parameters.json flexmeasures-server-1:/app

documentation/tut/toy-example-reporter.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,14 @@ In practice, we need to create the `config` and `parameters`:
120120
$ echo "
121121
$ {
122122
$ 'input': [{'name': 'grid connection capacity', 'sensor': 7},
123-
$ {'name': 'PV', 'sensor': 3}],
123+
$ {'name': 'PV', 'sensor': 3, 'sources': [4]}],
124124
$ 'output': [{'sensor': 8}]
125125
$ }" > headroom-parameters.json
126126
127127
The output sensor (ID: 8) is actually the one created just to store that information - the headroom our battery has when considering solar production.
128128

129+
We limit the PV input to data with source 4, which is the one created when we added the toy account and is associated with our solar forecasts. This way, we ensure that only the forecasted values are used in the report, and not (also) schedules from the 3rd tutorial.
130+
129131
Finally, we can create the report with the following command:
130132

131133
.. code-block:: bash

flexmeasures/data/models/reporting/aggregator.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def _compute_report(
8383
)
8484

8585
# Check for multiple sources within the entire frame (excluding different versions of the same source)
86+
# Raise error if that is the case and no source filter was applied - user should be explicit here
8687
unique_sources = df.lineage.sources
8788
properties = [
8889
"name",
@@ -99,9 +100,11 @@ def _compute_report(
99100
and (source is None or len(source) == 0)
100101
):
101102
raise ValueError(
102-
"Missing attribute source or sources. The fields `source` or `sources` is required when having multiple sources within the time window."
103+
f"Missing attribute 'sources' for input sensor {sensor.id}: {sensor.name} (to identify one specific source). The field `sources` is required when having data with multiple sources within the time window, to ensure only required data is used in the reporter. "
104+
f"We found data from the following sources: {[source.id for source in unique_sources]}."
103105
)
104106

107+
# drop all indexes but event_start
105108
df = df.droplevel([1, 2, 3])
106109

107110
# apply weight

0 commit comments

Comments
 (0)