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

Main allocation network #851

Closed
wants to merge 3 commits into from
Closed

Conversation

SouthEndMusic
Copy link
Collaborator

Fixes #768.

@SouthEndMusic SouthEndMusic marked this pull request as draft November 29, 2023 15:35
@SouthEndMusic
Copy link
Collaborator Author

@visr do you think something like this is useful as a plotting option?

from ribasim_testmodels import subnetwork_model
import matplotlib.pyplot as plt
import numpy as np
from scipy.spatial import ConvexHull

model = subnetwork_model()
df = model.network.node.df

for allocation_subnetwork_id, df_subnetwork in df.groupby("allocation_network_id"):
    points = np.stack((df.geometry.x.to_numpy(), df.geometry.y.to_numpy()), axis=1)
    hull = ConvexHull(points)
    bounding_polygon_vertices = points[hull.vertices, :]
    hull_center = np.mean(bounding_polygon_vertices, axis=0)
    bounding_polygon_vertices = (
        bounding_polygon_vertices - hull_center
    ) * 1.1 + hull_center

    ax = model.plot()
    ax.fill(
        bounding_polygon_vertices[:, 0],
        bounding_polygon_vertices[:, 1],
        linestyle="--",
        facecolor="none",
        linewidth=2,
        edgecolor="gray",
    )
    ax.text(
        *hull_center,
        f"Subnetwork {allocation_subnetwork_id}",
        horizontalalignment="center",
    )

plt.show()

subnetwork_convex_hull

P.s.: I am aware that hull_center is not correct, but I didn't find a centroid function in the current Python environment.

@SouthEndMusic SouthEndMusic mentioned this pull request Dec 22, 2023
@SouthEndMusic
Copy link
Collaborator Author

This PR is superseded by among others #914.

@deltamarnix deltamarnix deleted the main_allocation_network branch February 2, 2024 10:07
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.

Main (allocation) network
1 participant