Detect Treetop
This module implements functions for detecting treetop locations from canopy height models (CHMs) derived from lidar data.
DetectionParams
dataclass
Parameters for treetop detection algorithms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
detection_method
|
str
|
Method to use for treetop detection. Options: "prominence", "vws", "lmf". |
'prominence'
|
pixel_size
|
float
|
Spatial resolution of the CHM in the same units as min_tree_distance. |
0.25
|
min_height
|
float
|
Minimum height threshold for valid treetops (in same units as CHM). |
3.0
|
min_tree_distance
|
float
|
Minimum distance between detected treetops (in same units as CHM). |
1.5
|
prominence_height
|
float
|
Height above local background for prominence-based detection (in same units as CHM). |
1.0
|
vws_detection_sigma
|
float
|
Sigma for Gaussian smoothing in VWS method. Set to 0 for no smoothing. |
2.0
|
vws_distance_scale
|
float
|
Scaling factor for distance in VWS method (in same units as CHM). |
0.12
|
vws_power
|
float
|
Power to which height is raised in VWS method for distance scaling. |
1.0
|
Source code in src/phytospatial/lidar/detect_treetop.py
detect_treetops(chm_input, params=DetectionParams(), tile_mode='auto', tile_size=1024, overlap=64)
Detects treetop locations from a canopy height model (CHM) using specified detection parameters and memory-safe processing strategies.
Steps
- Utilizes
iter_core_haloto stream the CHM in partitioned spatial blocks. Each block includes a core processing area and a halo overlap to eliminate edge artifacts during algorithmic focal filtering. - Routes the active block array to the specified detection function
(Prominence, VWS, or LMF) based on the
DetectionParamsconfiguration. - Receives localized row and column peak indices from the algorithmic subroutines.
- Projects these localized pixel coordinates into global coordinate reference system (CRS) points via the block's Affine transform matrix.
- Performs spatial filtering using
core_box.contains()to discard any detected tops that occurred within the halo overlap region, preventing duplicate stem registrations across neighboring blocks. - Yields a standardized dictionary mapping the verified geometric point, associated elevation, and execution metadata back to the orchestrator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chm_input
|
Union[str, Path, Raster]
|
Input CHM raster or path to CHM file. |
required |
params
|
DetectionParams
|
Parameters dictating the active treetop detection algorithm. |
DetectionParams()
|
tile_mode
|
str
|
Tiling strategy for processing large rasters ('auto', 'in_memory', 'blocked', 'tiled'). |
'auto'
|
tile_size
|
int
|
Dimensions of the spatial partitions if streaming is necessary. |
1024
|
overlap
|
int
|
Margin of pixels surrounding each block to ensure algorithm continuity. |
64
|
Yields:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict[str, Any]: Structured payload containing 'height' (float), 'det_method' (str), and 'geometry' (shapely.Point). |
Source code in src/phytospatial/lidar/detect_treetop.py
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | |