From 292502852e25526229b04a204b1f91770060c0f3 Mon Sep 17 00:00:00 2001 From: Mario Santa Cruz Date: Tue, 26 Nov 2024 11:27:39 +0000 Subject: [PATCH 1/4] feat: expand plot_nodes to multi-dimensional attributes --- .../graphs/plotting/interactive_html.py | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/anemoi/graphs/plotting/interactive_html.py b/src/anemoi/graphs/plotting/interactive_html.py index 7021bf16..f3162507 100644 --- a/src/anemoi/graphs/plotting/interactive_html.py +++ b/src/anemoi/graphs/plotting/interactive_html.py @@ -15,6 +15,7 @@ import matplotlib.pyplot as plt import numpy as np import plotly.graph_objects as go +import torch from matplotlib.colors import rgb2hex from torch_geometric.data import HeteroData @@ -197,25 +198,26 @@ def plot_interactive_nodes(graph: HeteroData, nodes_name: str, out_file: Optiona for node_attr in node_attrs: node_attr_values = graph[nodes_name][node_attr].float().numpy() - # Skip multi-dimensional attributes. Supported only: (N, 1) or (N,) tensors - if node_attr_values.ndim > 1 and node_attr_values.shape[1] > 1: - continue - - node_traces[node_attr] = go.Scattergeo( - lat=node_latitudes, - lon=node_longitudes, - name=" ".join(node_attr.split("_")).capitalize(), - mode="markers", - hoverinfo="text", - marker={ - "color": node_attr_values.squeeze().tolist(), - "showscale": True, - "colorscale": "RdBu", - "colorbar": {"thickness": 15, "title": node_attr, "xanchor": "left"}, - "size": 5, - }, - visible=False, - ) + if node_attr_values.ndim == 1: + node_attr_values = torch.unsqueeze(node_attr_values, -1) + + for attr_dim in range(node_attr_values.shape[1]): + suffix = "" if node_attr_values.shape[1] == 1 else f"_[{attr_dim}]" + node_traces[node_attr + suffix] = go.Scattergeo( + lat=node_latitudes, + lon=node_longitudes, + name=" ".join((node_attr + suffix).split("_")).capitalize(), + mode="markers", + hoverinfo="text", + marker={ + "color": node_attr_values[:, attr_dim].squeeze().tolist(), + "showscale": True, + "colorscale": "RdBu", + "colorbar": {"thickness": 15, "title": node_attr + suffix, "xanchor": "left"}, + "size": 5, + }, + visible=False, + ) # Create and add slider slider_steps = [] From e4d711578ff51e4fd0191e3db599fd7d8becbefc Mon Sep 17 00:00:00 2001 From: Mario Santa Cruz Date: Tue, 26 Nov 2024 11:28:08 +0000 Subject: [PATCH 2/4] fix: update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fde4c3ef..6832da75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ Keep it human-readable, your future self will thank you! - feat: Add `RemoveUnconnectedNodes` post processor to clean unconnected nodes in LAM. (#71) - feat: Define node sets and edges based on an ICON icosahedral mesh (#53) - feat: Support for multiple edge builders between two sets of nodes (#70) +- feat: Support for multi-dimensional node attributes in plots (#86) # Changed - fix: bug when computing area weights with scipy.Voronoi. (#79) From e156afe109d4da838cf8990fa57e837777df1f5c Mon Sep 17 00:00:00 2001 From: Mario Santa Cruz Date: Tue, 26 Nov 2024 17:00:42 +0000 Subject: [PATCH 3/4] fix: changelog --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d0f90a9..adcac91d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ Keep it human-readable, your future self will thank you! ## [Unreleased](https://github.com/ecmwf/anemoi-graphs/compare/0.4.1...HEAD) +### Added + +- feat: Support for multi-dimensional node attributes in plots (#86) + ## [0.4.1 - ICON graphs, multiple edge builders and post processors](https://github.com/ecmwf/anemoi-graphs/compare/0.4.0...0.4.1) - 2024-11-26 ### Added @@ -19,7 +23,6 @@ Keep it human-readable, your future self will thank you! - feat: Add `RemoveUnconnectedNodes` post processor to clean unconnected nodes in LAM. (#71) - feat: Define node sets and edges based on an ICON icosahedral mesh (#53) - feat: Support for multiple edge builders between two sets of nodes (#70) -- feat: Support for multi-dimensional node attributes in plots (#86) # Changed From dba04f4d46bcf2ed90d89b787c13a479341d2c02 Mon Sep 17 00:00:00 2001 From: Mario Santa Cruz Date: Fri, 20 Dec 2024 12:23:26 +0000 Subject: [PATCH 4/4] udpate changelog --- graphs/CHANGELOG.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/graphs/CHANGELOG.md b/graphs/CHANGELOG.md index 6456fc82..4d7dbb32 100644 --- a/graphs/CHANGELOG.md +++ b/graphs/CHANGELOG.md @@ -10,6 +10,10 @@ Keep it human-readable, your future self will thank you! ## [Unreleased](https://github.com/ecmwf/anemoi-graphs/compare/0.4.2...HEAD) +### Added + +- feat: Support for multi-dimensional node attributes in plots (#48) + ## [0.4.2 - Optimisations and lat-lon](https://github.com/ecmwf/anemoi-graphs/compare/0.4.1...0.4.2) - 2024-12-19 ### Added @@ -23,10 +27,6 @@ Keep it human-readable, your future self will thank you! - fix: faster edge builder for tri icosahedron. (#92) -### Added - -- feat: Support for multi-dimensional node attributes in plots (#86) - ## [0.4.1 - ICON graphs, multiple edge builders and post processors](https://github.com/ecmwf/anemoi-graphs/compare/0.4.0...0.4.1) - 2024-11-26 ### Added