diff --git a/src/pyiem/grid/nav.py b/src/pyiem/grid/nav.py index fe26219f..cc729416 100644 --- a/src/pyiem/grid/nav.py +++ b/src/pyiem/grid/nav.py @@ -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: diff --git a/src/pyiem/grid/nav.pyi b/src/pyiem/grid/nav.pyi index 6975e033..c34ea8a0 100644 --- a/src/pyiem/grid/nav.pyi +++ b/src/pyiem/grid/nav.pyi @@ -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: ... diff --git a/tests/grid/test_grid_nav.py b/tests/grid/test_grid_nav.py index a795869b..bcdbee05 100644 --- a/tests/grid/test_grid_nav.py +++ b/tests/grid/test_grid_nav.py @@ -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") diff --git a/tests/models/test_models_gridnav.py b/tests/models/test_models_gridnav.py index 9008968e..709ada20 100644 --- a/tests/models/test_models_gridnav.py +++ b/tests/models/test_models_gridnav.py @@ -31,9 +31,23 @@ 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, @@ -41,8 +55,8 @@ def test_computing_nxny(): 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):