BERATools 0.2.0__py3-none-any.whl → 0.2.1__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 +1 -7
- beratools/core/algo_centerline.py +491 -351
- beratools/core/algo_common.py +497 -0
- beratools/core/algo_cost.py +192 -0
- beratools/core/{dijkstra_algorithm.py → algo_dijkstra.py} +503 -460
- beratools/core/algo_footprint_rel.py +577 -0
- beratools/core/algo_line_grouping.py +944 -0
- beratools/core/algo_merge_lines.py +214 -0
- beratools/core/algo_split_with_lines.py +304 -0
- beratools/core/algo_tiler.py +428 -0
- beratools/core/algo_vertex_optimization.py +469 -0
- beratools/core/constants.py +52 -86
- beratools/core/logger.py +76 -85
- beratools/core/tool_base.py +196 -133
- beratools/gui/__init__.py +11 -15
- beratools/gui/{beratools.json → assets/beratools.json} +2185 -2300
- beratools/gui/batch_processing_dlg.py +513 -463
- beratools/gui/bt_data.py +481 -487
- beratools/gui/bt_gui_main.py +710 -691
- beratools/gui/main.py +26 -0
- beratools/gui/map_window.py +162 -146
- beratools/gui/tool_widgets.py +725 -493
- beratools/tools/Beratools_r_script.r +1120 -1120
- beratools/tools/Ht_metrics.py +116 -116
- beratools/tools/__init__.py +7 -7
- beratools/tools/batch_processing.py +136 -132
- beratools/tools/canopy_threshold_relative.py +672 -670
- beratools/tools/canopycostraster.py +222 -222
- beratools/tools/centerline.py +136 -176
- beratools/tools/common.py +857 -885
- beratools/tools/fl_regen_csf.py +428 -428
- beratools/tools/forest_line_attributes.py +408 -408
- beratools/tools/line_footprint_absolute.py +213 -363
- beratools/tools/line_footprint_fixed.py +436 -282
- beratools/tools/line_footprint_functions.py +733 -720
- beratools/tools/line_footprint_relative.py +73 -64
- beratools/tools/line_grouping.py +45 -0
- beratools/tools/ln_relative_metrics.py +615 -615
- beratools/tools/r_cal_lpi_elai.r +24 -24
- beratools/tools/r_generate_pd_focalraster.r +100 -100
- beratools/tools/r_interface.py +79 -79
- beratools/tools/r_point_density.r +8 -8
- beratools/tools/rpy_chm2trees.py +86 -86
- beratools/tools/rpy_dsm_chm_by.py +81 -81
- beratools/tools/rpy_dtm_by.py +63 -63
- beratools/tools/rpy_find_cellsize.py +43 -43
- beratools/tools/rpy_gnd_csf.py +74 -74
- beratools/tools/rpy_hummock_hollow.py +85 -85
- beratools/tools/rpy_hummock_hollow_raster.py +71 -71
- beratools/tools/rpy_las_info.py +51 -51
- beratools/tools/rpy_laz2las.py +40 -40
- beratools/tools/rpy_lpi_elai_lascat.py +466 -466
- beratools/tools/rpy_normalized_lidar_by.py +56 -56
- beratools/tools/rpy_percent_above_dbh.py +80 -80
- beratools/tools/rpy_points2trees.py +88 -88
- beratools/tools/rpy_vegcoverage.py +94 -94
- beratools/tools/tiler.py +48 -206
- beratools/tools/tool_template.py +69 -54
- beratools/tools/vertex_optimization.py +61 -620
- beratools/tools/zonal_threshold.py +144 -144
- beratools-0.2.1.dist-info/METADATA +109 -0
- beratools-0.2.1.dist-info/RECORD +74 -0
- {beratools-0.2.0.dist-info → beratools-0.2.1.dist-info}/WHEEL +1 -1
- {beratools-0.2.0.dist-info → beratools-0.2.1.dist-info}/licenses/LICENSE +22 -22
- beratools/gui/cli.py +0 -18
- beratools/gui/gui.json +0 -8
- beratools/gui_tk/ASCII Banners.txt +0 -248
- beratools/gui_tk/__init__.py +0 -20
- beratools/gui_tk/beratools_main.py +0 -515
- beratools/gui_tk/bt_widgets.py +0 -442
- beratools/gui_tk/cli.py +0 -18
- beratools/gui_tk/img/BERALogo.png +0 -0
- beratools/gui_tk/img/closed.gif +0 -0
- beratools/gui_tk/img/closed.png +0 -0
- beratools/gui_tk/img/open.gif +0 -0
- beratools/gui_tk/img/open.png +0 -0
- beratools/gui_tk/img/tool.gif +0 -0
- beratools/gui_tk/img/tool.png +0 -0
- beratools/gui_tk/main.py +0 -14
- beratools/gui_tk/map_window.py +0 -144
- beratools/gui_tk/runner.py +0 -1481
- beratools/gui_tk/tooltip.py +0 -55
- beratools/third_party/pyqtlet2/__init__.py +0 -9
- beratools/third_party/pyqtlet2/leaflet/__init__.py +0 -26
- beratools/third_party/pyqtlet2/leaflet/control/__init__.py +0 -6
- beratools/third_party/pyqtlet2/leaflet/control/control.py +0 -59
- beratools/third_party/pyqtlet2/leaflet/control/draw.py +0 -52
- beratools/third_party/pyqtlet2/leaflet/control/layers.py +0 -20
- beratools/third_party/pyqtlet2/leaflet/core/Parser.py +0 -24
- beratools/third_party/pyqtlet2/leaflet/core/__init__.py +0 -2
- beratools/third_party/pyqtlet2/leaflet/core/evented.py +0 -180
- beratools/third_party/pyqtlet2/leaflet/layer/__init__.py +0 -5
- beratools/third_party/pyqtlet2/leaflet/layer/featuregroup.py +0 -34
- beratools/third_party/pyqtlet2/leaflet/layer/icon/__init__.py +0 -1
- beratools/third_party/pyqtlet2/leaflet/layer/icon/icon.py +0 -30
- beratools/third_party/pyqtlet2/leaflet/layer/imageoverlay.py +0 -18
- beratools/third_party/pyqtlet2/leaflet/layer/layer.py +0 -105
- beratools/third_party/pyqtlet2/leaflet/layer/layergroup.py +0 -45
- beratools/third_party/pyqtlet2/leaflet/layer/marker/__init__.py +0 -1
- beratools/third_party/pyqtlet2/leaflet/layer/marker/marker.py +0 -91
- beratools/third_party/pyqtlet2/leaflet/layer/tile/__init__.py +0 -2
- beratools/third_party/pyqtlet2/leaflet/layer/tile/gridlayer.py +0 -4
- beratools/third_party/pyqtlet2/leaflet/layer/tile/tilelayer.py +0 -16
- beratools/third_party/pyqtlet2/leaflet/layer/vector/__init__.py +0 -5
- beratools/third_party/pyqtlet2/leaflet/layer/vector/circle.py +0 -15
- beratools/third_party/pyqtlet2/leaflet/layer/vector/circlemarker.py +0 -18
- beratools/third_party/pyqtlet2/leaflet/layer/vector/path.py +0 -5
- beratools/third_party/pyqtlet2/leaflet/layer/vector/polygon.py +0 -14
- beratools/third_party/pyqtlet2/leaflet/layer/vector/polyline.py +0 -18
- beratools/third_party/pyqtlet2/leaflet/layer/vector/rectangle.py +0 -14
- beratools/third_party/pyqtlet2/leaflet/map/__init__.py +0 -1
- beratools/third_party/pyqtlet2/leaflet/map/map.py +0 -220
- beratools/third_party/pyqtlet2/mapwidget.py +0 -45
- beratools/third_party/pyqtlet2/web/custom.js +0 -43
- beratools/third_party/pyqtlet2/web/map.html +0 -23
- beratools/third_party/pyqtlet2/web/modules/leaflet_193/images/layers-2x.png +0 -0
- beratools/third_party/pyqtlet2/web/modules/leaflet_193/images/layers.png +0 -0
- beratools/third_party/pyqtlet2/web/modules/leaflet_193/images/marker-icon-2x.png +0 -0
- beratools/third_party/pyqtlet2/web/modules/leaflet_193/images/marker-icon.png +0 -0
- beratools/third_party/pyqtlet2/web/modules/leaflet_193/images/marker-shadow.png +0 -0
- beratools/third_party/pyqtlet2/web/modules/leaflet_193/leaflet.css +0 -656
- beratools/third_party/pyqtlet2/web/modules/leaflet_193/leaflet.js +0 -6
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/.codeclimate.yml +0 -14
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/.editorconfig +0 -4
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/.gitattributes +0 -22
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/.travis.yml +0 -43
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/LICENSE +0 -20
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/images/layers-2x.png +0 -0
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/images/layers.png +0 -0
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/images/marker-icon-2x.png +0 -0
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/images/marker-icon.png +0 -0
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/images/marker-shadow.png +0 -0
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/images/spritesheet-2x.png +0 -0
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/images/spritesheet.png +0 -0
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/images/spritesheet.svg +0 -156
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/leaflet.draw.css +0 -10
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/leaflet.draw.js +0 -10
- beratools/third_party/pyqtlet2/web/modules/leaflet_rotatedMarker_020/LICENSE +0 -22
- beratools/third_party/pyqtlet2/web/modules/leaflet_rotatedMarker_020/leaflet.rotatedMarker.js +0 -57
- beratools/tools/forest_line_ecosite.py +0 -216
- beratools/tools/lapis_all.py +0 -103
- beratools/tools/least_cost_path_from_chm.py +0 -152
- beratools-0.2.0.dist-info/METADATA +0 -63
- beratools-0.2.0.dist-info/RECORD +0 -142
- /beratools/gui/{img → assets}/BERALogo.png +0 -0
- /beratools/gui/{img → assets}/closed.gif +0 -0
- /beratools/gui/{img → assets}/closed.png +0 -0
- /beratools/{gui_tk → gui/assets}/gui.json +0 -0
- /beratools/gui/{img → assets}/open.gif +0 -0
- /beratools/gui/{img → assets}/open.png +0 -0
- /beratools/gui/{img → assets}/tool.gif +0 -0
- /beratools/gui/{img → assets}/tool.png +0 -0
- {beratools-0.2.0.dist-info → beratools-0.2.1.dist-info}/entry_points.txt +0 -0
beratools/tools/tiler.py
CHANGED
|
@@ -1,206 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
print('Generating {} tiles ...'.format(len(self.clip_data)))
|
|
50
|
-
for item in self.clip_data:
|
|
51
|
-
return_lines = clip_lines(item['geometry'], self.tile_buffer, self.in_line, item['line'])
|
|
52
|
-
return_raster = clip_raster(self.in_chm, item['geometry'], self.tile_buffer, item['raster'])
|
|
53
|
-
|
|
54
|
-
if not return_lines.empty and return_raster:
|
|
55
|
-
cell_data = {
|
|
56
|
-
'in_line': item['line'].as_posix(),
|
|
57
|
-
'in_chm': item['raster'].as_posix()
|
|
58
|
-
}
|
|
59
|
-
tasks_list.append(cell_data)
|
|
60
|
-
step += 1
|
|
61
|
-
print('%{}'.format(step / len(self.clip_data) * 100))
|
|
62
|
-
|
|
63
|
-
project_data['tasks'] = tasks_list
|
|
64
|
-
with open(self.out_project, 'w') as project_file:
|
|
65
|
-
json.dump(project_data, project_file, indent=4)
|
|
66
|
-
|
|
67
|
-
def generate_cells(self):
|
|
68
|
-
part_x = 0
|
|
69
|
-
part_y = 0
|
|
70
|
-
width = 0
|
|
71
|
-
height = 0
|
|
72
|
-
|
|
73
|
-
with(rasterio.open(self.in_chm)) as raster:
|
|
74
|
-
self.boundary = raster.bounds
|
|
75
|
-
width = raster.width
|
|
76
|
-
height = raster.height
|
|
77
|
-
self.in_crs = raster.crs
|
|
78
|
-
|
|
79
|
-
if self.boundary:
|
|
80
|
-
part_x = math.ceil(width / self.tile_size)
|
|
81
|
-
part_y = math.ceil(height / self.tile_size)
|
|
82
|
-
min_x, min_y, max_x, max_y = self.boundary
|
|
83
|
-
polygon_bound = Polygon([(min_x, min_y), (min_x, max_y), (max_x, max_y), (max_x, min_y)])
|
|
84
|
-
|
|
85
|
-
step_x = (max_x - min_x) / part_x
|
|
86
|
-
step_y = (max_y - min_y) / part_y
|
|
87
|
-
cells = []
|
|
88
|
-
for i in range(part_x):
|
|
89
|
-
for j in range(part_y):
|
|
90
|
-
cells.append(Polygon([(min_x + i * step_x, min_y + j * step_y),
|
|
91
|
-
(min_x + (i + 1) * step_x, min_y + j * step_y),
|
|
92
|
-
(min_x + (i + 1) * step_x, min_y + (j + 1) * step_y),
|
|
93
|
-
(min_x + i * step_x, min_y + (j + 1) * step_y)]))
|
|
94
|
-
|
|
95
|
-
# remove polygons not in boundary
|
|
96
|
-
for cell in cells:
|
|
97
|
-
if not polygon_bound.disjoint(cell):
|
|
98
|
-
self.clip_data.append({'geometry': cell})
|
|
99
|
-
|
|
100
|
-
return True
|
|
101
|
-
|
|
102
|
-
return False
|
|
103
|
-
|
|
104
|
-
def generate_tiles_info(self):
|
|
105
|
-
tiles_info = {'count': len(self.clip_data), 'dimension': self.tile_size}
|
|
106
|
-
return tiles_info
|
|
107
|
-
|
|
108
|
-
def cells_to_coord_list(self):
|
|
109
|
-
self.out_crs = CRS('EPSG:4326')
|
|
110
|
-
transformer = Transformer.from_crs(self.in_crs, self.out_crs)
|
|
111
|
-
coords_list = []
|
|
112
|
-
if self.clip_data:
|
|
113
|
-
for item in self.clip_data:
|
|
114
|
-
geom = item['geometry']
|
|
115
|
-
coords = mapping(geom)['coordinates']
|
|
116
|
-
if len(coords) > 0:
|
|
117
|
-
wgs84_coords = list(transformer.itransform(coords[0]))
|
|
118
|
-
wgs84_coords = [list(pt) for pt in wgs84_coords]
|
|
119
|
-
coords_list.append(wgs84_coords)
|
|
120
|
-
|
|
121
|
-
# find bounds
|
|
122
|
-
x = [pt[0] for polygon in coords_list for pt in polygon]
|
|
123
|
-
y = [pt[1] for polygon in coords_list for pt in polygon]
|
|
124
|
-
x_min = min(x)
|
|
125
|
-
x_max = max(x)
|
|
126
|
-
y_min = min(y)
|
|
127
|
-
y_max = max(y)
|
|
128
|
-
|
|
129
|
-
center = [(x_min + x_max) / 2, (y_min + y_max) / 2]
|
|
130
|
-
|
|
131
|
-
return coords_list, [[x_min, y_min], [x_max, y_max]], center
|
|
132
|
-
|
|
133
|
-
def shapefile_to_coord_list(self):
|
|
134
|
-
lines = read_geoms_from_shapefile(self.in_line)
|
|
135
|
-
line_coords = []
|
|
136
|
-
|
|
137
|
-
coords_list = []
|
|
138
|
-
for line in lines:
|
|
139
|
-
coords = line['coordinates']
|
|
140
|
-
for pt in coords:
|
|
141
|
-
coords_list.append(list(pt))
|
|
142
|
-
|
|
143
|
-
line_coords.append(coords_list)
|
|
144
|
-
|
|
145
|
-
return line_coords
|
|
146
|
-
|
|
147
|
-
def execute(self):
|
|
148
|
-
if self.generate_cells():
|
|
149
|
-
coords_list, bounds, center = self.cells_to_coord_list()
|
|
150
|
-
map_window = MapWindow()
|
|
151
|
-
|
|
152
|
-
# add lines to map
|
|
153
|
-
# lines = self.shapefile_to_coord_list()
|
|
154
|
-
# map_window.add_polylines_to_map(lines, 'gray')
|
|
155
|
-
|
|
156
|
-
# generate raster footprint and add to the map
|
|
157
|
-
footprint = generate_raster_footprint(self.in_chm)
|
|
158
|
-
|
|
159
|
-
# add AOI polygon and tile polygons
|
|
160
|
-
map_window.set_tiles_info(self.generate_tiles_info())
|
|
161
|
-
map_window.add_polygons_to_map('cells', coords_list, 'magenta')
|
|
162
|
-
map_window.add_polygons_to_map('base', footprint, 'green')
|
|
163
|
-
map_window.set_view(center, 10)
|
|
164
|
-
# bounds = [[56.143426823080134, 111.1130415762259], [56.26141944093645, 110.63627702636289]]
|
|
165
|
-
flag = map_window.exec()
|
|
166
|
-
|
|
167
|
-
if flag != QDialog.Accepted:
|
|
168
|
-
return
|
|
169
|
-
|
|
170
|
-
self.create_out_file_name()
|
|
171
|
-
self.save_clip_files()
|
|
172
|
-
|
|
173
|
-
# save polygons to shapefile
|
|
174
|
-
out_cells_file = self.proj_path.joinpath('cells.shp')
|
|
175
|
-
schema = {
|
|
176
|
-
'geometry': 'Polygon'
|
|
177
|
-
}
|
|
178
|
-
driver = 'ESRI Shapefile'
|
|
179
|
-
with fiona.open(out_cells_file, 'w', driver, schema, self.in_crs) as out_line_file:
|
|
180
|
-
for item in self.clip_data:
|
|
181
|
-
feature = {
|
|
182
|
-
'geometry': mapping(item['geometry'])
|
|
183
|
-
}
|
|
184
|
-
out_line_file.write(feature)
|
|
185
|
-
|
|
186
|
-
return
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
if __name__ == '__main__':
|
|
190
|
-
# supress web engine logging
|
|
191
|
-
os.environ["QTWEBENGINE_CHROMIUM_FLAGS"] = "--enable-logging --log-level=3"
|
|
192
|
-
|
|
193
|
-
app = QApplication(sys.argv)
|
|
194
|
-
|
|
195
|
-
parser = argparse.ArgumentParser()
|
|
196
|
-
parser.add_argument('-i', '--input', type=json.loads)
|
|
197
|
-
parser.add_argument('-p', '--processes')
|
|
198
|
-
parser.add_argument('-v', '--verbose')
|
|
199
|
-
args = parser.parse_args()
|
|
200
|
-
|
|
201
|
-
verbose = True if args.verbose == 'True' else False
|
|
202
|
-
|
|
203
|
-
tiling = Tiler(print, **args.input, processes=int(args.processes), verbose=verbose)
|
|
204
|
-
tiling.execute()
|
|
205
|
-
|
|
206
|
-
sys.exit(app.exec_())
|
|
1
|
+
"""
|
|
2
|
+
Copyright (C) 2025 Applied Geospatial Research Group.
|
|
3
|
+
|
|
4
|
+
This script is licensed under the GNU General Public License v3.0.
|
|
5
|
+
See <https://gnu.org/licenses/gpl-3.0> for full license details.
|
|
6
|
+
|
|
7
|
+
Author: Richard Zeng
|
|
8
|
+
|
|
9
|
+
Description:
|
|
10
|
+
This script is part of the BERA Tools.
|
|
11
|
+
Webpage: https://github.com/appliedgrg/beratools
|
|
12
|
+
|
|
13
|
+
The purpose of this script is to split input vector and raster data into
|
|
14
|
+
smaller tiles based on a specified tile size and buffer distance.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
import time
|
|
18
|
+
|
|
19
|
+
import beratools.tools.common as bt_common
|
|
20
|
+
import beratools.core.algo_tiler as bt_tiler
|
|
21
|
+
|
|
22
|
+
def tiler(
|
|
23
|
+
in_line,
|
|
24
|
+
in_raster,
|
|
25
|
+
out_file,
|
|
26
|
+
n_clusters,
|
|
27
|
+
processes,
|
|
28
|
+
verbose,
|
|
29
|
+
tile_buffer=50,
|
|
30
|
+
in_layer=None,
|
|
31
|
+
):
|
|
32
|
+
clustering = bt_tiler.DensityBasedClustering(
|
|
33
|
+
in_line=in_line,
|
|
34
|
+
in_raster=in_raster,
|
|
35
|
+
out_file=out_file,
|
|
36
|
+
n_clusters=int(n_clusters),
|
|
37
|
+
tile_buffer=tile_buffer,
|
|
38
|
+
layer=in_layer,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
clustering.run()
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
if __name__ == "__main__":
|
|
45
|
+
in_args, in_verbose = bt_common.check_arguments()
|
|
46
|
+
start_time = time.time()
|
|
47
|
+
tiler(**in_args.input, processes=int(in_args.processes), verbose=in_verbose)
|
|
48
|
+
print("Elapsed time: {}".format(time.time() - start_time))
|
beratools/tools/tool_template.py
CHANGED
|
@@ -1,54 +1,69 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
print('
|
|
1
|
+
"""
|
|
2
|
+
Copyright (C) 2025 Applied Geospatial Research Group.
|
|
3
|
+
|
|
4
|
+
This script is licensed under the GNU General Public License v3.0.
|
|
5
|
+
See <https://gnu.org/licenses/gpl-3.0> for full license details.
|
|
6
|
+
|
|
7
|
+
Author: AUTHOR NAME
|
|
8
|
+
|
|
9
|
+
Description:
|
|
10
|
+
This script is part of the BERA Tools.
|
|
11
|
+
Webpage: https://github.com/appliedgrg/beratools
|
|
12
|
+
|
|
13
|
+
The purpose of this script is to provide template for tool.
|
|
14
|
+
"""
|
|
15
|
+
import time
|
|
16
|
+
from multiprocessing.pool import Pool
|
|
17
|
+
from random import random
|
|
18
|
+
|
|
19
|
+
import numpy as np
|
|
20
|
+
|
|
21
|
+
import beratools.tools.common as bt_common
|
|
22
|
+
from beratools.core.tool_base import execute_multiprocessing
|
|
23
|
+
|
|
24
|
+
# Example task_data as a list of numpy ndarrays
|
|
25
|
+
task_data_list = [
|
|
26
|
+
np.array([1, 2, 3]),
|
|
27
|
+
np.array([4, 5, 6]),
|
|
28
|
+
np.array([7, 8, 9])
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
def tool_name(
|
|
32
|
+
in_line, in_cost_raster, line_radius, out_line, processes, verbose
|
|
33
|
+
):
|
|
34
|
+
"""
|
|
35
|
+
Define tool entry point.
|
|
36
|
+
|
|
37
|
+
These arguments are defined in beratools.json file.
|
|
38
|
+
execute_multiprocessing is common function to run tasks in parallel.
|
|
39
|
+
"""
|
|
40
|
+
result = execute_multiprocessing(
|
|
41
|
+
worker,
|
|
42
|
+
task_data_list,
|
|
43
|
+
"tool_template",
|
|
44
|
+
processes,
|
|
45
|
+
verbose=verbose
|
|
46
|
+
)
|
|
47
|
+
print(len(result))
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
# task executed in a worker process
|
|
51
|
+
def worker(task_data):
|
|
52
|
+
# report a message
|
|
53
|
+
value = np.mean(task_data)
|
|
54
|
+
print(f'Task with {value} executed', flush=True)
|
|
55
|
+
|
|
56
|
+
# block for a moment
|
|
57
|
+
time.sleep(value * 10)
|
|
58
|
+
|
|
59
|
+
# return the generated value
|
|
60
|
+
return value
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
if __name__ == '__main__':
|
|
64
|
+
in_args, in_verbose = bt_common.check_arguments()
|
|
65
|
+
start_time = time.time()
|
|
66
|
+
tool_name(
|
|
67
|
+
print, **in_args.input, processes=int(in_args.processes), verbose=in_verbose
|
|
68
|
+
)
|
|
69
|
+
print("Elapsed time: {}".format(time.time() - start_time))
|