import numpy as np
import matplotlib.pyplot as plt
import mikeio
Dfsu - Distance to land
Calculate the distance to land for each element in mesh and save to dfsu file
= mikeio.Mesh("../tests/testdata/odense_rough.mesh")
msh msh
Flexible Mesh
number of elements: 654
number of nodes: 399
projection: UTM-33
; msh.plot()
; msh.geometry.plot.outline()
Get a list of land nodes
= msh.node_coordinates[msh.codes==1]
ncland
0], ncland[:,1]); plt.scatter(ncland[:,
Get element coordinates
= msh.element_coordinates ec
Calculate distance to nearest land node
= 0
i = ec.shape[0]
ne = np.zeros(ne)
d
for i in range(ne):
= np.min(np.sqrt((ec[i,0] - ncland[:,0])**2 + (ec[i,1] -ncland[:,1])**2)) d[i]
= mikeio.DataArray(data=d,
da =msh.geometry,
geometry=mikeio.ItemInfo("Distance to land", mikeio.EUMType.Distance, mikeio.EUMUnit.meter))
item da
<mikeio.DataArray>
name: Distance to land
dims: (element:654)
time: 2018-01-01 00:00:00 (time-invariant)
geometry: Dfsu2D (654 elements, 399 nodes)
values: [1697, 435, ..., 1194]
; da.plot()
Store result in a new Dfsu file
"distance.dfsu") da.to_dfs(
Clean up
import os
"distance.dfsu") os.remove(