Skip to content

Commit

Permalink
✨ Add pyiem.grid.nav.get_nav
Browse files Browse the repository at this point in the history
  • Loading branch information
akrherz committed Dec 20, 2024
1 parent b08a536 commit 74efd59
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/pyiem/grid/nav.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@
}


def get_nav(name: str, dom: str) -> CartesianGridNavigation:
"""Helper to remove some boilerplate for fetching gridnav."""
extra = f"_{dom.upper()}" if dom != "" else ""
key = f"{name.upper()}{extra}"
return CartesianGridNavigation(**_GRID_CONFIGS[key])


def __getattr__(name: str):
"""Build stuff on the fly."""
if name in _GRID_CONFIGS:
Expand Down
2 changes: 2 additions & 0 deletions src/pyiem/grid/nav.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ class STAGE4(CartesianGridNavigation): ...
class STAGE4_PRE2002(CartesianGridNavigation): ...
class MRMS_IEMRE(CartesianGridNavigation): ...
class PRISM(CartesianGridNavigation): ...

def get_nav(name: str, region: str) -> CartesianGridNavigation: ...
6 changes: 6 additions & 0 deletions tests/grid/test_grid_nav.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ def test_api():
def test_prism_calc():
"""Test that PRISM works out to what we expect."""
assert (nav.PRISM.right - -66.50) < 0.01


def test_get_nav():
"""Test that we can get a helper."""
assert nav.get_nav("iemRE", "")
assert nav.get_nav("era5LAND", "china")
20 changes: 17 additions & 3 deletions tests/models/test_models_gridnav.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,32 @@ def test_non_even_spacing():
)


def test_computing_dxdy():
"""Test that we can get a dx and dy."""
_cgn = CartesianGridNavigation(
left_edge=0,
bottom_edge=0,
nx=10,
ny=10,
right_edge=10,
top_edge=10,
)
assert _cgn.dx == 1
assert _cgn.dy == 1


def test_computing_nxny():
"""Test that ny and ny can be computed."""
cgn = CartesianGridNavigation(
_cgn = CartesianGridNavigation(
left_edge=0,
bottom_edge=0,
dx=1,
dy=1,
right_edge=10,
top_edge=10,
)
assert cgn.nx == 10
assert cgn.ny == 10
assert _cgn.nx == 10
assert _cgn.ny == 10


def test_api(cgn):
Expand Down

0 comments on commit 74efd59

Please sign in to comment.