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

Rater's get_multipolygon should always return valid shape #134

Open
SorooshMani-NOAA opened this issue Jan 31, 2024 · 1 comment
Open

Rater's get_multipolygon should always return valid shape #134

SorooshMani-NOAA opened this issue Jan 31, 2024 · 1 comment
Assignees

Comments

@SorooshMani-NOAA
Copy link
Collaborator

SorooshMani-NOAA commented Jan 31, 2024

Right now it is possible for the get_multipolygon() to return invalid polygons. This can result in further issues when msh_t() is called which results in confusing errors for the end user. Ideally OCSMesh should always return valid (multi)polygons and throw exception when not possible to return valid (multi)polygons.

@SorooshMani-NOAA SorooshMani-NOAA self-assigned this Jan 31, 2024
@SorooshMani-NOAA SorooshMani-NOAA changed the title Geometry's get_multipolygon should always return valid shape Rater's get_multipolygon should always return valid shape Jan 31, 2024
@SorooshMani-NOAA
Copy link
Collaborator Author

Example callstack:

ValueError                                Traceback (most recent call last)
Cell In[24], line 1
----> 1 geom_msh_t = geom.msh_t()
      2 hfun = ocsmesh.Hfun(
      3     deepcopy(raster),
      4     hmin=100, #1000 #100
   (...)
      7     base_shape_crs=domain_crs
      8 )
     10 hfun.add_contour(
     11     level=0,
     12     target_size=100,
     13     expansion_rate=0.1,
     14 )

File ~/anaconda/conda_env_pchab/lib/python3.11/site-packages/ocsmesh/geom/base.py:86, in BaseGeom.msh_t(self, **kwargs)
     59 def msh_t(self, **kwargs: Any) -> jigsaw_msh_t:
     60     """Returns the `jigsawpy` representation of the geometry.
     61 
     62     This method calculates the vertex-edge representation of
   (...)
     83     passed to the mesh engine for cartesian meshing.
     84     """
---> 86     return multipolygon_to_jigsaw_msh_t(
     87         self.get_multipolygon(**kwargs),
     88         self.crs
     89     )

File ~/anaconda/conda_env_pchab/lib/python3.11/site-packages/ocsmesh/geom/base.py:146, in multipolygon_to_jigsaw_msh_t(multipolygon, crs)
    143     transformer = Transformer.from_crs(crs, utm_crs, always_xy=True)
    144     multipolygon = ops.transform(transformer.transform, multipolygon)
--> 146 msht = utils.shape_to_msh_t(multipolygon)
    147 msht.crs = crs
    148 if utm_crs is not None:

File ~/anaconda/conda_env_pchab/lib/python3.11/site-packages/ocsmesh/utils.py:2231, in shape_to_msh_t(shape)
   2228     raise ValueError(f"Invalid input shape type: {type(shape)}!")
   2230 if not shape.is_valid:
-> 2231     raise ValueError("Input contains invalid (multi)polygons!")
   2233 for polygon in shape.geoms:
   2234     if np.all(
   2235             np.asarray(
   2236                 polygon.exterior.coords).flatten() == float('inf')):

ValueError: Input contains invalid (multi)polygons!

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