Skip to content

Commit

Permalink
coord_on_land: fix buffer for global grids (#542)
Browse files Browse the repository at this point in the history
  • Loading branch information
tovogt authored Oct 7, 2022
1 parent 5d8e6ad commit 72eb8f0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
6 changes: 2 additions & 4 deletions climada/util/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,12 +684,10 @@ def coord_on_land(lat, lon, land_geom=None):
lon_mid = 0.5 * (bounds[0] + bounds[1])
# normalize lon
lon_normalize(lons, center=lon_mid)
bounds = latlon_bounds(lat, lons, buffer=delta_deg)
# load land geometry with appropriate same extent
land_geom = get_land_geometry(
extent=(bounds[0] - delta_deg,
bounds[1] + delta_deg,
np.min(lat) - delta_deg,
np.max(lat) + delta_deg),
extent=(bounds[0], bounds[2], bounds[1], bounds[3]),
resolution=10)
elif not land_geom.is_empty:
# ensure lon values are within extent of provided land_geom
Expand Down
12 changes: 6 additions & 6 deletions climada/util/test/test_coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -899,13 +899,13 @@ def test_get_land_geometry_all_pass(self):

def test_on_land_pass(self):
"""check point on land with 1:50.000.000 resolution."""
lat = np.array([28.203216, 28.555994, 28.860875])
lon = np.array([-16.567489, -18.554130, -9.532476])
rows, cols, trans = u_coord.pts_to_raster_meta((-179.5, -60, 179.5, 60), (1, -1))
xgrid, ygrid = u_coord.raster_to_meshgrid(trans, cols, rows)
lat = np.concatenate([[28.203216, 28.555994, 28.860875], ygrid.ravel()])
lon = np.concatenate([[-16.567489, -18.554130, -9.532476], xgrid.ravel()])
res = u_coord.coord_on_land(lat, lon)
self.assertEqual(res.size, 3)
self.assertTrue(res[0])
self.assertFalse(res[1])
self.assertTrue(res[2])
self.assertEqual(res.size, lat.size)
np.testing.assert_array_equal(res[:3], [True, False, True])

def test_dist_to_coast(self):
"""Test point in coast and point not in coast"""
Expand Down

0 comments on commit 72eb8f0

Please sign in to comment.