Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add io and extra to testing in ci again #482

Merged
merged 5 commits into from
Aug 21, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
activate-environment: hydromt
use-mamba: true
- name: Generate env spec
run: pip install tomli && python make_env.py test
run: pip install tomli && python make_env.py test,io,extra


- name: Set cache date
Expand Down
7 changes: 4 additions & 3 deletions hydromt/models/model_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def set_mesh(
raise ValueError(
f"Cannot set mesh from {str(type(data).__name__)} without a name."
)
data = data.to_dataset(optional_attributes=True)
data = data.to_dataset()

# Checks on grid topology
# TODO: check if we support setting multiple grids at once. For now just one
Expand Down Expand Up @@ -371,7 +371,8 @@ def set_mesh(
# update related geoms if necessary: region
if overwrite_grid or new_grid:
# add / updates region
self._geoms.pop("region", None)
if "region" in self.geoms:
self._geoms.pop("region", None)
self.region

def get_mesh(
Expand Down Expand Up @@ -437,7 +438,7 @@ def read_mesh(
Additional keyword arguments to be passed to the `read_nc` method.
"""
self._assert_read_mode
ds = xr.merge(self._read_nc(fn, **kwargs).values())
ds = xr.merge(self.read_nc(fn, **kwargs).values())
uds = xu.UgridDataset(ds)
if ds.rio.crs is not None: # parse crs
uds.ugrid.set_crs(ds.raster.crs)
Expand Down
11 changes: 10 additions & 1 deletion hydromt/workflows/basin_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,17 @@ def parse_region(region, logger=logger):
if _compat.HAS_XUGRID:
if isinstance(value0, (str, Path)) and isfile(value0):
kwarg = dict(mesh=xu.open_dataset(value0))
elif isinstance(value0, xu.UgridDataset):
elif isinstance(value0, (xu.UgridDataset, xu.UgridDataArray)):
kwarg = dict(mesh=value0)
elif isinstance(value0, (xu.Ugrid1d, xu.Ugrid2d)):
kwarg = dict(
mesh=xu.UgridDataset(value0.to_dataset(optional_attributes=True))
)
else:
raise ValueError(
f"Unrecognised type {type(value0)}."
"Should be a path, data catalog key or xugrid object."
)
kwargs.update(kwarg)
else:
raise ImportError("xugrid is required to read mesh files.")
Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ test = [
"pytest-cov", # test coverage
"pytest-mock", # mocking
"pytest-timeout", # darn hanging tests
]
"xugrid"
]
doc = [
"nbsphinx", # build notebooks in docs
"pydata-sphinx-theme", # theme
Expand Down Expand Up @@ -137,7 +138,7 @@ include = ["hydromt"]
exclude = ["docs", "examples", "envs", "tests", "binder", ".github"]

[tool.pytest.ini_options]
addopts = "--ff --timeout=120"
addopts = "--ff --timeout=120 "
testpaths = ["tests"]

filterwarnings = [
Expand Down
9 changes: 8 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from os.path import abspath, dirname, join

import geopandas as gpd
import numpy as np
import pandas as pd
import pyflwdir
import pytest
import xarray as xr
from dask import config as dask_config
from shapely.geometry import box

from hydromt import (
Expand All @@ -18,6 +21,10 @@
)
from hydromt.data_catalog import DataCatalog

dask_config.set(scheduler="single-threaded")

DATADIR = join(dirname(abspath(__file__)), "data")


@pytest.fixture()
def rioda():
Expand Down Expand Up @@ -80,7 +87,7 @@ def geodf(df):

@pytest.fixture()
def world():
world = gpd.read_file("tests/data/naturalearth_lowres.geojson")
world = gpd.read_file(join(DATADIR, "naturalearth_lowres.geojson"))
return world


Expand Down
2 changes: 1 addition & 1 deletion tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ def test_meshmodel_setup(griduda, world):
mod.setup_mesh2d(region, res=10000, crs=3857, grid_name="mesh2d")
mod.region

region = {"mesh": griduda.ugrid.to_dataset()}
region = {"mesh": griduda}
mod1 = MeshModel(data_libs=["artifact_data", dc_param_fn])
mod1.setup_mesh2d(region, grid_name="mesh2d")
mod1.setup_mesh2d_from_rasterdataset("vito", grid_name="mesh2d")
Expand Down
Loading