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

Fix islanded buses and add clustering by networks - clean branch #632

Merged
merged 18 commits into from Mar 14, 2023

Conversation

ekatef
Copy link
Collaborator

@ekatef ekatef commented Mar 13, 2023

A cleaned version of #614

Checklist

  • I tested my contribution locally and it seems to work fine.
  • Code and workflow changes are sufficiently documented.
  • Newly introduced dependencies are added to envs/environment.yaml and envs/environment.docs.yaml.
  • Changes in configuration options are added in all of config.default.yaml and config.tutorial.yaml.
  • Add a test config or line additions to test/ (note tests are changing the config.tutorial.yaml)
  • Changes in configuration options are also documented in doc/configtables/*.csv and line references are adjusted in doc/configuration.rst and doc/tutorial.rst.
  • A note for the release notes doc/release_notes.rst is amended in the format of previous release notes, including reference to the requested PR.

Copy link
Member

@davide-f davide-f left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice PR :)
temporary comments in the meantime :)
Let us know when ready

config.default.yaml Outdated Show resolved Hide resolved
scripts/simplify_network.py Show resolved Hide resolved
scripts/simplify_network.py Show resolved Hide resolved
@ekatef
Copy link
Collaborator Author

ekatef commented Mar 13, 2023

Thanks a lot! :)

Wouldn't it be more convenient to move back to #614? I have been experimenting a bit with git history and #614 has been cleaned-up as well. Although, checking results are better here :) Let me know please your preferences

Currently there are some problems with reproducibility of the workflow. Not sure what exactly is the reason

@ekatef
Copy link
Collaborator Author

ekatef commented Mar 13, 2023

Mmmm...
It looks like we have a new task with better data: more connections between buses are captured now. Which leads to some troubles when clustering:

simplified network

image

clustered network

(with minimum 28 buses)

image

Note please that the each of the seemingly isolated buses in elec_s.nc now has some company. The first my idea is to drop all the isolated buses remained after clustering. Or, probably, to remove all the isolated pair/groups of buses earlier, in simplify_network?

@ekatef
Copy link
Collaborator Author

ekatef commented Mar 14, 2023

Update: the above are effects of some specific config settings. The workflow and topology model seems to be quite sensitive to it. Probably, some kind of visual guide would be helpful to understand the model behaviour better.

By proper config setting, Testing results for Central Asia look quite appropriate:

kmeans (by load)

image

hac (by load)

image

hac (by gdp)

image

gadm

image

What is really surprising, hac algorithm doesn't require to decrease a number of clusters to a very few in this config setup. Not sure it's good news as I was not able to understand which exactly config changes had such an effect

@ekatef
Copy link
Collaborator Author

ekatef commented Mar 14, 2023

@davide-f, I think this PR is ready.

Testing on CD as well as CD + ZM was successful for all clustering types. I think we may assume that the introduced changes work properly.

However, there are some pitfalls along the workflow which can make difficult to reproduce clustering results. In particular, I'd keep in sight using inf values in aggregate_to_substations():

dist[
buses_i
] = np.inf # bus in buses_i should not be assigned to different bus in buses_i
for c in n.buses.country.unique():
incountry_b = n.buses.country == c
dist.loc[incountry_b, ~incountry_b] = np.inf
busmap = n.buses.index.to_series()
busmap.loc[buses_i] = dist.idxmin(1)

It can lead to the errors which are difficult to catch as idxmin() being applied to the row of inf gives a pretty arbitrary result. Being overlayed with variations in output of clustering algorithms and the overall complexity of our workflow, it can give really fascinating consequences :D

@ekatef
Copy link
Collaborator Author

ekatef commented Mar 14, 2023

Sorry for messing-up the branch history :( Haven't meant it, honestly!

@ekatef ekatef marked this pull request as ready for review March 14, 2023 17:38
Copy link
Member

@davide-f davide-f left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little comment, please modify but this PR looks good to me :)

@pz-max do you want to take a look or shall we go?
This is a quite heavy PR.

p_threshold_drop_isolated = max(
0.0, cluster_config.get("p_threshold_drop_isolated", 0.0)
)
p_threshold_merge_isolated = cluster_config.get("p_threshold_merge_isolated", 0.0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, let's have False as adefault: that means this merge is not executed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@pz-max
Copy link
Member

pz-max commented Mar 14, 2023

A little comment, please modify but this PR looks good to me :)

@pz-max do you want to take a look or shall we go? This is a quite heavy PR.

@davide-f no need to review. Trusting you both to do the best 🥇

@davide-f davide-f merged commit 8018eeb into pypsa-meets-earth:main Mar 14, 2023
@davide-f
Copy link
Member

Merged, many thanks @ekatef !

@ekatef
Copy link
Collaborator Author

ekatef commented Mar 15, 2023

Super :) Thank you so much, @davide-f!

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.

None yet

3 participants