spacetelescope / spherical_geometry

A Python package for handling spherical polygons that represent arbitrary regions of the sky
http://spherical-geometry.readthedocs.io/
62 stars 31 forks source link

Multi-union of nearly identical polygons may fail #232

Closed mcara closed 1 year ago

mcara commented 1 year ago

Multi-union of a set of polygons with some of them being nearly identical polygons may fail (crash):

  File "spherical_geometry/polygon.py", line 1176, in multi_union
    return g.union()
  File "spherical_geometry/graph.py", line 409, in union
    self._find_all_intersections()
  File "spherical_geometry/graph.py", line 643, in _find_all_intersections
    changed = self._find_arc_to_arc_intersections()
  File "spherical_geometry/graph.py", line 630, in _find_arc_to_arc_intersections
    starts = np.vstack(
  File "numpy/core/shape_base.py", line 289, in vstack
    return _nx.concatenate(arrs, 0, dtype=dtype, casting=casting)
ValueError: all the input array dimensions except for the concatenation axis mus
match exactly, but along dimension 1, the array at index 0 has size 3 and the array
at index 2 has size 0

I have attached a data set - a numpy list of arrays saved in .npz format using numpy.savez.

polygon_points_list.gz

After downloading the file, rename its extension .gz -> .npz. Then, to reproduce the above error, do the following:

import numpy as np
from spherical_geometry.polygon import SphericalPolygon

polygon_data = np.load("polygon_points_list.npz")
polygons = []
for k in range(len(polygon_data.files) // 2):
    polygons.append(
        SphericalPolygon(
            polygon_data[f'p{k:02d}_points'],
            inside=polygon_data[f'p{k:02d}_inside']
        )
    )
SphericalPolygon.multi_union(polygons)
mcara commented 1 year ago

This is the same error as reported in https://github.com/spacetelescope/spherical_geometry/issues/209