forked from HAFL-WWI/pyFINT
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_main.py
More file actions
133 lines (118 loc) · 6.11 KB
/
example_main.py
File metadata and controls
133 lines (118 loc) · 6.11 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
######################################################################
# Copyright (C) 2021 ecorisQ
# Use of this source code is governed by an MIT-style license that can be found in the LICENSE
# file or at https://opensource.org/licenses/MIT.
#
# Author: Christoph Schaller, BFH-HAFL, December 2020
#
# Script for demonstrating the use of pyFINT. The script expects
# input rasters of 1m resolution
######################################################################
import os
from datetime import timedelta
import time
from pyfintcontroller import *
# Default entry point
if __name__ == "__main__":
start_time = time.time()
#Expected resolution is 1m
#One Filter example
#One 1.5m resize example
#Path to output folder
working_dir = os.path.join(os.getcwd(), "output")
#Paths to input rasters
#Vegetation Height Model/Normalised Surface Model
# Demodata
#nsm_file = os.path.join(os.getcwd(), "sample_data/VHM_1m.tif")
# Example Schwamendingen
# nsm_file = os.path.join(os.getcwd(), "sample_data/normalized_2685-1250_0.5_2056_5728.tif")
# Real-world-data
# Thunersee reduced to AOI
nsm_file = os.path.join(os.getcwd(), "sample_data/normalized.tif")
#
# Standard Detection with 1m input VHM without resizing of filtering
#
fint_controller = pyFintController()
fint_controller.set_working_dir(working_dir)
#Whether to allow the use of altitude in DBH calculation (requires DTM)
fint_controller.m_altitude_allowed = False
#NSM/VHM used for detection
fint_controller.set_normalized_model_file_name(nsm_file,None)
#Set the function for calculating the DBH, whether to allow altitude in calculation
fint_controller.set_dbh_function("2.52*H^0.84", False)
#Whether to randomize the DBH value and the degree of deviation in percent
fint_controller.set_diameter_randomization(False,20)
#Minimum height of a pixel to be considered for a local maxima
fint_controller.set_minimum_height(1)
#Minimum height for a detected maxima to be consideres as a tree
fint_controller.set_minimum_detection_height(4)
#Tell the controller to run the detection
fint_controller.run_process()
#
# Detection with 1m input VHM resized to 1.5m
#
fint_controller = pyFintController()
fint_controller.set_working_dir(working_dir)
#Whether to allow the use of altitude in DBH calculation (requires DEM)
fint_controller.m_altitude_allowed = False
#NSM/VHM used for detection
fint_controller.set_normalized_model_file_name(nsm_file,None)
#Set the function for calculating the DBH, whether to allow altitude in calculation
fint_controller.set_dbh_function("2.52*H^0.84", False)
#Whether to randomize the DBH value and the degree of deviation in percent
fint_controller.set_diameter_randomization(False,20)
#Minimum height of a pixel to be considered for a local maxima
fint_controller.set_minimum_height(1)
#Minimum height for a detected maxima to be consideres as a tree
fint_controller.set_minimum_detection_height(4)
#Tell the controller to resize the input tho the specified resolution with the given method
#Supported methods basing on gdal: ["near", "bilinear", "cubic", "cubicspline", "lanczos", "average", "mode", "max", "min", "med", "q1", "q3"]
fint_controller.set_resize_resolution(1.5,"bilinear")
#Tell the controller to run the detection
fint_controller.run_process()
#
# Detection with 1m input VHM and with Gauss filter sigma=2 and radius=3
#
fint_controller = pyFintController()
fint_controller.set_working_dir(working_dir)
#Whether to allow the use of altitude in DBH calculation (requires DEM)
fint_controller.m_altitude_allowed = False
#NSM/VHM used for detection
fint_controller.set_normalized_model_file_name(nsm_file,None)
#Set the function for calculating the DBH, whether to allow altitude in calculation
fint_controller.set_dbh_function("2.52*H^0.84", False)
#Whether to randomize the DBH value and the degree of deviation in percent
fint_controller.set_diameter_randomization(False,20)
#Minimum height of a pixel to be considered for a local maxima
fint_controller.set_minimum_height(1)
#Minimum height for a detected maxima to be consideres as a tree
fint_controller.set_minimum_detection_height(4)
#Tell the controller to apply a Gauss filter of the given strength and radius; radius needs to be an odd number
fint_controller.set_gauss_filter(size = 3, sigma = 2)
#Tell the controller to run the detection
fint_controller.run_process()
#
# Detection with 1m input VHM with resizing to 1.5 as well as with Gauss filter sigma=2 and radius=3
#
fint_controller = pyFintController()
fint_controller.set_working_dir(working_dir)
#Whether to allow the use of altitude in DBH calculation (requires DEM)
fint_controller.m_altitude_allowed = False
#NSM/VHM used for detection
fint_controller.set_normalized_model_file_name(nsm_file,None)
#Set the function for calculating the DBH, whether to allow altitude in calculation
fint_controller.set_dbh_function("2.52*H^0.84", False)
#Whether to randomize the DBH value and the degree of deviation in percent
fint_controller.set_diameter_randomization(False,20)
#Minimum height of a pixel to be considered for a local maxima
fint_controller.set_minimum_height(1)
#Minimum height for a detected maxima to be consideres as a tree
fint_controller.set_minimum_detection_height(4)
#Tell the controller to resize the input tho the specified resolution with the given method
#Supported methods basing on gdal: ["near", "bilinear", "cubic", "cubicspline", "lanczos", "average", "mode", "max", "min", "med", "q1", "q3"]
fint_controller.set_resize_resolution(1.5,"bilinear")
#Tell the controller to apply a Gauss filter of the given strength and radius; radius needs to be an odd number
fint_controller.set_gauss_filter(size = 3, sigma = 2)
#Tell the controller to run the detection
fint_controller.run_process()
print("TOTAL PROCESSING TIME: %s (h:min:sec)" % str(timedelta(seconds=(time.time() - start_time))))