Skip to content

Commit

Permalink
Add fix for nu=2
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobbieker committed Dec 6, 2023
1 parent 1f3ffda commit bab39e0
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion graph_weather/models/graphs/ico.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)):
"""
Expand All @@ -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

Expand Down

0 comments on commit bab39e0

Please sign in to comment.