Skip to content

Commit

Permalink
Is time essential
Browse files Browse the repository at this point in the history
  • Loading branch information
ecomodeller committed Dec 1, 2023
1 parent 8d570c8 commit 60b914e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
12 changes: 6 additions & 6 deletions modelskill/comparison/_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ def _parse_dataset(data) -> xr.Dataset:

# Validate time
# assert len(data.dims) == 1, "Only 0-dimensional data are supported"
assert "time" in data.dims, "data must have a time dimension"
assert isinstance(data.time.to_index(), pd.DatetimeIndex), "time must be datetime"
data["time"] = pd.DatetimeIndex(data.time.to_index()).round(freq="100us") # 0.0001s
assert (
data.time.to_index().is_monotonic_increasing
), "time must be increasing (please check for duplicate times))"
# assert "time" in data.dims, "data must have a time dimension"
# assert isinstance(data.time.to_index(), pd.DatetimeIndex), "time must be datetime"
# data["time"] = pd.DatetimeIndex(data.time.to_index()).round(freq="100us") # 0.0001s
# assert (
# data.time.to_index().is_monotonic_increasing
# ), "time must be increasing (please check for duplicate times))"

# no missing values allowed in Observation
if data["Observation"].isnull().any():
Expand Down
24 changes: 24 additions & 0 deletions tests/test_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,30 @@ def test_matched_data_quantity():
assert cmp.quantity == quantity


def test_matched_data_not_time_index():
df = pd.DataFrame(
{
"ts_1": [
1.0,
2.0,
],
"sensor_a": [2.0, 3.0],
},
index=["A", "B"], # arbitrary index, not time
)

cmp = ms.from_matched(df, obs_item="sensor_a")

# scatter plot doesn't care about time
cmp.plot.scatter()

# skill metrics do not care about time
s = cmp.skill(metrics="mae")
assert s.loc["sensor_a", "mae"] == pytest.approx(1.0)

cmp.plot.timeseries()


def test_matched_data_name_xyz():
df = pd.DataFrame(
{"ts_1": [1.1, 2.0, 3.0, 4.0], "sensor_a": [0.9, 2.0, 3.0, 4.1]},
Expand Down

0 comments on commit 60b914e

Please sign in to comment.