Skip to content

Commit ff0e843

Browse files
authored
Merge pull request #475 from ghiggi/bugfix-duplicate-geo-bbox-lonlats
closes #474 Closes undefined
2 parents 952cec6 + d22496f commit ff0e843

2 files changed

Lines changed: 30 additions & 22 deletions

File tree

pyresample/geometry.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2691,24 +2691,30 @@ def get_geostationary_angle_extent(geos_area):
26912691
def get_geostationary_bounding_box_in_proj_coords(geos_area, nb_points=50):
26922692
"""Get the bbox in geos projection coordinates of the valid pixels inside `geos_area`.
26932693
2694-
Args:
2695-
nb_points: Number of points on the polygon
2694+
Notes:
2695+
- The first and last element of the output vectors are equal.
2696+
- If nb_points is even, it will return x and y vectors of length nb_points + 1.
2697+
2698+
Parameters
2699+
----------
2700+
nb_points : Number of points on the polygon.
2701+
26962702
"""
26972703
xmax, ymax = get_geostationary_angle_extent(geos_area)
26982704
h = get_geostationary_height(geos_area.crs)
26992705

27002706
# generate points around the north hemisphere in satellite projection
27012707
# make it a bit smaller so that we stay inside the valid area
2702-
x = np.cos(np.linspace(-np.pi, 0, int(nb_points / 2.0))) * (xmax - 0.0001)
2703-
y = -np.sin(np.linspace(-np.pi, 0, int(nb_points / 2.0))) * (ymax - 0.0001)
2708+
x = np.cos(np.linspace(-np.pi, 0, int(nb_points / 2.0) + 1)) * (xmax - 0.0001)
2709+
y = -np.sin(np.linspace(-np.pi, 0, int(nb_points / 2.0) + 1)) * (ymax - 0.0001)
27042710

27052711
ll_x, ll_y, ur_x, ur_y = geos_area.area_extent
27062712

27072713
x *= h
27082714
y *= h
2709-
2710-
x = np.clip(np.concatenate([x, x[::-1]]), min(ll_x, ur_x), max(ll_x, ur_x))
2711-
y = np.clip(np.concatenate([y, -y]), min(ll_y, ur_y), max(ll_y, ur_y))
2715+
# We remove one element with [:-1] to avoid duplicate values at the equator
2716+
x = np.clip(np.concatenate([x[:-1], x[::-1]]), min(ll_x, ur_x), max(ll_x, ur_x))
2717+
y = np.clip(np.concatenate([y[:-1], -y]), min(ll_y, ur_y), max(ll_y, ur_y))
27122718

27132719
return x, y
27142720

pyresample/test/test_geometry.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2603,19 +2603,21 @@ def test_get_geostationary_bbox(self):
26032603

26042604
lon, lat = geometry.get_geostationary_bounding_box(geos_area, 20)
26052605
# This musk be equal to lon.
2606-
elon = np.array([-79.23372832, -77.9694809, -74.55229623, -67.32816598,
2607-
-41.45591465, 41.45591465, 67.32816598, 74.55229623,
2608-
77.9694809, 79.23372832, 79.23372832, 77.9694809,
2609-
74.55229623, 67.32816598, 41.45591465, -41.45591465,
2610-
-67.32816598, -74.55229623, -77.9694809, -79.23372832])
2611-
elat = np.array([6.94302533e-15, 1.97333299e+01, 3.92114217e+01, 5.82244715e+01,
2612-
7.52409201e+01, 7.52409201e+01, 5.82244715e+01, 3.92114217e+01,
2613-
1.97333299e+01, -0.00000000e+00, -6.94302533e-15, -1.97333299e+01,
2614-
-3.92114217e+01, -5.82244715e+01, -7.52409201e+01, -7.52409201e+01,
2615-
-5.82244715e+01, -3.92114217e+01, -1.97333299e+01, 0.0])
2616-
2617-
np.testing.assert_allclose(lon, elon)
2618-
np.testing.assert_allclose(lat, elat)
2606+
elon = np.array([-79.23372832, -78.19662326, -75.42516215, -70.22636028,
2607+
-56.89851775, 0., 56.89851775, 70.22636028,
2608+
75.42516215, 78.19662326, 79.23372832, 78.19662326,
2609+
75.42516215, 70.22636028, 56.89851775, 0.,
2610+
-56.89851775, -70.22636028, -75.42516215, -78.19662326,
2611+
-79.23372832])
2612+
elat = np.array([0., 17.76879577, 35.34328897, 52.5978607,
2613+
69.00533142, 79.14811219, 69.00533142, 52.5978607,
2614+
35.34328897, 17.76879577, -0., -17.76879577,
2615+
-35.34328897, -52.5978607, -69.00533142, -79.14811219,
2616+
-69.00533142, -52.5978607, -35.34328897, -17.76879577,
2617+
0.])
2618+
2619+
np.testing.assert_allclose(lon, elon, atol=1e-07)
2620+
np.testing.assert_allclose(lat, elat, atol=1e-07)
26192621

26202622
geos_area = MagicMock()
26212623
lon_0 = 10
@@ -2825,7 +2827,7 @@ def test_get_area_slices(self):
28252827
assert isinstance(slice_x.start, int)
28262828
assert isinstance(slice_y.start, int)
28272829
self.assertEqual(slice(46, 3667, None), slice_x)
2828-
self.assertEqual(slice(52, 3663, None), slice_y)
2830+
self.assertEqual(slice(56, 3659, None), slice_y)
28292831

28302832
area_to_cover = geometry.AreaDefinition('areaD', 'Europe (3km, HRV, VTC)', 'areaD',
28312833
{'a': 6378144.0,
@@ -2883,7 +2885,7 @@ def test_get_area_slices(self):
28832885
assert isinstance(slice_x.start, int)
28842886
assert isinstance(slice_y.start, int)
28852887
self.assertEqual(slice_x, slice(46, 3667, None))
2886-
self.assertEqual(slice_y, slice(52, 3663, None))
2888+
self.assertEqual(slice_y, slice(56, 3659, None))
28872889

28882890
def test_get_area_slices_nongeos(self):
28892891
"""Check area slicing for non-geos projections."""

0 commit comments

Comments
 (0)