PDAL / python

PDAL's Python Support
Other
117 stars 35 forks source link

Numpy array input for pipelines causes IndexError #34

Closed philtau closed 5 years ago

philtau commented 5 years ago

I want to provide a numpy array as input for my pipeline. I am following the solution given in #28 like so:

import pdal
import numpy as np

# just some dummy data
x_vals = [1.0, 2.0, 3.0, 4.0, 5.0]
y_vals = [6.0, 7.0, 8.0, 9.0, 10.0]
z_vals = [1.5, 3.5, 5.5, 7.5, 9.5]
test_data = np.array(
    [(x, y, z) for x, y, z in zip(x_vals, y_vals, z_vals)],
    dtype=[('X', np.float), ('Y', np.float), ('Z', np.float)]
)

test_pipeline = """
{
    "pipeline": [
        {
            "type":"filters.range",
            "limits":"X[2.5:4.5]"
        }
    ]
}
"""

p = pdal.Pipeline(test_pipeline, arrays=[test_data,])
p.validate()
count = p.execute() # expect count to be 2

The constructed numpy array looks like this:

>>> test_data[0:1]
array([(1., 6., 1.5)],
     dtype=[('X', '<f8'), ('Y', '<f8'), ('Z', '<f8')])

However, upon execution I get this error:

Traceback (most recent call last):
    File "testpdal.py", line 25, in <module>
        p.validate()
    File "...\miniconda3\envs\pdal-36\lib\site-packages\pdal\pipeline.py", line 43, in validate
        return self.p.validate()
    File "pdal\libpdalpython.pyx", line 171, in pdal.libpdalpython.PyPipeline.validate
IndexError: stol argument out of range

The same error occurs when I am using the (correctly formatted) numpy array provided by another pipeline (e.g. a simple readers.las stage) as input like so:

data = reader_pipeline.arrays
p = pdal.Pipeline(test_pipeline, arrays=data)

As far as I can tell everything seems to be correct on my side or am I overlooking something? How can I make this work?

Python 3.6.9 Anaconda on Win10
pdal 2.0.1
python-pdal 2.2.0
abellgithub commented 5 years ago

I can't reproduce this. I get a count of 2. This seems like an issue with cython to me, but I'm not an expert. Note that I get the error: "RuntimeError: readers.memoryview: Can't provide shape option when Fields contain X, Y and Z." without the latest fix for #33, but this doesn't explain the error you're seeing.

hobu commented 5 years ago

Reproduced on windows with current Conda build of the Python extension.

hobu commented 5 years ago

2.2.2 has been released that should fix this issue. If you still have trouble, please reopen.