import matplotlib.pyplot as plt
import mikeio
Dfsu - Vertical Profile
This notebooks demonstrates plotting of vertical profile (transect) dfsu.
= "../tests/testdata/oresund_vertical_slice.dfsu"
filename = mikeio.read(filename)
ds ds
<mikeio.Dataset>
dims: (time:3, element:441)
time: 1997-09-15 21:00:00 - 1997-09-16 03:00:00 (3 records)
geometry: DfsuVerticalProfileSigmaZ (441 elements, 4 sigma-layers, 5 z-layers)
items:
0: Temperature <Temperature> (degree Celsius)
1: Salinity <Salinity> (PSU)
= ds.geometry
g g
Flexible Mesh Geometry: DfsuVerticalProfileSigmaZ
number of nodes: 550
number of elements: 441
number of layers: 9 (4 sigma-layers, max 5 z-layers)
projection: UTM-33
import numpy as np
= g.element_coordinates[g.top_elements,:2]
ec2d = ec2d[:,0], ec2d[:,1]
xe, ye - 359615.47172605) ** 2 + (ye - 6.145e+06) ** 2) np.argmin((xe
11
359615,6.145e+06]) g._find_nearest_element_2d([
array([11])
=359615, y=6.145e+06, z=-3).plot() ds.sel(x
The geometry can be visualized from above (to be shown on a map) using g.plot() and from the side showing the 2dv transect mesh with g.plot.mesh().
Let’s show the transect on top of the model domain…
= mikeio.open("../tests/testdata/oresundHD_run1.dfsu")
dfs = dfs.geometry model_domain
= plt.subplots(1,2,figsize=(12,4))
_, ax # left-side plot
=ax[0], title="Transect")
model_domain.plot(ax="r", ax=ax[0])
g.plot(color
# right-side plot
=ax[1], title="Transect mesh"); g.plot.mesh(ax
We would like to show two points of interest A and B on the map. The geometry object has a method for finding the nearest relative position…
= [3.55e+05, 6.145e+06]
ptA = [3.62e+05, 6.166e+06]
ptB = g.get_nearest_relative_distance(ptA)
distA = g.get_nearest_relative_distance(ptB)
distB distA, distB
(5462.327351236415, 27589.50308534942)
Let’s now visualize the points on the map and transect
= plt.subplots(1,2,figsize=(12,4))
_, ax =ax[0], title="Transect")
model_domain.plot(ax="r", ax=ax[0])
g.plot(color0].plot(*ptA, color="b", marker="*", markersize=10)
ax[0].plot(*ptB, color="b", marker="*", markersize=10)
ax[
=ax[1], title="Transect mesh");
g.plot.mesh(ax1].axvline(distA, color="0.5")
ax[1].text(distA + 500, -20, 'position A')
ax[1].axvline(distB, color="0.5")
ax[1].text(distB + 500, -20, 'position B'); ax[
= ds.Temperature.isel(time=2).plot(figsize=(12,4))
ax ="0.5")
ax.axvline(distA, color+ 500, -20, 'position A')
ax.text(distA ="0.5")
ax.axvline(distB, color+ 500, -20, 'position B'); ax.text(distB
= 1
time_step
= plt.subplots(2,1,figsize=(10,8))
fig, ax =ax[0])
ds.Temperature[time_step].plot(ax=ax[1], title=None); ds.Salinity[time_step].plot(ax
Kalundborg case
A non-straight vertical profile (transect) from a model in geographical coordinates.
= "../tests/testdata/kalundborg_coarse.mesh"
filename = mikeio.open(filename).geometry
model_domain = "../tests/testdata/kalundborg_transect.dfsu"
filename = mikeio.read(filename)
ds ds
<mikeio.Dataset>
dims: (time:10, element:1708)
time: 2018-02-11 00:00:00 - 2018-02-11 11:15:00 (10 records)
geometry: DfsuVerticalProfileSigmaZ (1708 elements, 5 sigma-layers, 20 z-layers)
items:
0: U velocity <u velocity component> (meter per sec)
1: V velocity <v velocity component> (meter per sec)
2: Temperature <Temperature> (degree Celsius)
3: Salinity <Salinity> (PSU)
= model_domain.plot.outline()
ax ="cyan", ax=ax); ds.geometry.plot(color
=(12,4)); ds.U_velocity.plot(figsize
Spatial subsetting
Both points and parts of the 2dv domain can selected.
= [10.8, 55.6, -3]
ptA ds.geometry.get_nearest_relative_distance(ptA)
28757.285254363647
Points can be extracted:
= ds.sel(x=ptA[0], y=ptA[1], z=ptA[2])
ds_pt ; ds_pt.plot()
And vertical columns…
= ds.sel(x=ptA[0], y=ptA[1]).U_velocity
u_col
u_col.plot(); plt.legend(ds.time)
Or parts of the 2dv transect… here selecting the part with relative distance between 10 and 25 km
= ds.geometry.relative_element_distance
rd = np.where(np.logical_and(10000 < rd, rd < 25000))[0]
idx = ds.isel(element=idx)
dssub dssub
<mikeio.Dataset>
dims: (time:10, element:579)
time: 2018-02-11 00:00:00 - 2018-02-11 11:15:00 (10 records)
geometry: DfsuVerticalProfileSigmaZ (579 elements, 4 sigma-layers, 16 z-layers)
items:
0: U velocity <u velocity component> (meter per sec)
1: V velocity <v velocity component> (meter per sec)
2: Temperature <Temperature> (degree Celsius)
3: Salinity <Salinity> (PSU)
; dssub.Temperature.plot()
Or specific layers:
# select top 5 layers
= ds.geometry.find_index(layers=range(-6,-1))
idx = ds.isel(element=idx)
dssub dssub
<mikeio.Dataset>
dims: (time:10, element:971)
time: 2018-02-11 00:00:00 - 2018-02-11 11:15:00 (10 records)
geometry: DfsuVerticalProfileSigmaZ (971 elements, 3 sigma-layers, 2 z-layers)
items:
0: U velocity <u velocity component> (meter per sec)
1: V velocity <v velocity component> (meter per sec)
2: Temperature <Temperature> (degree Celsius)
3: Salinity <Salinity> (PSU)
=(12,3)); dssub.Temperature.plot(figsize