laempy / pyoints

Pyoints: A Python package for point cloud, voxel and raster processing.
Other
42 stars 8 forks source link

Tolerances too narrow in some tests #7

Closed kbevers closed 5 years ago

kbevers commented 5 years ago

While running the test-suite I found that three tests failed. The test results are correct but the test fail since the output in the unittest is not reproduced 100% as seen in the output below. We are talking about minor numerical instabilities here. Usually this sort of problem is dealt with by specifying a tolerance for which the requested value is to lie within. Here it can be done by only printing a set amount of decimals for the test output which should truncate the floating point errors seen below.

$ python tests/test_pyoints.py
Run doctests for Pyoints
..................................../Users/kevers/dev/pyoints/pyoints/georecords.py:200: UserWarning: 'proj' not set, so I assume '+proj=latlong +datum=WGS84 +to +proj=latlong +datum=WGS84 +units=m +no_defs'
  warnings.warn("'proj' not set, so I assume '%s'" % proj.proj4)
......F................F................................................F.............................Warning 1: Setting nodata to nan on band 2, but band 1 has nodata at nan. The TIFFTAG_GDAL_NODATA only support one value per dataset. This value of nan will be used for all bands on re-opening
Warning 1: Setting nodata to nan on band 3, but band 1 has nodata at nan. The TIFFTAG_GDAL_NODATA only support one value per dataset. This value of nan will be used for all bands on re-opening
..Warning 1: Setting nodata to nan on band 2, but band 1 has nodata at nan. The TIFFTAG_GDAL_NODATA only support one value per dataset. This value of nan will be used for all bands on re-opening
Warning 1: Setting nodata to nan on band 3, but band 1 has nodata at nan. The TIFFTAG_GDAL_NODATA only support one value per dataset. This value of nan will be used for all bands on re-opening
..
======================================================================
FAIL: from_corners (pyoints.grid.grid.Grid)
Doctest: pyoints.grid.grid.Grid.from_corners
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/miniconda3/envs/pyoints/lib/python3.7/doctest.py", line 2198, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for pyoints.grid.grid.Grid.from_corners
  File "/Users/kevers/dev/pyoints/pyoints/grid/grid.py", line 188, in from_corners

----------------------------------------------------------------------
File "/Users/kevers/dev/pyoints/pyoints/grid/grid.py", line 210, in pyoints.grid.grid.Grid.from_corners
Failed example:
    print(raster.shape)
Expected:
    (2, 4)
Got:
    (2, 3)

======================================================================
FAIL: PolynomInterpolator (pyoints.interpolate)
Doctest: pyoints.interpolate.PolynomInterpolator
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/miniconda3/envs/pyoints/lib/python3.7/doctest.py", line 2198, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for pyoints.interpolate.PolynomInterpolator
  File "/Users/kevers/dev/pyoints/pyoints/interpolate.py", line 296, in PolynomInterpolator

----------------------------------------------------------------------
File "/Users/kevers/dev/pyoints/pyoints/interpolate.py", line 327, in pyoints.interpolate.PolynomInterpolator
Failed example:
    print(interpolator([0, 1]))
Expected:
    1.5
Got:
    1.4999999999999998

======================================================================
FAIL: Plane (pyoints.vector)
Doctest: pyoints.vector.Plane
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/miniconda3/envs/pyoints/lib/python3.7/doctest.py", line 2198, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for pyoints.vector.Plane
  File "/Users/kevers/dev/pyoints/pyoints/vector.py", line 909, in Plane

----------------------------------------------------------------------
File "/Users/kevers/dev/pyoints/pyoints/vector.py", line 1033, in pyoints.vector.Plane
Failed example:
    print(plane.t.to_global(local_coords))
Expected:
    [[ 1.  2.]
     [ 4.  6.]
     [ 0.  1.]
     [ 7. 10.]]
Got:
    [[ 1.00000000e+00  2.00000000e+00]
     [ 4.00000000e+00  6.00000000e+00]
     [-2.77555756e-17  1.00000000e+00]
     [ 7.00000000e+00  1.00000000e+01]]

----------------------------------------------------------------------
Ran 142 tests in 2.893s

FAILED (failures=3)
laempy commented 5 years ago

Thank you @kbevers. To get rid of the numerical instabilities I have added functions to round the output within the docstrings with a given tolerance. Thus, the tests should work now, even if a slightly different machine precision is used.