forked from mllam/weather-model-graphs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_save.py
43 lines (33 loc) · 1.34 KB
/
test_save.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import tempfile
import numpy as np
from loguru import logger
import weather_model_graphs as wmg
from weather_model_graphs.save import HAS_PYG
def _create_fake_xy(N=10):
x = np.linspace(0, 1, N)
y = np.linspace(0, 1, N)
xy = np.meshgrid(x, y)
xy = np.stack(xy, axis=0)
return xy
def test_save_to_pyg():
if not HAS_PYG:
logger.warning(
"Skipping test_save_to_pyg because weather-model-graphs[pytorch] is not installed."
)
return
xy = _create_fake_xy(N=64)
graph = wmg.create.archetype.create_oskarsson_hierarchical_graph(xy_grid=xy)
graph_components = wmg.split_graph_by_edge_attribute(graph=graph, attr="component")
# split the m2m graph into the different parts that create the up, in-level and down connections respectively
# this is how the graphs is stored in the neural-lam codebase
m2m_graph = graph_components.pop("m2m")
m2m_graph_components = wmg.split_graph_by_edge_attribute(
graph=m2m_graph, attr="direction"
)
m2m_graph_components = {
f"m2m_{name}": graph for name, graph in m2m_graph_components.items()
}
graph_components.update(m2m_graph_components)
with tempfile.TemporaryDirectory() as tmpdir:
for name, graph in graph_components.items():
wmg.save.to_pyg(graph=graph, output_directory=tmpdir, name=name)