Skip to content

Commit

Permalink
Preserve get_area_slices behavior when area to cover has an invalid b…
Browse files Browse the repository at this point in the history
…oundary
  • Loading branch information
djhoese committed Jun 19, 2023
1 parent 7a434c1 commit 0fa73f0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
19 changes: 11 additions & 8 deletions pyresample/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2592,14 +2592,8 @@ def get_area_slices(self, area_to_cover, shape_divisible_by=None):
"equal.")

data_boundary = Boundary(*get_geostationary_bounding_box_in_lonlats(self))
if area_to_cover.is_geostationary:
area_boundary = Boundary(
*get_geostationary_bounding_box_in_lonlats(area_to_cover))
else:
area_boundary = AreaDefBoundary(area_to_cover, 100)

intersection = data_boundary.contour_poly.intersection(
area_boundary.contour_poly)
area_boundary = self._get_area_to_cover_boundary(area_to_cover)
intersection = data_boundary.contour_poly.intersection(area_boundary.contour_poly)
if intersection is None:
logger.debug('Cannot determine appropriate slicing. '
"Data and projection area do not overlap.")
Expand All @@ -2619,6 +2613,15 @@ def get_area_slices(self, area_to_cover, shape_divisible_by=None):
return (check_slice_orientation(x_slice),
check_slice_orientation(y_slice))

@staticmethod
def _get_area_to_cover_boundary(area_to_cover: AreaDefinition) -> Boundary:
try:
if area_to_cover.is_geostationary:
return Boundary(*get_geostationary_bounding_box_in_lonlats(area_to_cover))
return AreaDefBoundary(area_to_cover, 100)
except ValueError:
raise NotImplementedError("Can't determine boundary of area to cover")

def crop_around(self, other_area):
"""Crop this area around `other_area`."""
xslice, yslice = self.get_area_slices(other_area)
Expand Down
11 changes: 11 additions & 0 deletions pyresample/test/test_geometry/test_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -1814,6 +1814,17 @@ def test_on_flipped_geos_area(self, create_test_area):
assert slice_lines == expected_slice_lines
assert slice_cols == expected_slice_cols

def test_area_to_cover_all_nan_bounds(self, geos_src_area, create_test_area):
"""Check area slicing when the target doesn't have a valid boundary."""
area_def = geos_src_area
# An area that is a subset of the original one
area_to_cover = create_test_area(
{"proj": "moll"},
1000, 1000,
area_extent=(-18000000.0, -9000000.0, 18000000.0, 9000000.0))
with pytest.raises(NotImplementedError):
area_def.get_area_slices(area_to_cover)


class TestBoundary:
"""Test 'boundary' method for AreaDefinition classes."""
Expand Down

0 comments on commit 0fa73f0

Please sign in to comment.