pyresample icon indicating copy to clipboard operation
pyresample copied to clipboard

create_area_def produces area definition with invalid latitudes

Open gerritholl opened this issue 2 years ago • 3 comments

Code Sample, a minimal, complete, and verifiable piece of code

from pyresample import create_area_def
ar = create_area_def(
        "fribullus_xax", 4326, units="degrees",
        resolution=0.1, center=(0, 90), shape=(5, 5))
print(ar.get_lonlats()[1])

Problem description

The latitudes returned are invalid.

Expected Output

[[89.8 89.8 89.8 89.8 89.8]
 [89.9 89.9 89.9 89.9 89.9]
 [90.  90.  90.  90.  90. ]
 [89.9 89.9 89.9 89.9 89.9]
 [89.8 89.8 89.8 89.8 89.8]]

Or maybe an exception that the operation is invalid.

Actual Result, Traceback if applicable

[[90.2 90.2 90.2 90.2 90.2]
 [90.1 90.1 90.1 90.1 90.1]
 [90.  90.  90.  90.  90. ]
 [89.9 89.9 89.9 89.9 89.9]
 [89.8 89.8 89.8 89.8 89.8]]

Versions of Python, package at hand and relevant dependencies

pyresample v1.22.3-14-ga742fd8

gerritholl avatar Feb 04 '22 17:02 gerritholl

Could you print out the area definition returned? Could you also explain why your expected output is what you expect?

Your center point is at the top of the projection. It can't go any further in projection space. I agree that the resulting latitudes are wrong, but I think the AreaDefinition is probably invalid. I'm not sure I would expect your request to work anyway (I don't want to support it at least).

djhoese avatar Feb 04 '22 17:02 djhoese

The area definition returned is:

Area ID: fribullus_xax
Description: fribullus_xax
Projection: {'datum': 'WGS84', 'no_defs': 'None', 'proj': 'longlat', 'type': 'crs'}
Number of columns: 5
Number of rows: 5
Area extent: (-0.25, 89.75, 0.25, 90.25)

Maybe it shouldn't work at all; maybe there should be a validity check?

gerritholl avatar Feb 04 '22 17:02 gerritholl

Yes a validity check would make sense. I think the logic assumes that the center you pick can simply have offsets added or subtracted to it to get the extent. It should probably check that the corner points actually exist in the projection space. I'm not sure how to do that though. I suppose the area of use could be used from the CRS object.

djhoese avatar Feb 04 '22 17:02 djhoese