How to disable console output on exception in scipy.spatial.qhull.Delaunay?

1k Views Asked by At

I have thousands of point sets which I feed to Scipy's Delaunay function to get a corresponding set of triangulations.

If my input points are invalid, ex. all points on a line or for some other reason the Delaunay triangulation fails, it result in a pretty detailed report in the console, like the following report:

QH6154 qhull precision error: initial facet 1 is coplanar with the interior point
ERRONEOUS FACET:
- f1
- flags: bottom simplicial upperDelaunay flipped
- normal: -0.3162 -0.9487 0
- offset: 5929262
- vertices: p4(v2) p3(v1) p0(v0)
- neighboring facets: f2 f3 f4

While executing: | qhull d Qbb Qt Qc Qz
Options selected for Qhull 2012.1 2012/02/18:
run-id 231396746 delaunay Qbbound-last Qtriangulate Qcoplanar-keep
Qz-infinity-point _pre-merge _zero-centrum Qinterior-keep Pgood
_max-width 33 Error-roundoff 5.8e-009 _one-merge 4e-008
Visible-distance 1.2e-008 U-coplanar-distance 1.2e-008
Width-outside 2.3e-008 _wide-facet 6.9e-008

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:
- p1(v3): 4.9e+005 6.1e+006 0.00016
- p4(v2): 4.9e+005 6.1e+006 33
- p3(v1): 4.9e+005 6.1e+006 0
- p0(v0): 4.9e+005 6.1e+006 0.0009

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 5.8e-009. The center point, facets and distances
to the center point are as follows:

center point 4.9e+005 6.087e+006 8.25

facet p4 p3 p0 distance= 0
facet p1 p3 p0 distance= 0
facet p1 p4 p0 distance= 0
facet p1 p4 p3 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: 4.9e+005 4.9e+005 difference= 33
1: 6.087e+006 6.087e+006 difference= 11
2: 0 33 difference= 33

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 5.8e-009.
- 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.

According to the documentation there are no immediate option to set on the Delaunay(...) call to suppress this report. I haven't found an option either in the rather long list of qhull options.

I have tried the solution provided here, but it seems to circumvent that.

Are there any way to suppress this?

2

There are 2 best solutions below

0
On

A way to fully suppress the warnings would be to use the warnings class from the standard library.

An implementation, that is risky because you are ignoring all errors, which would suppress all output. Your code would look like:

import warnings
import numpy
from scipy.spatial import Delaunay
#random point set
pts = numpy.random.rand(12,3)
#warnings catch - ignore filter
with warnings.catch_warnings():
    warnings.simplefilter("ignore")
    try:
        #call Delaunay with pts input
        out = Delaunay(pts)
    except:
        #when exception arises set out to False
        out = False

Keep in mind that it may be beneficial to modify the warnings, in order to print specific warnings at least once in case something unexpected arises.

0
On

The following code suppresses most of the printing:

if points.shape[0]>3:
    tri = Delaunay(points, qhull_options='Pp')

using qhull_options='QJ Pp' will further suppress warnings, however it will also modify slightly the original position of the points to avoid precision and coplanarity issues.