import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import mikeio
:::{note}
Example data can be found in the mini_book/data
folder in this zip-file.
:::
fn = "data/oresundHD_run1.dfsu"
msh = mikeio.open(fn)
msh
msh.geometry
msh.geometry.plot();
msh.n_items
msh.projection_string
msh.timestep # in seconds ...
ds = msh.read(items="Surface elevation")
ds.shape
da = ds["Surface elevation"] # =ds[0] = ds.Surface_elevation
da
da.plot();
ze = msh.element_coordinates[:,2] # third column is depth
ze<-20
elems = np.where(ze<-20)[0]
ds_sub = msh.read(items=0, time=-1, elements=elems) # read only data where depth is more than 20m
ds_sub
ax = ds_sub[0].plot()
msh.geometry.plot.mesh(ax=ax);
Alternatively, we can use boolean masking directly on the DataArray, like this (see also DataArray_Masking.ipynb):
dac = ds[0].isel(time=-1).copy()
dac[ze>=-20] = np.nan
dac.plot(show_mesh=True);
# insert your code here
fn = "data/two_elements.mesh"
msh = mikeio.open(fn)
data = 36.5 * np.ones(msh.n_elements) # set all elements to 36.5
time = pd.date_range("2020-1-1", periods=1) # arbitrary date
item = mikeio.ItemInfo(mikeio.EUMType.Chezy_No)
da = mikeio.DataArray(data, time=time, item=item, geometry=msh.geometry)
da.to_dfs("chezy_map.dfsu")
msh = mikeio.open("chezy_map.dfsu")
msh.read()[0][0,:]
msh = mikeio.open("data/oresundHD_run1.dfsu")
msh
The Dfsu geometry plot the same as the mesh. (plot the elements and color them according to the bathymetry).
The DataArray can be used to plot other data, such as surface elevation.
msh.geometry.plot();
ds = msh.read()
ds
wl_laststep = ds["Surface elevation"].isel(time=-1) # DataArray
wl_laststep
In order to customize the plot we can take return the axis and add additional things, like markers and a legend.
ax = wl_laststep.plot(cmap="winter", show_mesh=True, figsize=(12,12))
ax.scatter(x=350000, y=6.15e6, marker='*', s=200, label="Location of bouy")
ax.legend();
In order to create subplots, we can supply the axis as an argument to plot.
fig, (ax1, ax2) = plt.subplots(ncols=2, figsize = (12,7))
da = ds["Surface elevation"].isel(time=-1)
da.plot.contourf(ax=ax1, title="ax=ax1")
da = ds["V velocity"].isel(time=-1)
da.plot.contourf(ax=ax2, title="ax=ax2", label="Northward velocity [m/s]");
See the MIKE IO example notebooks which has "dfsu" in the name.
import utils
utils.sysinfo()