0

I am trying to execute PDAL within a python script for multiple tasks from conversion to filtering, etc. If there is any error with the file, PDAL stops executing and throws an error. But I am unable to capture any error that PDAL spits out.

You can find two approaches in the following. Could you provide some feedback on the code and potential errors?

Approach 1: Run pdal as bash command using subprocess.run.

Here pipeline_json contains the pdal pipeline I want to execute

pdal_command = ["pdal", "pipeline", "--stdin", "-v", "8"] result = run(pdal_command, input=pipeline_json, check=True, capture_output=True, text=True ) 

In this, on successful case, I get pdal's log in result.stderr. But if it fails, I access the stderr from CalledProcessError error thrown by subprocess.run But it is more often than not has process exited with errorcode 3221226505 along with initial PDAL debug messages and NOT the error message from PDAL.

(PDAL Debug) Debugging... (pdal pipeline Debug) Attempting to load plugin 'C: \Users\uuser\anaconda3\envs\volume\Library\bin\libpdal_plugin_reader_e57.dll'. (pdal pipeline Debug) Loaded plugin 'C:\Users\uuser\anaconda3\envs\volume\Library\bin\libpdal_plugin_reader_e57.dll'. (pdal pipeline Debug) Initialized plugin 'C:\Users\uuser\anaconda3\envs\volume\Library\bin\libpdal_plugin_reader_e57.dll'. (pdal pipeline Debug) Executing pipeline in standard mode. (pdal pipeline readers.e57 Info) Reading : .\test_file.e57 

Approach 2: using pdal python library. This time, if any error, the script just stops even if I wrap the whole code in try, except block. Which leaves me with no option to capture why pdal failed

import sys import json import pdal def convert_to_copc(input_file, output_copc): pipeline = { "pipeline": [ { "type": "readers.e57", "filename": input_file }, { "type": "writers.copc", "filename": output_copc, "forward": "all", } ] } pdal_las_json = json.dumps(pipeline) las_pipeline = pdal.Pipeline(pdal_las_json) try: result = las_pipeline.execute() log = las_pipeline.log print(log) print("done") except RuntimeError as e: print("RuntimeError", e) except Exception as e: print(f"Error processing file {input_file}: {str(e)}") return None def main(): if len(sys.argv) != 3: print("Usage: python script.py <input_las_file> <output_copc_file>") sys.exit(1) input_las = sys.argv[1] output_copc = sys.argv[2] convert_to_copc(input_las, output_copc) print("end") if __name__ == "__main__": main() 
10
  • I tried running your 2nd (python library) example with a missing and an invalid .e57 file, and in both cases the code hit the ` RuntimeError` exception block and the exception e contains some info about what the problem is. Which sounds like what you want. Commented Jan 21 at 3:05
  • What do you mean by 'capture'? Do you want to capture the errors in a variable, or to print them as output, or save them to a file, or something else? Why are you using try/except? If you remove them, then all errors will be printed out. Commented Jan 21 at 4:05
  • A big giant exit code on Windows (like 3221226505) generally indicates that the program segfaulted/crashed, so it won't even have the opportunity to report a friendly error message. Python itself may be crashing in your 2nd example which is why your try/except isn't working. Probably an issue with how PDAL was installed Commented Jan 21 at 22:12
  • @SonofaBeach I just want to capture what PDAL writes to console and store it, so that I could just look at it later and debug instead of re-running it and looking at it in real time. When i execute a pdal command in command line (aka terminal) I see the pdal printing logs and errors to cmd. For eg: If i execute PDAL in command line with an incorrect file (or) if i hardcode incorrect scale, offset values, PDAL sometimes throws an error saying the signed integer is too large to hold in int32. In approach 2, I thought I can capture it by wrapping in try/catch but the whole script crashes. Commented Jan 23 at 8:38
  • @mikewatt Can you share how PDAL installation affects this ? Have you had this experience ? I installed using conda from conda-forge channel. After some digging, I agree that in Approach 1, I cant get everything that PDAL writes to console when it fails. Hence I am trying out Approach 2. Commented Jan 23 at 8:42

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.