Skip to content

Commit

Permalink
Merge pull request #436 from DHI/fix/skill_to_geodataframe
Browse files Browse the repository at this point in the history
Fix comparer wrong gtype
  • Loading branch information
ecomodeller committed Jun 27, 2024
2 parents 6cba1fb + fe7c170 commit 1b1f578
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modelskill/comparison/_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ def _matched_data_to_xarray(
if z is not None:
ds.coords["z"] = z

if np.isscalar(ds.coords["x"]):
if ds.coords["x"].size == 1:
ds.attrs["gtype"] = str(GeometryType.POINT)
else:
ds.attrs["gtype"] = str(GeometryType.TRACK)
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ test = [
"dask",
"mypy",
"types-PyYAML",
"geopandas",
]

notebooks = [
Expand Down
9 changes: 9 additions & 0 deletions tests/test_comparer.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def tc() -> Comparer:

def test_matched_df(pt_df):
cmp = Comparer.from_matched_data(data=pt_df)
assert cmp.gtype == "point"
assert "m2" in cmp.mod_names
assert "m1" in cmp.mod_names
assert len(cmp.mod_names) == 2
Expand All @@ -95,6 +96,14 @@ def test_matched_df(pt_df):
assert cmp.score()["m2"] == pytest.approx(0.15811388300841905)


def test_matched_skill_geodataframe(pt_df):
cmp = Comparer.from_matched_data(data=pt_df, x=10.0, y=55.0)
sk = cmp.skill()
gdf = sk.to_geodataframe()
assert gdf.iloc[0].geometry.coords[0][0] == 10.0
assert gdf.iloc[0].geometry.coords[0][1] == 55.0


def test_df_score():
df = pd.DataFrame(
{"obs": [1.0, 2.0], "not_so_good": [0.9, 2.1], "perfect": [1.0, 2.0]}
Expand Down

0 comments on commit 1b1f578

Please sign in to comment.