Skip to content
Snippets Groups Projects
Commit 83b9bdd5 authored by Maciej Wielgosz's avatar Maciej Wielgosz
Browse files

cleaning bash scripts|

parent 191dd8fb
Branches
No related tags found
No related merge requests found
# remove all the files in the source folder
SOURCE_FOLDER=/home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/sample_playground
rm -rf $SOURCE_FOLDER/*
cp /home/nibio/mutable-outside-world/data/raw_for_pipeline_test/Plot69_2022-06-15_09-08-53_9pct_time.las \
/home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/sample_playground
# change name of the file to first.laz
mv /home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/sample_playground/Plot69_2022-06-15_09-08-53_9pct_time.las \
/home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/sample_playground/first.las
# copy first.laz to second.laz
cp /home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/sample_playground/first.las \
/home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/sample_playground/second.las
\ No newline at end of file
# remove all the files in the source folder
SOURCE_FOLDER=/home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/sample_playground
rm -rf $SOURCE_FOLDER/*
cp /home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/playground_data/* \
/home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/sample_playground
\ No newline at end of file
SOURCE_FOLDER=/home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/sample_playground
rm -rf $SOURCE_FOLDER/*
cp /home/nibio/mutable-outside-world/data/small_file_pipeline_test/small_file_pipeline_test.las \
/home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/sample_playground
# change name of the file to first.laz
mv /home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/sample_playground/small_file_pipeline_test.las \
/home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/sample_playground/first.las
# copy first.laz to second.laz
cp /home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/sample_playground/first.las \
/home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/sample_playground/second.las
\ No newline at end of file
# remove all the files in the source folder
SOURCE_FOLDER=/home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/sample_playground
rm -rf $SOURCE_FOLDER/*
cp /home/nibio/mutable-outside-world/data/strange_shape_cloud_for_pipeline_test/2022-08-05_11-03-31_9pct_time_scan.laz \
/home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/sample_playground
# change name of the file to first.laz
mv /home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/sample_playground/2022-08-05_11-03-31_9pct_time_scan.laz \
/home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/sample_playground/first.laz
# # copy first.laz to second.laz
cp /home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/sample_playground/first.laz \
/home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/sample_playground/second.laz
\ No newline at end of file
#!/bin/bash
############################ parameters #################################################
# General parameters
CLEAR_INPUT_FOLDER=1 # 1: clear input folder, 0: not clear input folder
CONDA_ENV="pdal-env-1" # conda environment for running the pipeline
# Tiling parameters
N_TILES=3
SLICE_THICKNESS=0.5
FIND_STEMS_HEIGHT=1.5
FIND_STEMS_THICKNESS=0.5
GRAPH_MAXIMUM_CUMULATIVE_GAP=3
ADD_LEAVES_VOXEL_LENGTH=0.5
FIND_STEMS_MIN_POINTS=50
############################# end of parameters declaration ############################
# Do the environment setup
# check if PYTHONPATH is set to the current directory
if [ -z "$PYTHONPATH" ]; then
echo "PYTHONPATH is not set. Setting it to the current directory"
export PYTHONPATH=$PWD
else
echo "PYTHONPATH is set to '$PYTHONPATH'"
fi
# conda activate pdal-env-1
# check if activated conda environment is the same as the one specified in the parameters
if [ "$CONDA_DEFAULT_ENV" != "$CONDA_ENV" ]; then
echo "The activated conda environment is not the same as the one specified in the parameters."
echo "Please activate the correct conda environment and run the script again."
exit 1
fi
# check if conda is activated if not activate it
# if [ -z "$CONDA_DEFAULT_ENV" ]; then
# echo "Conda is not activated. Activating it"
# conda activate pdal-env-1
# else
# echo "Conda is activated"
# fi
# read input folder as a command line argument
# show a message to provide the input folder
data_folder=$1
# if no input folder is provided, case a message and exit
if [ -z "$data_folder" ]
then
echo "No input folder provided, please provide the input folder as a command line argument"
exit 1
fi
# check there are las files in the input folder
count=`ls -1 $data_folder/*.las 2>/dev/null | wc -l`
if [ $count != 0 ]; then
echo "$count las files found in the input folder"
else
echo "No las files found in the input folder. All files in the input folder should have .las extension."
exit 1
fi
#TODO: do the point cloud filtering using nibio_preprocessing/filter_point_cloud.py
echo "Doing the point cloud filtering to density of 150 points per cubic meter"
python nibio_preprocessing/point_cloud_filter.py --dir $data_folder --density 150 --verbose --in_place
# covert all the files to ply format using nibio_preprocessing/convert_files_in_folder.py
echo "Converting all the files to ply format"
python nibio_preprocessing/convert_files_in_folder.py --input_folder $data_folder --output_folder $data_folder --out_file_type ply
# clear input folder if CLEAR_INPUT_FOLDER is set to 1
if [ $CLEAR_INPUT_FOLDER -eq 1 ]
then
# delete all the files and folders except the ply files in the input folder
echo "Clearing input folder"
find $data_folder/ -type f ! -name '*.ply' ! -name '*.las' -delete # delete all the files except the ply and las files
find $data_folder/* -type d -exec rm -rf {} + # delete all the folders in the input folder
fi
# # iterate over all files in the input folder and do sematic segmentation
echo "Starting semantic segmentation"
for file in $data_folder/*.ply; do
# python fsct/run.py --point-cloud $file --batch_size 5 --odir $data_folder --model ./fsct/model/model.pth
python fsct/run.py --point-cloud $file --batch_size 5 --odir $data_folder --verbose
done
# move the output of the first step to the input folder of the second step
mkdir -p $data_folder/segmented_point_clouds
# move all .segmented.ply files to the segmented_point_clouds folder if they are in the input folder
find $data_folder/ -type f -name '*.segmented.ply' -exec mv {} $data_folder/segmented_point_clouds/ \;
# do the tiling and tile index generation
echo "Tiling and tile index generation"
python nibio_preprocessing/tiling.py -i $data_folder/segmented_point_clouds/ -o $data_folder/segmented_point_clouds/tiled
# create folder for the output of the second step
mkdir -p $data_folder/instance_segmented_point_clouds
# Do the instances and iterate over all the segmented point clouds
for segmented_point_cloud in $data_folder/segmented_point_clouds/*.segmented.ply; do
# get the name of the segmented point cloud
segmented_point_cloud_name=$(basename $segmented_point_cloud)
# get the name of the segmented point cloud without the extension
segmented_point_cloud_name_no_ext="${segmented_point_cloud_name%.*}"
# create a directory for the instance segmented point clouds
mkdir -p $data_folder/instance_segmented_point_clouds/$segmented_point_cloud_name_no_ext
# iterate over all the tiles of the segmented point cloud
for tile in $data_folder/segmented_point_clouds/tiled/$segmented_point_cloud_name_no_ext/*.ply; do
# get the name of the tile
tile_name=$(basename $tile)
# get the name of the tile without the extension
tile_name_no_ext="${tile_name%.*}"
echo "Processing $tile"
# show the output folder
echo "Output folder: $data_folder/instance_segmented_point_clouds/$segmented_point_cloud_name_no_ext/$tile_name_no_ext"
python3 fsct/points2trees.py \
-t $tile \
--tindex $data_folder/segmented_point_clouds/tiled/$segmented_point_cloud_name_no_ext/tile_index.dat \
-o $data_folder/instance_segmented_point_clouds/$segmented_point_cloud_name_no_ext/$tile_name_no_ext \
--n-tiles $N_TILES \
--slice-thickness $SLICE_THICKNESS \
--find-stems-height $FIND_STEMS_HEIGHT \
--find-stems-thickness $FIND_STEMS_THICKNESS \
--pandarallel --verbose \
--add-leaves \
--add-leaves-voxel-length $ADD_LEAVES_VOXEL_LENGTH \
--graph-maximum-cumulative-gap $GRAPH_MAXIMUM_CUMULATIVE_GAP \
--save-diameter-class \
--ignore-missing-tiles \
--find-stems-min-points $FIND_STEMS_MIN_POINTS
done
done
# do merging of the instance segmented point clouds
for instance_segmented_point_cloud in $data_folder/instance_segmented_point_clouds/*; do
python nibio_preprocessing/merging_and_labeling.py \
--data_folder $instance_segmented_point_cloud \
--output_file $instance_segmented_point_cloud/output_instance_segmented.ply
done
# # create the results folder
mkdir -p $data_folder/results
# # create the input data folder
mkdir -p $data_folder/results/input_data
# # move input data (ply and las) to the input data folder
find $data_folder/ -maxdepth 1 -type f -name '*.ply' -exec mv {} $data_folder/results/input_data/ \;
find $data_folder/ -maxdepth 1 -type f -name '*.las' -exec mv {} $data_folder/results/input_data/ \;
# # create the segmented point clouds folder
mkdir -p $data_folder/results/segmented_point_clouds
# move segmented point clouds to the segmented point clouds folder
find $data_folder/segmented_point_clouds/ -maxdepth 1 -type f -name '*.ply' -exec mv {} $data_folder/results/segmented_point_clouds/ \;
# # create the instance segmented point clouds folder
mkdir -p $data_folder/results/instance_segmented_point_clouds
# iterate over all the instance segmented point clouds
# move instance segmented point clouds to the instance segmented point clouds folder and rename them
for instance_segmented_point_cloud in $data_folder/instance_segmented_point_clouds/*; do
# get the name of the instance segmented point cloud
instance_segmented_point_cloud_name=$(basename $instance_segmented_point_cloud)
# get the name of the instance segmented point cloud without the extension
instance_segmented_point_cloud_name_no_ext="${instance_segmented_point_cloud_name%.*}"
# move the instance segmented point cloud to the instance segmented point clouds folder
find $instance_segmented_point_cloud/ -maxdepth 1 -type f -name '*.ply' -exec mv {} $data_folder/results/instance_segmented_point_clouds/$instance_segmented_point_cloud_name_no_ext.ply \;
# map the instance segmented point cloud to las file
pdal translate \
$data_folder/results/instance_segmented_point_clouds/$instance_segmented_point_cloud_name_no_ext.ply \
$data_folder/results/instance_segmented_point_clouds/$instance_segmented_point_cloud_name_no_ext.las \
--writers.las.dataformat_id=3 \
--writers.las.scale_x=0.01 \
--writers.las.scale_y=0.01 \
--writers.las.scale_z=0.01 \
--writers.las.extra_dims=all
done
echo "Done"
echo "Results are in $data_folder/results"
#!/bin/bash
pdal chamfer sample_playground/results/input_data/output/0.las sample_playground/results/instance_segmented_point_clouds_with_ground/output/3.las
#!/bin/bash
python nibio_postprocessing/get_instances_side_by_side.py \
--input_folder /home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/sample_playground/results/instance_segmented_point_clouds/ \
--output_folder /home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/sample_playground/results/instance_segmented_point_clouds/output \
--instance_label 'instance_nr' \
--verbose \
# --merge
python nibio_postprocessing/get_instances_side_by_side.py \
--input_folder /home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/sample_playground/results/instance_segmented_point_clouds_with_ground/ \
--output_folder /home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/sample_playground/results/instance_segmented_point_clouds_with_ground/output \
--instance_label 'instance_nr' \
--verbose \
# --merge
python nibio_postprocessing/get_instances_side_by_side.py \
--input_folder /home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/sample_playground/results/input_data/ \
--output_folder /home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/sample_playground/results/input_data/output \
--instance_label 'treeID' \
--verbose \
# --merge
#!/bin/sh
# This is a sample run file for the "hello" example.
# It is used to run the example from the main folder of the repository.
#### The first step of the pipeline: Do semantic segmentation on the whole point cloud (has to be .ply file) ####
# if the file is not .ply, convert it to .ply first using the follwing command:
# pdal translate sample_data/sample_point_cloud.laz sample_data/sample_point_cloud_mapped.ply
python fsct/run.py --point-cloud sample_data/sample_point_cloud.ply --batch_size 5 --odir sample_data
#### The second step of the pipeline: do the tiling and tile index generation ####
# move the output of the first step to the input folder of the second step
mkdir -p sample_data/segmented_point_clouds
mv sample_data/*.segmented.ply sample_data/segmented_point_clouds
python nibio_preprocessing/tiling.py -i sample_data/segmented_point_clouds/ -o sample_data/segmented_point_clouds/tiled
# This is the third step of the protol pipeline
# python3 fsct/points2trees.py -t Plot82_2022-06-13_10-35-41_9pct_time_CLIPPED.segmented.ply --tindex /home/nibio/mutable-outside-world/data/raw_data/tiled_data/Plot82_2022-06-13_10-35-41_9pct_time_CLIPPED/tile_index.dat -o ../output_dir_our/ --n-tiles 5 --slice-thickness .5 --find-stems-height 2 --find-stems-thickness .5 --pandarallel --verbose --add-leaves --add-leaves-voxel-length .5 --graph-maximum-cumulative-gap 3 --save-diameter-class --ignore-missing-tiles
# python3 fsct/points2trees.py -t /home/nibio/mutable-outside-world/data/raw_data/tiled_data/Plot82_2022-06-13_10-35-41_9pct_time_CLIPPED/000.ply --tindex /home/nibio/mutable-outside-world/data/raw_data/tiled_data/Plot82_2022-06-13_10-35-41_9pct_time_CLIPPED/tile_index.dat -o ../output_dir_our/ --n-tiles 5 --slice-thickness .5 --find-stems-height 2 --find-stems-thickness .5 --pandarallel --verbose --add-leaves --add-leaves-voxel-length .5 --graph-maximum-cumulative-gap 3 --save-diameter-class --ignore-missing-tiles
# python3 fsct/points2trees.py \
# -t /home/nibio/mutable-outside-world/data/segmented_data_conda/tiled_data/Plot82_2022-06-13_10-35-41_9pct_time_CLIPPED.segmented/000.ply \
# --tindex /home/nibio/mutable-outside-world/data/segmented_data_conda/tiled_data/Plot82_2022-06-13_10-35-41_9pct_time_CLIPPED.segmented/tile_index.dat \
# -o ../output_dir_our/ --n-tiles 3 --slice-thickness .5 --find-stems-height 2 --find-stems-thickness .5 --pandarallel --verbose --add-leaves --add-leaves-voxel-length .5 --graph-maximum-cumulative-gap 3 --save-diameter-class --ignore-missing-tiles
mkdir -p sample_data/instance_segmented_point_clouds
python3 fsct/points2trees.py \
-t sample_data/segmented_point_clouds/tiled/sample_point_cloud.segmented/000.ply \
--tindex sample_data/segmented_point_clouds/tiled/sample_point_cloud.segmented/tile_index.dat \
-o sample_data/instance_segmented_point_clouds/ \
--n-tiles 3 \
--slice-thickness .5 \
--find-stems-height 2 \
--find-stems-thickness .5 \
--pandarallel --verbose \
--add-leaves \
--add-leaves-voxel-length .5 \
--graph-maximum-cumulative-gap 3 \
--save-diameter-class \
--ignore-missing-tiles
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment