Notebook for xarray.map_blocks
lacks description of how chunks affect the computation
#317
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
I think the current example for
xarray.map_blocks
(advanced/map_blocks/simple_map_blocks.ipynb
) has two issues:xarray.map_blocks
actually passes bits of data the supplied function, which I think is paramount to correctly apply the function (I added an exercise to the notebook to illustrate that the function could return an unexpected result if the user doesn't take care of setting the chunks correctly)What's the issue with the current example?
time_mean(obj)
actually computes the mean along thelat
dimension (based on the function name and chunks on the time dimension, I guess this was not the intention (?) ).identical(...)
returnsTrue
, suggesting that everything worked fine and that this has to do with how the chunks on the time dimension are set in the current example:The problem I see is: The comparison with
.identical(...)
works because actually the mean is computed along the lat dimension and the lat dimension is not chunked at all (more or less by chance), but it has nothing to do with setting the chunks of the time dimension when opening the dataset. Instead, when really computing the mean along the time dimension both intime_mean(obj)
and via xarrays built-in.mean("time")
and keepingchunks={"time": 100}
, the comparison via.identical(...)
fails exactly because the time dimension is chunked. I suggest to fix the notebook so it follows the original intention of computing the mean along the time dimension.I have tried to update the notebook accordingly and add an exercise (now
Exercise 1
) to illustrate the importance of taking care of the chunks.All the best
Andreas