Skip to content

Improve nearest-neighbor query perf#708

Open
Zaczero wants to merge 1 commit intopytroll:mainfrom
Zaczero:nearest-qnd-perf
Open

Improve nearest-neighbor query perf#708
Zaczero wants to merge 1 commit intopytroll:mainfrom
Zaczero:nearest-qnd-perf

Conversation

@Zaczero
Copy link
Contributor

@Zaczero Zaczero commented Mar 2, 2026

query_no_distance:
runtime: 0.01383s -> 0.01279s (-7.5%).
rss: 221096KB -> 204204KB (-7.6%).

_verify_input_object_type numpy array:
runtime: 0.02705s -> 0.02002s (-26%).
rss: same

_compute_radius_of_influence nan case:
runtime: 19.71s -> 2.10s.
rss: same

  • Tests added
  • Tests passed

@codecov
Copy link

codecov bot commented Mar 2, 2026

Codecov Report

❌ Patch coverage is 97.50000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 93.67%. Comparing base (4da28b0) to head (2d09c3b).
⚠️ Report is 32 commits behind head on main.

Files with missing lines Patch % Lines
pyresample/future/resamplers/nearest.py 90.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #708   +/-   ##
=======================================
  Coverage   93.67%   93.67%           
=======================================
  Files          89       89           
  Lines       13621    13652   +31     
=======================================
+ Hits        12759    12789   +30     
- Misses        862      863    +1     
Flag Coverage Δ
unittests 93.67% <97.50%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@djhoese djhoese left a comment

Choose a reason for hiding this comment

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

Nice job. Thanks for finding this. I've always disliked the indexing done in the query so I'm glad to see it cleaned up. I had a couple questions, but otherwise the majority of this looks good to me.

Otherwise could you check pre-commit's failures? Thanks.

Comment on lines +144 to +149
if np.isnan(src_res):
radius_of_influence = dst_res
elif np.isnan(dst_res):
radius_of_influence = src_res
else:
radius_of_influence = max(src_res, dst_res)
Copy link
Member

Choose a reason for hiding this comment

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

Could you explain why this is better? Because it prefers the source resolution?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It works just the same and avoids the all-nans warning print, which is quite expensive in Python. So it benefits only the worst-case scenario.

@Zaczero Zaczero force-pushed the nearest-qnd-perf branch from a17a10b to 2d09c3b Compare March 3, 2026 22:18
@djhoese
Copy link
Member

djhoese commented Mar 4, 2026

In your original description you talked about the performance of _verify_input_object_type. How does this PR affect that? Where is this function?

@djhoese
Copy link
Member

djhoese commented Mar 4, 2026

Oh and what was your test case for your timing? I'm surprised by how fast the query stuff was, but even more by how slow the NaN case was for the radius of influence stuff.

@djhoese
Copy link
Member

djhoese commented Mar 4, 2026

One last thing: I'm not ignoring your other pyresample and satpy PRs, but I'm still catching up on real work after being out for a couple days and I'm trying to fully understand the changes before commenting. Thanks again for all these changes/fixes/improvements.

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