Skip to content

Commit

Permalink
Antimeridian issue in get_country_code (#785)
Browse files Browse the repository at this point in the history
* define longitudinal extent by biggest gap rather than min/max

* normalize all the way

* coordinates.get_country_code: use laton_boudaries instead

* coordinates.get_country_code: swap extent order

* changelog
  • Loading branch information
emanuel-schmid authored Sep 26, 2023
1 parent 185ef96 commit 49937dd
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Code freeze date: YYYY-MM-DD

### Fixed

- `climada.util.coordinates.get_country_code` bug, occurring with non-standard longitudinal coordinates around the anti-meridian. [#770](https://github.com/CLIMADA-project/climada_python/issues/770)

### Deprecated

### Removed
Expand Down
5 changes: 2 additions & 3 deletions climada/util/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -1539,9 +1539,8 @@ def get_country_code(lat, lon, gridded=False):
method='nearest', fill_value=0)
region_id = region_id.astype(int)
else:
extent = (lon.min() - 0.001, lon.max() + 0.001,
lat.min() - 0.001, lat.max() + 0.001)
countries = get_country_geometries(extent=extent)
(lon_min, lat_min, lon_max, lat_max) = latlon_bounds(lat, lon, 0.001)
countries = get_country_geometries(extent=(lon_min, lon_max, lat_min, lat_max))
with warnings.catch_warnings():
# in order to suppress the following
# UserWarning: Geometry is in a geographic CRS. Results from 'area' are likely
Expand Down
1 change: 1 addition & 0 deletions climada/util/test/test_coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ def test_country_to_iso(self):
self.assertEqual(u_coord.country_natid2iso(natid_list), al3_list)
self.assertEqual(u_coord.country_natid2iso(natid_list[1]), al3_list[1])


class TestAssign(unittest.TestCase):
"""Test coordinate assignment functions"""

Expand Down

0 comments on commit 49937dd

Please sign in to comment.