Skip to content

Commit 887b076

Browse files
authored
Merge pull request #562 from Snowthe/dtype_Dfs3_read
Dtype dfs3 read
2 parents b4e19ee + a9d0ed7 commit 887b076

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

mikeio/dfs/_dfs2.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ def read(
200200
area: array[float], optional
201201
Read only data inside (horizontal) area given as a
202202
bounding box (tuple with left, lower, right, upper) coordinates
203-
203+
dtype: data-type, optional
204+
Define the dtype of the returned dataset (default = np.float32)
204205
Returns
205206
-------
206207
Dataset

mikeio/dfs/_dfs3.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ def read(
188188
area=None,
189189
layers=None,
190190
keepdims=False,
191+
dtype=np.float32,
191192
) -> Dataset:
192193
"""
193194
Read data from a dfs3 file
@@ -204,6 +205,8 @@ def read(
204205
in the returned Dataset? by default: False
205206
layers: int, str, list[int], optional
206207
Read only data for specific layers, by default None
208+
dtype: data-type, optional
209+
Define the dtype of the returned dataset (default = np.float32)
207210
208211
Returns
209212
-------
@@ -250,7 +253,7 @@ def read(
250253
shape = (nt, nz, yNum, xNum)
251254

252255
for item in range(n_items):
253-
data = np.ndarray(shape=shape, dtype=float)
256+
data = np.ndarray(shape=shape, dtype=dtype)
254257
data_list.append(data)
255258

256259
if single_time_selected and not keepdims:

tests/test_dfs3.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import pytest
3+
import numpy as np
34

45
import mikeio
56
from mikeio.spatial import GeometryUndefined
@@ -46,6 +47,12 @@ def test_dfs3_read():
4647
assert da.shape == (30, 10, 10, 10) # t # z # y # x
4748
assert da.dims == ("time", "z", "y", "x")
4849
assert da.name == "Item 1"
50+
assert da.to_numpy().dtype == np.float32
51+
52+
53+
def test_dfs3_read_double_precision():
54+
ds = mikeio.read("tests/testdata/Grid1.dfs3", dtype=np.float64)
55+
assert ds[0].to_numpy().dtype == np.float64
4956

5057

5158
def test_dfs3_read_time():

0 commit comments

Comments
 (0)