applying 2d->2d function to a chunked data array (bonus track in mask + reduce in flox) #9867
Unanswered
martibosch
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
i have a collection of samples for which i have the surrounding DEM array:
I have a function named
compute_terrain_attribute
that uses richdem to compute topographic aspects, e.g., slope, which takes a x, y array and also returns a x, y array of the same shape. The following works:However, my data array may actually have a large number of samples in a way that it becomes larger than memory. Therefore, I would like to process it by sample chunks. However, when I adapt my code accodingly, i.e.:
I get an error since each
compute_terrain_attribute
is no longer receiving an (x, y) array of shape (100, 100) but a (sample, x, y) array of (10, 100, 100). What am I doing wrong? How can I make my code work for a larger than memory data array?Thank you!
Bonus track
My end goal is not to compute the topographic aspect arrays for each sample but instead average them over circular buffers of multiple radii. I have a function named
get_buffer_mask
that returns a 2d boolean array of the desired shape representing a circular mask, e.g., get_buffer_mask(25, (100, 100)) returns a 100x100 array with a centered circular mask of radius 25. I am able to obtain my result as follows:However, I am wondering whether I could reduce overheads and improve the performance, e.g., by using flox, since both operations (masking pixels and nanmean) are quite elementary. The following works with numpy (non-chunked) data:
nonetheless, I am not sure that expanding the data array is the way to go since I am repeating data from the concentric buffers. Also I cannot properly assess the performance until I manage to compute the slope for chunked data arrays.
Thank you again.
Beta Was this translation helpful? Give feedback.
All reactions