PDAL / python

PDAL's Python Support
Other
116 stars 34 forks source link

Exception when python.filter is run more than 2 times but readers.las was not run #41

Closed ahalota closed 4 years ago

ahalota commented 4 years ago

This is a strange one, and not a real use case, but I want to make a note of it since something off is happening behind the scenes.

If I run a pipeline in python that only includes filters.python (no reading input step), by the 3rd item the program crashes. The code runs fine if I only have two items in namez, or if I start the process with a readers.las step.

My code is as follows:

def changeArgs():
    '''A test function see if arguments get changed with pdal filters.python

    Currently fails if 3 items are given but no las file is read in! Weird
    '''

    namez = ['apple1','banana2','chicken3']
    pipez = []
    print('changArgs():')

    for n in namez:
        pipe = {"pipeline" : [
            {   
                "type" : "filters.python",
                "script" : "pdal_filters.py",
                 "function" : "printArgs",
                 "module" : "anything",
                 "pdalargs" : "{\"namez\" : \"" + n + "\"}"
             }
        ]}
        print('\t'+str(pipe['pipeline'][0]['pdalargs']))
        pipez.append(pipe)

    print('pipelines:')
    for p in pipez:     
        pipeline = pdal.Pipeline(json.dumps(p))
        pipeline.validate() #check if our JSON and options were good
        pipeline.execute()
    return

pdal_filters.py:

def printArgs(ins,outs):
    '''To test if args even change if run multiple times!'''
    print(pdalargs)
    return True

Output:

changArgs():
    {"namez" : "apple1"}
    {"namez" : "banana2"}
    {"namez" : "chicken3"}
pipelines:
{'namez': 'apple1'}
{'namez': 'apple1'}
{'namez': 'apple1'}
Traceback (most recent call last):
  File "scratch.py", line 278, in <module>
    changeArgs()
  File "scratch.py", line 232, in changeArgs
    pipeline.execute()
  File "/home/myuser/anaconda3/envs/pdalEnv/lib/python3.7/site-packages/pdal/pipeline.py", line 40, in execute
    return self.p.execute()
  File "pdal/libpdalpython.pyx", line 165, in pdal.libpdalpython.PyPipeline.execute
RuntimeError: Unable to get dictionary item 'name'

Note: Values in pdalargs are unchanged, but this is discussed in #40

abellgithub commented 4 years ago

Could not recreate. Please retest with https://github.com/PDAL/PDAL/pull/2795