-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/centroids as gdf #787
Changes from 141 commits
8cf5e0a
e2a2a05
89b4051
70ea2fb
e34bc0f
02b4a8b
5ede9bd
98a898e
c77a2d9
913c0f1
5ec2859
e2ac9b7
5dd4ffe
950a722
923b066
abfff60
8e360e6
73c4392
0dc0abb
c2f626a
bdf77d2
cf0128d
4f40def
5f520fb
7c24df0
e4bb789
3df5a4b
7206446
d4d5e02
178e624
a94d7af
827c15b
e41191d
e412222
df6c3f4
cbab08e
5aeb35e
fb374d3
4119f33
2390c5a
4b1279e
315f7d9
2b1ac74
bab8c70
fe96975
a4cf3ce
9ce8e56
b22677f
1946bca
b2c0c74
6226bff
dc8d638
7002a52
73ee79e
0cabeac
3729248
6c3d1ac
8b15107
f3af2dd
5888dea
e22c857
847736b
756c587
e015000
b0dfd66
cfecf10
510f53f
e108432
5571755
baf88a0
5b37116
78811c5
84de9bf
1ab1b69
19b02a5
5e4e03d
a426247
c60e50f
ae6a0cc
fbf28d4
b3ae8c4
929f0e1
17ee8b1
e58aef2
b70a0f4
494d416
448cf77
c736356
2880bcc
8cc88e7
11a6439
a1fce1d
bfcfc01
4a4aed7
4460955
37c54ea
e4bc0db
b02ae1d
cf3f6e5
b3448d0
2beb6a3
a7eb166
147ee0d
445194b
425b9ce
b879ca6
d63fc8b
70928bd
b97491c
d9e98ce
274cf20
8101e3d
42634bb
8727895
429e74c
fb7c7cc
dd212db
5996714
164e689
4079f3f
dd7e4cd
f6b72ed
61f3c6b
adce3c1
9653e98
8e13e61
43c2f1b
32a4be9
d1475d8
2464066
bd5629c
d031a79
a1040f8
a748ee0
652a2b8
6806331
25a0930
5849acb
84107ee
bfb24d7
67a1d60
8f25d1f
0f54053
c4bb540
3f4ebb6
c7e6ffd
79cd84b
e5dffd9
1f6ec54
f59278c
4c641dc
e5c1c73
26e2702
e6fa996
37b5d19
622d326
a7311a0
99203ad
e5cd4ad
58360a5
2f248b8
19cae86
19fe589
5ccc278
ee512ca
4053565
fc0c7ec
a30a7c4
5404dba
4d62101
1ba2ade
62df2dd
a7b8cf9
e514195
ec11611
e77af81
bba7e49
655b749
03676d8
7dfa631
eda2755
8fcf3b3
57fd369
4ffd744
ddb6dcc
bd1f9fd
31aba1c
b84a76d
b1b0efa
473bc9d
017864e
441fbb1
0cd3530
db748c7
5863cb2
3dd4a50
065c868
5e1d9ff
f6f7db8
ead5e05
693af77
1f45167
bc75e0f
31409cd
e59eb18
0ad0804
88b320a
b543636
5f3904b
7b009e9
eac96d8
daa9812
53bd89c
5fba7f6
62f2637
cd960c2
05676cb
5988922
d6d2859
da98ff6
ab03d2a
abc78ab
6813a46
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ Code freeze date: YYYY-MM-DD | |
- Update `CONTRIBUTING.md` to better explain types of contributions to this repository [#797](https://github.com/CLIMADA-project/climada_python/pull/797) | ||
- The default tile layer in Exposures maps is not Stamen Terrain anymore, but [CartoDB Positron](https://github.com/CartoDB/basemap-styles). Affected methods are `climada.engine.Impact.plot_basemap_eai_exposure`,`climada.engine.Impact.plot_basemap_impact_exposure` and `climada.entity.Exposures.plot_basemap`. [#798](https://github.com/CLIMADA-project/climada_python/pull/798) | ||
- Recommend using Mamba instead of Conda for installing CLIMADA [#809](https://github.com/CLIMADA-project/climada_python/pull/809) | ||
- Centroids complete overhaul. Most function should be backward compatible. Internal data is stored in a geodataframe attribute. Raster are now stored as points, and the meta attribute is removed. The methods to read matlab files were removed. [#787](https://github.com/CLIMADA-project/climada_python/pull/787) | ||
|
||
### Fixed | ||
|
||
|
@@ -30,6 +31,7 @@ Code freeze date: YYYY-MM-DD | |
### Deprecated | ||
|
||
### Removed | ||
- Read/write matlab file methods for Centroids and Hazard objects. [#787](https://github.com/CLIMADA-project/climada_python/pull/787) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, the obsolete The list of removed methods from I'm actually tempted to formally add them as deprecated methods, that, i.g., fails with a warning message explaining how to deal with the changed situation. Some can even be implemented ( |
||
|
||
## 4.0.1 | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -35,16 +35,15 @@ | |||||
from climada.test import get_test_file | ||||||
|
||||||
|
||||||
HAZ_TEST_MAT = get_test_file('atl_prob_no_name') | ||||||
ENT_TEST_MAT = get_test_file('demo_today', file_format='MAT-file') | ||||||
|
||||||
HAZ_TEST_TC :Path = get_test_file('test_tc_florida') | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
class TestSteps(unittest.TestCase): | ||||||
"""Test intermediate steps""" | ||||||
def test_calc_impact_measures_pass(self): | ||||||
"""Test _calc_impact_measures against reference value""" | ||||||
self.assertTrue(HAZ_TEST_MAT.is_file(), "{} is not a file".format(HAZ_TEST_MAT)) | ||||||
hazard = Hazard.from_mat(HAZ_TEST_MAT) | ||||||
self.assertTrue(HAZ_TEST_TC.is_file(), "{} is not a file".format(HAZ_TEST_TC)) | ||||||
hazard = Hazard.from_hdf5(HAZ_TEST_TC) | ||||||
|
||||||
self.assertTrue(ENT_TEST_MAT.is_file(), "{} is not a file".format(ENT_TEST_MAT)) | ||||||
entity = Entity.from_mat(ENT_TEST_MAT) | ||||||
|
@@ -230,7 +229,7 @@ def test_cb_one_meas_fut_pass(self): | |||||
|
||||||
def test_calc_cb_no_change_pass(self): | ||||||
"""Test _calc_cost_benefit without present value against reference value""" | ||||||
hazard = Hazard.from_mat(HAZ_TEST_MAT) | ||||||
hazard = Hazard.from_hdf5(HAZ_TEST_TC) | ||||||
entity = Entity.from_mat(ENT_TEST_MAT) | ||||||
entity.measures._data['TC'] = entity.measures._data.pop('XX') | ||||||
for meas in entity.measures.get_measure('TC'): | ||||||
|
@@ -267,7 +266,7 @@ def test_calc_cb_no_change_pass(self): | |||||
|
||||||
def test_calc_cb_change_pass(self): | ||||||
"""Test _calc_cost_benefit with present value against reference value""" | ||||||
hazard = Hazard.from_mat(HAZ_TEST_MAT) | ||||||
hazard = Hazard.from_hdf5(HAZ_TEST_TC) | ||||||
entity = Entity.from_mat(ENT_TEST_MAT) | ||||||
entity.measures._data['TC'] = entity.measures._data.pop('XX') | ||||||
for meas in entity.measures.get_measure('TC'): | ||||||
|
@@ -438,7 +437,7 @@ def test_norm_value(self): | |||||
|
||||||
def test_combine_fut_pass(self): | ||||||
"""Test combine_measures with present and future""" | ||||||
hazard = Hazard.from_mat(HAZ_TEST_MAT) | ||||||
hazard = Hazard.from_hdf5(HAZ_TEST_TC) | ||||||
entity = Entity.from_excel(ENT_DEMO_TODAY) | ||||||
entity.check() | ||||||
entity.exposures.ref_year = 2018 | ||||||
|
@@ -498,7 +497,7 @@ def test_combine_fut_pass(self): | |||||
|
||||||
def test_combine_current_pass(self): | ||||||
"""Test combine_measures with only future""" | ||||||
hazard = Hazard.from_mat(HAZ_TEST_MAT) | ||||||
hazard = Hazard.from_hdf5(HAZ_TEST_TC) | ||||||
entity = Entity.from_excel(ENT_DEMO_TODAY) | ||||||
entity.check() | ||||||
entity.exposures.ref_year = 2018 | ||||||
|
@@ -538,7 +537,7 @@ def test_combine_current_pass(self): | |||||
|
||||||
def test_apply_transf_current_pass(self): | ||||||
"""Test apply_risk_transfer with only future""" | ||||||
hazard = Hazard.from_mat(HAZ_TEST_MAT) | ||||||
hazard = Hazard.from_hdf5(HAZ_TEST_TC) | ||||||
entity = Entity.from_excel(ENT_DEMO_TODAY) | ||||||
entity.check() | ||||||
entity.exposures.ref_year = 2018 | ||||||
|
@@ -588,7 +587,7 @@ def test_apply_transf_current_pass(self): | |||||
|
||||||
def test_apply_transf_cost_fact_pass(self): | ||||||
"""Test apply_risk_transfer with only future annd cost factor""" | ||||||
hazard = Hazard.from_mat(HAZ_TEST_MAT) | ||||||
hazard = Hazard.from_hdf5(HAZ_TEST_TC) | ||||||
entity = Entity.from_excel(ENT_DEMO_TODAY) | ||||||
entity.check() | ||||||
entity.exposures.ref_year = 2018 | ||||||
|
@@ -636,7 +635,7 @@ def test_apply_transf_cost_fact_pass(self): | |||||
|
||||||
def test_apply_transf_future_pass(self): | ||||||
"""Test apply_risk_transfer with present and future""" | ||||||
hazard = Hazard.from_mat(HAZ_TEST_MAT) | ||||||
hazard = Hazard.from_hdf5(HAZ_TEST_TC) | ||||||
entity = Entity.from_excel(ENT_DEMO_TODAY) | ||||||
entity.check() | ||||||
entity.exposures.ref_year = 2018 | ||||||
|
@@ -692,7 +691,7 @@ def test_apply_transf_future_pass(self): | |||||
|
||||||
def test_remove_measure(self): | ||||||
"""Test remove_measure method""" | ||||||
hazard = Hazard.from_mat(HAZ_TEST_MAT) | ||||||
hazard = Hazard.from_hdf5(HAZ_TEST_TC) | ||||||
entity = Entity.from_excel(ENT_DEMO_TODAY) | ||||||
entity.check() | ||||||
entity.exposures.ref_year = 2018 | ||||||
|
@@ -720,7 +719,7 @@ class TestCalc(unittest.TestCase): | |||||
def test_calc_change_pass(self): | ||||||
"""Test calc with future change""" | ||||||
# present | ||||||
hazard = Hazard.from_mat(HAZ_TEST_MAT) | ||||||
hazard = Hazard.from_hdf5(HAZ_TEST_TC) | ||||||
entity = Entity.from_excel(ENT_DEMO_TODAY) | ||||||
entity.exposures.gdf.rename(columns={'impf_': 'impf_TC'}, inplace=True) | ||||||
entity.check() | ||||||
|
@@ -777,7 +776,7 @@ def test_calc_change_pass(self): | |||||
|
||||||
def test_calc_no_change_pass(self): | ||||||
"""Test calc without future change""" | ||||||
hazard = Hazard.from_mat(HAZ_TEST_MAT) | ||||||
hazard = Hazard.from_hdf5(HAZ_TEST_TC) | ||||||
entity = Entity.from_excel(ENT_DEMO_TODAY) | ||||||
entity.check() | ||||||
entity.exposures.ref_year = 2018 | ||||||
|
@@ -808,7 +807,7 @@ class TestRiskFuncs(unittest.TestCase): | |||||
def test_impact(self): | ||||||
ent = Entity.from_excel(ENT_DEMO_TODAY) | ||||||
ent.check() | ||||||
hazard = Hazard.from_mat(HAZ_TEST_MAT) | ||||||
hazard = Hazard.from_hdf5(HAZ_TEST_TC) | ||||||
impact = ImpactCalc(ent.exposures, ent.impact_funcs, hazard).impact() | ||||||
return impact | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,7 +60,6 @@ def test_assign_pass(self): | |
np_rand = np.random.RandomState(123456789) | ||
|
||
haz = Hazard.from_raster([HAZ_DEMO_FL], haz_type='FL', window=Window(10, 20, 50, 60)) | ||
haz.raster_to_vector() | ||
ncentroids = haz.centroids.size | ||
|
||
exp = Exposures(crs=haz.centroids.crs) | ||
|
@@ -74,8 +73,8 @@ def test_assign_pass(self): | |
|
||
# make sure that it works for both float32 and float64 | ||
for test_dtype in [np.float64, np.float32]: | ||
haz.centroids.lat = haz.centroids.lat.astype(test_dtype) | ||
haz.centroids.lon = haz.centroids.lon.astype(test_dtype) | ||
haz.centroids.gdf.lat = haz.centroids.lat.astype(test_dtype) | ||
haz.centroids.gdf.lon = haz.centroids.lon.astype(test_dtype) | ||
exp.assign_centroids(haz) | ||
self.assertEqual(exp.gdf.shape[0], len(exp.gdf[INDICATOR_CENTR + 'FL'])) | ||
np.testing.assert_array_equal(exp.gdf[INDICATOR_CENTR + 'FL'].values, expected_result) | ||
|
@@ -131,7 +130,7 @@ def test_assign_raster_pass(self): | |
'width': 20, 'height': 10, | ||
'transform': rasterio.Affine(1.5, 0.0, -20, 0.0, -1.4, 8) | ||
} | ||
haz = Hazard('FL', centroids=Centroids(meta=meta)) | ||
haz = Hazard('FL', centroids=Centroids.from_meta(meta)) | ||
|
||
# explicit points with known results (see `expected_result` for details) | ||
exp = Exposures(crs=DEF_CRS) | ||
|
@@ -151,9 +150,9 @@ def test_assign_raster_pass(self): | |
|
||
expected_result = [ | ||
# constant y-value, varying x-value | ||
-1, 0, 0, 0, 0, 1, | ||
0, 0, 0, 0, 0, 1, | ||
# constant x-value, varying y-value | ||
-1, 0, 0, 20, | ||
0, 0, 0, 20, | ||
# out of bounds: topleft, top, topright, right, bottomright, bottom, bottomleft, left | ||
-1, -1, -1, -1, -1, -1, -1, -1, | ||
# some explicit points within the raster | ||
|
@@ -171,18 +170,20 @@ def test_assign_raster_same_pass(self): | |
np.testing.assert_array_equal(exp.gdf[INDICATOR_CENTR + 'FL'].values, | ||
np.arange(haz.centroids.size, dtype=int)) | ||
|
||
# Test fails because exposures stores the crs in the meta attribute as rasterio object, | ||
# while the centroids stores the crs in the geodataframe, which is not a rasterio object. | ||
# The comparison in assign_centroids then fails. | ||
def test_assign_large_hazard_subset_pass(self): | ||
"""Test assign_centroids with raster hazard""" | ||
exp = Exposures.from_raster(HAZ_DEMO_FL, window=Window(10, 20, 50, 60)) | ||
exp.gdf.latitude[[0, 1]] = exp.gdf.latitude[[1, 0]] | ||
exp.gdf.longitude[[0, 1]] = exp.gdf.longitude[[1, 0]] | ||
exp.check() | ||
haz = Hazard.from_raster([HAZ_DEMO_FL], haz_type='FL') | ||
haz.raster_to_vector() | ||
exp.assign_centroids(haz) | ||
assigned_centroids = haz.centroids.select(sel_cen=exp.gdf[INDICATOR_CENTR + 'FL'].values) | ||
np.testing.assert_array_equal(assigned_centroids.lat, exp.gdf.latitude) | ||
np.testing.assert_array_equal(assigned_centroids.lon, exp.gdf.longitude) | ||
np.testing.assert_array_equal(np.unique(assigned_centroids.lat), np.unique(exp.gdf.latitude)) | ||
np.testing.assert_array_equal(np.unique(assigned_centroids.lon), np.unique(exp.gdf.longitude)) | ||
Comment on lines
+185
to
+186
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. er - why the |
||
|
||
def test_affected_total_value(self): | ||
haz_type = "RF" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we list the functions that are known to have changed?
u_coord.match_centroids
? (s.b.)