Skip to content

Commit bcb48b5

Browse files
author
Chahan Kropf
committed
Add test assign other crs
1 parent 9a1b296 commit bcb48b5

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

climada/entity/exposures/test/test_base.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,41 @@ def test_assign_pass(self):
103103
self.assertEqual(exp.gdf.shape[0], len(exp.hazard_centroids("FL")))
104104
np.testing.assert_array_equal(exp.hazard_centroids("FL"), expected_result)
105105

106+
def test_assign_meter_crs_pass(self):
107+
"""Check that attribute `assigned` is correctly set."""
108+
np_rand = np.random.RandomState(123456789)
109+
110+
haz = Hazard.from_raster(
111+
[HAZ_DEMO_FL], haz_type="FL", window=Window(10, 20, 50, 60)
112+
)
113+
ncentroids = haz.centroids.size
114+
crs_meters = "EPSG:4087"
115+
haz.centroids.to_crs(crs_meters, inplace=True)
116+
exp = Exposures(
117+
crs=haz.centroids.crs,
118+
lon=np.concatenate(
119+
[
120+
haz.centroids.lon,
121+
haz.centroids.lon + 0.001 * (-0.5 + np_rand.rand(ncentroids)),
122+
]
123+
),
124+
lat=np.concatenate(
125+
[
126+
haz.centroids.lat,
127+
haz.centroids.lat + 0.001 * (-0.5 + np_rand.rand(ncentroids)),
128+
]
129+
),
130+
)
131+
expected_result = np.concatenate([np.arange(ncentroids), np.arange(ncentroids)])
132+
133+
# make sure that it works for both float32 and float64
134+
for test_dtype in [np.float64, np.float32]:
135+
haz.centroids.gdf["lat"] = haz.centroids.lat.astype(test_dtype)
136+
haz.centroids.gdf["lon"] = haz.centroids.lon.astype(test_dtype)
137+
exp.assign_centroids(haz)
138+
self.assertEqual(exp.gdf.shape[0], len(exp.hazard_centroids("FL")))
139+
np.testing.assert_array_equal(exp.hazard_centroids("FL"), expected_result)
140+
106141
def test__init__meta_type(self):
107142
"""Check if meta of type list raises a ValueError in __init__"""
108143
with self.assertRaises(TypeError) as cm:

0 commit comments

Comments
 (0)