-
Notifications
You must be signed in to change notification settings - Fork 124
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
Improve performance of LitPop #720
Conversation
* Assume data from LitPop is gridded when determining region IDs. * Add option to pass 'region_id' parameter to LitPop.from_shape.
* Avoid copying data by using np.asarray. * Streamline computations by relying on numpy broadcasting.
Looks all very reasonable! Any estimates of the gained computation time? Also, changelog needs to be updated. Maybe also the documentation to point people towards how to use custom shapes correctly. |
I was afraid you would ask that 😬 I can come up with some benchmarks tomorrow. The most important improvement is from using So, tldr: |
Not sure what you mean by that. How are people using it "incorrectly" in your perspective? |
Sorry for being unclear. I was referring to the original issue which was about how to use arbitrary shapes with LitPop. This functionality was clearly not obvious, so a documentation entry could help. |
Ah, sorry, you were referring to #715. I'll see what I can do. |
* Rename return value in local function. * Remove named argument call in `LitPop.from_shape`. * Improve `region_id` parameter documentation.
I moved the Issue to Discussions/Q&A and marked my workaround as answer, see #723 |
Small improvements, but certainly useful! In particular since |
@@ -992,47 +1017,49 @@ def gridpoints_core_calc(data_arrays, offsets=None, exponents=None, | |||
|
|||
Returns | |||
------- | |||
result_array : np.array of same shape as arrays in data_arrays | |||
result : np.array of same shape as arrays in data_arrays |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really nitpicking, but result
is a terrible variable name ^^.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, but result_array
was even worse. Do you have something better? The name can also be omitted here:
result : np.array of same shape as arrays in data_arrays | |
np.array of same shape as arrays in data_arrays |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, the variable name still would be there. Maybe convoluted_array
since this is essentially doing a convolution? Or rescaled_product
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about leaving out the result
variable and storing everything in the data
variable? I think that the new variable definition actually is not needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also fine. Although data
is not a better name than result
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then I'll do that. My goal is not to refactor this function 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 620d346
Yes, I think I mixed something up. The major improvement was upgrading to shapely v2.0 on my side. |
@chahank Ready to merge from my side! |
Changes proposed in this PR:
LitPop
by assuming the data is gridded (it is)gridpoints_core_calc
to use numpy array tools and broadcasting, and avoid copying arraysLitPop.from_shape
. This avoids country-code detection.PR Author Checklist
develop
)PR Reviewer Checklist