Skip to content

Commit

Permalink
Fix goes bbox computation for gradient search tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mraspaud committed Feb 3, 2023
1 parent dd2ed80 commit 493e859
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
7 changes: 5 additions & 2 deletions pyresample/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2792,8 +2792,11 @@ def get_geostationary_bounding_box_in_proj_coords(geos_area, nb_points=50):
geo_bbox = Polygon(np.vstack((x, y)).T)
area_bbox = Polygon(((ll_x, ll_y), (ll_x, ur_y), (ur_x, ur_y), (ur_x, ll_y)))
intersection = area_bbox.intersection(geo_bbox)
x, y = intersection.boundary.xy
return x[:-1], y[:-1]
try:
x, y = intersection.boundary.xy
except NotImplementedError:
return [], []
return np.asanyarray(x[:-1]), np.asanyarray(y[:-1])


def get_full_geostationary_bounding_box_in_proj_coords(geos_area, nb_points=50):
Expand Down
4 changes: 2 additions & 2 deletions pyresample/gradient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from pyresample.geometry import (
AreaDefinition,
SwathDefinition,
get_geostationary_bounding_box,
get_geostationary_bounding_box_in_lonlats,
)
from pyresample.gradient._gradient_search import (
one_step_gradient_indices,
Expand Down Expand Up @@ -375,7 +375,7 @@ def _check_input_coordinates(dst_x, dst_y,
def get_border_lonlats(geo_def):
"""Get the border x- and y-coordinates."""
if geo_def.proj_dict['proj'] == 'geos':
lon_b, lat_b = get_geostationary_bounding_box(geo_def, 3600)
lon_b, lat_b = get_geostationary_bounding_box_in_lonlats(geo_def, 3600)
else:
lons, lats = geo_def.get_boundary_lonlats()
lon_b = np.concatenate((lons.side1, lons.side2, lons.side3, lons.side4))
Expand Down
30 changes: 24 additions & 6 deletions pyresample/test/test_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2603,6 +2603,18 @@ def truncated_geos_area():
return geos_area


@pytest.fixture
def truncated_geos_area_in_space():
"""Create a truncated geostationary area."""
projection = {'a': '6378169', 'h': '35785831', 'lon_0': '9.5', 'no_defs': 'None', 'proj': 'geos',
'rf': '295.488065897014', 'type': 'crs', 'units': 'm', 'x_0': '0', 'y_0': '0'}
area_extent = (5575000, 5575000, 5570000, 5570000)
width = 10
height = 10
geos_area = geometry.AreaDefinition('msg_rss', "msg_rss", "msg_rss", projection, width, height, area_extent)
return geos_area


class TestGeostationaryTools:
"""Test the geostationary bbox tools."""

Expand Down Expand Up @@ -2667,6 +2679,13 @@ def test_get_geostationary_bbox_does_not_contain_inf(self, truncated_geos_area):
assert not any(np.isinf(lon))
assert not any(np.isinf(lat))

def test_get_geostationary_bbox_returns_empty_lonlats_in_space(self, truncated_geos_area_in_space):
"""Ensure the geostationary bbox is empty when in space."""
lon, lat = geometry.get_geostationary_bounding_box_in_lonlats(truncated_geos_area_in_space, 20)

assert len(lon) == 0
assert len(lat) == 0

def test_get_geostationary_bbox(self):
"""Get the geostationary bbox."""
geos_area = MagicMock()
Expand Down Expand Up @@ -3230,20 +3249,19 @@ def test_geostationary_projection(self):
# Check boundary vertices
n_vertices = 10
boundary = areadef.boundary(frequency=n_vertices, force_clockwise=False)
boundary.vertices.shape

# Check boundary vertices is in correct order
expected_vertices = np.array([[-7.92337283e+01, 6.94302533e-15],
[-7.54251621e+01, 3.53432890e+01],
expected_vertices = np.array([[-7.54251621e+01, 3.53432890e+01],
[-5.68985178e+01, 6.90053314e+01],
[5.68985178e+01, 6.90053314e+01],
[7.54251621e+01, 3.53432890e+01],
[7.92337283e+01, -6.94302533e-15],
[7.92337283e+01, -0.00000000e+00],
[7.54251621e+01, -3.53432890e+01],
[5.68985178e+01, -6.90053314e+01],
[-5.68985178e+01, -6.90053314e+01],
[-7.54251621e+01, -3.53432890e+01]])
assert np.allclose(expected_vertices, boundary.vertices)
[-7.54251621e+01, -3.53432890e+01],
[-7.92337283e+01, 6.94302533e-15]])
np.testing.assert_allclose(expected_vertices, boundary.vertices)

def test_global_platee_caree_projection(self):
"""Test boundary for global platee caree projection."""
Expand Down
2 changes: 1 addition & 1 deletion pyresample/test/test_gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ def test_check_overlap():
assert check_overlap(poly1, poly2) is False


@mock.patch('pyresample.gradient.get_geostationary_bounding_box')
@mock.patch('pyresample.gradient.get_geostationary_bounding_box_in_lonlats')
def test_get_border_lonlats(get_geostationary_bounding_box):
"""Test that correct methods are called in get_border_lonlats()."""
from pyresample.gradient import get_border_lonlats
Expand Down

0 comments on commit 493e859

Please sign in to comment.