Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Add test to check python codeblocks in README keep working as code changes
[\#38](https://github.com/mllam/weather-model-graphs/pull/38) @leifdenby

- Add coords_crs and graph_crs arguments to allow for using lat-lons coordinates
or other CRSs as input. These are then converted to the specific CRS used when
constructing the graph.
Expand All @@ -25,6 +28,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix crash when trying to create flat multiscale graphs with >= 3 levels
[\#41](https://github.com/mllam/weather-model-graphs/pull/41), @joeloskarsson

- Fix example in README
[\#38](https://github.com/mllam/weather-model-graphs/pull/38) @leifdenby

### Maintenance

- Update github CI actions, including pre-commit action to fix caching issue
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,14 @@ import numpy as np
import weather_model_graphs as wmg

# define your (x,y) grid coodinates
xy_grid = np.meshgrid(np.linspace(0, 1, 32), np.linspace(0, 1, 32))
xy_grid = np.stack(xy_grid, axis=0)
xs, ys = np.meshgrid(np.linspace(0, 1, 32), np.linspace(0, 1, 32))
coords = np.stack([xs.flatten(), ys.flatten()], axis=-1)

# create the full graph
graph = wmg.create.archetype.create_keisler_graph(xy_grid=xy_grid)
graph = wmg.create.archetype.create_keisler_graph(
coords=coords,
mesh_node_distance=1.0/16 # use half the grid spacing for mesh nodes
)

# split the graph by component
graph_components = wmg.split_graph_by_edge_attribute(graph=graph, attr='component')
Expand Down
8 changes: 8 additions & 0 deletions src/weather_model_graphs/create/mesh/kinds/flat.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,12 @@ def create_flat_singlescale_mesh_graph(xy, mesh_node_distance: float):
nx = int(range_x / mesh_node_distance)
ny = int(range_y / mesh_node_distance)

if nx == 0 or ny == 0:
raise ValueError(
"The given `mesh_node_distance` is too large for the provided coordinates. "
f"Got mesh_node_distance={mesh_node_distance}, but the x-range is {range_x} "
f"and y-range is {range_y}. Maybe you want to decrease the `mesh_node_distance`"
" so that the mesh nodes are spaced closer together?"
)

return mesh_graph.create_single_level_2d_mesh_graph(xy=xy, nx=nx, ny=ny)
21 changes: 21 additions & 0 deletions tests/test_readme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import re
from pathlib import Path

import pytest


def _parse_readme_examples():
lines = open(Path(__file__).parent.parent / "README.md").read().splitlines()

# use regex to find all python code blocks
code_blocks = re.findall(r"```python(.*?)```", "\n".join(lines), re.DOTALL)
Comment thread
leifdenby marked this conversation as resolved.

return code_blocks


@pytest.mark.parametrize("codeblock_example", _parse_readme_examples())
def test_readme_example(codeblock_example: str):
"""
Check that execution of the python code block in the README does not raise an exception.
"""
exec(codeblock_example)
Comment thread
leifdenby marked this conversation as resolved.
Loading