Skip to content
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
12 changes: 6 additions & 6 deletions modelskill/matching.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import warnings
from datetime import timedelta
from pathlib import Path
from typing import (
Expand Down Expand Up @@ -361,19 +360,20 @@ def match_space_time(

observation = observation.trim(period.start, period.end)

data = observation.data
data = observation.data.copy()
data.attrs["name"] = observation.name
data = data.rename({observation.name: "Observation"})

for mr in raw_mod_data.values():
# TODO is `align` the correct name for this operation?
aligned = mr.align(observation, max_gap=max_model_gap)

if overlapping_names := set(aligned.data_vars) & set(data.data_vars):
warnings.warn(
"Model result has overlapping variable names with observation. Renamed with suffix `_model`."
if overlapping := set(aligned.filter_by_attrs(kind="aux").data_vars) & set(
observation.data.filter_by_attrs(kind="aux").data_vars
):
raise ValueError(
f"Aux variables are not allowed to have identical names. Choose either aux from obs or model. Overlapping: {overlapping}"
)
aligned = aligned.rename({v: f"{v}_mod" for v in overlapping_names})

for dv in aligned:
data[dv] = aligned[dv]
Expand Down
8 changes: 3 additions & 5 deletions tests/test_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,10 +444,8 @@ def test_obs_and_mod_can_not_have_same_aux_item_names():
obs = ms.PointObservation(obs_df, item="wl", aux_items=["wind_speed"])
mod = ms.PointModelResult(mod_df, item="wl", aux_items=["wind_speed"])

with pytest.warns(match="_model"):
cmp = ms.match(obs=obs, mod=mod)
assert "wind_speed" in cmp
assert "wind_speed_mod" in cmp # renamed
with pytest.raises(ValueError, match="aux"):
ms.match(obs=obs, mod=mod)


def test_mod_aux_items_overlapping_names():
Expand All @@ -474,7 +472,7 @@ def test_mod_aux_items_overlapping_names():
mod2_df, item="wl", aux_items=["wind_speed"], name="remote"
)

# we don't care which model the aux data comes from
# we don't care which model the aux data comes from, last one wins
cmp = ms.match(obs=obs, mod=[mod, mod2])

assert "wind_speed" in cmp
Expand Down