equinor / xtgeo

XTGeo Python class library for subsurface Surfaces, Cubes, Wells, Grids, Points, etc
https://xtgeo.readthedocs.io/en/latest/
GNU Lesser General Public License v3.0
109 stars 56 forks source link

Possible bug in `simplify_polygons` #1160

Closed mferrera closed 5 months ago

mferrera commented 5 months ago

From an RMS script:

 Traceback (most recent call last):
   Python script, line 89
   Python script, line 65, in main
   Python script, line 34, in _get_polygons
   File "xx/xtgeo/surface/regular_surface.py", line 2802, in get_boundary_polygons
     return _regsurf_boundary.create_boundary(self, alpha_factor, convex, simplify)
   File "xx/xtgeo/surface/_regsurf_boundary.py", line 22, in create_boundary
     pol.simplify(tolerance=0.1)
   File "xx/xyz/polygons.py", line 707, in simplify
     return _polygons_oper.simplify_polygons(self, tolerance, preserve_topology)
   File "xx/xtgeo/xyz/_polygons_oper.py", line 231, in simplify_polygons
     idgroups = self.get_dataframe(copy=False).groupby(self.pname)
   File "xx/13.1.2/linux-amd64-gcc_4_8-release/lib/python3.8/site-packages/pandas/core/frame.py";, line 6511, in groupby
     return DataFrameGroupBy(
   File "xx/13.1.2/linux-amd64-gcc_4_8-release/lib/python3.8/site-packages/pandas/core/groupby/groupby.py", line 525, in __init__
     grouper, exclusions, obj = get_grouper(
   File "xx/13.1.2/linux-amd64-gcc_4_8-release/lib/python3.8/site-packages/pandas/core/groupby/grouper.py", line 781, in get_grouper
     raise KeyError(gpr)
 KeyError: 'POLY_ID'

With calling context

surface = xtgeo.surface_from_roxar(
    PRJ, STRUCTURAL_HORIZON_NAME, STRUCTURAL_CATEGORY_NAME
)
contact = xtgeo.surface_from_roxar(
    PRJ, "GOC", CONTACTS_FOLDER_NAME, stype="clipboard"
)
tmpsurf = surface.copy()
usecontact = surface.copy()
usecontact.resample(contact)

# set surface undefined where below contact
tmpsurf.values = np.ma.masked_where(
    usecontact.values <= tmpsurf.values, tmpsurf.values
)
tmpsurf.to_roxar(PRJ, f"_surface--{contact_name}", CLIPBOARD_FOLDER_NAME, stype="clipboard")
tmpsurf.unrotate()
poly = tmpsurf.get_boundary_polygons(alpha_factor=ALPHA_FACTOR)

Could relate to 749b73e11a5e3f9c0ab48a257f015f2fceda8eae, but maybe not. @jcrivenaes

jcrivenaes commented 5 months ago

Could you look at this, @tnatt ?

tnatt commented 5 months ago

This should fix the issue 🙂 #1163 I've done quite some testing, and it is much more robust now.

mferrera commented 5 months ago

Closing as presumed fixed in #1163