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

Support qhull options for alpha_shape_auto to resolve ill-conditioned inputs #524

Open
ljwolf opened this issue Apr 12, 2023 · 2 comments
Open

Comments

@ljwolf
Copy link
Member

ljwolf commented Apr 12, 2023

  • Platform information:
posix darwin
posix.uname_result(sysname='Darwin', nodename='wolfbook.local', release='22.3.0', version='Darwin Kernel Version 22.3.0: Mon Jan 30 20:42:11 PST 2023; root:xnu-8792.81.3~2/RELEASE_X86_64', machine='x86_64')
  • Python version:
3.9.16 | packaged by conda-forge | (main, Feb  1 2023, 21:42:20)
[Clang 14.0.6 ]
  • SciPy version:
1.10.0
  • NumPy version:
1.23.5

Working with @LVConsult, we noted that when alpha_shape_auto() receives ill-conditioned input (such as collinear or coincident points), the underlying scipy.spatial.Delaunay() routine will fail with a scipy.spatial.QhullError. But, because we cannot access the underlying Delaunay() call, we cannot provide any qhull_options to resolve or address this error.

For an example testbench:

import numpy
from libpysal.cg import alpha_shape_auto

good = numpy.random.random(size=(20, 2))
alpha_shape_auto(good) # succeeds
collinear = numpy.column_stack((numpy.arange(6), numpy.arange(6)))
# alpha_shape_auto(collinear) # fails with a Qhull error, needs to be jittered
collinear_plus = numpy.row_stack((collinear, good))
alpha_shape_auto(collinear_plus) # succeeds
coincident = numpy.zeros((6, 2))
# alpha_shape_auto(coincident) # fails with a Qhull error, needs to have coincident points deleted
coincident_plus = numpy.row_stack((coincident, good))
alpha_shape_auto(coincident_plus) # succeeds
two_coincident = numpy.row_stack((numpy.zeros((3, 2)), numpy.ones((3, 2))))
#alpha_shape_auto(two_coincident) # fails with a Qhull error, needs to have coincident points deleted
col_and_coi = numpy.row_stack((collinear, coincident))
#alpha_shape_auto(col_and_coi) # fails with a Qhull error, needs to have coincident points deleted, then jittered

The usual solution to conditioning problems (either delete the coincident points or jitter the collinear points) can be done very efficiently by Qhull ( Delaunay(coords, qhull_options="Qbk:0Bk:0") or Delaunay(coords, qhull_options="QJ"), respectively) but the end user can't use these options because the alpha_shape_auto() does not deal with the options for Delaunay().

Think we could support these options?

@martinfleis
Copy link
Member

Can we just pass kwargs to Delaunay()?

@ljwolf
Copy link
Member Author

ljwolf commented Apr 13, 2023

Yep!

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

2 participants