diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cf6767dc3..e05260953 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,7 +32,7 @@ jobs: # Do not abort other tests if only a single one fails fail-fast: false matrix: - python-version: ["3.11", "3.12", "3.13"] + python-version: ["3.12", "3.13", "3.14"] steps: - diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c6e1434f..922a1d657 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,8 @@ Code freeze date: YYYY-MM-DD ### Removed +- `climada.util.coordinates.km_to_degree` and `climada.util.coordinates.degree_to_km`, use `climada.util.constants.ONE_LAT_KM` instead. + ## 6.2.0 Release date: 2026-11-06 diff --git a/climada/entity/exposures/base.py b/climada/entity/exposures/base.py index 9d9b54796..9e4a30146 100644 --- a/climada/entity/exposures/base.py +++ b/climada/entity/exposures/base.py @@ -632,10 +632,6 @@ def assign_centroids( method to associate centroids to exposure points climada.util.coordinates.estimate_matching_threshold: method to calculate the default threshold - climada.util.coordinates.km_to_degree: - method to approximately convert kilometers to degrees - climada.util.coordinates.degree_to_km: - method to approximately convert degrees to kilometers Notes ----- diff --git a/climada/entity/exposures/test/test_base.py b/climada/entity/exposures/test/test_base.py index a5c5f3574..3f97358b6 100644 --- a/climada/entity/exposures/test/test_base.py +++ b/climada/entity/exposures/test/test_base.py @@ -269,7 +269,7 @@ def test_assign_raster_pass(self): 0.0, ], ) - exp.assign_centroids(haz, threshold=u_coord.km_to_degree(100)) + exp.assign_centroids(haz, threshold=100.0 / ONE_LAT_KM) expected_result = [ # constant y-value, varying x-value diff --git a/climada/util/coordinates.py b/climada/util/coordinates.py index ff50b3b3a..1b08af727 100644 --- a/climada/util/coordinates.py +++ b/climada/util/coordinates.py @@ -1134,82 +1134,6 @@ def estimate_matching_threshold(coords_to_assign): return 2 * max(abs(r) for r in get_resolution(coords_to_assign.T)) -def degree_to_km(degree): - r"""Convert an angle from degrees to kilometers. - - This function converts a given angle in degrees to its equivalent distance in - kilometers on the Earth's surface. It assumes a spherical Earth with a constant - radius. - - Parameters - ---------- - degree : float or array_like - The angle(s) in degrees to convert. - - Returns - ------- - float or ndarray - The equivalent distance(s) in kilometers. - - See Also - -------- - km_to_degree : The inverse function to convert kilometers to degrees. - - Notes - ----- - The conversion is based on the formula: - - .. math:: - d = a \times R - - where d is the distance in km, a is the angle in radians, and R is the Earth's radius in km. - - Examples - -------- - >>> degree_to_km(1.0) - 111.19492664455822 - """ - return np.deg2rad(degree) * EARTH_RADIUS_KM - - -def km_to_degree(km): - r"""Convert a distance from kilometers to degrees. - - This function converts a given distance in kilometers on the Earth's surface - to its equivalent angle in degrees. It assumes a spherical Earth with a - constant radius. - - Parameters - ---------- - km : float or array_like - The distance(s) in kilometers to convert. - - Returns - ------- - float or ndarray - The equivalent angle(s) in degrees. - - See Also - -------- - degree_to_km : The inverse function to convert degrees to kilometers. - - Notes - ----- - The conversion is based on the formula: - - .. math:: - a = d / R - - where a is the angle in radians, d is the distance in km, and R is the Earth's radius in km. - - Examples - -------- - >>> km_to_degree(111.195) - 1.0000030589140416 - """ - return np.rad2deg(km / EARTH_RADIUS_KM) - - def match_coordinates( coords, coords_to_assign, @@ -1282,10 +1206,6 @@ def match_coordinates( -------- climada.util.coordinates.estimate_matching_threshold: method to calculate the default threshold - climada.util.coordinates.km_to_degree: - method to approximately convert kilometers to degrees - climada.util.coordinates.degree_to_km: - method to approximately convert degrees to kilometers """ crs = PCRS.from_user_input(crs) @@ -1396,10 +1316,6 @@ def match_centroids( climada.util.coordinates.match_coordinates: method to match coordinates climada.util.coordinates.estimate_matching_threshold: method to estimate the default threshold - climada.util.coordinates.km_to_degree: - method to approximately convert kilometers to degrees - climada.util.coordinates.degree_to_km: - method to approximately convert degrees to kilometers climada.util.coordinates.match_grid_points: method to associate centroids to coordinate points when centroids is a raster @@ -1478,7 +1394,7 @@ def _nearest_neighbor_approx( crs : pyproj crs Coordinate reference system (crs) of the input coordinates and centroids. threshold : float - Assignement threshold in units of the provided crs. + Assignement threshold in degree. If the distance to the nearest neighbor exceeds `threshold`, the index `-1` is assigned. check_antimedirian: bool, optional If True, the nearest neighbor in a strip with lon size equal to threshold around the @@ -1500,7 +1416,7 @@ def _nearest_neighbor_approx( check_if_geo_coords(centroids[:, 0], centroids[:, 1]) check_if_geo_coords(coordinates[:, 0], coordinates[:, 1]) # convert the degree threshold in to km at equator threshold - threshold_km = degree_to_km(threshold) + threshold_km = abs(threshold) * ONE_LAT_KM # Compute only for the unique coordinates. Copy the results for the # not unique coordinates _, idx, inv = np.unique(coordinates, axis=0, return_index=True, return_inverse=True) diff --git a/climada/util/test/test_coordinates.py b/climada/util/test/test_coordinates.py index 03f32f837..a66cfbefa 100644 --- a/climada/util/test/test_coordinates.py +++ b/climada/util/test/test_coordinates.py @@ -1481,7 +1481,7 @@ def test_match_coordinates_projected_foot_crs(self): convert_coordinates(self.coords_to_assign, DEF_CRS, crs)[:-1], distance=distance, crs=crs, - threshold=u_coord.degree_to_km(thresh) * 3280, # US foot + threshold=thresh * ONE_LAT_KM * 3280, # US foot ) np.testing.assert_array_equal(assigned_idx, result[:-1]) @@ -1498,7 +1498,7 @@ def test_match_coordinates_projected_meters_crs(self): convert_coordinates(self.coords_to_assign, DEF_CRS, crs)[:-1], distance=distance, crs=crs, - threshold=u_coord.degree_to_km(thresh) * 1000, # meters + threshold=thresh * ONE_LAT_KM * 1000, # meters ) np.testing.assert_array_equal(assigned_idx, result[:-1]) @@ -1515,7 +1515,7 @@ def test_match_coordinates_projected_meters2_crs(self): convert_coordinates(self.coords_to_assign, DEF_CRS, crs)[:-1], distance=distance, crs=crs, - threshold=u_coord.degree_to_km(thresh) * 1000, # meters + threshold=thresh * ONE_LAT_KM * 1000, # meters ) np.testing.assert_array_equal(assigned_idx, result[:-1]) @@ -1927,10 +1927,16 @@ def test_get_resolution_large_pass(self): def test_get_resolution_meters_pass(self): centr = Centroids.from_pnt_bounds((-180, -90, 180, 90), 1) centr.to_crs("EPSG:4087", inplace=True) # meters - res = u_coord.degree_to_km(1) * 1000 + res = ONE_LAT_KM * 1000 res_lat, res_lon = u_coord.get_resolution(centr.lat, centr.lon) - self.assertAlmostEqual(res_lat, res, delta=500) # approx to 500m correct - self.assertAlmostEqual(res_lon, res, delta=500) # approx to 500m correct + # since proj 9.8.1 the ellipsoid shape of earth is taken into account and latitudinal + # so the latitudinal resolution is a bit further off from the ONE_LAT_KM approximation + self.assertAlmostEqual( + res_lat, res, delta=550 + ) # approx to 550m correct, off by 0.5% + self.assertAlmostEqual( + res_lon, res, delta=200 + ) # approx to 200m correct, off by 0.2% def test_vector_to_raster_pass(self): """Test vector_to_raster""" diff --git a/pyproject.toml b/pyproject.toml index b1fe80e9a..7721dcf1f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ name = "climada" version = "6.2.1-dev" description = "Framework for climate risk assessment and adaptation option appraisal" readme = "README.md" -requires-python = ">=3.11,<3.14" +requires-python = ">=3.12,<3.15" license = { text = "GNU General Public License v3 (GPLv3)" } authors = [ { name = "ETH", email = "climada-info@sympa.ethz.ch" } diff --git a/requirements/env_climada.yml b/requirements/env_climada.yml index 671ca01f2..5bf1f43e3 100644 --- a/requirements/env_climada.yml +++ b/requirements/env_climada.yml @@ -30,10 +30,10 @@ dependencies: - pip - pyarrow>=24.0 - pycountry>=24.6 - - pyproj>=3.7 + - pyproj>=3.8 - pytables>=3.11 # this is the name of the pypi 'tables' package on conda-forge - pyxlsb>=1.0 - - rasterio>=1.4,<1.5 # 1.4 compatible with python 3.11; discrepancies between 1.4 and 1.5, see #1316 + - rasterio>=1.5 - requests>=2.34 - rtree>=1.4 - salib>=1.5