Dataset containing one or more DataArrays with common geometry and time.
Most often obtained by reading a dfs file. But can also be created a sequence or dictonary of DataArrays. The mikeio.Dataset is inspired by and similar to the xarray.Dataset.
The Dataset is primarily a container for one or more DataArrays all having the same time and geometry (and shape, dims, etc). For convenience, the Dataset provides access to these common properties:
time - a pandas.DatetimeIndex with the time instances of the data
geometry - a geometry object e.g. Grid2D or GeometryFM
shape - a tuple of array dimensions (for each DataArray)
dims - a tuple of dimension labels
Selecting items
Selecting a specific item “itemA” (at position 0) from a Dataset ds can be done with:
ds[[“itemA”]] - returns a new Dataset with “itemA”
This method currently has limited functionality for spatial interpolation. It will be extended in the future.
The spatial parameters available depend on the geometry of the Dataset:
Grid1D: x
Grid2D: x, y
Grid3D: [not yet implemented!]
GeometryFM: (x,y)
GeometryFMLayered: (x,y) [surface point will be returned!]
Parameters
Name
Type
Description
Default
time
(float, pd.DatetimeIndex or Dataset)
timestep in seconds or discrete time instances given by pd.DatetimeIndex (typically from another Dataset da2.time), by default None (=don’t interp in time)
None
x
float
x-coordinate of point to be interpolated to, by default None
None
y
float
y-coordinate of point to be interpolated to, by default None
None
z
float
z-coordinate of point to be interpolated to, by default None
None
n_nearest
int
When using IDW interpolation, how many nearest points should be used, by default: 3
3
**kwargs
Any
Additional keyword arguments are passed to the interpolant
{}
Returns
Name
Type
Description
Dataset
new Dataset with interped data
See Also
sel : Select data using label indexing interp_like : Interp to another time/space of another DataSet interp_time : Interp in the time direction only
output timestep in seconds or discrete time instances given as a pd.DatetimeIndex (typically from another Dataset ds2.time)
None
freq
str | None
pandas frequency
None
method
str
Specifies the kind of interpolation as a string (‘linear’, ‘nearest’, ‘zero’, ‘slinear’, ‘quadratic’, ‘cubic’, ‘previous’, ‘next’, where ‘zero’, ‘slinear’, ‘quadratic’ and ‘cubic’ refer to a spline interpolation of zeroth, first, second or third order; ‘previous’ and ‘next’ simply return the previous or next value of the point) or as an integer specifying the order of the spline interpolator to use. Default is ‘linear’.
'linear'
extrapolate
bool
Default True. If False, a ValueError is raised any time interpolation is attempted on a value outside of the range of x (where extrapolation is necessary). If True, out of bounds values are assigned fill_value
True
fill_value
float
Default NaN. this value will be used to fill in for points outside of the time range.
np.nan
Returns
Name
Type
Description
Dataset
Examples
ds = mikeio.read("../data/HD2D.dfsu")ds
<mikeio.Dataset>
dims: (time:9, element:884)
time: 1985-08-06 07:00:00 - 1985-08-07 03:00:00 (9 records)
geometry: Dfsu2D (884 elements, 529 nodes)
items:
0: Surface elevation <Surface Elevation> (meter)
1: U velocity <u velocity component> (meter per sec)
2: V velocity <v velocity component> (meter per sec)
3: Current speed <Current Speed> (meter per sec)
ds.interp_time(dt=1800)
<mikeio.Dataset>
dims: (time:41, element:884)
time: 1985-08-06 07:00:00 - 1985-08-07 03:00:00 (41 records)
geometry: Dfsu2D (884 elements, 529 nodes)
items:
0: Surface elevation <Surface Elevation> (meter)
1: U velocity <u velocity component> (meter per sec)
2: V velocity <v velocity component> (meter per sec)
3: Current speed <Current Speed> (meter per sec)
ds.interp_time(freq='2h')
<mikeio.Dataset>
dims: (time:11, element:884)
time: 1985-08-06 07:00:00 - 1985-08-07 03:00:00 (11 records)
geometry: Dfsu2D (884 elements, 529 nodes)
items:
0: Surface elevation <Surface Elevation> (meter)
1: U velocity <u velocity component> (meter per sec)
2: V velocity <v velocity component> (meter per sec)
3: Current speed <Current Speed> (meter per sec)
isel
Dataset.isel(idx=None, axis=0, **kwargs)
Return a new Dataset whose data is given by integer indexing along the specified dimension(s).
The spatial parameters available depend on the dims (i.e. geometry) of the Dataset:
Grid1D: x
Grid2D: x, y
Grid3D: x, y, z
GeometryFM: element
Parameters
Name
Type
Description
Default
idx
int | Sequence[int] | slice | None
Index, or indices, along the specified dimension(s)
None
axis
int | str
axis number or “time”, by default 0
0
time
int
time index,by default None
required
x
int
x index, by default None
required
y
int
y index, by default None
required
z
int
z index, by default None
required
element
int
Bounding box of coordinates (left lower and right upper) to be selected, by default None
Return a new Dataset whose data is given by selecting index labels along the specified dimension(s).
In contrast to Dataset.isel, indexers for this method should use labels instead of integers.
The spatial parameters available depend on the geometry of the Dataset:
Grid1D: x
Grid2D: x, y, coords, area
Grid3D: [not yet implemented! use isel instead]
GeometryFM: (x,y), coords, area
GeometryFMLayered: (x,y,z), coords, area, layers
Parameters
Name
Type
Description
Default
time
(str, pd.DatetimeIndex or Dataset)
time labels e.g. “2018-01” or slice(“2018-1-1”,“2019-1-1”), by default None
required
x
float
x-coordinate of point to be selected, by default None
required
y
float
y-coordinate of point to be selected, by default None
required
z
float
z-coordinate of point to be selected, by default None
required
coords
np.array(float, float)
As an alternative to specifying x, y and z individually, the argument coords can be used instead. (x,y)- or (x,y,z)-coordinates of point to be selected, by default None
required
area
(float, float, float, float)
Bounding box of coordinates (left lower and right upper) to be selected, by default None
required
layers
int or str or list
layer(s) to be selected: “top”, “bottom” or layer number from bottom 0,1,2,… or from the top -1,-2,… or as list of these; only for layered dfsu, by default None