Skip to content

Commit

Permalink
Fix multiprocessing bug when setting min/max on empty points (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
CCInc authored Oct 10, 2022
1 parent bce7bb4 commit f4f81e3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-18.04, macos-10.15] #, windows-latest]
os: [ubuntu-latest, macos-latest] #, windows-latest]
python-version: [3.6, 3.7, 3.8, 3.9]

steps:
Expand Down
30 changes: 16 additions & 14 deletions python/copclib/mp/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def transform_multithreaded(
"""Scaffolding for reading COPC files and writing them back out in a multithreaded way.
It queues all nodes from either the provided list of nodes or nodes within the given resolution to be processed.
Within the multiprocess, `transform_function` is called with `transform_function_args` keyword arguments, as well as the
keyword arguments "points", "node", and "reader".
keyword arguments "points", "node", "writer_header", and "reader".
This function should take those parameters and return a copclib.Points object, and optionally a dictionary of
return values which will be passed to the callback function.
The points returned by the transform_function are passed back to the main thread, where those points
Expand Down Expand Up @@ -132,20 +132,22 @@ def transform_multithreaded(
**return_vals,
)

# Add the min/max of each node to the list
all_mins.append(xyz_min)
all_maxs.append(xyz_max)

# Write the node out
writer.AddNodeCompressed(
node.key,
compressed_points,
point_count,
node.page_key,
)
if point_count > 0:
# Add the min/max of each node to the list
if xyz_min and xyz_max:
all_mins.append(xyz_min)
all_maxs.append(xyz_max)

# Write the node out
writer.AddNodeCompressed(
node.key,
compressed_points,
point_count,
node.page_key,
)

# Compute the global min/max of all the nodes and update the LAS header, if necessary
if update_minmax:
if update_minmax and len(all_mins) > 0 and len(all_maxs) > 0:
import numpy as np

global_min = np.min(all_mins, axis=0)
Expand Down Expand Up @@ -196,7 +198,7 @@ def _transform_node(
# compute the minimum and maximum of the node's points, if necessary
xyz_min = None
xyz_max = None
if update_minmax:
if update_minmax and len(points) > 0:
xyz_min = [min(points.x), min(points.y), min(points.z)]
xyz_max = [max(points.x), max(points.y), max(points.z)]

Expand Down

0 comments on commit f4f81e3

Please sign in to comment.