Skip to content
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

exposures-init-geometry #890

Merged
merged 66 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
4859ba7
wip
emanuel-schmid May 15, 2024
98da61d
Merge branch 'develop' into feature/exposures_crs
emanuel-schmid May 15, 2024
57c81e5
climada.entity.Exposures rewrite __init__
emanuel-schmid May 15, 2024
42d0b39
wip
emanuel-schmid May 15, 2024
cd464ef
climada.entity.Exposures: refactor __init__
emanuel-schmid May 16, 2024
f0cc985
adaptations to changed Exposures structure: gdf.latitude and gdf.long…
emanuel-schmid May 16, 2024
7e8970b
adaptations to changed Exposures structure: gdf.latitude and gdf.long…
emanuel-schmid May 16, 2024
55753c9
adaptations to changed Exposures structure: gdf.latitude and gdf.long…
emanuel-schmid May 16, 2024
7233e34
centroids.Centroids.from_exposures() will always work as geometry col…
emanuel-schmid May 16, 2024
b0a0e65
adaptation to eliminated lat/lon columns
emanuel-schmid May 16, 2024
fa4e0f7
hazard.Centroids: region_id and on_land are not necessarily present i…
emanuel-schmid May 17, 2024
1036b79
Exposures() requires geometry or lat/lon
emanuel-schmid May 17, 2024
98f14d6
cangelog
emanuel-schmid May 17, 2024
2f57870
points_to_raster function getting more complicated,
emanuel-schmid May 17, 2024
715fea6
pydoc argument description fix
emanuel-schmid May 22, 2024
5f5f21a
Merge branch 'develop' into feature/exposures_crs
emanuel-schmid Jul 9, 2024
9aea03d
Merge branch 'develop' into feature/exposures_crs
emanuel-schmid Jul 10, 2024
55ce078
fix typo (bug really)
emanuel-schmid Jul 10, 2024
0775be2
exposures: remove meta from attributes
emanuel-schmid Jul 10, 2024
5104503
introduce exposures properties, region_id etc.
emanuel-schmid Jul 11, 2024
cb666dc
rename and use hazard_impf and hazard_centroids
emanuel-schmid Jul 11, 2024
ae3b91a
lint
emanuel-schmid Jul 11, 2024
1379eac
Exposures: rename pmeta property to _meta
emanuel-schmid Jul 11, 2024
5e5584d
Merge branch 'develop' into feature/exposures_crs
emanuel-schmid Jul 16, 2024
a4df7cf
Merge branch 'develop' into feature/exposures_crs
emanuel-schmid Aug 23, 2024
91f56eb
fix changelog
emanuel-schmid Aug 23, 2024
06ef584
Merge branch 'develop' into feature/exposures_crs
emanuel-schmid Aug 23, 2024
4a12e2a
exposures: gracefully handle empty exposures
emanuel-schmid Aug 26, 2024
eeb51b2
exposures: linting
emanuel-schmid Aug 26, 2024
2d93e4d
Update climada/entity/exposures/base.py
emanuel-schmid Aug 26, 2024
456720b
petals compatibility test: try and switch the petals branch
emanuel-schmid Aug 26, 2024
5e9f6f4
Merge branch 'develop' into feature/exposures_crs
emanuel-schmid Sep 9, 2024
92eb4ae
Merge branch 'develop' into feature/exposures_crs
emanuel-schmid Sep 9, 2024
b843362
fix merging mistake
emanuel-schmid Sep 10, 2024
73252ed
deprecate set_geomety_points
emanuel-schmid Sep 16, 2024
ab80a98
deprecate set_geomety_points
emanuel-schmid Sep 16, 2024
ce33777
remove properties and methods from the pydoc attributes section
emanuel-schmid Sep 16, 2024
98e248c
typo
emanuel-schmid Sep 16, 2024
231ba57
typo
emanuel-schmid Sep 16, 2024
1c229f0
deprecate set_geomety_points
emanuel-schmid Sep 16, 2024
f5221e2
Exposures.__init__: no need for a temporary geodataframe
emanuel-schmid Sep 16, 2024
f93b0df
Exposures.base: amend pydocs
emanuel-schmid Sep 16, 2024
32b48f0
Exposures.base: use get_impf_column in hazard_impf
emanuel-schmid Sep 16, 2024
7e58137
pydoc Exposures.__init__
emanuel-schmid Sep 16, 2024
88ebfbc
pydoc Exposures.__init__
emanuel-schmid Sep 16, 2024
5b3e071
changelog updates
emanuel-schmid Sep 16, 2024
689a032
deprecate set_geomety_points
emanuel-schmid Sep 16, 2024
70fd104
Merge branch 'develop' into feature/exposures_crs
emanuel-schmid Sep 23, 2024
c15ec0d
jenkins: align with petals
emanuel-schmid Sep 23, 2024
bc87f51
Merge branch 'develop' into feature/exposures_crs
emanuel-schmid Oct 4, 2024
ed9d6ce
exposures tutorial: listing attributes and properties
emanuel-schmid Oct 4, 2024
e1800f5
exposures: don't do anything in check, update Tutorial
emanuel-schmid Oct 4, 2024
4a7c65c
Merge branch 'develop' into feature/exposures_crs
emanuel-schmid Oct 20, 2024
822c7f1
format
emanuel-schmid Oct 20, 2024
1b78bdf
import Impact from climada.engine.impact
emanuel-schmid Oct 20, 2024
87cb6fd
avoid circular imports
emanuel-schmid Oct 20, 2024
b9be992
Merge branch 'develop' into develop-black
emanuel-schmid Oct 20, 2024
5143b99
pre-commit run --all-files
emanuel-schmid Oct 20, 2024
bc60010
setup: DEPS_TEST update
emanuel-schmid Oct 20, 2024
7c13bc9
Merge branch 'develop-white' into feature/exposures_crs
emanuel-schmid Oct 20, 2024
f88825f
format all
emanuel-schmid Oct 20, 2024
038c4cd
Merge branch 'develop-black' into feature/exposures_crs
emanuel-schmid Oct 20, 2024
706ad6c
Merge branch 'develop' into feature/exposures_crs
emanuel-schmid Oct 20, 2024
696f6cb
Merge branch 'develop' into feature/exposures_crs
emanuel-schmid Oct 21, 2024
4d52d9b
exposures tutorial: add information about optional columns
emanuel-schmid Oct 21, 2024
06477e8
clean up tutorials
emanuel-schmid Oct 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ Code freeze date: YYYY-MM-DD
### Added

