Skip to content

Commit

Permalink
use assert_geodataframe_equal & fix workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
DirkEilander committed Aug 11, 2023
1 parent a871269 commit 14eaf59
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
Test:
name: HydroMT dev - py3.10
name: HydroMT dev - ubuntu-latest - py3.10
runs-on: "ubuntu-latest"
defaults:
run:
Expand All @@ -20,7 +20,7 @@ jobs:
- uses: actions/checkout@v2
- uses: conda-incubator/setup-miniconda@v2
with:
python-version: 3.10
python-version: "3.10"
mamba-version: "*"
channels: conda-forge,defaults
channel-priority: true
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ dependencies:
- hydromt>=0.8.0
- hydromt_sfincs>=1.0
- jupyterlab # to run examples
- matplotlib==3.5.* # to run examples / https://github.com/SciTools/cartopy/issues/2086
- matplotlib # to run examples
- pip
- python=3.10 # fixing python version for binder
2 changes: 1 addition & 1 deletion envs/hydromt-sfincs-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies:
- geopandas>=0.8
- hydromt>=0.8.0
- jupyterlab # to run examples
- matplotlib==3.5.* # to run examples / https://github.com/SciTools/cartopy/issues/2086
- matplotlib # to run examples
- nbsphinx # docs
- numba
- numpy
Expand Down
26 changes: 15 additions & 11 deletions tests/test_1model_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pandas as pd
import pytest
import xarray as xr
from geopandas.testing import assert_geodataframe_equal
from hydromt.cli.cli_utils import parse_config
from hydromt.log import setuplog

Expand Down Expand Up @@ -262,6 +263,7 @@ def test_model_build(tmpdir, case):
mod0.read()
mod1 = SfincsModel(root=root, mode="r")
mod1.read()
# TODO using hydromt core Model._check_equal after fix https://github.com/Deltares/hydromt/issues/253
# check config
if mod0.config:
assert mod0.config == mod1.config, "config mismatch"
Expand All @@ -271,7 +273,7 @@ def test_model_build(tmpdir, case):
assert np.all(mod0.crs == mod1.crs), "map crs"
mask = (mod0.grid["msk"] > 0).values # compare only active cells
mask1 = (mod1.grid["msk"] > 0).values
assert np.allclose(mask, mask1), "mask not matching"
assert np.allclose(mask, mask1), "mask mismatch"
for name in mod0.grid.raster.vars:
if name == "msk":
continue
Expand All @@ -282,18 +284,20 @@ def test_model_build(tmpdir, case):
invalid_map_str = ", ".join(invalid_maps)
assert len(invalid_maps) == 0, f"invalid maps: {invalid_map_str}"
# check geoms
invalid_geoms = []
if mod0.geoms:
for name in mod0.geoms:
geom0 = mod0.geoms[name]
geom1 = mod1.geoms[name]
assert geom0.index.size == geom1.index.size and np.all(
geom0.index == geom1.index
), f"geom index {name}"
assert geom0.columns.size == geom1.columns.size and np.all(
geom0.columns == geom1.columns
), f"geom columns {name}"
assert geom0.crs == geom1.crs, f"geom crs {name}"
assert np.all(geom0.geometry == geom1.geometry), f"geom {name}"
try:
assert_geodataframe_equal(
mod0.geoms[name],
mod1.geoms[name],
check_less_precise=True, # allow for rounding errors in geoms
check_like=True, # order may be different
check_geom_type=True, # geometry types should be the same
)
except AssertionError: # re-raise error with geom name
invalid_geoms.append(name)
assert len(invalid_geoms) == 0, f"invalid geoms: {invalid_geoms}"
# check forcing
if mod0.forcing:
for name in mod0.forcing:
Expand Down

0 comments on commit 14eaf59

Please sign in to comment.