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

Preserve dtype during interpolation #796

Merged
merged 1 commit into from
Feb 19, 2025
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
5 changes: 3 additions & 2 deletions mikeio/_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ def interp2d(

else:
nt, _ = da.shape
idatitem = np.empty(shape=(nt, ni))
# use dtype of da
idatitem = np.empty(shape=(nt, ni), dtype=da.values.dtype)
for step in range(nt):
idatitem[step, :] = _interp_itemstep(
da[step].to_numpy(), elem_ids, weights
Expand Down Expand Up @@ -146,7 +147,7 @@ def interp2d(
ni = len(elem_ids)
datitem = data
nt, _ = datitem.shape
idatitem = np.empty(shape=(nt, ni))
idatitem = np.empty(shape=(nt, ni), dtype=datitem.dtype)
for step in range(nt):
idatitem[step, :] = _interp_itemstep(datitem[step], elem_ids, weights)
if shape:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_dfsu.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,8 +939,10 @@ def test_dataset_interp_to_xarray():
def test_interp_like_grid():
ds = mikeio.read("tests/testdata/wind_north_sea.dfsu")
ws = ds[0]
assert ws.values.dtype == np.float32
grid = ds.geometry.get_overset_grid(dx=0.1)
ws_grid = ws.interp_like(grid)
assert ws_grid.values.dtype == np.float32
assert ws_grid.n_timesteps == ds.n_timesteps
assert isinstance(ws_grid, DataArray)
assert isinstance(ws_grid.geometry, Grid2D)
Expand Down