Skip to content

Commit 9205a19

Browse files
committed
Add test exception exp.assign_centroids when crs not equal
1 parent f8e6268 commit 9205a19

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

climada/entity/exposures/test/test_base.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,24 @@ def test_assign_meter_crs_pass(self):
138138
self.assertEqual(exp.gdf.shape[0], len(exp.hazard_centroids("FL")))
139139
np.testing.assert_array_equal(exp.hazard_centroids("FL"), expected_result)
140140

141+
def test_assign_no_equal_crs(self):
142+
haz = Hazard.from_raster(
143+
[HAZ_DEMO_FL], haz_type="FL", window=Window(10, 20, 50, 60)
144+
)
145+
crs_km = "EPSG:4326"
146+
crs_meters = "EPSG:4087"
147+
exp = Exposures(
148+
crs=crs_meters,
149+
lon=haz.centroids.lon,
150+
lat=haz.centroids.lat,
151+
)
152+
haz.centroids.to_crs(crs_km, inplace=True)
153+
with self.assertRaises(ValueError) as cm:
154+
exp.assign_centroids(haz)
155+
self.assertEqual(
156+
"Set hazard and exposure to the same CRS first!", str(cm.exception)
157+
)
158+
141159
def test__init__meta_type(self):
142160
"""Check if meta of type list raises a ValueError in __init__"""
143161
with self.assertRaises(TypeError) as cm:

0 commit comments

Comments
 (0)