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

Newly generated xugrid.ugrid.ugrid2d.Ugrid2d does not have the attribute 'plot' #39

Closed
veenstrajelmer opened this issue Jan 9, 2023 · 1 comment

Comments

@veenstrajelmer
Copy link
Collaborator

Newly generated xugrid.ugrid.ugrid2d.Ugrid2d does not have the attribute 'plot', while this was the case before. A quite large MWE attached, where something might well be missing to generate a proper xugrid grid.

import meshkernel
import xugrid as xu
import matplotlib.pyplot as plt
plt.close('all')
import numpy as np

make_grid_parameters = meshkernel.MakeGridParameters() # Create an instance of MakeGridParameters with its default values
geometry_list = meshkernel.GeometryList(np.empty(0), np.empty(0)) # A polygon must to be provided. If empty it will not be used.
mk1 = meshkernel.MeshKernel()
mk1.curvilinear_make_uniform(make_grid_parameters, geometry_list) #TODO: make geometry_list argument optional
mk1.curvilinear_convert_to_mesh2d() #convert to ugrid/mesh2d
mesh2d_grid1 = mk1.mesh2d_get() #in case of curvi grid: mk.curvilinear_convert_to_mesh2d()
fig, ax = plt.subplots(figsize=(10,4))
mesh2d_grid1.plot_edges(ax,linewidth=1.2)

#generate face_node_connectivity array to make conversion to xugrid possible #TODO: move this to meshkernelpy internal?
num_faces = len(mesh2d_grid1.nodes_per_face)
num_face_nodes_max = np.max(mesh2d_grid1.nodes_per_face)
face_node_connectivity = np.full(shape=(num_faces,num_face_nodes_max), dtype=np.int32, fill_value=-1)
index_in_mesh2d = 0
for face_index, num_face_nodes in enumerate(mesh2d_grid1.nodes_per_face):
    range_face_node_index = index_in_mesh2d+num_face_nodes
    face_node_connectivity[face_index,range(num_face_nodes)] = mesh2d_grid1.face_nodes[index_in_mesh2d:range_face_node_index]
    index_in_mesh2d = index_in_mesh2d + num_face_nodes

#convert to xugrid grid and plot
xu_grid = xu.Ugrid2d(node_x=mesh2d_grid1.node_x, #array([ 0., 10., 20., 30.,  0., 10., 20., 30.,  0., 10., 20., 30.,  0., 10., 20., 30.])
                     node_y=mesh2d_grid1.node_y, #array([ 0.,  0.,  0.,  0., 10., 10., 10., 10., 20., 20., 20., 20., 30., 30., 30., 30.])
                     fill_value=-1,
                     face_node_connectivity=face_node_connectivity)
# face_node_connectivity:
# array([[ 0,  1,  5,  4],
#        [ 1,  2,  6,  5],
#        [ 2,  3,  7,  6],
#        [ 4,  5,  9,  8],
#        [ 5,  6, 10,  9],
#        [ 6,  7, 11, 10],
#        [ 8,  9, 13, 12],
#        [ 9, 10, 14, 13],
#        [10, 11, 15, 14]])

fig, ax = plt.subplots(figsize=(10,4))
xu_grid.plot(ax=ax) #TODO: generates "AttributeError: 'Ugrid2d' object has no attribute 'plot'" (was not the case before)
@veenstrajelmer
Copy link
Collaborator Author

Issue is solved in main, probably by other maintenance

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