ImperialCollegeLondon / ImperialCollegeLondon/SWMManywhere
Graphfcn to validate graph for SWMM?
- Dominant language
- Python
- Stars
- 51
- Forks
- 11
- PR merge metrics
- No merged PRs in 30d
Description
Could have something like this:
```
@register_graphfcn
class subselect_swmm(BaseGraphFunction):
"""subselect_swmm class."""
def __call__(self, G: nx.Graph, **kwargs):
"""Subselect a graph to only include SWMM required attributes.
This function subselects a graph to only include nodes and edges that
have meaningful values for swmm_edges_require and swmm_nodes_require.
Args:
G (nx.Graph): A graph.
Returns:
G (nx.Graph): A graph, with valid SWMM nodes/edges only.
"""
# Identify invalid edges and nodes based on missing or NaN attribute values
edges_to_remove = {(u, v) for u, v, d in G.edges(data=True)
if any(d.get(item) is None or np.isnan(d.get(item)) for item in swmm_edges_require)}
nodes_to_remove = {u for u, d in G.nodes(data=True)
if any(d.get(item) is None or np.isnan(d.get(item)) for item in swmm_nodes_require)}
# Create a new graph and remove the identified invalid edges and nodes
new_graph = G.copy()
new_graph.remove_edges_from(edges_to_remove)
new_graph.remove_nodes_from(nodes_to_remove)
return new_graph
```
where `swmm_edges_require` and `swmm_nodes_require` are defined in `post_processing`
This is currently handled in `post_processing.py/synthetic_write` - would probably need to see how #84 is addressed first
Be quite useful to have a function to call this before `synthetic_write` and enable `swmmanywhere.swmmanywhere` to exit successfully up to just the current graph.
Contributor guide
Research direction
Start by reviewing post_processing.py, especially synthetic_write, and inspect how issue #84 affects the proposed validation. Trace the entry point in swmmanywhere.swmmanywhere and determine where a graph-validation function could run before synthetic_write. Done means invalid SWMM graph data is handled by the new function and the workflow exits successfully up to the current graph.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100