Skip to content

Commit 3147715

Browse files
author
Chahan Kropf
committed
Update tests to use dynamic threshold
1 parent 90602b1 commit 3147715

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

climada/entity/exposures/test/test_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def test_assign_raster_pass(self):
212212
0.0,
213213
],
214214
)
215-
exp.assign_centroids(haz)
215+
exp.assign_centroids(haz, threshold=100)
216216

217217
expected_result = [
218218
# constant y-value, varying x-value

climada/util/test/test_coordinates.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ def test_match_centroids(self):
868868
geometry=gpd.points_from_xy(df["longitude"], df["latitude"]),
869869
crs=DEF_CRS,
870870
)
871-
assigned = u_coord.match_centroids(gdf, centroids)
871+
assigned = u_coord.match_centroids(gdf, centroids, threshold=0.9)
872872

873873
expected_result = [
874874
# constant y-value, varying x-value
@@ -918,9 +918,9 @@ def test_match_centroids(self):
918918
centroids_empty = Centroids(lat=np.array([]), lon=np.array([]))
919919

920920
expected_results = [
921-
# test with different thresholds (in km)
922-
(100, [2, 1, 2, 0, 3, -1, 4]),
923-
(20, [-1, 1, 2, 0, 3, -1, -1]),
921+
# test with different thresholds (in degrees)
922+
(1.5, [2, 1, 2, 0, 3, 1, 4]),
923+
(0.1, [-1, 1, 2, 0, 3, -1, -1]),
924924
(0, [-1, 1, 2, 0, -1, -1, -1]),
925925
]
926926

@@ -1215,7 +1215,9 @@ def normal_pass(self, dist):
12151215
centroids, exposures = self.data_input_values()
12161216

12171217
# Interpolate with default threshold
1218-
neighbors = u_coord.match_coordinates(exposures, centroids, distance=dist)
1218+
neighbors = u_coord.match_coordinates(
1219+
exposures, centroids, distance=dist, threshold=100
1220+
)
12191221
# Reference output
12201222
ref_neighbors = self.data_ref()
12211223
# Check results
@@ -1229,7 +1231,7 @@ def normal_warning(self, dist):
12291231
centroids, exposures = self.data_input_values()
12301232

12311233
# Interpolate with lower threshold to raise warnings
1232-
threshold = 40
1234+
threshold = 40 / EARTH_RADIUS_KM
12331235
with self.assertLogs("climada.util.coordinates", level="INFO") as cm:
12341236
neighbors = u_coord.match_coordinates(
12351237
exposures, centroids, distance=dist, threshold=threshold
@@ -1262,7 +1264,7 @@ def distance_threshold_warning_antimeridian(self, dist):
12621264
centroids, exposures = self.data_antimeridian_values()
12631265

12641266
# Interpolate with lower threshold to raise warnings
1265-
threshold = 100
1267+
threshold = 100 / EARTH_RADIUS_KM
12661268
with self.assertLogs("climada.util.coordinates", level="INFO") as cm:
12671269
neighbors = u_coord.match_coordinates(
12681270
exposures, centroids, distance=dist, threshold=threshold
@@ -1321,7 +1323,7 @@ def test_euc_antimeridian_warning(self):
13211323

13221324
def test_diff_outcomes(self):
13231325
"""Different NN interpolation outcomes"""
1324-
threshold = 100000
1326+
threshold = 100000 / EARTH_RADIUS_KM
13251327

13261328
# Define centroids
13271329
lons = np.arange(-160, 180 + 1, 20)
@@ -1361,8 +1363,8 @@ def setUp_match_coordinates(self):
13611363
self.expected_results = {
13621364
"degree": [
13631365
# test with different thresholds (in degree (converted to km))
1364-
(100, [2, 1, 2, 0, 3, -1, 4]),
1365-
(20, [-1, 1, 2, 0, 3, -1, -1]),
1366+
(2, [2, 1, 2, 0, 3, 1, 4]),
1367+
(1.5, [-1, 1, 2, 0, 3, -1, -1]),
13661368
(0, [-1, 1, 2, 0, -1, -1, -1]),
13671369
],
13681370
"m": [

0 commit comments

Comments
 (0)