util
array3Dto2D
array3Dto2D(data, vox_dim, PlotDim)
Convert a 3D voxel grid into a 2D array of voxel center coordinates and values.
Parameters:
-
data(ndarray) –3D voxel grid (e.g., occupancy or classification values).
-
vox_dim(float) –Size of each voxel in meters.
-
PlotDim(dict) –Dictionary defining the spatial extent of the grid. Must include 'minX', 'maxX', 'minY', 'maxY', 'minZ', 'maxZ'.
Returns:
-
ndarray–2D array of shape (N, 4), where each row contains [x, y, z, value] for voxels with values greater than zero.
Source code in occpy/util.py
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 | |
calculate_voxel_corners
calculate_voxel_corners(data, vox_dim)
Compute the 3D corner coordinates of each voxel for mesh generation.
Parameters:
-
data(ndarray) –2D array of shape (N, 4), where each row contains [x, y, z, value] representing the center of a voxel and its scalar value.
-
vox_dim(float) –Length of the voxel edge in meters (assumed cubic).
Returns:
-
ndarray–Array of shape (N * 8, 4), where each group of 8 rows corresponds to the corners of one voxel, and each row contains [x, y, z, value].
Source code in occpy/util.py
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 | |
filterPointsIntersectingBox
filterPointsIntersectingBox(laz_in, laz_out, min_bound, max_bound, sensor_pos=None, traj_in=None, points_per_iter=100000)
Filter points from a LAS/LAZ file whose pulses intersect a defined 3D bounding box.
This filter considers the sensor or trajectory position to compute which pulses intersect
the bounding box defined by min_bound and max_bound.
Parameters:
-
laz_in(str) –Path to the input LAS/LAZ file.
-
laz_out(str) –Path to the output LAS/LAZ file where filtered points will be written.
-
min_bound(tuple or list of float) –Minimum bounding box coordinates in the order (min_y, min_x, min_z).
-
max_bound(tuple or list of float) –Maximum bounding box coordinates in the order (max_y, max_x, max_z).
-
sensor_pos(DataFrame or None, default:None) –Sensor position DataFrame with columns ['ScanPos', 'sensor_x', 'sensor_y', 'sensor_z']. Required if
traj_inis not provided. -
traj_in(DataFrame or None, default:None) –Trajectory DataFrame with columns ['time', 'sensor_x', 'sensor_y', 'sensor_z']. If provided, assumes a mobile platform.
-
points_per_iter(int, default:100000) –Number of points to process per chunk iteration (default is 100000).
Returns:
-
list–List of GPS times for pulses intersecting the bounding box.
Notes
This filter does not work as intended for solid-state scanners (e.g., GeoSLAM ZebHorizon, FARO ORBIS) where GPSTime is not a unique pulse identifier. To properly handle these, pulse shooting directions should also be accounted for. This is partially implemented on the C++ side but not yet passed to Python.
Source code in occpy/util.py
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 | |
generate_mesh_data
generate_mesh_data(data, vox_dim, PlotDim)
Generate mesh vertex and face data from a 2D array of voxel center coordinates and values.
Parameters:
-
data(ndarray) –2D array of shape (N, 4), where each row contains [x, y, z, value] representing the center and value of a filled voxel.
-
vox_dim(float) –Size of each voxel in meters.
-
PlotDim(dict) –Dictionary defining the spatial extent of the voxel grid. Must include 'minX', 'maxX', 'minY', 'maxY', 'minZ', 'maxZ'.
Returns:
-
verts(ndarray) –Array of vertex coordinates and associated voxel values.
-
faces(ndarray) –Array of face indices defining triangles for visualization (PLY format).
Source code in occpy/util.py
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 | |
interpolate_traj
interpolate_traj(traj_time, traj_x, traj_y, traj_z, pts_gpstime)
Interpolate trajectory coordinates at specified GPS timestamps.
Parameters:
-
traj_time(array - like) –Known trajectory time stamps.
-
traj_x(array - like) –Known x-coordinates of the trajectory.
-
traj_y(array - like) –Known y-coordinates of the trajectory.
-
traj_z(array - like) –Known z-coordinates of the trajectory.
-
pts_gpstime(array - like) –GPS timestamps at which to interpolate the trajectory.
Returns:
-
DataFrame–DataFrame containing interpolated 'time', 'sensor_x', 'sensor_y', and 'sensor_z' columns.
Source code in occpy/util.py
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 | |
last_nonzero
last_nonzero(arr, axis, invalid_val=-1)
Find the index of the last non-zero element along a specified axis.
Parameters:
-
arr(ndarray) –Input array to search.
-
axis(int) –Axis along which to find the last non-zero element.
-
invalid_val(int, default:-1) –Value to return if no non-zero elements are found (default is -1).
Returns:
-
ndarray–Indices of the last non-zero element along the specified axis. If none found, returns
invalid_val.
Source code in occpy/util.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | |
normalize_occlusion_output
normalize_occlusion_output(input_folder, PlotDim, vox_dim, dtm_file, dsm_file=None, lower_threshold=0, output_voxels=False)
normalize_occlusion_output normalizes all occlusion output grids (Nhit, Nmiss, Nocc, Classification) with the specified DTM This function also calculates occlusion statistics for the total canopy volume (defined by the volume between DTM and DSM). Currently only binary occlusion is analysed at the moment (TODO: implement also fractional occlusion), i.e. only voxels that are completely occluded (Nhit==0 and Nmiss==0 and Nocc >0)
Parameters:
-
input_folder(string) –directory to the output of the raytracing algorithm
-
PlotDim(list) –Plot Dimensions defined as a list: (minX, minY, minZ, maxX, maxY, maxZ)
-
dtm_file–DTM file (.tif) of the area of interest. Currently, both dimensions and pixel size should match the output grids
-
dsm_file–DSM file (.tif) of the area of interest. Currently, both dimensions and pixel size should match the output grids
-
lower_threshold–minimum Z coordinate to cut off lower part of the canopy, i.e. Voxels lieing at or below DTM. default=0
-
output_voxels–if the voxel grids should be outputted as a ply file. default=False -> not yet working properly, recommend leaving this to False!
Returns:
-
Nhit_norm(numpy array (3D)) –height normalized 3D voxel grid for the number of hits per voxel
-
Nmiss_norm(numpy array (3D)) –height normalized 3D voxel grid with number of missed pulses (unoccluded pulses with no interaction)per voxel
-
Nocc_norm(numpy array (3D)) –height normalized 3D voxel grid with number of occluded pulses per voxel
-
Classification_norm(numpy array (3d)) –height normalized 3D voxel grid with classification (1 = observed with hit, 2 = observed but no hit, 3 = occluded, 4 = unobserved)
-
chm(numpy array (2D)) –canopy height model as raster with specified vox_dim dimensions
Source code in occpy/util.py
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 134 135 136 137 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 169 170 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 199 200 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 | |
prepare_ply
prepare_ply(vox_dim, PlotDim, data)
Convert a 3D voxel grid into mesh data for PLY export.
Parameters:
-
vox_dim(float) –Size of a single voxel in meters.
-
PlotDim(dict) –Dictionary with plot bounding box coordinates. Must contain keys: 'minX', 'maxX', 'minY', 'maxY', 'minZ', 'maxZ'.
-
data(ndarray) –3D voxel grid (e.g., Nhit, Nmiss, Nocc, Classification).
Returns:
-
verts(ndarray) –Array of mesh vertices with shape (N, 4), where the last column is the voxel value.
-
faces(ndarray) –Array of triangular face indices with shape (M, 3).
Source code in occpy/util.py
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 | |
read_sensorpos_file
read_sensorpos_file(path2senspos, delimiter=' ', hdr_scanpos_id='', hdr_x='', hdr_y='', hdr_z='', sens_pos_id_offset=0)
Read a sensor position CSV file and extract sensor position data.
Parameters:
-
path2senspos(str) –Path to the sensor position CSV file.
-
delimiter(str, default:' ') –Delimiter used in the CSV file (default is space).
-
hdr_scanpos_id(str, default:'') –Column name for scan position ID (default is '').
-
hdr_x(str, default:'') –Column name for x-coordinate (default is '').
-
hdr_y(str, default:'') –Column name for y-coordinate (default is '').
-
hdr_z(str, default:'') –Column name for z-coordinate (default is '').
-
sens_pos_id_offset(int, default:0) –Offset to add to scan position IDs (default is 0).
Returns:
-
DataFrame–DataFrame with columns ['ScanPos', 'sensor_x', 'sensor_y', 'sensor_z'] representing sensor positions.
Source code in occpy/util.py
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 | |
read_trajectory_file
read_trajectory_file(path2traj, delimiter=' ', hdr_time='%time', hdr_x='x', hdr_y='y', hdr_z='z')
Read a trajectory CSV file and extract trajectory data.
Parameters:
-
path2traj(str) –Path to the trajectory CSV file.
-
delimiter(str, default:' ') –Delimiter used in the CSV file (default is space).
-
hdr_time(str, default:'%time') –Column name for time data (default is '%time').
-
hdr_x(str, default:'x') –Column name for x-coordinate data (default is 'x').
-
hdr_y(str, default:'y') –Column name for y-coordinate data (default is 'y').
-
hdr_z(str, default:'z') –Column name for z-coordinate data (default is 'z').
Returns:
-
DataFrame–DataFrame with columns ['time', 'sensor_x', 'sensor_y', 'sensor_z'] representing the trajectory.
Notes
Defaults correspond to the GeoSLAM ZebHorizon scanner trajectory format.
Source code in occpy/util.py
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 | |