From bab39e0189a59104aaaaa1d2a8f6a5041e26e66c Mon Sep 17 00:00:00 2001 From: Jacob Bieker Date: Wed, 6 Dec 2023 21:53:24 +0000 Subject: [PATCH] Add fix for nu=2 --- graph_weather/models/graphs/ico.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/graph_weather/models/graphs/ico.py b/graph_weather/models/graphs/ico.py index b3b4fc00..fd2e7a21 100644 --- a/graph_weather/models/graphs/ico.py +++ b/graph_weather/models/graphs/ico.py @@ -270,6 +270,14 @@ def inside_points(vAB, vAC): """ out = [] + if vAB.shape[0] == 1: # Optimized code fails for nu=2 + v = [] + for i in range(1, vAB.shape[0]): + w = np.arange(1, i + 1) / (i + 1) + for k in range(i): + v.append(w[-1 - k] * vAB[i, :] + w[k] * vAC[i, :]) + + return np.array(v).reshape(-1, 3) # reshape needed for empty return for i in range(1, vAB.shape[0]): # Linearly interpolate between vABi and vACi in `i + 1` (`j`) steps, # not including the endpoints. @@ -298,6 +306,17 @@ def generate_icosphere_graph(resolution=1): edges = np.unique(np.sort(edges, axis=1), axis=0) return vertices, edges +vertex, edges = generate_icosphere_graph(2) +print(f"Vertices: {vertex.shape}") +print(f"Edges: {edges.shape}") +print(f"Edges: {edges}") +print(f"Vertices: {vertex}") +vertex2, edges = generate_icosphere_graph(3) +print(f"Vertices: {vertex2.shape}") +print(f"Edges: {vertex2}") +# Check if the first 12 vertices are the same +print(f"Vertices: {np.isclose(vertex2[:12], vertex)}") +exit() def generate_icosphere_mapping(lat_lons, resolutions=(1,2,3,4,5,6,7)): """ @@ -323,7 +342,9 @@ def generate_icosphere_mapping(lat_lons, resolutions=(1,2,3,4,5,6,7)): verticies_per_level.append(vertices) edges_per_level.append(edges) - # TODO Align the verticies so the same positions line up + # TODO Align the verticies so the same positions line up, and deduplicate the edges + # Each set of verticies is the same as the one before, but with more verticies, e.g. first 12 are always the same + # Should just need to deduplicate the edges, after combining them all # TODO Create Data object where there is a minimal amount of verticies (the overlapping ones are the same) # TODO Create mapping from the lat/lon to the icosphere nodes