Skip to content

Fix nuts3 es #1579

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

Closed
wants to merge 103 commits into from
Closed

Fix nuts3 es #1579

wants to merge 103 commits into from

Conversation

cristobal-GC
Copy link
Contributor

I've been testing the new NUTS clustering feature (congratulations, it's a great update!). It works pretty well, but I get an error when running it only for Spain and for clustering at NUTS3 level.

The error occurs during the 'base_network' rule.

In short, the problem seems to be that the "clean_dict" function is not robust if the provided dic has no values with len=1.

In detail: At some point, "build_admin_shapes" calls to "merge_regions_recursive" at:

admin_shapes = merge_regions_recursive(admin_shapes, neighbours_missing=False)

In this function there is a call to the function "clean_dict" on line:

first_neighbours = clean_dict(first_neighbours)

where the input dictionary at this point is just: {'ES532': ['ES531', 'ES533']}

(just for info: ES531 and ES533 are two small islands without electrical buses, and here the code aims to add them to the larger island of Mallorca, ES532, which is connected with peninsular Spain with a DC-link).

The problem is that "clean_dict" seems to break at line:

drop_keys = set(single_keys) - set(single_df[0].values)

because the variable "single_occurrences" is empty, due to the fact that there are no values in the input dictionary with length=1). This probably does not happen when running a case for Europe, but for the case of a single country like Spain, it leads to the mentioned break.

So, this PR is just to add a check step on "single_occurrences", to proceed only if it is not empty.

Checklist

  • [x ] I tested my contribution locally and it works as intended.
  • Code and workflow changes are sufficiently documented.
  • Changed dependencies are added to envs/environment.yaml.
  • Changes in configuration options are added in config/config.default.yaml.
  • Changes in configuration options are documented in doc/configtables/*.csv.
  • Sources of newly added data are documented in doc/data_sources.rst.
  • A release note doc/release_notes.rst is added.

@cristobal-GC
Copy link
Contributor Author

I tried to make a PR only in a newly created branch with a small addition, but obviously I did it wrong, and the PR includes other updates associated with the fork pypsa-spain. Please ignore this PR, I will try again.

Sorry for the noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant