PyPSA / pypsa-eur

PyPSA-Eur: A Sector-Coupled Open Optimisation Model of the European Energy System
https://pypsa-eur.readthedocs.io/
317 stars 222 forks source link

Option "all" not supported for clustering: TypeError: Clustering.__init__() takes 4 positional arguments but 6 were given #1150

Closed fhg-isi closed 2 weeks ago

fhg-isi commented 1 month ago

a) I tried to use the sector tutorial with a larger number of clusters and changed the value from 5 to 'all'. Then I get the error below. Maybe you want to use tools like pylint etc. to check for number of arguments.

INFO:pypsa.io:Imported network elec_s.nc has buses, carriers, generators, lines, loads, shapes ERROR:root:Uncaught exception Traceback (most recent call last): File "/home/projekt-resilient03/pypsa-eur/.snakemake/scripts/tmpnlfyn0go.cluster_network.py", line 528, in clustering = pypsa.clustering.spatial.Clustering( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: Clustering.init() takes 4 positional arguments but 6 were given RuleException: CalledProcessError in file /home/projekt-resilient03/pypsa-eur/rules/build_electricity.smk, line 511: Command 'set -euo pipefail; /home/projekt-resilient03/conda/envs/pypsa-eur/bin/python3.11 /home/projekt-resilient03/pypsa-eur/.snakemake/scripts/tmpnlfyn0go.cluster_network.py' returned non-zero exit status 1. [Fri Jul 12 10:11:45 2024]

b) After removing some of the arguments I got another error:

INFO:main:Using biomass potentials for 2030. Traceback (most recent call last): File "/home/projekt-resilient03/pypsa-eur/.snakemake/scripts/tmp9so9_wsv.build_shipping_demand.py", line 60, in nodal_demand = demand.loc[countries].fillna(0.0)


  File "/home/projekt-resilient03/conda/envs/pypsa-eur/lib/python3.11/site-packages/pandas/core/indexing.py", line 1191, in __getitem__
    return self._getitem_axis(maybe_callable, axis=axis)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/projekt-resilient03/conda/envs/pypsa-eur/lib/python3.11/site-packages/pandas/core/indexing.py", line 1420, in _getitem_axis
    return self._getitem_iterable(key, axis=axis)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/projekt-resilient03/conda/envs/pypsa-eur/lib/python3.11/site-packages/pandas/core/indexing.py", line 1360, in _getitem_iterable
    keyarr, indexer = self._get_listlike_indexer(key, axis)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/projekt-resilient03/conda/envs/pypsa-eur/lib/python3.11/site-packages/pandas/core/indexing.py", line 1558, in _get_listlike_indexer
    keyarr, indexer = ax._get_indexer_strict(key, axis_name)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/projekt-resilient03/conda/envs/pypsa-eur/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 6200, in _get_indexer_strict
    self._raise_if_missing(keyarr, indexer, axis_name)
  File "/home/projekt-resilient03/conda/envs/pypsa-eur/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 6249, in _raise_if_missing
    raise KeyError(f"None of [{key}] are in the [{axis_name}]")
KeyError: "None of [Index(['50', '50', '74'], dtype='object', name='name')] are in the [index]"

Related:

https://github.com/PyPSA/pypsa-eur/issues/1149

## Checklist

- [ ] I am using the current [`master`](https://github.com/PyPSA/pypsa-eur/tree/master) branch or the latest [release](https://github.com/PyPSA/pypsa-eur/releases). Please indicate.
- [ ] I am running on an up-to-date [`pypsa-eur` environment](https://github.com/PyPSA/pypsa-eur/blob/master/envs/environment.yaml). Update via `conda env update -f envs/environment.yaml`.
mxh970120 commented 1 month ago

I had the same problem. I am creating a network for a German network. When I set clusters to all or 337 (max) I get the following error

INFO:pypsa.io:Imported network elec_s.nc has buses, carriers, generators, lines, links, loads, shapes, storage_units
ERROR:root:Uncaught exception
Traceback (most recent call last):
  File "C:\Workspace\EnergyModels\PyPSA\pypsa-eur\.snakemake\scripts\tmpl0wy95f3.cluster_network.py", line 516, in <module>
    clustering = pypsa.clustering.spatial.Clustering(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Clustering.__init__() takes 4 positional arguments but 6 were given
RuleException:
CalledProcessError in file C:\Workspace\EnergyModels\PyPSA\pypsa-eur\rules/build_electricity.smk, line 541:
Command 'C:/Users/ii6823/AppData/Local/miniconda3/envs/pypsa-eur/python.exe "C:\Workspace\EnergyModels\PyPSA\pypsa-eur\.snakemake\scripts\tmpl0wy95f3.cluster_network.py"' returned non-zero exit status 1.

But when I use 336, I can get the result normally

fneum commented 1 month ago

In cluster_network.py, change to:

clustering = pypsa.clustering.spatial.Clustering(
    n, busmap, linemap
)
fneum commented 2 weeks ago

closed via 73d135360