Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coord_on_land: fix buffer for global grids #542

Merged
merged 1 commit into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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