Skip to content

Commit 847b906

Browse files
consistent naming of functions
1 parent 8ad36cb commit 847b906

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

climada/util/coordinates.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,7 +1693,7 @@ def _ensure_utf8(val):
16931693
return admin1_info, admin1_shapes
16941694

16951695

1696-
def global_bounding_box():
1696+
def bounding_box_global():
16971697
"""
16981698
Return global bounds in EPSG 4326
16991699
@@ -1705,7 +1705,7 @@ def global_bounding_box():
17051705
return (-180, -90, 180, 90)
17061706

17071707

1708-
def get_country_bounding_box(country_names, buffer=1.0):
1708+
def bounding_box_from_countries(country_names, buffer=1.0):
17091709
"""
17101710
Return bounding box in EPSG 4326 containing given countries.
17111711
@@ -1738,7 +1738,7 @@ def get_country_bounding_box(country_names, buffer=1.0):
17381738
return latlon_bounds(np.array(latitudes), np.array(longitudes), buffer=buffer)
17391739

17401740

1741-
def bounds_from_cardinal_bounds(*, northern, eastern, western, southern):
1741+
def bounding_box_from_cardinal_bounds(*, northern, eastern, western, southern):
17421742
"""
17431743
Return and normalize bounding box in EPSG 4326 from given cardinal bounds.
17441744

climada/util/test/test_coordinates.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2297,15 +2297,15 @@ def test_mask_raster_with_geometry(self):
22972297
class TestBoundsFromUserInput(unittest.TestCase):
22982298
"""Unit tests for the bounds_from_user_input function."""
22992299

2300-
def global_bounding_box(self):
2300+
def test_bounding_box_global(self):
23012301
"""Test for 'global' area selection."""
2302-
result = u_coord.global_bounding_box()
2302+
result = u_coord.bounding_box_global()
23032303
expected = (-180, -90, 180, 90)
23042304
np.testing.assert_almost_equal(result, expected)
23052305

2306-
def test_get_country_bounding_box(self):
2306+
def test_bounding_box_from_countries(self):
23072307
"""Test for a list of ISO country codes."""
2308-
result = u_coord.get_country_bounding_box(
2308+
result = u_coord.bounding_box_from_countries(
23092309
["ITA"], buffer=1.0
23102310
) # Testing with Italy (ITA)
23112311
# Real expected bounds for Italy (calculated or manually known)
@@ -2316,56 +2316,57 @@ def test_get_country_bounding_box(self):
23162316
48.08521494500006,
23172317
] # Italy's bounding box
23182318

2319-
def test_bounds_from_cardinal_bounds(self):
2319+
# invalid input
2320+
with self.assertRaises(ValueError):
2321+
u_coord.bounding_box_from_countries(["invalid_ISO", "DEU"])
2322+
2323+
def test_bounding_box_from_cardinal_bounds(self):
23202324
"""Test for conversion from cardinal bounds to bounds."""
23212325
np.testing.assert_array_almost_equal(
2322-
u_coord.bounds_from_cardinal_bounds(
2326+
u_coord.bounding_box_from_cardinal_bounds(
23232327
northern=90, southern=-20, eastern=30, western=20
23242328
),
23252329
(20, -20, 30, 90),
23262330
)
23272331
np.testing.assert_array_almost_equal(
2328-
u_coord.bounds_from_cardinal_bounds(
2332+
u_coord.bounding_box_from_cardinal_bounds(
23292333
northern=90, southern=-20, eastern=20, western=30
23302334
),
23312335
(30, -20, 380, 90),
23322336
)
23332337
np.testing.assert_array_almost_equal(
2334-
u_coord.bounds_from_cardinal_bounds(
2338+
u_coord.bounding_box_from_cardinal_bounds(
23352339
northern=90, southern=-20, eastern=170, western=-170
23362340
),
23372341
(-170, -20, 170, 90),
23382342
)
23392343
np.testing.assert_array_almost_equal(
2340-
u_coord.bounds_from_cardinal_bounds(
2344+
u_coord.bounding_box_from_cardinal_bounds(
23412345
northern=90, southern=-20, eastern=-170, western=170
23422346
),
23432347
(170, -20, 190, 90),
23442348
)
23452349
np.testing.assert_array_almost_equal(
2346-
u_coord.bounds_from_cardinal_bounds(
2350+
u_coord.bounding_box_from_cardinal_bounds(
23472351
northern=90, southern=-20, eastern=170, western=175
23482352
),
23492353
(175, -20, 530, 90),
23502354
)
23512355

23522356
# some invalid cases
23532357
with self.assertRaises(TypeError):
2354-
u_coord.bounds_from_cardinal_bounds(southern=-20, eastern=30, western=20)
2358+
u_coord.bounding_box_from_cardinal_bounds(
2359+
southern=-20, eastern=30, western=20
2360+
)
23552361
with self.assertRaises(TypeError):
2356-
u_coord.bounds_from_cardinal_bounds([90, -20, 30, 20])
2362+
u_coord.bounding_box_from_cardinal_bounds([90, -20, 30, 20])
23572363
with self.assertRaises(TypeError):
2358-
u_coord.bounds_from_cardinal_bounds(90, -20, 30, 20)
2364+
u_coord.bounding_box_from_cardinal_bounds(90, -20, 30, 20)
23592365
with self.assertRaises(TypeError):
2360-
u_coord.bounds_from_cardinal_bounds(
2366+
u_coord.bounding_box_from_cardinal_bounds(
23612367
northern="90", southern=-20, eastern=30, western=20
23622368
)
23632369

2364-
def test_invalid_input_string(self):
2365-
"""Test for invalid string input."""
2366-
with self.assertRaises(Exception):
2367-
u_coord.get_bound("invalid_ISO")
2368-
23692370

23702371
# Execute Tests
23712372
if __name__ == "__main__":

0 commit comments

Comments
 (0)