Dfs1 has in addition to the dfs0 file a single spatial dimension.
This spatial dimension has information on the grid spacing, but do not contain enough metadata to determine their geographical position, but have a relative distance from the origo.
import mikeio
ds = mikeio.read("data/waterlevel_north.dfs1")
ds
ds.geometry
This dfs1 file contains only two nodes (nx=2
) and has a grid spacing of 8800 m.
The dataset has a single item North WL
which we can access in three different ways.
ds.North_WL
ds["North WL"]
ds[0]
da = ds.North_WL
da
The dataarray variable da
contains all the data for the North WL
item from the dfs1 file.
The data can be visualized with the .plot()
method.
The default plot show time on the vertical axis and space on the horizontal axis since dfs1 are often used to represent horizontal variations along an open boundary.
da.plot();
Fort this example, with only a few nodes on the spatial axis, it makes more sense to visualize the data as individual lines in a timeseries plot.
da.plot.timeseries();
Inline exercise
Are there other possible visualizations?
Spatial subsetting can be done in two ways:
.isel()
x=0..(nx-1) (or with negative indexing from the end)sel()
x=0..8800 (pick closest node)da.isel(x=0).plot(title="First");
da.isel(x=-1).plot(title="Last");
da.sel(x=8800).plot(title="Last (x=8800)")
Creating a new dataarray in the dataset based on an existing dataarray is easy.
ds["North WL calibrated"] = da + 0.1 # add 0.1 m to the original data
After subsetting into a single spatial point the result no longer has any spatial dimension and has become a simple timeseries which can be saved as a dfs0 file.
ds.isel(x=0)
ds.isel(x=0).geometry
ds.isel(x=0).to_dfs("random_0.dfs0")
mikeio.read("random_0.dfs0").plot();
Inline exercise
Export the timeseries in the last spatial element as a csv file
import utils
utils.sysinfo()