PI-2472: _regrid_area_weighted_array: Move averaging out of loop #3589
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.
Optimise the averaging in the _regrid_area_weighted_array.
This is achieved by refactoring the weights calculation, collating the data and the weights in a single array, then finally computing the weighted mean as a whole-array-manipulation.
Calculating the weights first is necessary because the size (i.e. number of elements) of the weights and source data region varies per target grid point. In order to record all the values in a single array, the maximum size of the weights array needs to be established, so the single array can be setup. Therefore we first computing the weights and record the maximum weight-array size, hence we have refactored the weights calculation too.