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

Fix colrow2lonlat working only for square areadefs #294

Merged
merged 2 commits into from
Jul 20, 2020

Conversation

ameraner
Copy link
Member

This PR fixes a bug observed in the AreaDefinition method colrow2lonlat. The function was working properly only for square areadefs, while returning wrong values for other areas.

To reproduce:

from satpy.resample import get_area_def
from satpy.scene import Scene

def lonlat2colrow2lonlat(lon_in, lat_in, area_def, desc):
    """Checks the reciprocity of lonlat2colrow and colrow2lonlat."""

    col, row = area_def.lonlat2colrow(lon_in, lat_in)
    lon_out, lat_out = area_def.colrow2lonlat(col, row)

    print("\nLon out "+desc+": ", lon_out)
    print("Lat out "+desc+": ", lat_out)

    return

lon_in = 30
lat_in = 40
print("Lon in: ", lon_in)
print("Lat in: ", lat_in)

# let's check upright areadefs
area_def = get_area_def("seviri_0deg")
lonlat2colrow2lonlat(lon_in, lat_in, area_def, 'seviri_0deg')

area_def = get_area_def("eurol")
lonlat2colrow2lonlat(lon_in, lat_in, area_def, 'eurol')

# let's check flipped areadefs
test_image = '/you/path/to/a/SEVIRI/native/image.nat'
scn = Scene(reader="seviri_l1b_native", filenames=[test_image])

scn.load(['HRV'])
area_def = scn['HRV'].attrs['area'].defs[1]
lonlat2colrow2lonlat(lon_in, lat_in, area_def, 'nat HRV')

scn.load(['VIS008'])
area_def = scn['VIS008'].attrs['area']
lonlat2colrow2lonlat(lon_in, lat_in, area_def, 'nat vis08')

Output with the current master:

Lon in:  30
Lat in:  40

Lon out seviri_0deg:  29.99159844726278 
Lat out seviri_0deg:  40.006400108344515

Lon out eurol:  -94.68203082968928
Lat out eurol:  27.231622640431453

Lon out nat HRV:  73.08085247495852
Lat out nat HRV:  -17.06078516437714

Lon out nat vis08:  30.037311995180985
Lat out nat vis08:  39.92747931402665

note how the non-square eurol and the (upper) HRV areas have wrong values.

Output after this PR:

Lon in:  30
Lat in:  40

Lon out seviri_0deg:  29.99159844726278 
Lat out seviri_0deg:  40.006400108344515

Lon out eurol:  29.992464774442446
Lat out eurol:  40.01002332383795

Lon out nat HRV:  29.999208764610334
Lat out nat HRV:  39.993233105064675

Lon out nat vis08:  29.991595970000212
Lat out nat vis08:  40.006397985178815

All values are correct.

  • Tests added
  • Tests passed
  • Passes git diff origin/master **/*py | flake8 --diff

@@ -1618,7 +1618,7 @@ def colrow2lonlat(self, cols, rows):
p = Proj(self.proj_str)
x = self.projection_x_coords
y = self.projection_y_coords
return p(y[y.size - cols], x[x.size - rows], inverse=True)
return p(x[cols], y[rows], inverse=True)
Copy link
Member

Choose a reason for hiding this comment

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

Any idea why the inverse was used in the first place (the y.size - part I mean)? Shouldn't that still be used?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's because of the test area definition it was using before, plus the fact that it was mixing x and y with cols and rows. In that specific case, the x and y are the inverse of each other, so actually y[y.size - cols]==x[cols] holds, and vice versa.

Copy link
Member

Choose a reason for hiding this comment

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

I think that makes sense to me. If the old tests still pass then I'm ok with it.

Copy link
Member Author

@ameraner ameraner Jul 20, 2020

Choose a reason for hiding this comment

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

Yep they do, I actually just reintroduced them! (See Martin's comment below)

@coveralls
Copy link

coveralls commented Jul 20, 2020

Coverage Status

Coverage decreased (-0.006%) to 92.586% when pulling 3a4fb5a on ameraner:fix_areadef_colrow2lonlat into 0e0c485 on pytroll:master.

@mraspaud mraspaud added the bug label Jul 20, 2020
@codecov
Copy link

codecov bot commented Jul 20, 2020

Codecov Report

Merging #294 into master will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #294      +/-   ##
==========================================
+ Coverage   92.59%   92.60%   +0.01%     
==========================================
  Files          43       43              
  Lines        9057     9077      +20     
==========================================
+ Hits         8386     8406      +20     
  Misses        671      671              
Impacted Files Coverage Δ
pyresample/geometry.py 83.05% <100.00%> (ø)
pyresample/test/test_geometry.py 97.94% <100.00%> (+0.03%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0e0c485...3a4fb5a. Read the comment docs.

Copy link
Member

@mraspaud mraspaud left a comment

Choose a reason for hiding this comment

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

Great catch! I just would like to keep the existing test if possible.

pyresample/test/test_geometry.py Outdated Show resolved Hide resolved
Copy link
Member

@mraspaud mraspaud left a comment

Choose a reason for hiding this comment

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

LGTM

@djhoese djhoese merged commit b84acad into pytroll:master Jul 20, 2020
@ameraner ameraner deleted the fix_areadef_colrow2lonlat branch December 7, 2020 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants