Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PI-2472: _regrid_area_weighted_array: Move averaging out of loop #3589

Conversation

abooton
Copy link
Contributor

@abooton abooton commented Dec 9, 2019

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.

@abooton abooton mentioned this pull request Dec 9, 2019
12 tasks
# Determine whether to mask element i, j based on whether
# there are valid weights.
weights = cached_weights[j][i]
if isinstance(weights, bool) and weights == False:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E712 comparison to False should be 'if cond is False:' or 'if not cond:'

@abooton abooton force-pushed the tweak_area_weighting_regrid_move_averaging_out_of_loop branch from 883e0e8 to a3e9de7 Compare December 10, 2019 13:28
@abooton abooton force-pushed the tweak_area_weighting_regrid_move_averaging_out_of_loop branch from a9ccf47 to 174a3f3 Compare December 12, 2019 09:09
@abooton
Copy link
Contributor Author

abooton commented Dec 12, 2019

Closed superseded by #3596

@abooton abooton closed this Dec 12, 2019
@abooton abooton changed the title _regrid_area_weighted_array: Move averaging out of loop PI-2472: _regrid_area_weighted_array: Move averaging out of loop Dec 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants