Refactor raster_clip_weighted to use threading#25
Closed
krosenfeld-IDM wants to merge 7 commits intomainfrom
Closed
Refactor raster_clip_weighted to use threading#25krosenfeld-IDM wants to merge 7 commits intomainfrom
krosenfeld-IDM wants to merge 7 commits intomainfrom
Conversation
…ce and simplify code structure
… argument descriptions and return type information
Collaborator
Author
|
closes #19 |
There was a problem hiding this comment.
Pull Request Overview
This PR refactors raster_clip_weighted to run per‐shape clipping and aggregation in parallel threads by extracting the core logic into a helper and streamlining how the output dictionary is built.
- Introduces
_clip_weighted_singlefor shape‐level processing - Uses
ThreadPoolExecutorto submit tasks and aggregate results concurrently - Simplifies default
weight_summary_funchandling and removes pre‐initializeddata_dict
Comments suppressed due to low confidence (2)
rastertoolkit/raster.py:159
- Add a docstring to
_clip_weighted_singledescribing its parameters (shp,k1,n_shapes) and return value to improve readability and maintainability.
def _clip_weighted_single(shp, k1, n_shapes):
rastertoolkit/raster.py:159
- [nitpick] The parameter name
k1is ambiguous; consider renaming it toshape_indexoridxto clarify that it represents the current shape’s index.
def _clip_weighted_single(shp, k1, n_shapes):
rastertoolkit/raster.py
Outdated
| print_status(shp, data_dict, k1, len(shapes)) | ||
|
|
||
| data_dict = dict() | ||
| from concurrent.futures import ThreadPoolExecutor |
There was a problem hiding this comment.
Since this workload is CPU‐bound (NumPy and interpolation), you may see better scaling with ProcessPoolExecutor instead of ThreadPoolExecutor to bypass the GIL.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Check whether this impacts the ordering Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
… simplify result handling
…prove result handling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pull request refactors the
raster_clip_weightedfunction inrastertoolkit/raster.pyto improve performance and maintainability. The changes include introducing parallel processing usingThreadPoolExecutor, encapsulating shape-specific operations into a helper function, and streamlining the code structure.Performance improvements:
_clip_weighted_single. This allows for cleaner code and better separation of concerns.ThreadPoolExecutorto process shapes concurrently, leveraging available CPU cores for faster execution.Code structure and maintainability:
weight_summary_func) by using default values directly within the helper function.These updates enhance the readability and scalability of the
raster_clip_weightedfunction while maintaining its core functionality.