Skip to content

Commit 6505dfe

Browse files
authored
Merge pull request #524 from djhoese/bugfix-noboundary-areaslices
2 parents e406472 + 0fa73f0 commit 6505dfe

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

pyresample/geometry.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2601,14 +2601,8 @@ def get_area_slices(self, area_to_cover, shape_divisible_by=None):
26012601
"equal.")
26022602

26032603
data_boundary = Boundary(*get_geostationary_bounding_box_in_lonlats(self))
2604-
if area_to_cover.is_geostationary:
2605-
area_boundary = Boundary(
2606-
*get_geostationary_bounding_box_in_lonlats(area_to_cover))
2607-
else:
2608-
area_boundary = AreaDefBoundary(area_to_cover, 100)
2609-
2610-
intersection = data_boundary.contour_poly.intersection(
2611-
area_boundary.contour_poly)
2604+
area_boundary = self._get_area_to_cover_boundary(area_to_cover)
2605+
intersection = data_boundary.contour_poly.intersection(area_boundary.contour_poly)
26122606
if intersection is None:
26132607
logger.debug('Cannot determine appropriate slicing. '
26142608
"Data and projection area do not overlap.")
@@ -2628,6 +2622,15 @@ def get_area_slices(self, area_to_cover, shape_divisible_by=None):
26282622
return (check_slice_orientation(x_slice),
26292623
check_slice_orientation(y_slice))
26302624

2625+
@staticmethod
2626+
def _get_area_to_cover_boundary(area_to_cover: AreaDefinition) -> Boundary:
2627+
try:
2628+
if area_to_cover.is_geostationary:
2629+
return Boundary(*get_geostationary_bounding_box_in_lonlats(area_to_cover))
2630+
return AreaDefBoundary(area_to_cover, 100)
2631+
except ValueError:
2632+
raise NotImplementedError("Can't determine boundary of area to cover")
2633+
26312634
def crop_around(self, other_area):
26322635
"""Crop this area around `other_area`."""
26332636
xslice, yslice = self.get_area_slices(other_area)

pyresample/test/test_geometry/test_area.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,6 +1814,17 @@ def test_on_flipped_geos_area(self, create_test_area):
18141814
assert slice_lines == expected_slice_lines
18151815
assert slice_cols == expected_slice_cols
18161816

1817+
def test_area_to_cover_all_nan_bounds(self, geos_src_area, create_test_area):
1818+
"""Check area slicing when the target doesn't have a valid boundary."""
1819+
area_def = geos_src_area
1820+
# An area that is a subset of the original one
1821+
area_to_cover = create_test_area(
1822+
{"proj": "moll"},
1823+
1000, 1000,
1824+
area_extent=(-18000000.0, -9000000.0, 18000000.0, 9000000.0))
1825+
with pytest.raises(NotImplementedError):
1826+
area_def.get_area_slices(area_to_cover)
1827+
18171828

18181829
class TestBoundary:
18191830
"""Test 'boundary' method for AreaDefinition classes."""

0 commit comments

Comments
 (0)