Scipy GridData QhullError: center point is coplanar with a facet, or a vertex is coplanar with a neighboring facet

十年热恋 提交于 2021-01-29 05:20:44

问题


I'm having a strange issue using scipy.interpolate.griddata. It's a QhullError. It says center point is coplanar with a facet, or a vertex is coplanar with a neighboring facet.. What does this error mean? How can it be overcome?

from scipy.interpolate import griddata
import numpy as np
def f(x, y): return (1 - x) ** 2 * 10 * (y - x**2) ** 2
X = np.linspace(-3, 3)
Y = np.linspace(-3, 3)
Z = f(X, Y)
xi = np.linspace(X.min(), X.max(), 1000)
yi = np.linspace(Y.min(), Y.max(), 1000)
zi = griddata((X, Y), Z, (xi[None,:], yi[:,None]), method='cubic')





QhullError                                Traceback (most recent call last)
~/Documents/SAStatement/sss.py in <module>
      7 xi = np.linspace(X.min(), X.max(), 1000)
      8 yi = np.linspace(Y.min(), Y.max(), 1000)
----> 9 zi = griddata((X, Y), Z, (xi[None,:], yi[:,None]), method='cubic')

/anaconda3/lib/python3.7/site-packages/scipy/interpolate/ndgriddata.py in griddata(points, values, xi, method, fill_value, rescale)
    224     elif method == 'cubic' and ndim == 2:
    225         ip = CloughTocher2DInterpolator(points, values, fill_value=fill_value,
--> 226                                         rescale=rescale)
    227         return ip(xi)
    228     else:

interpnd.pyx in scipy.interpolate.interpnd.CloughTocher2DInterpolator.__init__()

qhull.pyx in scipy.spatial.qhull.Delaunay.__init__()

qhull.pyx in scipy.spatial.qhull._Qhull.__init__()

QhullError: QH6154 Qhull precision error: Initial simplex is flat (facet 1 is coplanar with the interior point)

While executing:  | qhull d Qz Qt Qc Q12 Qbb
Options selected for Qhull 2015.2.r 2016/01/18:
  run-id 62852831  delaunay  Qz-infinity-point  Qtriangulate  Qcoplanar-keep
  Q12-no-wide-dup  Qbbound-last  _pre-merge  _zero-centrum  Qinterior-keep
  Pgood  _max-width  6  Error-roundoff 8.3e-15  _one-merge 5.8e-14
  Visible-distance 1.7e-14  U-coplanar-distance 1.7e-14  Width-outside 3.3e-14
  _wide-facet 1e-13

precision problems (corrected unless 'Q0' or an error)
      2 flipped facets

The input to qhull appears to be less than 3 dimensional, or a
computation has overflowed.

Qhull could not construct a clearly convex simplex from points:
- p38(v3):   1.7   1.7   1.7
- p50(v2): 8.9e-17 8.9e-17     6
- p49(v1):     3     3   5.5
- p0(v0):    -3    -3   5.5

The center point is coplanar with a facet, or a vertex is coplanar
with a neighboring facet.  The maximum round off error for
computing distances is 8.3e-15.  The center point, facets and distances
to the center point are as follows:

center point   0.4133   0.4133    4.641

facet p50 p49 p0 distance=    0
facet p38 p49 p0 distance=    0
facet p38 p50 p0 distance=    0
facet p38 p50 p49 distance=    0

These points either have a maximum or minimum x-coordinate, or
they maximize the determinant for k coordinates.  Trial points
are first selected from points that maximize a coordinate.

The min and max coordinates for each dimension are:
  0:        -3         3  difference=    6
  1:        -3         3  difference=    6
  2:  -4.337e-19         6  difference=    6

If the input should be full dimensional, you have several options that
may determine an initial simplex:
  - use 'QJ'  to joggle the input and make it full dimensional
  - use 'QbB' to scale the points to the unit cube
  - use 'QR0' to randomly rotate the input for different maximum points
  - use 'Qs'  to search all points for the initial simplex
  - use 'En'  to specify a maximum roundoff error less than 8.3e-15.
  - trace execution with 'T3' to see the determinant for each point.

If the input is lower dimensional:
  - use 'QJ' to joggle the input and make it full dimensional
  - use 'Qbk:0Bk:0' to delete coordinate k from the input.  You should
    pick the coordinate with the least range.  The hull will have the
    correct topology.
  - determine the flat containing the points, rotate the points
    into a coordinate plane, and delete the other coordinates.
  - add one or more points to make the input full dimensional.

回答1:


Because your X and Y are identical, wich means all the points you provided to interpolate are the on the plane x=y.

X = np.linspace(-3, 3)
Y = (np.random.random(50)-0.5)*6 # Just make sure X and Y are non-linear.
Z = f(X, Y)
xi = np.linspace(X.min(), X.max(), 1000)
yi = np.linspace(Y.min(), Y.max(), 1000)
zi = griddata((X, Y), Z, (xi[None,:], yi[:,None]), method='cubic')


来源:https://stackoverflow.com/questions/56654686/scipy-griddata-qhullerror-center-point-is-coplanar-with-a-facet-or-a-vertex-is

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!