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

mismatch edge order xugrid and meshkernel #72

Closed
veenstrajelmer opened this issue Jul 4, 2023 · 2 comments · Fixed by #84
Closed

mismatch edge order xugrid and meshkernel #72

veenstrajelmer opened this issue Jul 4, 2023 · 2 comments · Fixed by #84
Labels
bug Something isn't working

Comments

@veenstrajelmer
Copy link
Collaborator

veenstrajelmer commented Jul 4, 2023

Describe the bug
The ordering of the edge-orthogonality array seems different than the ordering of the edges in the xugrid.UgridDataset. Would be convenient if they are aligned so we can easily plot these type of values.

To Reproduce

from meshkernel import MeshKernel, ProjectionType, MakeGridParameters
import xarray as xr
import dfm_tools as dfmt

#general settings
lon_min,lon_max = -1,-0.2
lat_min,lat_max = 49.1,49.6
lon_res,lat_res = 0.1,0.1

figsize = (10,4)
crs = 'EPSG:4326'

# Create an instance of MakeGridParameters and set the values
make_grid_parameters = MakeGridParameters()
make_grid_parameters.angle = 0.0
make_grid_parameters.origin_x = lon_min
make_grid_parameters.origin_y = lat_min
make_grid_parameters.upper_right_x = lon_max
make_grid_parameters.upper_right_y = lat_max
make_grid_parameters.block_size_x = lon_res
make_grid_parameters.block_size_y = lat_res

mk2 = MeshKernel(projection=ProjectionType.SPHERICAL)
mk2.curvilinear_compute_rectangular_grid_on_extension(make_grid_parameters)
mk2.curvilinear_convert_to_mesh2d()

mesh2d_grid2 = mk2.mesh2d_get()

uds = dfmt.meshkernel_to_UgridDataset(mk2, crs=crs)

aa = mk2.mesh2d_get_orthogonality()
uds['ortho'] = xr.DataArray(aa.values,dims=(uds.grid.edge_dimension))
uds['ortho'] = uds['ortho'].where(uds['ortho']!=-999) #TODO: hardcoded -999, better to have nans in this array already
uds['ortho'].ugrid.plot() #TODO: ordering of the orthogonality array does not seem to align with the edge-order in the uds

Gives:
image

Expected behavior
The missing values are now scattered around trough the grid, but they probably belong to the outer edges of the grid. Not sure if this is a meshkernel issue or a xugrid issue.

Version info (please complete the following information):

@Huite
Copy link
Contributor

Huite commented Aug 15, 2023

This is an issue in xugrid indeed. In the from_meshkernel method, the edge_nodes from the meshkernel aren't used. Consequently, xugrid generates its own edge_node_connectivity, which doesn't match the order of the orthogonality array.

I'll make a change to use the edge_nodes from the meshkernel object.

@lucacarniato lucacarniato linked a pull request Sep 12, 2023 that will close this issue
@veenstrajelmer
Copy link
Collaborator Author

This will be fixed in xugrid after Deltares/xugrid#250 is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants