Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add examples to use python scripts in the docker image #27

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
leavauchier marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ to be able to run the compilation in this environment.

run ci/build.sh

Set the `PDAL_DRIVER_PATH` environment variable to point to `${THIS REPO}/install/lib`
in order for pdal to find the plugins.

### Windows

one day, maybe...
Expand All @@ -27,6 +30,7 @@ The code is structured as:
│ │ ├── CMakeLists.txt
├── doc
│ ├── pluginFilter.md
├── examples # examples of usage of the code or the docker image
├── ci
├── macro # Python module with ready-to-use filters combinations
│   ├── __init__.py
Expand Down Expand Up @@ -129,3 +133,11 @@ docker run \
python /scripts/my_script.py --input /data/my_data_file.las -o /output/my_output.las
```

Another example can be found in the [./example](./examples/) folder:

Run the following command to run the [demo_script](./examples/demo_script.py) python script
which copies an input las file into the output folder as a las1.4 file :

```bash
./examples/run_custom_script_in_docker_image.sh -i ./test/data/mnx/input/bat.laz -o ./tmp/demo -s ./examples/demo_script.py
```
2 changes: 2 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- Add example to run a local python script in the pdal_ign_plugin docker image

### 0.3.1

- improve code readability in the radius_assign filter (Z limits part).
Expand Down
33 changes: 33 additions & 0 deletions examples/demo_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""Example python script used to demonstrate the usage of local python scripts inside the pdal_ign_plugin
docker image
"""

import argparse

import pdal

from pdal_ign_macro import version as pim_version


def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument(
"-i", "--input_file", type=str, help="Input las/laz file on which to run the script"
)
parser.add_argument("-o", "--output_file", type=str, help="Out las/laz file of the script")
return parser.parse_args()


def main(input_file, output_file):
print("Pdal version is:", pdal.__version__)
print("pdal_ign_macro version is:", pim_version.__version__)
print("Copy input file to output file as LAS1.4")
pipeline = pdal.Pipeline()
pipeline |= pdal.Reader.las(filename=input_file)
pipeline |= pdal.Writer.las(filename=output_file, major_version=1, minor_version=4)
pipeline.execute()


if __name__ == "__main__":
args = parse_args()
main(args.input_file, args.output_file)
49 changes: 49 additions & 0 deletions examples/run_custom_script_in_docker_image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash
# Bash script to run a local python script in the pdal_ign_plugin docker image

while [[ $# -gt 0 ]]; do
case $1 in
-i|--input_file)
input_dir=$(realpath $(dirname "$2"))
input_filename=$(basename "$2")
shift # past argument
shift # past value
;;
-o|--output_dir)
output_dir=$(realpath "$2")
shift # past argument
shift # past value
;;
-s|--script)
script_dir=$(realpath $(dirname "$2"))
script_filename=$(basename "$2")
shift # past argument
shift # past value
;;
*)
echo "Unknown option $1"
exit 1
;;
esac
done

echo "Run script:"
echo "* dir=${script_dir}"
echo "* name=${script_filename}"
echo "on file:"
echo "* dir=${input_dir}"
echo "* name=${input_filename}"
echo "save output to:"
echo "* dir=${output_dir}"
echo "* name=${input_filename}"
echo "--------"


docker run --rm --userns=host \
-v ${input_dir}:/input \
-v ${output_dir}:/output \
-v ${script_dir}:/script \
ghcr.io/ignf/pdal-ign-plugin:latest \
python /script/${script_filename} \
-i /input/${input_filename} \
-o /output/${input_filename}
Loading