import numpy as np
import mikeio
Dataset - Add new item
A common workflow is to create a new item based on existing items in a dataset.
This can be in done in several ways. Let’s try one of the options.
= mikeio.read("../tests/testdata/NorthSea_HD_and_windspeed.dfsu")
ds ds
<mikeio.Dataset>
dims: (time:67, element:958)
time: 2017-10-27 00:00:00 - 2017-10-29 18:00:00 (67 records)
geometry: Dfsu2D (958 elements, 570 nodes)
items:
0: Surface elevation <Surface Elevation> (meter)
1: Wind speed <Wind speed> (meter per sec)
- Create a copy of the DataArray
= ds.Wind_speed.copy()
ws2 ; ws2.plot.hist()
- Make some modifications
= np.clip(ws2.values, 1,18)
ws2.values ; ws2.plot.hist()
- Assign it to a new name in the dataset
"Wind speed 2"] = ws2 ds[
ds
<mikeio.Dataset>
dims: (time:67, element:958)
time: 2017-10-27 00:00:00 - 2017-10-29 18:00:00 (67 records)
geometry: Dfsu2D (958 elements, 570 nodes)
items:
0: Surface elevation <Surface Elevation> (meter)
1: Wind speed <Wind speed> (meter per sec)
2: Wind speed 2 <Wind speed> (meter per sec)
- Reorder items if necessary
= ds[["Wind speed 2","Surface elevation", "Wind speed"]]
ds2 ds2
<mikeio.Dataset>
dims: (time:67, element:958)
time: 2017-10-27 00:00:00 - 2017-10-29 18:00:00 (67 records)
geometry: Dfsu2D (958 elements, 570 nodes)
items:
0: Wind speed 2 <Wind speed> (meter per sec)
1: Surface elevation <Surface Elevation> (meter)
2: Wind speed <Wind speed> (meter per sec)
"modified.dfsu") ds2.to_dfs(