From 3373852086e612561f0f14fc93af8283bcce1a43 Mon Sep 17 00:00:00 2001 From: mdupays Date: Tue, 24 Sep 2024 18:08:04 +0200 Subject: [PATCH] add scripts for launch and test : clip virtual poins by tiles --- lidro/main_clip_virtual_point_by_tile.py | 58 +++++++++++++++++++ .../example_clip_virtual_point_default .sh | 7 +++ test/test_main_clip_virtual_point_by_tile.py | 44 ++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 lidro/main_clip_virtual_point_by_tile.py create mode 100644 scripts/example_clip_virtual_point_default .sh create mode 100644 test/test_main_clip_virtual_point_by_tile.py diff --git a/lidro/main_clip_virtual_point_by_tile.py b/lidro/main_clip_virtual_point_by_tile.py new file mode 100644 index 00000000..9bab36ac --- /dev/null +++ b/lidro/main_clip_virtual_point_by_tile.py @@ -0,0 +1,58 @@ +""" Main script for create virtuals points +""" + +import logging +import os + +import hydra +from omegaconf import DictConfig +from pyproj import CRS + +from lidro.create_virtual_point.pointcloud.auto_tiling_from_las import ( + create_geojson_from_laz_files, +) +from lidro.create_virtual_point.vectors.run_add_virtual_points_by_tile import ( + compute_virtual_points_by_tiles, +) + + +@hydra.main(config_path="../configs/", config_name="configs_lidro.yaml", version_base="1.2") +def main(config: DictConfig): + """Create a virtual point inside hydro surfaces (3D grid) from the points classification of + the input LAS/LAZ file and the Hyro Skeleton (GeoJSON) and save it as LAS file. + + It can run either on a single file, or on each file of a folder + + Args: + config (DictConfig): hydra configuration (configs/configs_lidro.yaml by default) + It contains the algorithm parameters and the input/output parameters + """ + logging.basicConfig(level=logging.INFO) + # Check input/output files and folders + input_dir = config.io.input_dir + if input_dir is None: + raise ValueError("""config.io.input_dir is empty, please provide an input directory in the configuration""") + + if not os.path.isdir(input_dir): + raise FileNotFoundError(f"""The input directory ({input_dir}) doesn't exist.""") + + output_dir = config.io.output_dir + if output_dir is None: + raise ValueError("""config.io.output_dir is empty, please provide an input directory in the configuration""") + + os.makedirs(output_dir, exist_ok=True) + + # Parameters for clip virtual point by tiles + crs = CRS.from_user_input(config.io.srid) + + # Clip virtual points file by LIDAR tiles + # Create the tiling of lidar tiles + json_tiles = os.path.join(output_dir, "tiles_from_las.GeoJSON") + create_geojson_from_laz_files([os.path.join(input_dir, file) for file in os.listdir(input_dir)], json_tiles, crs) + # Clip virtual points (3D point grid in LAZ format) by LIDAR tiles (tiling file) + virtul_points_file = os.path.join(output_dir, "virtual_points.laz") + compute_virtual_points_by_tiles(virtul_points_file, json_tiles, input_dir, output_dir) + + +if __name__ == "__main__": + main() diff --git a/scripts/example_clip_virtual_point_default .sh b/scripts/example_clip_virtual_point_default .sh new file mode 100644 index 00000000..c4d030fa --- /dev/null +++ b/scripts/example_clip_virtual_point_default .sh @@ -0,0 +1,7 @@ +# Launch hydro mask merging +python -m lidro.main_create_virtual_point \ +io.input_dir=./data/pointcloud/ \ +io.output_dir=./tmp/ \ + + + diff --git a/test/test_main_clip_virtual_point_by_tile.py b/test/test_main_clip_virtual_point_by_tile.py new file mode 100644 index 00000000..64a64ee6 --- /dev/null +++ b/test/test_main_clip_virtual_point_by_tile.py @@ -0,0 +1,44 @@ +import os +import subprocess as sp +from pathlib import Path + +from hydra import compose, initialize + +from lidro.main_create_virtual_point import main + +INPUT_DIR = Path("data/pointcloud") +OUTPUT_DIR = Path("tmp") / "create_virtual_point/main" + + +def setup_module(module): + os.makedirs("tmp/create_virtual_point/main", exist_ok=True) + + +def test_main_run_okay(): + repo_dir = Path.cwd().parent + cmd = f"""python -m lidro.main_clip_virtual_point_by_tile \ + io.input_dir="{repo_dir}/lidro/data/pointcloud/"\ + io.output_dir="{repo_dir}/lidro/tmp/clip_virtual_point_by_tile/main/" + """ + sp.run(cmd, shell=True, check=True) + + +def test_main_lidro_input_file(): + input_dir = INPUT_DIR + output_dir = OUTPUT_DIR / "main_lidro_input_file" + input_filename = "Semis_2021_0830_6291_LA93_IGN69.laz" + srid = 2154 + + with initialize(version_base="1.2", config_path="../configs"): + # config is relative to a module + cfg = compose( + config_name="configs_lidro", + overrides=[ + f"io.input_filename={input_filename}", + f"io.input_dir={input_dir}", + f"io.output_dir={output_dir}", + f"io.srid={srid}", + ], + ) + main(cfg) + assert (Path(output_dir) / "tiles_from_las.GeoJSON").is_file()