- GitHub actions workflow for CLIMADA Petals compatibility tests [#855](https://github.com/CLIMADA-project/climada_python/pull/855)
- Generic s-shaped impact function via `ImpactFunc.from_poly_s_shape` [#878](https://github.com/CLIMADA-project/climada_python/pull/878)
- climada.hazard.centroids.centr.Centroids.get_area_pixel
- climada.hazard.centroids.centr.Centroids.get_dist_coast
- climada.hazard.centroids.centr.Centroids.get_elevation
- climada.hazard.centroids.centr.Centroids.get_meta
- climada.hazard.centroids.centr.Centroids.get_pixel_shapes
- climada.hazard.centroids.centr.Centroids.to_crs
- climada.hazard.centroids.centr.Centroids.to_default_crs
- climada.hazard.centroids.centr.Centroids.write_csv
- climada.hazard.centroids.centr.Centroids.write_excel
- climada.exposures.exposures.Exposures.geometry
- climada.exposures.exposures.Exposures.latitude
- climada.exposures.exposures.Exposures.longitude
- climada.exposures.exposures.Exposures.value
- `climada.util.calibrate` module for calibrating impact functions [#692](https://github.com/CLIMADA-project/climada_python/pull/692)

### Changed
Expand All @@ -23,6 +37,8 @@ Code freeze date: YYYY-MM-DD
- Remove content tables and make minor improvements (fix typos and readability) in
CLIMADA tutorials. [#872](https://github.com/CLIMADA-project/climada_python/pull/872)
- 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. Several methds were deprecated or removed. [#787](https://github.com/CLIMADA-project/climada_python/pull/787)
- Exposures complete overhaul. Notably the _geometry_ column of the inherent `GeoDataFrame` is set up at initialization, while
latitude and longitude column are no longer persent there (the according arrays can be retrieved as properties of the Exposures object: `exp.latitude` instead of `exp.gdf.latitude.values`).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
latitude and longitude column are no longer persent there (the according arrays can be retrieved as properties of the Exposures object: `exp.latitude` instead of `exp.gdf.latitude.values`).
latitude and longitude column are no longer present there (the according arrays can be retrieved as properties of the Exposures object: `exp.latitude` instead of `exp.gdf["latitude"].values`).

- Improved error messages produced by `ImpactCalc.impact()` in case impact function in the exposures is not found in impf_set [#863](https://github.com/CLIMADA-project/climada_python/pull/863)
- Update the Holland et al. 2010 TC windfield model and introduce `model_kwargs` parameter to adjust model parameters [#846](https://github.com/CLIMADA-project/climada_python/pull/846)
- Changed module structure: `climada.hazard.Hazard` has been split into the modules `base`, `io` and `plot` [#871](https://github.com/CLIMADA-project/climada_python/pull/871)
Expand All @@ -37,19 +53,6 @@ CLIMADA tutorials. [#872](https://github.com/CLIMADA-project/climada_python/pull
- Fix broken links in `CONTRIBUTING.md` [#900](https://github.com/CLIMADA-project/climada_python/pull/900)
- When writing `TCTracks` to NetCDF, only apply compression to `float` or `int` data types. This fixes a downstream issue, see [climada_petals#135](https://github.com/CLIMADA-project/climada_petals/issues/135) [#911](https://github.com/CLIMADA-project/climada_python/pull/911)

### Added

- Generic s-shaped impact function via `ImpactFunc.from_poly_s_shape` [#878](https://github.com/CLIMADA-project/climada_python/pull/878)
- climada.hazard.centroids.centr.Centroids.get_area_pixel
- climada.hazard.centroids.centr.Centroids.get_dist_coast
- climada.hazard.centroids.centr.Centroids.get_elevation
- climada.hazard.centroids.centr.Centroids.get_meta
- climada.hazard.centroids.centr.Centroids.get_pixel_shapes
- climada.hazard.centroids.centr.Centroids.to_crs
- climada.hazard.centroids.centr.Centroids.to_default_crs
- climada.hazard.centroids.centr.Centroids.write_csv
- climada.hazard.centroids.centr.Centroids.write_excel

### Deprecated

- climada.hazard.centroids.centr.Centroids.from_lat_lon
Expand All @@ -59,6 +62,8 @@ CLIMADA tutorials. [#872](https://github.com/CLIMADA-project/climada_python/pull
- climada.hazard.centroids.centr.Centroids.empty_geometry_points
- climada.hazard.centroids.centr.Centroids.set_meta_to_lat_lon
- climada.hazard.centroids.centr.Centroids.set_lat_lon_to_meta
- climada.entity.exposures.Exposures.set_lat_lon
- climada.entity.exposures.Exposures.set_geometry_points

### Removed

Expand Down
2 changes: 1 addition & 1 deletion climada/engine/forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def __init__(
if exposure_name is None:
try:
self.exposure_name = u_coord.country_to_iso(
exposure.gdf.region_id.unique()[0], "name"
np.unique(exposure.region_id)[0], "name"
)
except (KeyError, AttributeError):
self.exposure_name = "custom"
Expand Down
4 changes: 2 additions & 2 deletions climada/engine/impact.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ def from_eih(cls, exposures, hazard, at_event, eai_exp, aai_agg, imp_mat=None):
date = hazard.date,
frequency = hazard.frequency,
frequency_unit = hazard.frequency_unit,
coord_exp = np.stack([exposures.gdf.latitude.values,
exposures.gdf.longitude.values],
coord_exp = np.stack([exposures.latitude,
exposures.longitude],
axis=1),
crs = exposures.crs,
unit = exposures.value_unit,
Expand Down
14 changes: 7 additions & 7 deletions climada/engine/test/test_impact.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_from_eih_pass(self):
np.testing.assert_array_almost_equal(imp.at_event, fake_at_event)
np.testing.assert_array_almost_equal(
imp.coord_exp,
np.stack([exp.gdf.latitude.values, exp.gdf.longitude.values], axis=1)
np.stack([exp.latitude, exp.longitude], axis=1)
)

def test_pyproj_crs(self):
Expand Down Expand Up @@ -910,9 +910,9 @@ def test__build_exp(self):

imp = dummy_impact()
exp = imp._build_exp()
np.testing.assert_array_equal(imp.eai_exp, exp.gdf['value'])
np.testing.assert_array_equal(imp.coord_exp[:, 0], exp.gdf['latitude'])
np.testing.assert_array_equal(imp.coord_exp[:, 1], exp.gdf['longitude'])
np.testing.assert_array_equal(imp.eai_exp, exp.value)
np.testing.assert_array_equal(imp.coord_exp[:, 0], exp.latitude)
np.testing.assert_array_equal(imp.coord_exp[:, 1], exp.longitude)
self.assertTrue(u_coord.equal_crs(exp.crs, imp.crs))
self.assertEqual(exp.value_unit, imp.unit)
self.assertEqual(exp.ref_year, 0)
Expand All @@ -923,9 +923,9 @@ def test__exp_build_event(self):
imp = dummy_impact()
event_id = imp.event_id[1]
exp = imp._build_exp_event(event_id=event_id)
np.testing.assert_array_equal(imp.imp_mat[1].todense().A1, exp.gdf['value'])
np.testing.assert_array_equal(imp.coord_exp[:, 0], exp.gdf['latitude'])
np.testing.assert_array_equal(imp.coord_exp[:, 1], exp.gdf['longitude'])
np.testing.assert_array_equal(imp.imp_mat[1].todense().A1, exp.value)
np.testing.assert_array_equal(imp.coord_exp[:, 0], exp.latitude)
np.testing.assert_array_equal(imp.coord_exp[:, 1], exp.longitude)
self.assertTrue(u_coord.equal_crs(exp.crs, imp.crs))
self.assertEqual(exp.value_unit, imp.unit)
self.assertEqual(exp.ref_year, 0)
Expand Down
14 changes: 10 additions & 4 deletions climada/engine/test/test_impact_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ def check_impact(self, imp, haz, exp, aai_agg, eai_exp, at_event, imp_mat_array=
"""Test properties of imapcts"""
self.assertEqual(len(haz.event_id), len(imp.at_event))
self.assertIsInstance(imp, Impact)
np.testing.assert_allclose(imp.coord_exp[:,0], exp.gdf.latitude)
np.testing.assert_allclose(imp.coord_exp[:,1], exp.gdf.longitude)
np.testing.assert_allclose(imp.coord_exp[:,0], exp.latitude)
np.testing.assert_allclose(imp.coord_exp[:,1], exp.longitude)
self.assertAlmostEqual(imp.aai_agg, aai_agg, 3)
np.testing.assert_allclose(imp.eai_exp, eai_exp, rtol=1e-5)
np.testing.assert_allclose(imp.at_event, at_event, rtol=1e-5)
Expand Down Expand Up @@ -414,7 +414,10 @@ def test_minimal_exp_gdf(self):

def test_stitch_impact_matrix(self):
"""Check how sparse matrices from a generator are stitched together"""
icalc = ImpactCalc(Exposures({'blank': [1, 2, 3, 4]}), ImpactFuncSet(), Hazard())
icalc = ImpactCalc(Exposures(
{"blank": [1, 2, 3, 4]},
geometry = [],
), ImpactFuncSet(), Hazard())
icalc.hazard.event_id = np.array([1, 2, 3])
icalc._orig_exp_idx = np.array([0, 1, 2, 3])

Expand Down Expand Up @@ -445,7 +448,10 @@ def test_apply_deductible_to_mat(self):

def test_stitch_risk_metrics(self):
"""Test computing risk metrics from an impact matrix generator"""
icalc = ImpactCalc(Exposures({'blank': [1, 2, 3]}), ImpactFuncSet(), Hazard())
icalc = ImpactCalc(Exposures(
{"blank": [1, 2, 3]},
geometry = [],
), ImpactFuncSet(), Hazard())
icalc.hazard.event_id = np.array([1, 2])
icalc.hazard.frequency = np.array([2, 0.5])
icalc._orig_exp_idx = np.array([0, 1, 2])
Expand Down
3 changes: 2 additions & 1 deletion climada/engine/unsequa/calc_impact.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ def uncertainty(self,

if calc_eai_exp:
exp = self.exp_input_var.evaluate()
coord_df = exp.gdf[['latitude', 'longitude']]
coord_df = pd.DataFrame(dict(
latitude=exp.latitude, longitude=exp.longitude))
else:
coord_df = pd.DataFrame([])

Expand Down
Loading
Loading