Skip to content

Commit a2f6eac

Browse files
authored
Merge pull request #55 from PDAL/remove-python-from-pdal-base
Remove python from pdal base
2 parents b048960 + cfe6391 commit a2f6eac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+26101
-191
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
pdal/libpdalpython.cpp
22
*.pyc
3+
_skbuild/*
4+
.vscode/*
35
__pycache__
46
build/*
57
PDAL.egg-info/*
68
dist/*
9+
*.o
10+
*.so
11+
*.dylib

Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
FROM continuumio/miniconda3:latest
2+
MAINTAINER Howard Butler <[email protected]>
3+
4+
RUN apt-get install -y \
5+
gdb && \
6+
apt-get clean && \
7+
rm -rf /var/lib/apt/lists/*
8+
9+
RUN conda update -n base -c defaults conda \
10+
&& conda install -y -c conda-forge \
11+
compilers \
12+
pdal \
13+
make ninja \
14+
python=3.8
15+
16+
17+
RUN git clone https://github.com/PDAL/python.git pdal-python \
18+
&& cd pdal-python \
19+
&& git checkout remove-python-from-pdal-base
20+
21+
RUN cd pdal-python \
22+
&& pip install -e .
23+
24+
ENV PDAL_DRIVER_PATH=/pdal-python/_skbuild/linux-x86_64-3.8/cmake-install/lib/
25+
26+
27+
# docker build -t pdal-python
28+
# docker run -t -i --cap-add=SYS_PTRACE --security-opt seccomp=unconfined pdal-python
29+
#gdb --args /pdal-python/_skbuild/linux-x86_64-3.8/cmake-build/pdal_filters_python_test
30+
31+
32+

MANIFEST.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
exclude *.txt
22
exclude MANIFEST.in
3-
include CHANGES.txt README.rst
3+
include CHANGES.txt README.rst pyproject.toml
44
recursive-include test *.py
55
recursive-include pdal *.pyx
66
recursive-include pdal *.hpp
7+
recursive-include pdal *.cpp

README.rst

Lines changed: 109 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,39 @@
22
PDAL
33
================================================================================
44

5-
The PDAL Python extension allows you to process data with PDAL into `Numpy`_
6-
arrays. Additionally, you can use it to fetch `schema`_ and `metadata`_ from
5+
PDAL Python support allows you to process data with PDAL into `Numpy`_
6+
arrays. It supports embedding Python in PDAL pipelines with the `readers.numpy <https://pdal.io/stages/readers.numpy.html>`__
7+
and `filters.python <https://pdal.io/stages/filters.python.html>`__ stages, and it provides a PDAL extension module to control
8+
Python interaction with PDAL.
9+
10+
Additionally, you can use it to fetch `schema`_ and `metadata`_ from
711
PDAL operations.
812

13+
Installation
14+
--------------------------------------------------------------------------------
15+
16+
PyPI
17+
................................................................................
18+
19+
PDAL Python support is installable via PyPI:
20+
21+
.. code-block::
22+
23+
pip install PDAL
24+
25+
GitHub
26+
................................................................................
27+
928
The repository for PDAL's Python extension is available at https://github.com/PDAL/python
1029

11-
It is released independently from PDAL itself as of PDAL 1.7.
30+
Python support released independently from PDAL itself as of PDAL 1.7.
1231

1332
Usage
1433
--------------------------------------------------------------------------------
1534

35+
Simple
36+
................................................................................
37+
1638
Given the following pipeline, which simply reads an `ASPRS LAS`_ file and
1739
sorts it by the ``X`` dimension:
1840

@@ -34,30 +56,107 @@ sorts it by the ``X`` dimension:
3456
3557
import pdal
3658
pipeline = pdal.Pipeline(json)
37-
pipeline.validate() # check if our JSON and options were good
38-
pipeline.loglevel = 8 #really noisy
3959
count = pipeline.execute()
4060
arrays = pipeline.arrays
4161
metadata = pipeline.metadata
4262
log = pipeline.log
4363
64+
Reading using Numpy Arrays
65+
................................................................................
66+
67+
The following more complex scenario demonstrates the full cycling between
68+
PDAL and Python:
69+
70+
* Read a small testfile from GitHub into a Numpy array
71+
* Filters those arrays with Numpy for Intensity
72+
* Pass the filtered array to PDAL to be filtered again
73+
* Write the filtered array to an LAS file.
74+
75+
.. code-block:: python
76+
77+
data = "https://github.com/PDAL/PDAL/blob/master/test/data/las/1.2-with-color.las?raw=true"
78+
79+
80+
json = """
81+
{
82+
"pipeline": [
83+
{
84+
"type": "readers.las",
85+
"filename": "%s"
86+
}
87+
]
88+
}"""
89+
90+
import pdal
91+
import numpy as np
92+
pipeline = pdal.Pipeline(json % data)
93+
count = pipeline.execute()
94+
95+
# get the data from the first array
96+
# [array([(637012.24, 849028.31, 431.66, 143, 1, 1, 1, 0, 1, -9., 132, 7326, 245380.78254963, 68, 77, 88),
97+
# dtype=[('X', '<f8'), ('Y', '<f8'), ('Z', '<f8'), ('Intensity', '<u2'), ('ReturnNumber', 'u1'), ('NumberOfReturns', 'u1'), ('ScanDirectionFlag', 'u1'), ('EdgeOfFlightLine', 'u1'), ('Classification', 'u1'), ('ScanAngleRank', '<f4'), ('UserData', 'u1'), ('PointSourceId', '<u2'), ('GpsTime', '<f8'), ('Red', '<u2'), ('Green', '<u2'), ('Blue', '<u2')])
98+
99+
arr = pipeline.arrays[0]
100+
print (len(arr)) # 1065 points
101+
102+
103+
# Filter out entries that have intensity < 50
104+
intensity = arr[arr['Intensity'] > 30]
105+
print (len(intensity)) # 704 points
106+
107+
108+
# Now use pdal to clamp points that have intensity
109+
# 100 <= v < 300, and there are 387
110+
clamp =u"""{
111+
"pipeline":[
112+
{
113+
"type":"filters.range",
114+
"limits":"Intensity[100:300)"
115+
}
116+
]
117+
}"""
118+
119+
p = pdal.Pipeline(clamp, [intensity])
120+
count = p.execute()
121+
clamped = p.arrays[0]
122+
print (count)
123+
124+
# Write our intensity data to an LAS file
125+
output =u"""{
126+
"pipeline":[
127+
{
128+
"type":"writers.las",
129+
"filename":"clamped.las",
130+
"offset_x":"auto",
131+
"offset_y":"auto",
132+
"offset_z":"auto",
133+
"scale_x":0.01,
134+
"scale_y":0.01,
135+
"scale_z":0.01
136+
}
137+
]
138+
}"""
139+
140+
p = pdal.Pipeline(output, [clamped])
141+
count = p.execute()
142+
print (count)
143+
144+
145+
44146
45147
.. _`Numpy`: http://www.numpy.org/
46148
.. _`schema`: http://www.pdal.io/dimensions.html
47149
.. _`metadata`: http://www.pdal.io/development/metadata.html
48150

49151

50-
.. image:: https://travis-ci.org/PDAL/python.svg?branch=master
51-
:target: https://travis-ci.org/PDAL/python
52-
53152
.. image:: https://ci.appveyor.com/api/projects/status/of4kecyahpo8892d
54153
:target: https://ci.appveyor.com/project/hobu/python/
55154

56155
Requirements
57156
================================================================================
58157

59-
* PDAL 1.7+
60-
* Python >=2.7 (including Python 3.x)
158+
* PDAL 2.1+
159+
* Python >=3.6
61160
* Cython (eg :code:`pip install cython`)
62161
* Packaging (eg :code:`pip install packaging`)
63162

debug.sh

Lines changed: 0 additions & 1 deletion
This file was deleted.

pdal/CMakeLists.txt

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
cmake_minimum_required(VERSION 3.11.0)
2+
project(pdal)
3+
4+
# macros for creating targets
5+
include(${PROJECT_SOURCE_DIR}/macros.cmake NO_POLICY_SCOPE)
6+
7+
set(CMAKE_CXX_STANDARD 11)
8+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
9+
set(CMAKE_CXX_EXTENSIONS OFF)
10+
set(CMAKE_BUILD_TYPE "Release")
11+
12+
enable_testing()
13+
14+
# Python-finding settings
15+
set(Python3_FIND_STRATEGY "LOCATION")
16+
set(Python3_FIND_REGISTRY "LAST")
17+
set(Python3_FIND_FRAMEWORK "LAST")
18+
find_package(Python3 COMPONENTS Interpreter Development NumPy REQUIRED)
19+
20+
# find PDAL. Require 2.1+
21+
find_package(PDAL 2.1 REQUIRED)
22+
23+
if(SKBUILD)
24+
find_package(PythonExtensions REQUIRED)
25+
find_package(Cython REQUIRED)
26+
message(STATUS "The project is built using scikit-build")
27+
endif()
28+
29+
execute_process(
30+
COMMAND
31+
${Python3_EXECUTABLE} -c "from distutils import sysconfig; print(sysconfig.get_config_var('Py_ENABLE_SHARED'))"
32+
OUTPUT_VARIABLE Py_ENABLE_SHARED
33+
OUTPUT_STRIP_TRAILING_WHITESPACE
34+
)
35+
36+
#execute_process(
37+
# COMMAND
38+
# ${Python3_EXECUTABLE} -c "from distutils import sysconfig; print(sysconfig.get_config_var('LDSHARED').split(' ', 1)[1])"
39+
# OUTPUT_VARIABLE PYTHON_LDSHARED
40+
# OUTPUT_STRIP_TRAILING_WHITESPACE
41+
#)
42+
43+
#if (NOT Py_ENABLE_SHARED)
44+
# message(STATUS "Python ${Python3_EXECUTABLE} is statically linked")
45+
# if (APPLE)
46+
# # conda gives us -bundle, which isn't valid
47+
# message(STATUS "Removing extra -bundle argument from sysconfig.get_config_var('LDSHARED')")
48+
# string(REPLACE "-bundle" "" PYTHON_LDSHARED "${PYTHON_LDSHARED}")
49+
# string(STRIP ${PYTHON_LDSHARED} PYTHON_LDSHARED)
50+
# endif()
51+
# # set(Python3_LIBRARIES ${PYTHON_LDSHARED})
52+
# message(STATUS "Setting Python3_LIBRARIES to '${Python3_LIBRARIES}' due to static Python")
53+
#endif()
54+
55+
set(EXTENSION_SRC
56+
PyArray.cpp
57+
PyArray.hpp
58+
PyDimension.hpp
59+
PyPipeline.cpp
60+
PyPipeline.hpp)
61+
62+
set(extension "libpdalpython")
63+
add_cython_target(${extension} libpdalpython.pyx CXX PY3)
64+
65+
add_library(${extension} MODULE ${EXTENSION_SRC} libpdalpython)
66+
target_include_directories( ${extension}
67+
PRIVATE
68+
.
69+
${PDAL_INCLUDE_DIRS}
70+
${Python3_INCLUDE_DIRS}
71+
${Python3_NumPy_INCLUDE_DIRS})
72+
73+
target_link_libraries(${extension} ${PDAL_LIBRARIES})
74+
python_extension_module(${extension})
75+
76+
install(TARGETS ${extension} LIBRARY DESTINATION ${PROJECT_NAME})
77+
78+
PDAL_PYTHON_ADD_PLUGIN(numpy_reader reader numpy
79+
FILES
80+
./io/NumpyReader.cpp
81+
./io/NumpyReader.hpp
82+
./plang/Invocation.cpp
83+
./plang/Environment.cpp
84+
./plang/Redirector.cpp
85+
./plang/Script.cpp
86+
LINK_WITH
87+
${PDAL_LIBRARIES}
88+
${Python3_LIBRARIES}
89+
${CMAKE_DL_LIBS}
90+
SYSTEM_INCLUDES
91+
${PDAL_INCLUDE_DIRS}
92+
${Python3_INCLUDE_DIRS}
93+
${Python3_NumPy_INCLUDE_DIRS}
94+
COMPILE_OPTIONS
95+
${PYTHON_LINK_LIBRARY}
96+
)
97+
98+
99+
# Download and unpack googletest at configure time
100+
configure_file(test/gtest/CMakeLists.txt.in googletest-download/CMakeLists.txt)
101+
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
102+
RESULT_VARIABLE result
103+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
104+
if(result)
105+
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
106+
endif()
107+
execute_process(COMMAND ${CMAKE_COMMAND} --build .
108+
RESULT_VARIABLE result
109+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
110+
if(result)
111+
message(FATAL_ERROR "Build step for googletest failed: ${result}")
112+
endif()
113+
114+
# Prevent overriding the parent project's compiler/linker
115+
# settings on Windows
116+
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
117+
118+
# Add googletest directly to our build. This defines
119+
# the gtest and gtest_main targets.
120+
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
121+
${CMAKE_CURRENT_BINARY_DIR}/googletest-build
122+
EXCLUDE_FROM_ALL)
123+
124+
PDAL_PYTHON_ADD_PLUGIN(python_filter filter python
125+
FILES
126+
./filters/PythonFilter.cpp
127+
./filters/PythonFilter.hpp
128+
./plang/Invocation.cpp
129+
./plang/Environment.cpp
130+
./plang/Redirector.cpp
131+
./plang/Script.cpp
132+
LINK_WITH
133+
${PDAL_LIBRARIES}
134+
${Python3_LIBRARIES}
135+
${CMAKE_DL_LIBS}
136+
SYSTEM_INCLUDES
137+
${PDAL_INCLUDE_DIRS}
138+
${Python3_INCLUDE_DIRS}
139+
${Python3_NumPy_INCLUDE_DIRS}
140+
COMPILE_OPTIONS
141+
${PYTHON_LINK_LIBRARY}
142+
)
143+
144+
PDAL_PYTHON_ADD_TEST(pdal_io_numpy_test
145+
FILES
146+
./test/NumpyReaderTest.cpp
147+
./test/Support.cpp
148+
./plang/Invocation.cpp
149+
./plang/Environment.cpp
150+
./plang/Redirector.cpp
151+
./plang/Script.cpp
152+
LINK_WITH
153+
${numpy_reader}
154+
${Python3_LIBRARIES}
155+
${PDAL_LIBRARIES}
156+
${CMAKE_DL_LIBS}
157+
SYSTEM_INCLUDES
158+
${PDAL_INCLUDE_DIRS}
159+
${Python3_INCLUDE_DIRS}
160+
${Python3_NumPy_INCLUDE_DIRS}
161+
)
162+
163+
PDAL_PYTHON_ADD_TEST(pdal_filters_python_test
164+
FILES
165+
./test/PythonFilterTest.cpp
166+
./test/Support.cpp
167+
./plang/Invocation.cpp
168+
./plang/Environment.cpp
169+
./plang/Redirector.cpp
170+
./plang/Script.cpp
171+
LINK_WITH
172+
${python_filter}
173+
${Python3_LIBRARIES}
174+
${PDAL_LIBRARIES}
175+
${CMAKE_DL_LIBS}
176+
SYSTEM_INCLUDES
177+
${PDAL_INCLUDE_DIRS}
178+
${Python3_INCLUDE_DIRS}
179+
${Python3_NumPy_INCLUDE_DIRS}
180+
)

0 commit comments

Comments
 (0)