Skip to content

Make geometry_list argument for curvilinear_make_uniform() optional #30

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

Closed
veenstrajelmer opened this issue Feb 7, 2023 · 2 comments · Fixed by #38
Closed

Make geometry_list argument for curvilinear_make_uniform() optional #30

veenstrajelmer opened this issue Feb 7, 2023 · 2 comments · Fixed by #38
Labels
enhancement New feature or request

Comments

@veenstrajelmer
Copy link
Collaborator

Is your feature request related to a problem? Please describe.
curvilinear_make_uniform() contains a non-optional geometry_list argument. This geometry_list can be empty, but in this case it makes more sense to supply no geometry_list argument. This is more user friendly.

Describe the solution you'd like
Make the geometry_list argument optional

Describe alternatives you've considered
Supplying an empty list works, but is cumbersome

Additional context
MWE:


import meshkernel
import xarray as xr
import matplotlib.pyplot as plt
plt.close('all')
import numpy as np
import contextily as ctx


#general settings
lon_min,lon_max = -6,2
lat_min,lat_max = 48.5,51.2
lon_res,lat_res = 0.2,0.2
num_x = int(np.ceil((lon_max-lon_min)/lon_res))
num_y = int(np.ceil((lat_max-lat_min)/lat_res))

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


"""
Make a regular (potentially rotated) rectilinear grid. First generate a curvilinear grid than convert the curvilinear grid into unstructured grid. The steps are the following:
- curvilinear_make_uniform, see the following notebook: https://github.com/Deltares/MeshKernelPy/blob/AddCurvilinearGridSupport/docs/examples/04_curvilineargrid_basics.ipynb
- curvilinear_convert_to_mesh2d: https://github.com/Deltares/MeshKernelPy/blob/118cb4953c4e95d5b18ed283bb37f391134b2bb2/meshkernel/meshkernel.py#L1399 

"""

# Create an instance of MakeGridParameters and set the values
make_grid_parameters = meshkernel.MakeGridParameters() #TODO: contains default values that are maybe not intuitive
make_grid_parameters.num_columns = num_x
make_grid_parameters.num_rows = num_y
make_grid_parameters.angle = 0.0 #TODO: does non-zero result in an orthogonal spherical grid?
#make_grid_parameters.block_size = 0.0
make_grid_parameters.origin_x = lon_min
make_grid_parameters.origin_y = lat_min
make_grid_parameters.block_size_x = lon_res
make_grid_parameters.block_size_y = lat_res

grid_in_pol = False
# A polygon must to be provided. If empty it will not be used. If a polygon is provided it will be used in the generation of the curvilinear grid. The polygon must be closed
if grid_in_pol: #can be used instead of origin_x/origin_y and num_x/num_y
    pol_x = np.array([-6,-4,0,-6], dtype=np.double)
    pol_y = np.array([48,51,49.5,48], dtype=np.double)
else:
    pol_x = np.empty(0, dtype=np.double)
    pol_y = np.empty(0, dtype=np.double)
geometry_list = meshkernel.GeometryList(pol_x, pol_y)

mk1 = meshkernel.MeshKernel()
mk1.curvilinear_make_uniform(make_grid_parameters, geometry_list)
@veenstrajelmer
Copy link
Collaborator Author

veenstrajelmer commented Apr 5, 2023

In another example I saw different usage of meshkernel to get to the same result but without requiring geometry_list:

mesh2d_input = Mesh2dFactory.create(rows=noy, columns=nox, origin_x=lon_min, origin_y=lat_min, spacing_x=dx, spacing_y=dy)

mk = MeshKernel()
mk.mesh2d_set(mesh2d_input)

What is the recommended usage?

@lucacarniato
Copy link
Contributor

Solved in the following pull request:

#38

@lucacarniato lucacarniato linked a pull request Apr 14, 2023 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants