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.

import numpy as np
import mikeio
ds = mikeio.read("../tests/testdata/NorthSea_HD_and_windspeed.dfsu")
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)
  1. Create a copy of the DataArray
ws2 = ds.Wind_speed.copy()
ws2.plot.hist();

  1. Make some modifications
ws2.values = np.clip(ws2.values, 1,18)
ws2.plot.hist();

  1. Assign it to a new name in the dataset
ds["Wind speed 2"] = ws2
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)
  1. Reorder items if necessary
ds2 = ds[["Wind speed 2","Surface elevation", "Wind speed"]]
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)
ds2.to_dfs("modified.dfsu")