Skip to content

Breaking postprocessing in plot_balance_timeseries if Heating sector is deactivated #1661

@daniel-rdt

Description

@daniel-rdt

Version Checks (indicate both or one)

  • I have confirmed this bug exists on the lastest release of PyPSA-Eur.

  • I have confirmed this bug exists on the current master branch of PyPSA-Eur.

Issue Description

When one of the carrier_groups defined for plot_balance_timeseries is not included in the model scope (e.g. heating), the workflow will break at this postprocessing step since none of the carriers defined for this group are included in the network. A fix is needed here to either:

  • be able to overwrite the default plotting configuration so that you can deactivate a carrier_group for balance_timeseries here
  • or check for missing/empty carrier_groups in plot_balance_timeseries.py

Reproducible Example

# Run 
snakemake -call --configfile config/test/config.overnight.yaml

# with the following changes in config/test/config.overnight.yaml:
sector:
  heating: false
  industry: false
  agriculture: false
  shipping: false
  aviation: false
  biomass: false
plotting:
  balance_map:
    bus_carriers:
      - AC
      - H2
      - gas
      - oil
      - co2 stored

Expected Behavior

This will run into a workflow error in plot_balance_timeseries:

Traceback (most recent call last):
  File "/Users/daniel/Desktop/Work/OET/Coding/my_forks/pypsa-eur/.snakemake/scripts/tmpnwatj5uv.plot_balance_timeseries.py", line 256, in <module>
    list(tqdm(pool.imap(func, groups.items()), **tqdm_kwargs))
  File "/opt/homebrew/Caskroom/miniforge/base/envs/pypsa-eur/lib/python3.12/site-packages/tqdm/std.py", line 1181, in __iter__
    for obj in iterable:
               ^^^^^^^^
  File "/opt/homebrew/Caskroom/miniforge/base/envs/pypsa-eur/lib/python3.12/multiprocessing/pool.py", line 873, in next
    raise value
  File "/opt/homebrew/Caskroom/miniforge/base/envs/pypsa-eur/lib/python3.12/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
    ^^^^^^^^^^^^^^^^^
  File "/Users/daniel/Desktop/Work/OET/Coding/my_forks/pypsa-eur/scripts/plot_balance_timeseries.py", line 177, in process_carrier
    plot_energy_balance_timeseries(
    ^^^^^^^^^^^^^^^^^
  File "/Users/daniel/Desktop/Work/OET/Coding/my_forks/pypsa-eur/scripts/plot_balance_timeseries.py", line 112, in plot_energy_balance_timeseries
    plot_stacked_area_steplike(ax, pos, colors)
      ^^^^^^^^^^^^^^^^^
  File "/Users/daniel/Desktop/Work/OET/Coding/my_forks/pypsa-eur/scripts/plot_balance_timeseries.py", line 33, in plot_stacked_area_steplike
    previous_series = np.zeros_like(df_cum.iloc[:, 0].values)
      ^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniforge/base/envs/pypsa-eur/lib/python3.12/site-packages/pandas/core/indexing.py", line 1184, in __getitem__
    return self._getitem_tuple(key)
    ^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniforge/base/envs/pypsa-eur/lib/python3.12/site-packages/pandas/core/indexing.py", line 1690, in _getitem_tuple
    tup = self._validate_tuple_indexer(tup)
    ^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniforge/base/envs/pypsa-eur/lib/python3.12/site-packages/pandas/core/indexing.py", line 966, in _validate_tuple_indexer
    self._validate_key(k, i)
    ^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniforge/base/envs/pypsa-eur/lib/python3.12/site-packages/pandas/core/indexing.py", line 1592, in _validate_key
    self._validate_integer(key, axis)
    ^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniforge/base/envs/pypsa-eur/lib/python3.12/site-packages/pandas/core/indexing.py", line 1685, in _validate_integer
    raise IndexError("single positional indexer is out-of-bounds")
    ^^^^^^^^^^^^^^^^^
IndexError: single positional indexer is out-of-bounds

Installed Versions

Details Replace this line.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions