Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify line plots along cross-section #673

Open
veenstrajelmer opened this issue Nov 20, 2023 · 0 comments
Open

Simplify line plots along cross-section #673

veenstrajelmer opened this issue Nov 20, 2023 · 0 comments

Comments

@veenstrajelmer
Copy link
Collaborator

veenstrajelmer commented Nov 20, 2023

When slicing a dataset, it is very complex to get the variables without depth component (like bedlevel, waterlevel) out of it. An example for bedlevel is given below. The desired result is the bed level along the slice line_array in a line plot with distance along the line_array on the xaxis. This should be simplified.

import matplotlib.pyplot as plt
plt.close('all')
import numpy as np
import dfm_tools as dfmt

file_nc = dfmt.data.fm_grevelingen_map(return_filepath=True)
uds = dfmt.open_partitioned_dataset(file_nc)
line_array = np.array([[ 53181.96942503, 424270.83361629],
                       [ 55160.15232593, 416913.77136685]])

# fig, ax = plt.subplots()
# uds['mesh2d_flowelem_bl'].ugrid.plot(cmap='jet') #TODO: default is edgecolor='face', should work even better with edgecolor='none', but that results in seethrough edges anyway, report to matplotlib?
# ax.plot(line_array[:,0],line_array[:,1],'b',linewidth=3)

xr_crs_ugrid = dfmt.polyline_mapslice(uds.isel(time=0).max(dim="nmesh2d_layer").max(dim="nmesh2d_interface"), line_array)
fig, ax = plt.subplots()
xr_crs_ugrid['mesh2d_flowelem_bl'].ugrid.plot()

fig, ax = plt.subplots()
xr_crs_ugrid['mesh2d_flowelem_bl'].plot()

# s_array = xr_crs_ugrid.grid.face_coordinates[:,0] #contains nans for some reason
s_array_nonan = xr_crs_ugrid.grid.node_coordinates[:,0][xr_crs_ugrid.grid.face_node_connectivity].mean(axis=1)
bed_array = xr_crs_ugrid['mesh2d_flowelem_bl'].to_numpy()
fig, ax = plt.subplots()
ax.plot(s_array_nonan,bed_array)

Looks nice but not desired:
image

Desired, but complex workaround needed at this moment:
image

A simpler alternative, but results in degrees on x-axis for spherical models:

from shapely import LineString
uds_crs = uds.ugrid.intersect_linestring(LineString(line_array))
fig,ax = plt.subplots()
uds_crs.mesh2d_flowelem_bl.plot(x="mesh2d_s")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant