BERATools 0.2.3__py3-none-any.whl → 0.2.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- beratools/__init__.py +8 -3
- beratools/core/{algo_footprint_rel.py → algo_canopy_footprint_exp.py} +176 -139
- beratools/core/algo_centerline.py +61 -77
- beratools/core/algo_common.py +48 -57
- beratools/core/algo_cost.py +18 -25
- beratools/core/algo_dijkstra.py +37 -45
- beratools/core/algo_line_grouping.py +100 -100
- beratools/core/algo_merge_lines.py +40 -8
- beratools/core/algo_split_with_lines.py +289 -304
- beratools/core/algo_vertex_optimization.py +25 -46
- beratools/core/canopy_threshold_relative.py +755 -0
- beratools/core/constants.py +8 -9
- beratools/{tools → core}/line_footprint_functions.py +411 -258
- beratools/core/logger.py +18 -2
- beratools/core/tool_base.py +17 -75
- beratools/gui/assets/BERALogo.ico +0 -0
- beratools/gui/assets/BERA_Splash.gif +0 -0
- beratools/gui/assets/BERA_WizardImage.png +0 -0
- beratools/gui/assets/beratools.json +475 -2171
- beratools/gui/bt_data.py +585 -234
- beratools/gui/bt_gui_main.py +129 -91
- beratools/gui/main.py +4 -7
- beratools/gui/tool_widgets.py +530 -354
- beratools/tools/__init__.py +0 -7
- beratools/tools/{line_footprint_absolute.py → canopy_footprint_absolute.py} +81 -56
- beratools/tools/canopy_footprint_exp.py +113 -0
- beratools/tools/centerline.py +30 -37
- beratools/tools/check_seed_line.py +127 -0
- beratools/tools/common.py +65 -586
- beratools/tools/{line_footprint_fixed.py → ground_footprint.py} +140 -117
- beratools/tools/line_footprint_relative.py +64 -35
- beratools/tools/tool_template.py +48 -40
- beratools/tools/vertex_optimization.py +20 -34
- beratools/utility/env_checks.py +53 -0
- beratools/utility/spatial_common.py +210 -0
- beratools/utility/tool_args.py +138 -0
- beratools-0.2.5.dist-info/METADATA +134 -0
- beratools-0.2.5.dist-info/RECORD +50 -0
- {beratools-0.2.3.dist-info → beratools-0.2.5.dist-info}/WHEEL +1 -1
- beratools-0.2.5.dist-info/entry_points.txt +3 -0
- beratools-0.2.5.dist-info/licenses/LICENSE +674 -0
- beratools/core/algo_tiler.py +0 -428
- beratools/gui/__init__.py +0 -11
- beratools/gui/batch_processing_dlg.py +0 -513
- beratools/gui/map_window.py +0 -162
- beratools/tools/Beratools_r_script.r +0 -1120
- beratools/tools/Ht_metrics.py +0 -116
- beratools/tools/batch_processing.py +0 -136
- beratools/tools/canopy_threshold_relative.py +0 -672
- beratools/tools/canopycostraster.py +0 -222
- beratools/tools/fl_regen_csf.py +0 -428
- beratools/tools/forest_line_attributes.py +0 -408
- beratools/tools/line_grouping.py +0 -45
- beratools/tools/ln_relative_metrics.py +0 -615
- beratools/tools/r_cal_lpi_elai.r +0 -25
- beratools/tools/r_generate_pd_focalraster.r +0 -101
- beratools/tools/r_interface.py +0 -80
- beratools/tools/r_point_density.r +0 -9
- beratools/tools/rpy_chm2trees.py +0 -86
- beratools/tools/rpy_dsm_chm_by.py +0 -81
- beratools/tools/rpy_dtm_by.py +0 -63
- beratools/tools/rpy_find_cellsize.py +0 -43
- beratools/tools/rpy_gnd_csf.py +0 -74
- beratools/tools/rpy_hummock_hollow.py +0 -85
- beratools/tools/rpy_hummock_hollow_raster.py +0 -71
- beratools/tools/rpy_las_info.py +0 -51
- beratools/tools/rpy_laz2las.py +0 -40
- beratools/tools/rpy_lpi_elai_lascat.py +0 -466
- beratools/tools/rpy_normalized_lidar_by.py +0 -56
- beratools/tools/rpy_percent_above_dbh.py +0 -80
- beratools/tools/rpy_points2trees.py +0 -88
- beratools/tools/rpy_vegcoverage.py +0 -94
- beratools/tools/tiler.py +0 -48
- beratools/tools/zonal_threshold.py +0 -144
- beratools-0.2.3.dist-info/METADATA +0 -108
- beratools-0.2.3.dist-info/RECORD +0 -74
- beratools-0.2.3.dist-info/entry_points.txt +0 -2
- beratools-0.2.3.dist-info/licenses/LICENSE +0 -22
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
#create a 'generate_pd' function
|
|
2
|
-
generate_pd <- function(ctg, radius_fr_CHM, focal_radius, cell_size, cache_folder,
|
|
3
|
-
cut_ht, PD_Ground_folder, PD_Total_folder, rprocesses) {
|
|
4
|
-
library(terra)
|
|
5
|
-
library(lidR)
|
|
6
|
-
|
|
7
|
-
plan(multisession, workers = rprocesses)
|
|
8
|
-
set_lidr_threads(rprocesses)
|
|
9
|
-
|
|
10
|
-
opts <- paste0("-drop_class 7")
|
|
11
|
-
|
|
12
|
-
print("Processing using R packages.")
|
|
13
|
-
|
|
14
|
-
folder <- paste0(cache_folder, "/nlidar/n_{*}")
|
|
15
|
-
opt_output_files(ctg) <- opt_output_files(ctg) <- folder
|
|
16
|
-
opt_laz_compression(ctg) <- FALSE
|
|
17
|
-
opt_filter(ctg) <- "-drop_class 7"
|
|
18
|
-
opt_chunk_alignment(ctg) <- c(0, 0)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
#normalized LAS with pulse info
|
|
22
|
-
print("Indexing LAS Tiles ...")
|
|
23
|
-
lidR:::catalog_laxindex(ctg)
|
|
24
|
-
print("Normalize point cloud using K-nearest neighbour IDW ...")
|
|
25
|
-
normalize_height(ctg, algorithm = knnidw())
|
|
26
|
-
|
|
27
|
-
print("Generating point density (total focal sum) raster ...")
|
|
28
|
-
|
|
29
|
-
pd_total <- function(chunk, radius, cell_size)
|
|
30
|
-
{
|
|
31
|
-
las <- readLAS(chunk)
|
|
32
|
-
if (is.empty(las)) return(NULL)
|
|
33
|
-
|
|
34
|
-
las_1 <- filter_poi(readLAS(chunk), buffer == 0)
|
|
35
|
-
hull <- st_convex_hull(las_1)
|
|
36
|
-
# bbox <- ext(las_1)
|
|
37
|
-
|
|
38
|
-
# convert to SpatialPolygons
|
|
39
|
-
bbox <- vect(hull)
|
|
40
|
-
|
|
41
|
-
las <- filter_poi(las, Classification != 7L)
|
|
42
|
-
#las <- retrieve_pulses(las)
|
|
43
|
-
density_raster_total <- rasterize_density(las, res = cell_size, pkg = "terra")[[1]]
|
|
44
|
-
|
|
45
|
-
tfw <- focalMat(density_raster_total, radius, "circle")
|
|
46
|
-
|
|
47
|
-
tfw[tfw > 0] = 1
|
|
48
|
-
tfw[tfw == 0] = NA
|
|
49
|
-
|
|
50
|
-
Total_focal <- focal(density_raster_total, w = tfw, fun = "sum", na.rm = TRUE, na.policy = "omit", fillvalue = NA, expand = FALSE)
|
|
51
|
-
Total_focal <- crop(Total_focal, bbox)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
opt <- list(need_output_file =TRUE, autocrop = TRUE)
|
|
55
|
-
opt_chunk_alignment(ctg) <- c(0,0)
|
|
56
|
-
ctg@output_options$drivers$SpatRaster$param$overwrite <- TRUE
|
|
57
|
-
opt_output_files(ctg) <- paste0(PD_Total_folder,"/{*}_PD_Tfocalsum")
|
|
58
|
-
opt_stop_early(ctg) <- FALSE
|
|
59
|
-
catalog_apply(ctg, pd_total, radius = focal_radius, cell_size = cell_size, .options = opt)
|
|
60
|
-
|
|
61
|
-
#load normalized LAS for ground point density
|
|
62
|
-
ht <- paste0("-drop_class 7 -drop_z_above ", cut_ht)
|
|
63
|
-
ctg2 <- readLAScatalog(paste0(cache_folder, "/nlidar"), filter = ht)
|
|
64
|
-
lidR:::catalog_laxindex(ctg2)
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
print("Generating point density (ground focal sum) raster ...")
|
|
68
|
-
|
|
69
|
-
pd_ground <- function(chunk, radius, cell_size, cut_ht)
|
|
70
|
-
{
|
|
71
|
-
las <- readLAS(chunk)
|
|
72
|
-
if (is.empty(las)) return(NULL)
|
|
73
|
-
|
|
74
|
-
las_1 <- filter_poi(readLAS(chunk), buffer == 0)
|
|
75
|
-
hull <- st_convex_hull(las_1)
|
|
76
|
-
|
|
77
|
-
# convert to SpatialPolygons
|
|
78
|
-
bbox <- vect(hull)
|
|
79
|
-
# bbox <- ext(las_1)
|
|
80
|
-
|
|
81
|
-
#las <- retrieve_pulses(las)
|
|
82
|
-
density_raster_ground <- rasterize_density(las, res = cell_size, pkg = "terra")[[1]]
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
gfw <- focalMat(density_raster_ground, radius, "circle")
|
|
86
|
-
gfw[gfw > 0] = 1
|
|
87
|
-
gfw[gfw == 0] = NA
|
|
88
|
-
|
|
89
|
-
Ground_focal <- focal(density_raster_ground, w = gfw, fun = "sum", na.policy = "omit", na.rm = TRUE, fillvalue = NA, expand = FALSE)
|
|
90
|
-
ground_focal <- crop(Ground_focal, bbox)
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
opt <- list(need_output_file =TRUE, autocrop = TRUE)
|
|
94
|
-
opt_chunk_alignment(ctg2) <- c(0,0)
|
|
95
|
-
ctg2@output_options$drivers$SpatRaster$param$overwrite <- TRUE
|
|
96
|
-
opt_output_files(ctg2) <- paste0(PD_Ground_folder,"/{*}_PD_Gfocalsum")
|
|
97
|
-
opt_stop_early(ctg2) <- FALSE
|
|
98
|
-
catalog_apply(ctg2, pd_ground,radius=focal_radius,cell_size=cell_size,cut_ht=cut_ht,.options=opt)
|
|
99
|
-
# reset R mutilsession back to default
|
|
100
|
-
plan("default")
|
|
101
|
-
}
|
beratools/tools/r_interface.py
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import psutil
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
# def check_r_env():
|
|
6
|
-
try: # integrated R env
|
|
7
|
-
# check R language within env
|
|
8
|
-
current_env_path = os.environ['CONDA_PREFIX']
|
|
9
|
-
# if os.path.isdir(current_env_path):
|
|
10
|
-
os.environ['R_HOME'] = os.path.join(current_env_path, r"Lib\R")
|
|
11
|
-
os.environ['R_USER'] = os.path.expanduser('~')
|
|
12
|
-
os.environ['R_LIBS_USER'] = os.path.join(current_env_path, r"Lib\R\library")
|
|
13
|
-
|
|
14
|
-
except FileNotFoundError:
|
|
15
|
-
print("Warning: Please install R for this process!!")
|
|
16
|
-
exit()
|
|
17
|
-
|
|
18
|
-
import rpy2.robjects as robjects
|
|
19
|
-
from rpy2.robjects.packages import importr, data
|
|
20
|
-
from rpy2.robjects.vectors import StrVector
|
|
21
|
-
|
|
22
|
-
r = robjects.r
|
|
23
|
-
|
|
24
|
-
def r_processes(processes):
|
|
25
|
-
stats = psutil.virtual_memory() # returns a named tuple
|
|
26
|
-
available = getattr(stats, 'available') / 1024000000
|
|
27
|
-
rprocesses = processes
|
|
28
|
-
|
|
29
|
-
if 2 < processes <= 8:
|
|
30
|
-
if available <= 50:
|
|
31
|
-
rprocesses = 2
|
|
32
|
-
elif 50 < available <= 150:
|
|
33
|
-
rprocesses = 4
|
|
34
|
-
elif 150 < available <= 250:
|
|
35
|
-
rprocesses = 8
|
|
36
|
-
else:
|
|
37
|
-
rprocesses = 8
|
|
38
|
-
|
|
39
|
-
return rprocesses
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
def check_las_files_existence(folder):
|
|
43
|
-
if not os.path.exists(folder):
|
|
44
|
-
print("Error! Cannot locate Las folder, please check.")
|
|
45
|
-
exit()
|
|
46
|
-
else:
|
|
47
|
-
found = False
|
|
48
|
-
for files in os.listdir(folder):
|
|
49
|
-
if files.endswith(".las") or files.endswith(".laz"):
|
|
50
|
-
found = True
|
|
51
|
-
break
|
|
52
|
-
if not found:
|
|
53
|
-
print("Error! Cannot locate input LAS file(s), please check!")
|
|
54
|
-
exit()
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
def check_r_packages_installation(packages):
|
|
58
|
-
utils = importr('utils')
|
|
59
|
-
base = importr('base')
|
|
60
|
-
utils.chooseCRANmirror(ind=12) # select the 12th mirror in the list: Canada
|
|
61
|
-
print("Checking R packages....")
|
|
62
|
-
|
|
63
|
-
cran_names_to_install = [x for x in packages if not robjects.packages.isinstalled(x)]
|
|
64
|
-
need_fasterRaster = False
|
|
65
|
-
if len(cran_names_to_install) > 0:
|
|
66
|
-
if not 'fasterRaster' in cran_names_to_install:
|
|
67
|
-
utils.install_packages(StrVector(cran_names_to_install))
|
|
68
|
-
else:
|
|
69
|
-
cran_names_to_install.remove('fasterRaster')
|
|
70
|
-
need_fasterRaster = True
|
|
71
|
-
utils.install_packages(StrVector(cran_names_to_install))
|
|
72
|
-
packages_found = True
|
|
73
|
-
else:
|
|
74
|
-
packages_found = True
|
|
75
|
-
|
|
76
|
-
if need_fasterRaster:
|
|
77
|
-
devtools=importr('devtools')
|
|
78
|
-
devtools.install_github("adamlilith/fasterRaster", dependencies=True)
|
|
79
|
-
|
|
80
|
-
print("Checking R packages....Done")
|
beratools/tools/rpy_chm2trees.py
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import time
|
|
3
|
-
from multiprocessing.pool import Pool
|
|
4
|
-
|
|
5
|
-
from beratools.tools.common import *
|
|
6
|
-
from beratools.tools.r_interface import *
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
def chm2trees(callback, in_chm_folder, Min_ws, hmin, out_folder, processes, verbose):
|
|
10
|
-
rprocesses = r_processes(processes)
|
|
11
|
-
|
|
12
|
-
# assign R script file to local variable
|
|
13
|
-
Beratools_R_script = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'Beratools_r_script.r')
|
|
14
|
-
# Defining the R script and loading the instance in Python
|
|
15
|
-
r['source'](Beratools_R_script)
|
|
16
|
-
# Loading the function defined in R script.
|
|
17
|
-
r_chm2trees = robjects.globalenv['chm2trees']
|
|
18
|
-
|
|
19
|
-
args_list = []
|
|
20
|
-
for root, dirs, files in sorted(os.walk(in_chm_folder)):
|
|
21
|
-
for file in files:
|
|
22
|
-
if file.endswith(".tif"):
|
|
23
|
-
result = []
|
|
24
|
-
chm_file = os.path.join(root, file)
|
|
25
|
-
chm_file = chm_file.replace("\\", "/")
|
|
26
|
-
result.append(chm_file)
|
|
27
|
-
result.append(Min_ws)
|
|
28
|
-
result.append(hmin)
|
|
29
|
-
result.append(out_folder)
|
|
30
|
-
result.append(rprocesses)
|
|
31
|
-
args_list.append(result)
|
|
32
|
-
# Invoking the R function
|
|
33
|
-
r_chm2trees(chm_file, Min_ws, hmin, out_folder, rprocesses)
|
|
34
|
-
|
|
35
|
-
del root, dirs, files
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if __name__ == '__main__':
|
|
39
|
-
start_time = time.time()
|
|
40
|
-
print('Starting tree detection from CHM processing\n @ {}'
|
|
41
|
-
.format(time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime())))
|
|
42
|
-
|
|
43
|
-
packages = ['lidR', 'rgrass', 'rlas', 'future', 'terra']
|
|
44
|
-
check_r_packages_installation(packages)
|
|
45
|
-
|
|
46
|
-
print("Checking input parameters....")
|
|
47
|
-
in_args, in_verbose = check_arguments()
|
|
48
|
-
in_chm_folder = in_args.input["in_chm_folder"]
|
|
49
|
-
try:
|
|
50
|
-
ws = float(in_args.input["Min_ws"])
|
|
51
|
-
in_args.input["Min_ws"] = ws
|
|
52
|
-
except ValueError:
|
|
53
|
-
print("Invalid input of circular diameter, default is used")
|
|
54
|
-
in_args.input["Min_ws"] = 2.5
|
|
55
|
-
try:
|
|
56
|
-
hmin = float(in_args.input["hmin"])
|
|
57
|
-
in_args.input["hmin"] = hmin
|
|
58
|
-
except ValueError:
|
|
59
|
-
print("Invalid input of minimum height of a tree, default is used")
|
|
60
|
-
in_args.input["hmin"] = 3.0
|
|
61
|
-
|
|
62
|
-
out_folder = in_args.input["out_folder"]
|
|
63
|
-
|
|
64
|
-
if not os.path.exists(in_chm_folder):
|
|
65
|
-
print("Error! Cannot locate CHM raster folder, please check.")
|
|
66
|
-
exit()
|
|
67
|
-
else:
|
|
68
|
-
found = False
|
|
69
|
-
for files in os.listdir(in_chm_folder):
|
|
70
|
-
if files.endswith(".tif"):
|
|
71
|
-
found = True
|
|
72
|
-
break
|
|
73
|
-
if not found:
|
|
74
|
-
print("Error! Cannot locate input CHM raster file(s), please check!")
|
|
75
|
-
exit()
|
|
76
|
-
|
|
77
|
-
if not os.path.exists(out_folder):
|
|
78
|
-
print("Warning! Cannot locate output folder, It will be created.")
|
|
79
|
-
os.makedirs(out_folder)
|
|
80
|
-
|
|
81
|
-
print("Checking input parameters....Done")
|
|
82
|
-
|
|
83
|
-
chm2trees(print, **in_args.input, processes=int(in_args.processes), verbose=in_verbose)
|
|
84
|
-
|
|
85
|
-
print('Tree detection from CHM raster data processing is done in {} seconds)'
|
|
86
|
-
.format(round(time.time() - start_time, 5)))
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import time
|
|
3
|
-
|
|
4
|
-
from beratools.tools.common import *
|
|
5
|
-
from beratools.tools.r_interface import *
|
|
6
|
-
|
|
7
|
-
def chm_by(callback, in_las_folder, is_normalized, out_folder, cell_size, style, processes, verbose):
|
|
8
|
-
rprocesses = r_processes(processes)
|
|
9
|
-
|
|
10
|
-
# assign R script file to local variable
|
|
11
|
-
Beratools_R_script = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'Beratools_r_script.r')
|
|
12
|
-
# Defining the R script and loading the instance in Python
|
|
13
|
-
r['source'](Beratools_R_script)
|
|
14
|
-
# Loading the function defined in R script.
|
|
15
|
-
if style == "tin":
|
|
16
|
-
r_chm_by_algorithm = robjects.globalenv['chm_by_dsmtin']
|
|
17
|
-
else:
|
|
18
|
-
r_chm_by_algorithm = robjects.globalenv['chm_by_pitfree']
|
|
19
|
-
|
|
20
|
-
# Invoking the R function
|
|
21
|
-
r_chm_by_algorithm(in_las_folder, out_folder, cell_size, is_normalized, rprocesses)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if __name__ == '__main__':
|
|
26
|
-
start_time = time.time()
|
|
27
|
-
print('Normalize Lidar data processing\n @ {}'
|
|
28
|
-
.format(time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime())))
|
|
29
|
-
|
|
30
|
-
packages = ['lidR', 'future', 'terra']
|
|
31
|
-
check_r_packages_installation(packages)
|
|
32
|
-
|
|
33
|
-
print("Checking input parameters....")
|
|
34
|
-
in_args, in_verbose = check_arguments()
|
|
35
|
-
try:
|
|
36
|
-
cell_size = float(in_args.input["cell_size"])
|
|
37
|
-
in_args.input["cell_size"] = cell_size
|
|
38
|
-
except ValueError:
|
|
39
|
-
print("Invalid input of cell size, default value is used")
|
|
40
|
-
in_args.input["DSMcell_size"] = 1.0
|
|
41
|
-
|
|
42
|
-
try:
|
|
43
|
-
is_normalized = bool(in_args.input["is_normalized"])
|
|
44
|
-
|
|
45
|
-
except ValueError:
|
|
46
|
-
print("Invalid input of checking normalized data box, DSM will be created")
|
|
47
|
-
in_args.input["is_normalized"] = False
|
|
48
|
-
|
|
49
|
-
in_las_folder = in_args.input["in_las_folder"]
|
|
50
|
-
|
|
51
|
-
out_folder = in_args.input["out_folder"]
|
|
52
|
-
|
|
53
|
-
if not os.path.exists(in_las_folder):
|
|
54
|
-
print("Error! Cannot locate Las folder, please check.")
|
|
55
|
-
exit()
|
|
56
|
-
else:
|
|
57
|
-
found = False
|
|
58
|
-
for files in os.listdir(in_las_folder):
|
|
59
|
-
if files.endswith(".las") or files.endswith(".laz"):
|
|
60
|
-
found = True
|
|
61
|
-
break
|
|
62
|
-
if not found:
|
|
63
|
-
print("Error! Cannot locate input LAS file(s), please check!")
|
|
64
|
-
exit()
|
|
65
|
-
|
|
66
|
-
if in_args.input["style"] in ["tin", "pitfree"]:
|
|
67
|
-
style = in_args.input["style"]
|
|
68
|
-
else:
|
|
69
|
-
print("Warning! invalid alogrithm, default algorthim will be used.")
|
|
70
|
-
in_args.input["style"] = "tin"
|
|
71
|
-
|
|
72
|
-
if not os.path.exists(out_folder):
|
|
73
|
-
print("Warning! Cannot locate output folder, It will be created.")
|
|
74
|
-
os.makedirs(out_folder)
|
|
75
|
-
|
|
76
|
-
print("Checking input parameters....Done")
|
|
77
|
-
|
|
78
|
-
chm_by(print, **in_args.input, processes=int(in_args.processes), verbose=in_verbose)
|
|
79
|
-
|
|
80
|
-
print('Normalize Lidar data processing is done in {} seconds)'
|
|
81
|
-
.format(round(time.time() - start_time, 5)))
|
beratools/tools/rpy_dtm_by.py
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import time
|
|
3
|
-
|
|
4
|
-
from beratools.tools.common import *
|
|
5
|
-
from beratools.tools.r_interface import *
|
|
6
|
-
|
|
7
|
-
def dtm_by(callback, in_las_folder, out_folder, cell_size, style, processes, verbose):
|
|
8
|
-
rprocesses = r_processes(processes)
|
|
9
|
-
|
|
10
|
-
# assign R script file to local variable
|
|
11
|
-
Beratools_R_script = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'Beratools_r_script.r')
|
|
12
|
-
# Defining the R script and loading the instance in Python
|
|
13
|
-
r['source'](Beratools_R_script)
|
|
14
|
-
|
|
15
|
-
# Loading the function defined in R script.
|
|
16
|
-
if style == "tin":
|
|
17
|
-
r_chm_by_algorithm = robjects.globalenv['dtm_by_tin']
|
|
18
|
-
elif style == "idw":
|
|
19
|
-
r_chm_by_algorithm = robjects.globalenv['dtm_by_knnidw ']
|
|
20
|
-
else:
|
|
21
|
-
r_chm_by_algorithm = robjects.globalenv['dtm_by_kriging']
|
|
22
|
-
# Invoking the R function
|
|
23
|
-
r_chm_by_algorithm(in_las_folder, out_folder, cell_size, rprocesses)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if __name__ == '__main__':
|
|
27
|
-
start_time = time.time()
|
|
28
|
-
print('Normalize Lidar data processing\n @ {}'
|
|
29
|
-
.format(time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime())))
|
|
30
|
-
|
|
31
|
-
packages = ['lidR', 'rgrass', 'rlas', 'future', 'terra', 'sp']
|
|
32
|
-
check_r_packages_installation(packages)
|
|
33
|
-
|
|
34
|
-
print("Checking input parameters....")
|
|
35
|
-
in_args, in_verbose = check_arguments()
|
|
36
|
-
|
|
37
|
-
try:
|
|
38
|
-
cell_size = float(in_args.input["cell_size"])
|
|
39
|
-
in_args.input["cell_size"] = cell_size
|
|
40
|
-
except ValueError:
|
|
41
|
-
print("Invalid input of cell size, default value is used")
|
|
42
|
-
in_args.input["DSMcell_size"] = 1.0
|
|
43
|
-
|
|
44
|
-
in_las_folder = in_args.input["in_las_folder"]
|
|
45
|
-
out_folder = in_args.input["out_folder"]
|
|
46
|
-
check_las_files_existence(in_las_folder)
|
|
47
|
-
|
|
48
|
-
if in_args.input["style"] in ["tin", "idw", "kriging"]:
|
|
49
|
-
style = in_args.input["style"]
|
|
50
|
-
else:
|
|
51
|
-
print("Warning! invalid alogrithm, default algorthim will be used.")
|
|
52
|
-
in_args.input["style"] = "tin"
|
|
53
|
-
|
|
54
|
-
if not os.path.exists(out_folder):
|
|
55
|
-
print("Warning! Cannot locate output folder, It will be created.")
|
|
56
|
-
os.makedirs(out_folder)
|
|
57
|
-
|
|
58
|
-
print("Checking input parameters....Done")
|
|
59
|
-
|
|
60
|
-
dtm_by(print, **in_args.input, processes=int(in_args.processes), verbose=in_verbose)
|
|
61
|
-
|
|
62
|
-
print('Normalize Lidar data processing is done in {} seconds)'
|
|
63
|
-
.format(round(time.time() - start_time, 5)))
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import sys
|
|
3
|
-
import time
|
|
4
|
-
|
|
5
|
-
from beratools.tools.common import *
|
|
6
|
-
from beratools.tools.r_interface import *
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
def find_cell_size(callback, in_las_folder, processes, verbose):
|
|
10
|
-
rprocesses = r_processes(processes)
|
|
11
|
-
|
|
12
|
-
# assign R script file to local variable
|
|
13
|
-
Beratools_R_script = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'Beratools_r_script.r')
|
|
14
|
-
# Defining the R script and loading the instance in Python
|
|
15
|
-
r['source'](Beratools_R_script)
|
|
16
|
-
# Loading the function defined in R script.
|
|
17
|
-
r_pd2cellsize = robjects.globalenv['pd2cellsize']
|
|
18
|
-
|
|
19
|
-
# Invoking the R function
|
|
20
|
-
cell_size = r_pd2cellsize(in_las_folder, rprocesses)
|
|
21
|
-
print("The recommended cell size for the input liDAR data(set) is {}.".format(cell_size))
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if __name__ == '__main__':
|
|
25
|
-
start_time = time.time()
|
|
26
|
-
print('Calculate cell size from liDAR data point density processing..\n @ {}'
|
|
27
|
-
.format(time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime())))
|
|
28
|
-
|
|
29
|
-
packages = ['lidR', 'future']
|
|
30
|
-
check_r_packages_installation(packages)
|
|
31
|
-
|
|
32
|
-
print("Checking input parameters....")
|
|
33
|
-
in_args, in_verbose = check_arguments()
|
|
34
|
-
|
|
35
|
-
in_las_folder = in_args.input["in_las_folder"]
|
|
36
|
-
check_las_files_existence(in_las_folder)
|
|
37
|
-
|
|
38
|
-
print("Checking input parameters....Done")
|
|
39
|
-
|
|
40
|
-
find_cell_size(print, **in_args.input, processes=int(in_args.processes), verbose=in_verbose)
|
|
41
|
-
|
|
42
|
-
print('Calculate cell size from liDAR data point density processing is done in {} seconds)'
|
|
43
|
-
.format(round(time.time() - start_time, 5)))
|
beratools/tools/rpy_gnd_csf.py
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import time
|
|
3
|
-
|
|
4
|
-
from beratools.tools.common import *
|
|
5
|
-
from beratools.tools.r_interface import *
|
|
6
|
-
|
|
7
|
-
def gnd_csf(callback, in_las_folder, out_folder, slope, class_threshold, cloth_resolution, rigidness, processes,
|
|
8
|
-
verbose):
|
|
9
|
-
# assign R script file to local variable
|
|
10
|
-
Beratools_R_script = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'Beratools_r_script.r')
|
|
11
|
-
# Defining the R script and loading the instance in Python
|
|
12
|
-
r['source'](Beratools_R_script)
|
|
13
|
-
# Loading the function defined in R script.
|
|
14
|
-
r_classify_gnd = robjects.globalenv['classify_gnd']
|
|
15
|
-
# Invoking the R function
|
|
16
|
-
r_classify_gnd(in_las_folder, out_folder, slope, class_threshold, cloth_resolution, rigidness)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if __name__ == '__main__':
|
|
20
|
-
start_time = time.time()
|
|
21
|
-
print('Ground Classification (Cloth Simulation Filter) processing\n @ {}'
|
|
22
|
-
.format(time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime())))
|
|
23
|
-
|
|
24
|
-
packages = ['lidR', 'RCSF']
|
|
25
|
-
check_r_packages_installation(packages)
|
|
26
|
-
|
|
27
|
-
print("Checking input parameters....")
|
|
28
|
-
in_args, in_verbose = check_arguments()
|
|
29
|
-
try:
|
|
30
|
-
slope = bool(in_args.input["slope"])
|
|
31
|
-
in_args.input["slope"] = slope
|
|
32
|
-
except ValueError:
|
|
33
|
-
print("Invalid input of indicate slope exists, default value is used")
|
|
34
|
-
in_args.input["slope"] = False
|
|
35
|
-
|
|
36
|
-
try:
|
|
37
|
-
class_threshold = float(in_args.input["class_threshold"])
|
|
38
|
-
in_args.input["class_threshold"] = class_threshold
|
|
39
|
-
except ValueError:
|
|
40
|
-
print("Invalid input of ground threshold, default value is used")
|
|
41
|
-
in_args.input["class_threshold"] = 0.5
|
|
42
|
-
|
|
43
|
-
try:
|
|
44
|
-
cloth_resolution = float(in_args.input["cloth_resolution"])
|
|
45
|
-
in_args.input["cloth_resolution"] = cloth_resolution
|
|
46
|
-
except ValueError:
|
|
47
|
-
print("Invalid input of distance between particles in the cloth, default value is used")
|
|
48
|
-
in_args.input["cloth_resolution"] = 0.5
|
|
49
|
-
|
|
50
|
-
try:
|
|
51
|
-
rigidness = int(in_args.input["rigidness"])
|
|
52
|
-
if rigidness in [1, 2, 3]:
|
|
53
|
-
in_args.input["rigidness"] = rigidness
|
|
54
|
-
else:
|
|
55
|
-
raise ValueError
|
|
56
|
-
except ValueError:
|
|
57
|
-
print("Invalid input of rigidness of the cloth, default value is used")
|
|
58
|
-
in_args.input["rigidness"] = 1
|
|
59
|
-
|
|
60
|
-
in_las_folder = in_args.input["in_las_folder"]
|
|
61
|
-
out_folder = in_args.input["out_folder"]
|
|
62
|
-
|
|
63
|
-
check_las_files_existence(in_las_folder)
|
|
64
|
-
|
|
65
|
-
if not os.path.exists(out_folder):
|
|
66
|
-
print("Warning! Cannot locate output folder, It will be created.")
|
|
67
|
-
os.makedirs(out_folder)
|
|
68
|
-
|
|
69
|
-
print("Checking input parameters....Done")
|
|
70
|
-
|
|
71
|
-
gnd_csf(print, **in_args.input, processes=int(in_args.processes), verbose=in_verbose)
|
|
72
|
-
|
|
73
|
-
print('Ground Classification (Cloth Simulation Filter) processing is done in {} seconds)'
|
|
74
|
-
.format(round(time.time() - start_time, 5)))
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import math
|
|
2
|
-
import os
|
|
3
|
-
import time
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
from beratools.tools.common import *
|
|
7
|
-
from beratools.tools.r_interface import *
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
def hh_raster(callback, in_las_folder, Min_ws, lawn_range, cell_size, out_folder, processes, verbose):
|
|
11
|
-
rprocesses = r_processes(processes)
|
|
12
|
-
|
|
13
|
-
in_las_folder = in_las_folder.replace("\\", "/")
|
|
14
|
-
out_folder = out_folder.replace("\\", "/")
|
|
15
|
-
|
|
16
|
-
# assign R script file to local variable
|
|
17
|
-
Beratools_R_script = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'Beratools_r_script.r')
|
|
18
|
-
# Defining the R script and loading the instance in Python
|
|
19
|
-
r['source'](Beratools_R_script)
|
|
20
|
-
# Loading the function defined in R script.
|
|
21
|
-
r_hh_function = robjects.globalenv['hh_function']
|
|
22
|
-
|
|
23
|
-
# Invoking the R function
|
|
24
|
-
r_hh_function(in_las_folder, cell_size, Min_ws, lawn_range, out_folder, rprocesses)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if __name__ == '__main__':
|
|
28
|
-
start_time = time.time()
|
|
29
|
-
print('Hummock and Hollow detection from LiDAR process.\n'
|
|
30
|
-
'@ {}'.format(time.strftime("%d %b %Y %H:%M:%S", time.localtime())))
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
packages = ['lidR', 'rgrass', 'rlas', 'future',
|
|
34
|
-
'terra'] # ,'comprehenr','na.tools','sf','sp']#,'devtools','gdal']#,'fasterRaster']
|
|
35
|
-
check_r_packages_installation(packages)
|
|
36
|
-
|
|
37
|
-
print("Checking input parameters ...")
|
|
38
|
-
in_args, in_verbose = check_arguments()
|
|
39
|
-
|
|
40
|
-
in_las_folder = in_args.input["in_las_folder"]
|
|
41
|
-
try:
|
|
42
|
-
cell_size = float(in_args.input["cell_size"])
|
|
43
|
-
in_args.input["cell_size"] = cell_size
|
|
44
|
-
except ValueError:
|
|
45
|
-
print("Invalid input of cell_size, default value will be used")
|
|
46
|
-
in_args.input["cell_size"] = 1.0
|
|
47
|
-
|
|
48
|
-
try:
|
|
49
|
-
ws = float(in_args.input["Min_ws"])
|
|
50
|
-
in_args.input["Min_ws"] = ws
|
|
51
|
-
except ValueError:
|
|
52
|
-
print("Invalid input of circular diameter, default value will be used")
|
|
53
|
-
in_args.input["Min_ws"] = 3.0
|
|
54
|
-
try:
|
|
55
|
-
lawn_range = float(in_args.input["lawn_range"])
|
|
56
|
-
in_args.input["lawn_range"] = lawn_range
|
|
57
|
-
except ValueError:
|
|
58
|
-
print("Invalid input of range height of lawns, default value will be used")
|
|
59
|
-
in_args.input["lawn_range"] = 0.1
|
|
60
|
-
|
|
61
|
-
out_folder = in_args.input["out_folder"]
|
|
62
|
-
|
|
63
|
-
if not os.path.exists(in_las_folder):
|
|
64
|
-
print("Error! Cannot locate Las folder, please check.")
|
|
65
|
-
exit()
|
|
66
|
-
else:
|
|
67
|
-
found = False
|
|
68
|
-
for files in os.listdir(in_las_folder):
|
|
69
|
-
if files.endswith(".las") or files.endswith(".laz"):
|
|
70
|
-
found = True
|
|
71
|
-
break
|
|
72
|
-
if not found:
|
|
73
|
-
print("Error! Cannot locate input LAS file(s), please check!")
|
|
74
|
-
exit()
|
|
75
|
-
|
|
76
|
-
if not os.path.exists(out_folder):
|
|
77
|
-
print("Warning! Cannot locate output folder, It will be created.")
|
|
78
|
-
os.makedirs(out_folder)
|
|
79
|
-
|
|
80
|
-
print("Checking input parameters ... Done")
|
|
81
|
-
|
|
82
|
-
hh_raster(print, **in_args.input, processes=int(in_args.processes), verbose=in_verbose)
|
|
83
|
-
|
|
84
|
-
print('Hummock and Hollow detection from LiDAR process is done in {} seconds)'
|
|
85
|
-
.format(round(time.time() - start_time, 5)))
|