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

make mesh2d_make_global in line with interacter behaviour #181

Open
veenstrajelmer opened this issue Jul 1, 2024 · 0 comments
Open

make mesh2d_make_global in line with interacter behaviour #181

veenstrajelmer opened this issue Jul 1, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@veenstrajelmer
Copy link

veenstrajelmer commented Jul 1, 2024

Is your feature request related to a problem? Please describe.
When generating a global grid with mesh2d_make_global, the resulting grid is sort of flipped with respect to the reference in interacter. This is inconvenient, since it complicates conversions in other tools like the xugrid.to_nonperiodic() conversion.

To reproduce:

from meshkernel import DeleteMeshOption, MeshKernel, ProjectionType, GeometryList
import matplotlib.pyplot as plt
plt.close('all')
import xugrid as xu
import numpy as np

mk = MeshKernel(projection=ProjectionType.SPHERICAL)
mk.mesh2d_make_global(num_longitude_nodes=192, num_latitude_nodes=100)

line_array = np.array([[-68.37701613,  21.48864852],
       [-71.26512097,  51.0113413 ],
       [  1.65952621,  57.30306271],
       [ 15.37802419,  19.55273423],
       [-32.99773185, -14.32576568],
       [-62.60080645,  11.32509854],
       [-68.37701613,  21.48864852]])
xx = line_array[:,0]
yy = line_array[:,1]
delete_pol_geom = GeometryList(x_coordinates=xx, y_coordinates=yy)
mk.mesh2d_delete(geometry_list=delete_pol_geom, 
                 delete_option=DeleteMeshOption.INSIDE_NOT_INTERSECTED,
                 invert_deletion=False)

mesh2d = mk.mesh2d_get()

fig, ax = plt.subplots()
mesh2d.plot_edges(ax)
ax.plot(xx, yy, 'r-')

# xugrid conversion
xu_grid = xu.Ugrid2d.from_meshkernel(mesh=mesh2d, projected=False, crs=4326)
# TODO: this to_nonperiodic conversion now only partly works, it does not result in grid in the upper/lower left corners if the figure.
xu_grid_flat = xu_grid.to_nonperiodic(xmax=180)

#fig, ax = plt.subplots()
#xu_grid.plot()
fig, ax = plt.subplots()
xu_grid_flat.plot()

Gives:
image
image

Describe the solution you'd like
Get a flipped version of the figure above, in other words: get the continuous longitude line at lon=-180 instead of lon=180.

Additional context
Additionally, the algorithm seems not to be robust for different lat/lon values.

When supplying a low number of longitude values, we get orphan edges at the min/max latitudes

from meshkernel import MeshKernel, ProjectionType
import matplotlib.pyplot as plt
plt.close('all')
mk = MeshKernel(projection=ProjectionType.SPHERICAL)
mk.mesh2d_make_global(num_longitude_nodes=20, num_latitude_nodes=100)
mesh2d = mk.mesh2d_get()
fig, ax = plt.subplots()
mesh2d.plot_edges(ax)

image

When supplying a low number of latitude values, the resulting grid does not extent to +/- 90 latitudes:

from meshkernel import MeshKernel, ProjectionType
import matplotlib.pyplot as plt
plt.close('all')
mk = MeshKernel(projection=ProjectionType.SPHERICAL)
mk.mesh2d_make_global(num_longitude_nodes=100, num_latitude_nodes=20)
mesh2d = mk.mesh2d_get()
fig, ax = plt.subplots()
mesh2d.plot_edges(ax)

image

@veenstrajelmer veenstrajelmer added the enhancement New feature or request label Jul 1, 2024
@veenstrajelmer veenstrajelmer changed the title make mesh2d_make_global in line with interacter behaviour make mesh2d_make_global in line with interacter behaviour and robust Jul 1, 2024
@veenstrajelmer veenstrajelmer changed the title make mesh2d_make_global in line with interacter behaviour and robust make mesh2d_make_global in line with interacter behaviour Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant