Calculate Module¶
assign_voxels(arr, voxel_resolution)
¶
Assigns voxel grids to spatial data points based on the specified resolutions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arr
|
ndarray
|
Input array-like object containing point cloud data with 'X', 'Y', and 'HeightAboveGround' fields. |
required |
voxel_resolution
|
tuple of floats
|
The resolution for x, y, and z dimensions of the voxel grid. |
required |
Returns:
Type | Description |
---|---|
Tuple[ndarray, List]
|
tuple of (numpy.ndarray, List): A tuple containing the histogram of the voxel grid (with corrected orientation) and the extent of the point cloud. |
Source code in pyforestscan/calculate.py
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 |
|
calculate_chm(arr, voxel_resolution, interpolation='linear', interp_valid_region=False, interp_clean_edges=False)
¶
Calculate the Canopy Height Model (CHM) for a given voxel grid.
The CHM is computed as the maximum 'HeightAboveGround' value within each (X, Y) voxel. Optionally, gaps in the CHM can be filled using interpolation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arr
|
ndarray
|
Input structured numpy array containing point cloud data with fields 'X', 'Y', and 'HeightAboveGround'. |
required |
voxel_resolution
|
tuple of float
|
The resolution for the X and Y dimensions of the voxel grid, specified as (x_resolution, y_resolution). |
required |
interpolation
|
str or None
|
Method for interpolating gaps in the CHM. Supported methods are "nearest", "linear", "cubic", or None. If None, no interpolation is performed. Defaults to "linear". |
'linear'
|
interp_valid_region
|
bool
|
Whether to calculate a valid region mask using morphological operations for
interpolation. If True, interpolation is only applied within the valid data region. If False (default),
interpolation is applied to all NaN values. Ignored if |
False
|
interp_clean_edges
|
bool
|
Whether to clean edge fringes of the interpolated CHM. Default is False.
Ignored if |
False
|
Returns:
Name | Type | Description |
---|---|---|
tuple |
Tuple[ndarray, List]
|
|
Raises:
Type | Description |
---|---|
ValueError
|
If input array does not contain the required fields. |
ValueError
|
If |
Source code in pyforestscan/calculate.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 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 |
|
calculate_fhd(voxel_returns)
¶
Calculate the Foliage Height Diversity (FHD) for a given set of voxel returns.
This function computes FHD by calculating the entropy of the voxel return proportions along the Z (height) axis, which represents the vertical diversity of canopy structure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
voxel_returns
|
ndarray
|
3D numpy array of shape (X, Y, Z) representing voxel returns, where X and Y are spatial dimensions and Z represents height bins (vertical layers). |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: 2D numpy array of shape (X, Y) with FHD values for each (X, Y) location. Areas with no voxel returns will have NaN values. |
Source code in pyforestscan/calculate.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
|
calculate_pad(voxel_returns, voxel_height=1.0, beer_lambert_constant=1.0, drop_ground=True)
¶
Calculate the Plant Area Density (PAD) using the Beer-Lambert Law.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
voxel_returns
|
ndarray
|
3D numpy array of shape (X, Y, Z) representing the LiDAR returns in each voxel column. |
required |
voxel_height
|
float
|
Height of each voxel. Defaults to 1.0. |
1.0
|
beer_lambert_constant
|
float
|
The Beer-Lambert constant used in the calculation. Defaults to 1.0. |
1.0
|
drop_ground
|
bool
|
If True, sets PAD values in the ground (lowest) voxel layer to NaN in the output. Defaults to True. |
True
|
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: 3D numpy array containing PAD values for each voxel, same shape as |
Source code in pyforestscan/calculate.py
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 134 135 |
|
calculate_pai(pad, voxel_height, min_height=1.0, max_height=None)
¶
Calculate Plant Area Index (PAI) from Plant Area Density (PAD) data by summing PAD values along the height (Z) axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pad
|
ndarray
|
3D numpy array representing Plant Area Density (PAD) values, shape (X, Y, Z). |
required |
voxel_height
|
float
|
Height of each voxel in meters. |
required |
min_height
|
float
|
Minimum height in meters for summing PAD values. Defaults to 1.0. |
1.0
|
max_height
|
float
|
Maximum height in meters for summing PAD values. If None, uses the full height of the input array. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: 2D numpy array of shape (X, Y) with PAI values for each (x, y) voxel column. |
Raises:
Type | Description |
---|---|
ValueError
|
If min_height is greater than or equal to max_height. |
Source code in pyforestscan/calculate.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
|
generate_dtm(ground_points, resolution=2.0)
¶
Generates a Digital Terrain Model (DTM) raster from classified ground points.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ground_points
|
list
|
Point cloud arrays of classified ground points. |
required |
resolution
|
float
|
Spatial resolution of the DTM in meters. |
2.0
|
Returns:
Name | Type | Description |
---|---|---|
tuple |
Tuple[ndarray, List]
|
A tuple containing the DTM as a 2D NumPy array and the spatial extent [x_min, x_max, y_min, y_max]. |
Raises:
Type | Description |
---|---|
ValueError
|
If no ground points are found for DTM generation. |
KeyError
|
If point cloud data is missing 'X', 'Y', or 'Z' fields. |
Source code in pyforestscan/calculate.py
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 |
|