Skip to content

Commit 52a5a75

Browse files
committed
run_udf: more graceful degradation when dealing with inhomogeneous input
1 parent f867e7a commit 52a5a75

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

openeogeotrellis/geopysparkdatacube.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,15 @@ def tile_function(metadata:Metadata,
568568
# Sort by instant
569569
tile_list.sort(key=lambda tup: tup[0].instant)
570570
dates = map(lambda t: t[0].instant, tile_list)
571-
arrays = map(lambda t: t[1].cells, tile_list)
572-
multidim_array = np.array(list(arrays))
571+
arrays = list(map(lambda t: t[1].cells, tile_list))
572+
573+
#check if all elements in arrays have the same shape, if not, log a warning and create a new list retaining only elements with most common shape
574+
shapes = [a.shape for a in arrays]
575+
most_common_shape = max(set(shapes), key=shapes.count)
576+
if len(set(shapes)) > 1:
577+
_log.warning(f"run_udf: Not all tiles have the same shape. Shapes found: {set(shapes)}. Only using tiles with shape {most_common_shape} for further processing.")
578+
arrays = [a for a in arrays if a.shape == most_common_shape]
579+
multidim_array = np.array(arrays)
573580

574581
extent = GeopysparkDataCube._mapTransform(metadata.layout_definition, tile_list[0][0])
575582

0 commit comments

Comments
 (0)