pytroll / pyresample

Geospatial image resampling in Python
http://pyresample.readthedocs.org
GNU Lesser General Public License v3.0
344 stars 95 forks source link

Fix performance regression in base resampler class when comparing geometries #520

Closed djhoese closed 1 year ago

djhoese commented 1 year ago

As mentioned in #517, the new comparison added to the base resampler class in #508 was significantly slowing down any cases where non-areas were involved. This was most noticeable with EWA resampling as it is based on this resampler class and only deals with swath definitions.

The primary issue is/was that if the swaths are not equal the == used in the if statement was comparing the every coordinate (every pixel) of the source swath arrays to every pixel of the area definitions generated coordinates. This is usually not necessary since when we get to that point the objects are probably not equal and two swaths that aren't the same exact objects (or the underlying arrays are not the same) are probably not equal even if they have the same shape.

This PR is the first step in a proper fix. This should be released in a 1.27.1 release to fix the performance issue. The second step will be a separate PR (as discussed on the pytroll slack) where a coordinates_equal method will be added to the geometries to compare coordinates values no matter the cost in performance. The __eq__ method will be updated to be strict about objects needing to be the same type and then take the shortcuts implemented in this PR.

codecov[bot] commented 1 year ago

Codecov Report

Merging #520 (9e6101a) into main (2b94b70) will increase coverage by 0.01%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #520      +/-   ##
==========================================
+ Coverage   94.32%   94.33%   +0.01%     
==========================================
  Files          79       79              
  Lines       12944    12976      +32     
==========================================
+ Hits        12209    12241      +32     
  Misses        735      735              
Flag Coverage Δ
unittests 94.33% <100.00%> (+0.01%) :arrow_up:

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

Impacted Files Coverage Δ
pyresample/test/test_resamplers/test_resampler.py 100.00% <100.00%> (ø)
coveralls commented 1 year ago

Coverage Status

Coverage: 93.936% (+0.09%) from 93.846% when pulling 9e6101a52c4230e330a2708ebe2487780c1e59a7 on djhoese:regression-swath-comparison into 2b94b704365507a3ac9b2de9e9a25e5414792b73 on pytroll:main.

djhoese commented 1 year ago

Oh shoot. I thought this already had approval and I just forgot to merge it. Sorry @mraspaud. Let me know if you want any changes to this. I completely didn't realize this wasn't already reviewed.

djhoese commented 1 year ago

Note the user in the related issue said that this PR fixes their performance issues.

mraspaud commented 1 year ago

No worries, LGTM