Skip to content

Consider refactoring mesh2d_get_property and related methods #260

@veenstrajelmer

Description

@veenstrajelmer

The meshkernelpy code related to getting properties is slightly inconsistent, some example code to illustrate this:

import numpy as np
import matplotlib.pyplot as plt
plt.close('all')
from meshkernel import (
    MeshKernel,
    ProjectionType,
    GeometryList,
    MakeGridParameters,
    MeshRefinementParameters,
    Mesh2d,
    Mesh2dLocation,
    )

# create basegrid
lon_min, lon_max, lat_min, lat_max = -6, 2, 48.5, 51.2
dxy = 0.7
make_grid_parameters = MakeGridParameters(
    origin_x=lon_min,
    origin_y=lat_min,
    upper_right_x=lon_max,
    upper_right_y=lat_max,
    block_size_x=dxy,
    block_size_y=dxy,
    )
mk = MeshKernel(projection=ProjectionType.SPHERICAL)
mk.curvilinear_compute_rectangular_grid_on_extension(make_grid_parameters)
mk.curvilinear_convert_to_mesh2d() #convert to ugrid/mesh2d

# refine with polygon
pol_x = np.array([-5,-4,0,-5], dtype=np.double)
pol_y = np.array([49,51,49.5,49], dtype=np.double)
geometry_list = GeometryList(pol_x, pol_y)
mrp = MeshRefinementParameters()
mk.mesh2d_refine_based_on_polygon(polygon=geometry_list, mesh_refinement_params=mrp)

# TODO: instead of providing property and location, just get properties FACE_CIRCUMCENTER, EDGE_ORTHOGONALITY, etc
# since getting EDGE_LENGTHS at FACES results in error anyway: "MeshKernelError: Exception of type 'MeshKernelError': Property not supported at this location"
face_circumcenters = mk.mesh2d_get_property(mesh2d_location=Mesh2dLocation.FACES, property=Mesh2d.Property.FACE_CIRCUMCENTER)
edge_orthogonality = mk.mesh2d_get_property(mesh2d_location=Mesh2dLocation.EDGES, property=Mesh2d.Property.ORTHOGONALITY)
edge_length = mk.mesh2d_get_property(mesh2d_location=Mesh2dLocation.EDGES, property=Mesh2d.Property.EDGE_LENGTHS)

# TODO: remove mesh2d_get_orthogonality() since it can be retrieved via mesh2d_get_property()
edge_orthogonality2 = mk.mesh2d_get_orthogonality()
# TODO: deprecate mesh2d_get_smoothness in favor of a EDGE_SMOOTHNESS property
edge_smoothness = mk.mesh2d_get_smoothness()

# TODO: x/y coordinates are valid for edge_orthogonality2 and face_circumcenters
# but are arrays with arbitrary values for edge_orthogonality. This is inconvenient for plotting
print(face_circumcenters.x_coordinates[:5])
print(edge_orthogonality.x_coordinates[:5]) # contains arbitrary/nan values
print(edge_orthogonality2.x_coordinates[:5])

Todo:

  • Mesh2d.Property is the only IntEnum under Mesh2d. Consider moving it outside of the Mesh2d class and renaming it to Mesh2dProperty for consistency.
  • orthogonality can be retrieved with mesh2d_get_orthogonality or with mesh2d_get_property, deprecate the first one
  • smoothness can now only be retrieved via mesh2d_get_smoothness, but this should be possible via mesh2d_get_property instead.
  • All properties are location-specific. Therefore it does not make sense to ask the user to provide both. Instead, make the IntEnum self-explanatory (EDGE_ORTHOGONALITY instead of ORTHOGONALITY just like the others: EDGE_LENGTHS and FACE_CIRCUMCENTERS) and deprecate the location argument. Incorrect combinations will just raise an error anyway: "MeshKernelError: Exception of type 'MeshKernelError': Property not supported at this location"
  • some x/y arrays contain arbitrary/nan values, for instance the coordinates for edge_orthogonality. This is inconvenient for plotting, so would be better to just have valid values there.

Version info

  • meshkernelpy version 8.2.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions