-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add scripts for launch and test : clip virtual poins by tiles
- Loading branch information
1 parent
e51af2c
commit 3373852
Showing
3 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Launch hydro mask merging | ||
python -m lidro.main_create_virtual_point \ | ||
io.input_dir=./data/pointcloud/ \ | ||
io.output_dir=./tmp/ \ | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |