Skip to content

Commit

Permalink
Efficient way to convert a structured numpy array into a 3d array.
Browse files Browse the repository at this point in the history
This CL uses a more efficient way to convert the numpy structured array removing the need to copy the array into memory as a list. Using `.view()` doesn't seem to change the data buffer and should be more memory efficient.

closes #9

PiperOrigin-RevId: 587594128
  • Loading branch information
Xee authors committed Dec 4, 2023
1 parent 49d82f8 commit f244a8a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions xee/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,9 @@ def image_to_array(
pixels_getter, params, catch=ee.ee_exception.EEException
)

# TODO(#9): Find a way to make this more efficient. This is needed because
# `raw` is a structured array of all the same dtype (i.e. number of images).
arr = np.array(raw.tolist(), dtype=dtype)
# This is needed because `raw` is a structured array of all the same dtype
# (i.e. number of images).
arr = raw.view(dtype)
data = arr.T
current_mask_value = np.array(self.mask_value, dtype=data.dtype)
# Sets EE nodata masked value to NaNs.
Expand Down

0 comments on commit f244a8a

Please sign in to comment.