-
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
Merged
Merged
Changes from 119 commits
Commits
Show all changes
223 commits
Select commit
Hold shift + click to select a range
8cf5e0a
Add geodataframe to centroids: first commit
e2a2a05
Merge branch 'develop' into feature/centroids_as_gdf
89b4051
Remove raster methods, obsolete methods, and fix some.
70ea2fb
Remove test for removed methods
e34bc0f
Fix from geodataframe method
02b4a8b
Remove set meta to lat lon
5ede9bd
Update all I/O methods
98a898e
Remove area pixel
c77a2d9
Add method to compute the area per pixel (not attribute)
913c0f1
Make get_area_pixel
5ec2859
Remove not often used dist_coast and elevation
e2ac9b7
Remove unused meta
5dd4ffe
Change Centroids call to new signature
950a722
Remove vector - raster hazard methods
923b066
Restore legacy excell reader
abfff60
Remove clear method
8e360e6
Remove clear test
73c4392
Update read/write centroids in hazard
0dc0abb
Support empty on land or region id
c2f626a
Check for empty region id
bdf77d2
Set region id correctly
cf0128d
Remove scheduler
4f40def
Add docstring
5f520fb
Add legacy read hdf5
7c24df0
Replace incorrect dot product
e4bb789
Remove meta in assign centroids
3df5a4b
Remove matlab test file
7206446
Update set lat/lon
d4d5e02
Update test with init
178e624
'Automated update v4.0.0'
climada-jenkins a94d7af
Add note on method
827c15b
Merge branch 'develop'
emanuel-schmid e41191d
changelog: for 4.0.1
emanuel-schmid e412222
'Automated update v4.0.1'
climada-jenkins df6c3f4
Merge tag 'v4.0.1' into feature/centroids_as_gdf
cbab08e
Add from_meta class method
5aeb35e
Update centroids init
fb374d3
Update read raster intensity / fraction data
4119f33
Merge branch 'develop' into feature/centroids_as_gdf
2390c5a
undo changelog duplications
emanuel-schmid 4b1279e
Merge branch 'develop' into feature/centroids_as_gdf
315f7d9
Update test for points outside of raster within threshold
2b1ac74
Docstring and cosmetics
bab8c70
Add to default crs method
fe96975
Fix legacy from hdf5 for empty extra values
a4cf3ce
Update legacy from_hdf5 to exclude 'latitude'/'longitude' from extra
9ce8e56
Merge remote-tracking branch 'origin/develop' into feature/centroids_…
b22677f
Update centroids.select to work properly with mask and indices
1946bca
Fix forecast translate bug
b2c0c74
Remove _set_centroids
6226bff
Remove reproject raster
dc8d638
Remove test hazard raster
7002a52
Update naming for plot fraction centroids
73ee79e
Replace HAZ_DEMO_MAT with HAZ_TEST_TC
0cabeac
Replace mat file with hdf5 test file
3729248
Rewrite write raster method for hazard
6c3d1ac
Add a default for sel_cen in mask
8b15107
Correct indent typos
f3af2dd
Change duplicate test function name
5888dea
Replace mat file with hdf5
e22c857
Remove unused mat file import
847736b
Add legacy code to read old centroid hdf5 files.
756c587
Update access to centroids dist coast in gdf
e015000
test_trop_cyclone: get test centroids from data api
emanuel-schmid b0dfd66
Merge remote-tracking branch 'origin/develop' into feature/centroids_…
emanuel-schmid cfecf10
Add method to estimate meta raster from centroids
510f53f
Remove unecessary conversion to ne_geom
e108432
Add good lat/lon values for unit test
5571755
centroids.centr.write_hdf5: eliminate side effect
emanuel-schmid baf88a0
centroids.centr.write_hdf5: elimination of side effect futile for pan…
emanuel-schmid 5b37116
centroids.test.TestCentroidsFuns.test_select_pass: adapt to downsized…
emanuel-schmid 78811c5
test_vec_ras: fix TestCentroids.test_centroids_check_pass
emanuel-schmid 84de9bf
test_vec_ras: remove TestReader.test_write_read_points_h5 as it is re…
emanuel-schmid 1ab1b69
fix typo in from_exposures method
sarah-hlsn 19b02a5
centroids.centr.from_csv: write class method
sarah-hlsn 5e4e03d
centroids.centr.from_csv: correct order of xy
sarah-hlsn a426247
centroids.centr.from_excel: update method for gdf
sarah-hlsn c60e50f
centroids.centr. update csv and excel methods
sarah-hlsn ae6a0cc
Update tests in test_vec_ras
fbf28d4
Update more tests and remove some with meta
b3ae8c4
Merge remote-tracking branch 'origin/feature/centroids_as_gdf' into f…
sarah-hlsn 929f0e1
centroids.centr.from_excel fix columnn indexing
sarah-hlsn 17ee8b1
Add possibility to NOT recenter crs for countires.
e58aef2
Add to_csre convenience method
b70a0f4
Prepare the stage for setting other than admin0 region id
494d416
Remove uneeded import
448cf77
cenctroids.centr: fix the obvious
emanuel-schmid c736356
gencenctroids.centr: change crs of the geodataframe instead of the ge…
emanuel-schmid 2880bcc
white space cosmetics
emanuel-schmid 8cc88e7
PEP8
emanuel-schmid 11a6439
Add solid region id and on land tests
a1fce1d
Merge branch 'feature/centroids_as_gdf' of https://github.com/CLIMADA…
bfcfc01
Auto stash before merge of "feature/centroids_as_gdf" and "origin/fea…
4a4aed7
Update distance and area tests
4460955
Update set crs in load vector shape file
37c54ea
centr.Centroids.from_excel: deal with region_id column
emanuel-schmid e4bc0db
Merge branch 'feature/centroids_as_gdf' of github.com:CLIMADA-project…
emanuel-schmid b02ae1d
Fix write hazard raster with centroids.get_meta
cf3f6e5
Merge branch 'feature/centroids_as_gdf' of https://github.com/CLIMADA…
sarah-hlsn b3448d0
Area pixel now correctly uses CEA
2beb6a3
Add actual NE CRS test.
a7eb166
Make on_land and region_id always part of centroids
147ee0d
Update docstring
445194b
Update import path
425b9ce
Add overwrite argument to set region id and on land
b879ca6
Remove from base grid method
d63fc8b
Fix some linting
70928bd
Add some docstrings
b97491c
Avoid costly computation in from geodataframe
d9e98ce
Add comment
274cf20
Fix typo
8101e3d
Merge branch 'feature/centroids_as_gdf' of https://github.com/CLIMADA…
sarah-hlsn 42634bb
Fix set crs in from geodataframe
8727895
Make properties return arrays and not series
429e74c
Remove not needed matlab vars
fb7c7cc
Revert return numpy arrays.
dd212db
update from excel
sarah-hlsn 5996714
Merge branch 'feature/centroids_as_gdf' of https://github.com/CLIMADA…
sarah-hlsn 164e689
update from_excel and from_csv
sarah-hlsn 4079f3f
centroids.centr: from_excel fix column renaming and adapt to "new arg…
emanuel-schmid dd7e4cd
Centroids.from_excel fix: switch key,val in test_storm_europe rather …
emanuel-schmid f6b72ed
Return numpy arrays instead of series
61f3c6b
Add some basic tests
adce3c1
Add tests for meta
9653e98
Add tentative changelog.
8e13e61
Make keywords argument only : name lat/lon : remove set_*
43c2f1b
Auto stash before revert of "Make keywords argument only : name lat/l…
32a4be9
remove file
d1475d8
Merge branch 'local/geodataframe_temp' into feature/centroids_as_gdf
2464066
Fix exposures method test
bd5629c
Merge remote-tracking branch 'origin/develop' into feature/centroids_…
d031a79
Fix setting region id and on land at init.
a1040f8
Fix typo
a748ee0
Fix all close values for big numbers
652a2b8
Improve cosmetics.
6806331
update docstrings, doc cosmetics
idetring 25a0930
update from_csv method, add test
sarah-hlsn 5849acb
remove DEF_VAR_CSV
sarah-hlsn 84107ee
Update from_excel method and test
sarah-hlsn bfb24d7
remove unnecessary import
sarah-hlsn 67a1d60
fix storm_europe tests
sarah-hlsn 8f25d1f
improve csv and excel tests
sarah-hlsn 0f54053
Apply suggestions from code review
chahank c4bb540
add excel, csv write methods and tests
sarah-hlsn 3f4ebb6
Merge branch 'feature/centroids_as_gdf' of https://github.com/CLIMADA…
sarah-hlsn c7e6ffd
Replace gdf with _gdf
79cd84b
Revert "Replace gdf with _gdf"
e5dffd9
Update to_crs methods
1f6ec54
Raise error if wrong exposures
f59278c
Make from geodataframe more restrictive.
4c641dc
Use consistently to_crs method
e5c1c73
Improve read centroids
26e2702
Add literal to import
e6fa996
Update to crs with inplace argument
37b5d19
improve excel, csv method, test based on review
sarah-hlsn 622d326
Update typing
a7311a0
Fix equal centroids for different gdf columns ordering
99203ad
Make consistent gdf column ordering
e5cd4ad
Simplify from excel/csv
58360a5
Add support for legacy hazard excell
2f248b8
Avoid single column loading error for df
19cae86
fix path in write_excel, write_csv
sarah-hlsn 19fe589
fixing docstrings in centr.py
idetring 5ccc278
Update code cosmetics
ee512ca
Fix typo
4053565
Allo for kwargs in init and update from exposures
fc0c7ec
Merge branch 'develop' into feature/centroids_as_gdf
emanuel-schmid a30a7c4
Merge branch 'feature/centroids_as_gdf' of https://github.com/CLIMADA…
emanuel-schmid 5404dba
Merge branch 'develop' into feature/centroids_as_gdf
emanuel-schmid 4d62101
code linting
1ba2ade
Centroids: test from_meta
62df2dd
Centroids: refined tests
a7b8cf9
Centroids: fix from_exposures
e514195
Centroids: implement get_pixel_shapes
ec11611
Centroids: code linting and docstrings
e77af81
hazard.test.test_base: remove undefined classes from main
emanuel-schmid bba7e49
hazard.base: remove unused imports
emanuel-schmid 655b749
hazard.base: clean up imports
03676d8
Merge branch 'develop' into feature/centroids_as_gdf
emanuel-schmid 7dfa631
cosmetics
emanuel-schmid eda2755
hazard.base.write_htdf5: add inline comment.
emanuel-schmid 8fcf3b3
Centroids: fix _gdf_from_legacy_hdf signature
emanuel-schmid 57fd369
Centroids._gdf_from_legacy_hdf5: static, not classmethod
4ffd744
Merge branch 'develop' into feature/centroids_as_gdf
emanuel-schmid ddb6dcc
hazard.centroids.centr: pylint
emanuel-schmid bd1f9fd
centroids.centr : fix pydoc typos and pylint
emanuel-schmid 31aba1c
climada.hazard.base: pylint
emanuel-schmid b84a76d
hazard.centroids.centr: pylint
emanuel-schmid b1b0efa
climada.test.test_calicbration: use hzard test file with hdf5 format
emanuel-schmid 473bc9d
Update climada/hazard/centroids/test/test_vec_ras.py
tovogt 017864e
Hazard: fix write_raster, and some docstrings
441fbb1
test.test_calibration: fix test file name
emanuel-schmid 0cd3530
Merge branch 'feature/centroids_as_gdf' of github.com:CLIMADA-project…
emanuel-schmid db748c7
test_api_client: added test for basic centroids plotting
emanuel-schmid 5863cb2
centr.Centroids.plot: all changes reverted
emanuel-schmid 3dd4a50
Hazard tutorial: use centroids.get_meta() instead of the attribute meta
emanuel-schmid 065c868
Hazard tutorial: use Centroids() instead of from_lat_lon()
emanuel-schmid 5e1d9ff
Merge branch 'develop' into feature/centroids_as_gdf
emanuel-schmid f6f7db8
hazard tutorial: update Hazard from raster section
emanuel-schmid ead5e05
hazard tutorial: fix dist_coast access
emanuel-schmid 693af77
climada.hazard.Hazard: remove broken vector file support
emanuel-schmid 1f45167
Merge branch 'develop' into feature/centroids_as_gdf
emanuel-schmid bc75e0f
climada.hazard.centr: add deprecated methods section
emanuel-schmid 31409cd
Merge branch 'develop' into feature/centroids_as_gdf
emanuel-schmid e59eb18
fix from_tracks method, remove side effect
emanuel-schmid 0ad0804
climada.hazard.trop_cyclone.TropCytlone.from_tracks: option for prede…
emanuel-schmid 88b320a
TropicalCyclone.from_tracks pydoc
emanuel-schmid b543636
white space cosmetics
emanuel-schmid 5f3904b
CHANGELOG: list deprecated and removed methods
emanuel-schmid 7b009e9
Refactor and add to centroids testing
idetring eac96d8
Merge branch 'develop' into feature/centroids_as_gdf
emanuel-schmid daa9812
Merge branch 'develop' into feature/centroids_as_gdf
emanuel-schmid 53bd89c
Merge branch 'develop' into feature/centroids_as_gdf
emanuel-schmid 5fba7f6
trop_cyclone.TropCyclone.from_tracks: fix dist_coast type
emanuel-schmid 62f2637
climada.hazard.Centroids: raise exception in deprecated methods that …
emanuel-schmid cd960c2
changelog: list added Centroids methods
emanuel-schmid 05676cb
hazard.centr: depreecated methods: pydoc string instaed of pass
emanuel-schmid 5988922
Merge branch 'develop' into feature/centroids_as_gdf
emanuel-schmid d6d2859
fixing geodataframe issues
emanuel-schmid da98ff6
Merge branch 'develop' into feature/centroids_as_gdf
emanuel-schmid ab03d2a
Revert "fixing geodataframe issues"
emanuel-schmid abc78ab
centroids: deprecation warnings improved
emanuel-schmid 6813a46
Merge branch 'develop' into feature/centroids_as_gdf
emanuel-schmid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
@@ -196,7 +197,7 @@ def test_affected_total_value(self): | |
) | ||
exp = Exposures(gdf, crs=4326) | ||
intensity = sp.sparse.csr_matrix(np.array([[0, 0, 1, 10, 2], [-1, 0, 0, 1, 2]])) | ||
cent = Centroids(lat=np.array([1, 2, 3, 4]), lon=np.array([-1, -2, -3, -4])) | ||
cent = Centroids(latitude=np.array([1, 2, 3, 4]), longitude=np.array([-1, -2, -3, -4])) | ||
haz = Hazard( | ||
haz_type=haz_type, centroids=cent, intensity=intensity, event_id=[1, 2] | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.