Skip to content

Commit

Permalink
Merge pull request #121 from Deltares/fix/tests
Browse files Browse the repository at this point in the history
Fix tests
  • Loading branch information
roeldegoede authored Aug 24, 2023
2 parents b02401c + 14eaf59 commit f6d5546
Show file tree
Hide file tree
Showing 15 changed files with 126 additions and 66 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Tests
name: Tests stable

on:
push:
Expand All @@ -17,7 +17,7 @@ jobs:
fail-fast: false
matrix:
os: ["ubuntu-latest"] #, "macos-latest", "windows-latest"]
python-version: ["3.9", "3.10"] # fix tests to support older versions
python-version: ["3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v2
Expand All @@ -36,7 +36,7 @@ jobs:
conda list
- name: Intall hydromt_sfincs
run: flit install
run: pip install .

- name: Test
run: python -m pytest --verbose --cov=hydromt_sfincs --cov-report xml
Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/tests_dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Tests Dev

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
Test:
name: HydroMT dev - ubuntu-latest - py3.10
runs-on: "ubuntu-latest"
defaults:
run:
shell: bash -l {0}
strategy:
fail-fast: false

steps:
- uses: actions/checkout@v2
- uses: conda-incubator/setup-miniconda@v2
with:
python-version: "3.10"
mamba-version: "*"
channels: conda-forge,defaults
channel-priority: true
environment-file: envs/hydromt-sfincs-dev.yml
activate-environment: hydromt-sfincs-dev

- name: Conda info
run: |
conda info
conda list
- name: Intall hydromt core dev version
run: pip install git+https://github.com/Deltares/hydromt.git

- name: Intall hydromt_sfincs
run: pip install .

- name: Test
run: python -m pytest --verbose --cov=hydromt_sfincs --cov-report xml

- name: Check style
run: black --check .

- uses: codecov/codecov-action@v3
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
5 changes: 2 additions & 3 deletions 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 All @@ -34,5 +34,4 @@ dependencies:
- sphinx # docs
- xarray
- pip:
- sphinx_design # docs
- git+https://github.com/Deltares/hydromt.git # bathymetry.burn_river_rect requires v0.7.2
- sphinx_design # docs
33 changes: 19 additions & 14 deletions hydromt_sfincs/sfincs.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,12 @@ def setup_dep(
)

# check if no nan data is present in the bed levels
if np.isnan(da_dep).any():
self.logger.warning(
f"Interpolate data at {int(np.sum(np.isnan(da_dep.values)))} cells"
nmissing = int(np.sum(np.isnan(da_dep.values)))
if nmissing > 0:
self.logger.warning(f"Interpolate elevation at {nmissing} cells")
da_dep = da_dep.raster.interpolate_na(
method="rio_idw", extrapolate=True
)
# TODO add extrapolate=True option when available in hydromt core
da_dep = da_dep.raster.interpolate_na(method="rio_idw")

self.set_grid(da_dep, name="dep")
# FIXME this shouldn't be necessary, since da_dep should already have a crs
Expand Down Expand Up @@ -2524,7 +2524,7 @@ def plot_basemap(
for fname, gname in self._FORCING_1D.values():
if fname[0] in self.forcing and gname is not None:
try:
sg.update({gname: self._forcing[fname[0]].vector.to_gdf()})
sg.update({gname: self.forcing[fname[0]].vector.to_gdf()})
except ValueError:
self.logger.debug(f'unable to plot forcing location: "{fname}"')
if plot_region and "region" not in self.geoms:
Expand Down Expand Up @@ -2993,12 +2993,17 @@ def read_states(self):
self._assert_read_mode

# read index file
ind_fn = self.get_config("indexfile", fallback="sfincs.ind", abs_path=True)
if not isfile(ind_fn):
raise IOError(f".ind path {ind_fn} does not exist")

# TODO make reggrid a property where we trigger the initialization of reggrid
if self.reggrid is None:
self.update_grid_from_config()
if self.reggrid is not None:
ind = self.reggrid.read_ind(ind_fn=ind_fn)
ind_fn = self.get_config("indexfile", fallback="sfincs.ind", abs_path=True)
if "msk" in self.grid: # triggers reading grid if empty and in read mode
ind = self.reggrid.ind(self.grid["msk"].values)
elif isfile(ind_fn):
ind = self.reggrid.read_ind(ind_fn=ind_fn)
else:
raise IOError(f"indexfile {ind_fn} does not exist")
if "inifile" in self.config:
fn = self.get_config("inifile", abs_path=True)
if not isfile(fn):
Expand Down Expand Up @@ -3036,8 +3041,8 @@ def write_states(self):
ind_fn = self.get_config("indexfile", abs_path=True)
self.reggrid.write_ind(ind_fn=ind_fn, mask=mask)

if f"inifile" not in self.config:
self.set_config(f"inifile", f"sfincs.{name}")
if "inifile" not in self.config:
self.set_config("inifile", f"sfincs.{name}")
fn = self.get_config("inifile", abs_path=True)
da = self.states[name]
if da.raster.res[1] < 0:
Expand Down Expand Up @@ -3098,7 +3103,7 @@ def read_results(
fn_his, crs=self.crs, chunksize=chunksize
)
# drop double vars (map files has priority)
drop_vars = [v for v in ds_his.data_vars if v in self._results or v in drop]
drop_vars = [v for v in ds_his.data_vars if v in self.results or v in drop]
ds_his = ds_his.drop_vars(drop_vars)
self.set_results(ds_his, split_dataset=True)

Expand Down
Binary file modified tests/data/sfincs_test/gis/dep.tif
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/data/sfincs_test/gis/drn.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "FeatureCollection",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::32633" } },
"features": [
{ "type": "Feature", "properties": { "id": 1, "type": 1, "par1": 10.0, "par2": 0, "par3": 0, "par4": 0, "par5": 0 }, "geometry": { "type": "LineString", "coordinates": [ [ 322021.879048462666105, 5045547.683568798005581 ], [ 322378.691038294811733, 5045133.781660593114793 ] ] } },
{ "type": "Feature", "properties": { "id": 2, "type": 2, "par1": 40.0, "par2": 0, "par3": 0, "par4": 0, "par5": 0 }, "geometry": { "type": "LineString", "coordinates": [ [ 319160.246890009148046, 5045262.233976932242513 ], [ 319167.383129805792123, 5044976.784385066479445 ] ] } }
{ "type": "Feature", "properties": { "id": 1, "par1": 10.0, "type": 1, "par2": 0, "par3": 0, "par4": 0, "par5": 0 }, "geometry": { "type": "LineString", "coordinates": [ [ 322021.879048462666105, 5045547.683568798005581 ], [ 322378.691038294811733, 5045133.781660593114793 ] ] } },
{ "type": "Feature", "properties": { "id": 2, "par1": 40.0, "type": 2, "par2": 0, "par3": 0, "par4": 0, "par5": 0 }, "geometry": { "type": "LineString", "coordinates": [ [ 319160.246890009148046, 5045262.233976932242513 ], [ 319167.383129805792123, 5044976.784385066479445 ] ] } }
]
}
Binary file modified tests/data/sfincs_test/gis/msk.tif
Binary file not shown.
Loading

0 comments on commit f6d5546

Please sign in to comment.