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

Avoid mismatch #350

Merged
merged 2 commits into from
Dec 20, 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
14 changes: 14 additions & 0 deletions modelskill/matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,20 @@ def match(

assert isinstance(obs, Iterable)

if len(obs) > 1 and isinstance(mod, Iterable) and len(mod) > 1:
if not all(isinstance(m, (DfsuModelResult, GridModelResult)) for m in mod):
raise ValueError(
"""
In case of multiple observations, multiple models can _only_
be matched if they are _all_ of SpatialField type, e.g. DfsuModelResult
or GridModelResult.

If you want match multiple point observations with multiple point model results,
please match one observation at a time and then create a collection of these
using modelskill.ComparerCollection(cmp_list) afterwards. The same applies to track data.
"""
)

clist = [
_single_obs_compare(
o,
Expand Down
52 changes: 52 additions & 0 deletions tests/test_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,3 +457,55 @@ def test_mod_aux_items_must_be_unique():

assert "wind_speed" in str(e.value)
assert "remote" in str(e.value)


def test_multiple_obs_not_allowed_with_non_spatial_modelresults():
o1 = ms.PointObservation(
pd.DataFrame(
{"wl": [1.0, 2.0]}, index=pd.date_range("2000", freq="H", periods=2)
),
name="o1",
x=1,
y=2,
)
o2 = ms.PointObservation(
pd.DataFrame(
{"wl": [1.0, 2.0]}, index=pd.date_range("2000", freq="H", periods=2)
),
name="o2",
x=2,
y=3,
)
m1 = ms.PointModelResult(
pd.DataFrame(
{"wl": [1.0, 2.0]}, index=pd.date_range("2000", freq="H", periods=2)
),
name="m1",
x=1,
y=2,
)
m2 = ms.PointModelResult(
pd.DataFrame(
{"wl": [1.0, 2.0]}, index=pd.date_range("2000", freq="H", periods=2)
),
name="m2",
x=2,
y=3,
)
m3 = ms.PointModelResult(
pd.DataFrame(
{"wl": [1.0, 2.0]}, index=pd.date_range("2000", freq="H", periods=2)
),
name="m3",
x=3,
y=4,
)

# a single observation and model is ok
cmp = ms.match(obs=o1, mod=[m1, m2])
assert "m1" in cmp.mod_names
assert "m2" in cmp.mod_names

# but this is not allowed
with pytest.raises(ValueError, match="SpatialField type"):
ms.match(obs=[o1, o2], mod=[m1, m2, m3])
Loading