Skip to content

Commit

Permalink
Override name is possible
Browse files Browse the repository at this point in the history
  • Loading branch information
ecomodeller committed Jan 22, 2025
1 parent 0895a1f commit a05682c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 5 additions & 2 deletions modelskill/timeseries/_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,15 @@ def _parse_point_input(

if isinstance(data, (str, Path)):
suffix = Path(data).suffix
name = name or Path(data).stem
if suffix == ".dfs0":
name = name or Path(data).stem
# TODO avoid changing type of data
data = mikeio.read(data) # now mikeio.Dataset
elif suffix == ".nc":
stem = Path(data).stem
# TODO avoid changing type of data
data = xr.open_dataset(data)
name = name or data.attrs.get("name") or stem
elif isinstance(data, mikeio.Dfs0):
data = data.read() # now mikeio.Dataset

Expand Down Expand Up @@ -132,7 +136,6 @@ def _parse_point_input(
ds = data

assert isinstance(ds, xr.Dataset)
name = ds.attrs.get("name", name)

name = name or item_name
name = _validate_data_var_name(name)
Expand Down
3 changes: 3 additions & 0 deletions tests/observation/test_point_obs.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,6 @@ def test_point_observation_from_netcdf_with_x_y_name():
assert obs.name == "HKNA"
assert obs.quantity.unit == "m"
assert obs.quantity.name == "Hm0"

obs2 = ms.PointObservation("tests/testdata/SW/HKNA_Hm0.nc", name="A better name")
assert obs2.name == "A better name"

0 comments on commit a05682c

Please sign in to comment.