Skip to content

Commit

Permalink
Make use of bounding_box for area freezing when available
Browse files Browse the repository at this point in the history
  • Loading branch information
mraspaud committed Oct 1, 2024
1 parent b279d35 commit 62f8a59
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pyresample/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,10 @@ def _extract_lons_lats(lonslats):
try:
lons, lats = lonslats
except (TypeError, ValueError):
lons, lats = lonslats.get_lonlats()
try:
lons, lats = lonslats.attrs["bounding_box"]
except (AttributeError, KeyError):
lons, lats = lonslats.get_lonlats()
return lons, lats

def _compute_new_x_corners_for_antimeridian(self, xarr, antimeridian_mode):
Expand Down
9 changes: 9 additions & 0 deletions pyresample/test/test_geometry/test_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from pyresample.future.geometry.area import ignore_pyproj_proj_warnings
from pyresample.future.geometry.base import get_array_hashable
from pyresample.geometry import AreaDefinition as LegacyAreaDefinition
from pyresample.geometry import DynamicAreaDefinition
from pyresample.test.utils import assert_future_geometry


Expand Down Expand Up @@ -1754,3 +1755,11 @@ def test_non2d_shape_error(shape):
"""Test that non-2D shapes fail."""
with pytest.raises(NotImplementedError):
AreaDefinition("EPSG:4326", shape, (-1000.0, -1000.0, 1000.0, 1000.0))


def test_dynamic_area_can_use_bounding_box_attribute():
"""Test that area freezing can use bounding box info."""
area_def = DynamicAreaDefinition("test_area", "", "epsg:3035", resolution=500)
swath_def_to_freeze_on = SwathDefinition(None, None, attrs=dict(bounding_box=[[0, 20, 20, 0], [55, 55, 45, 45]]))
res_area = area_def.freeze(swath_def_to_freeze_on)
assert res_area.area_extent == (3533500, 2484500, 5108500, 3588500)

0 comments on commit 62f8a59

Please sign in to comment.