import matplotlib.pyplot as plt
import mikeio
Combining Datasets
Datasets can be combined along the items and time axis
Concatenate Datasets (along the time axis)
= mikeio.read("../tests/testdata/tide1.dfs1")
ds1 ds1
<mikeio.Dataset>
dims: (time:97, x:10)
time: 2019-01-01 00:00:00 - 2019-01-03 00:00:00 (97 records)
geometry: Grid1D (n=10, dx=0.06667)
items:
0: Level <Water Level> (meter)
= mikeio.read("../tests/testdata/tide2.dfs1") + 0.5 # add offset
ds2 ds2
<mikeio.Dataset>
dims: (time:97, x:10)
time: 2019-01-02 00:00:00 - 2019-01-04 00:00:00 (97 records)
geometry: Grid1D (n=10, dx=0.06667)
items:
0: Level <Water Level> (meter)
Concatenating data along the time axis can be done with Dataset.concat
= mikeio.Dataset.concat([ds1, ds2])
ds3 ds3
<mikeio.Dataset>
dims: (time:145, x:10)
time: 2019-01-01 00:00:00 - 2019-01-04 00:00:00 (145 records)
geometry: Grid1D (n=10, dx=0.06667)
items:
0: Level <Water Level> (meter)
0].to_numpy()[:,1], 'ro', label="Dataset 1")
plt.plot(ds1.time, ds1[0].to_numpy()[:,1], 'k+', label="Dataset 2")
plt.plot(ds2.time, ds2[0].to_numpy()[:,1], 'g-', label="Dataset 3")
plt.plot(ds3.time, ds3["Notice the offset...")
plt.title(; plt.legend()
Merging datasets
= mikeio.read("../tests/testdata/tide1.dfs1")
dsA dsA
<mikeio.Dataset>
dims: (time:97, x:10)
time: 2019-01-01 00:00:00 - 2019-01-03 00:00:00 (97 records)
geometry: Grid1D (n=10, dx=0.06667)
items:
0: Level <Water Level> (meter)
= dsA.copy()
dsB = dsB.rename({"Level":"Other_level"})
dsB = dsB + 2
dsB dsB
<mikeio.Dataset>
dims: (time:97, x:10)
time: 2019-01-01 00:00:00 - 2019-01-03 00:00:00 (97 records)
geometry: Grid1D (n=10, dx=0.06667)
items:
0: Other_level <Water Level> (meter)
Merge datasets with different items can be done like this:
= mikeio.Dataset.merge([dsA, dsB])
dsC dsC
<mikeio.Dataset>
dims: (time:97, x:10)
time: 2019-01-01 00:00:00 - 2019-01-03 00:00:00 (97 records)
geometry: Grid1D (n=10, dx=0.06667)
items:
0: Level <Water Level> (meter)
1: Other_level <Water Level> (meter)
Which in this simple case with a single item in each dataset is equivalent to:
= dsA[0]
daA daA
<mikeio.DataArray>
name: Level
dims: (time:97, x:10)
time: 2019-01-01 00:00:00 - 2019-01-03 00:00:00 (97 records)
geometry: Grid1D (n=10, dx=0.06667)
= dsB[0]
daB daB
<mikeio.DataArray>
name: Other_level
dims: (time:97, x:10)
time: 2019-01-01 00:00:00 - 2019-01-03 00:00:00 (97 records)
geometry: Grid1D (n=10, dx=0.06667)
mikeio.Dataset([daA, daB])
<mikeio.Dataset>
dims: (time:97, x:10)
time: 2019-01-01 00:00:00 - 2019-01-03 00:00:00 (97 records)
geometry: Grid1D (n=10, dx=0.06667)
items:
0: Level <Water Level> (meter)
1: Other_level <Water Level> (meter)